Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] 自定义脚本-如何调用Mac电脑(作为Agent)的python #418

Open
2 tasks done
Ghomeling opened this issue Mar 11, 2024 · 4 comments
Open
2 tasks done
Labels
question Further information is requested

Comments

@Ghomeling
Copy link

Search before asking

  • I searched in the issue and found nothing similar. | 我查找了并确认issue列表无相似报告。

Sonic version

server和agent均为V2.6.4

Deploy platform

Macosx

Minimal reproduce step

  1. 自定义python脚本如下:
    if name == 'main':
    print("success")
  2. 执行自定义脚本报错,本地mac电脑直接执行python没问题:
    INFO 13553 --- [ios-run-step-task-0-13-00008030-00161C1C2620C02E] org.cloud.sonic.agent.tests.LogUtil : {"msg":"step","des":"","log":"异常信息: java.lang.RuntimeException: Run script failed","rid":0,"udId":"00008030-00161C1C2620C02E","status":3,"cid":0}
    java.lang.RuntimeException: Run script failed
    at org.cloud.sonic.agent.tests.handlers.IOSStepHandler.exceptionLog(IOSStepHandler.java:976)
    at org.cloud.sonic.agent.tests.handlers.IOSStepHandler.switchType(IOSStepHandler.java:1977)
    at org.cloud.sonic.agent.tests.handlers.IOSStepHandler.runStep(IOSStepHandler.java:1945)
    at org.cloud.sonic.agent.tests.handlers.NoneConditionHandler.runStep(NoneConditionHandler.java:56)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:578)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
    at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:102)
    at org.cloud.sonic.agent.aspect.IteratorAspect.around(IteratorAspect.java:41)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:578)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:637)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:627)
    at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:71)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:173)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:702)
    at org.cloud.sonic.agent.tests.handlers.NoneConditionHandler$$SpringCGLIB$$0.runStep()
    at org.cloud.sonic.agent.tests.handlers.StepHandlers.runStep(StepHandlers.java:58)
    at org.cloud.sonic.agent.tests.ios.IOSRunStepThread.run(IOSRunStepThread.java:65)
    at org.cloud.sonic.agent.transport.TransportClient$2.run(TransportClient.java:409)
    Caused by: java.io.IOException: Cannot run program "python": error=2, No such file or directory
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1140)
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1074)
    at java.base/java.lang.Runtime.exec(Runtime.java:647)
    at java.base/java.lang.Runtime.exec(Runtime.java:504)
    at org.cloud.sonic.agent.tests.script.PythonScriptImpl.execIsFailed(PythonScriptImpl.java:73)
    at org.cloud.sonic.agent.tests.script.PythonScriptImpl.runIOS(PythonScriptImpl.java:47)
    at org.cloud.sonic.agent.tests.handlers.IOSStepHandler.runScript(IOSStepHandler.java:1622)
    at org.cloud.sonic.agent.tests.handlers.IOSStepHandler.runStep(IOSStepHandler.java:1877)
    ... 24 more
    Caused by: java.io.IOException: error=2, No such file or directory
    at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
    at java.base/java.lang.ProcessImpl.(ProcessImpl.java:319)
    at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:249)
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1111)
    ... 31 more

Are you willing to submit a PR?

  • I'm willing to submit a PR! | 我将发起PR!
@Ghomeling Ghomeling added the bug Something isn't working label Mar 11, 2024
@ZhouYixun
Copy link
Member

你直接终端使用 python xxx.py可以?

@Ghomeling
Copy link
Author

Ghomeling commented Mar 12, 2024 via email

@ZhouYixun
Copy link
Member

Cannot run program "python": error=2, No such file or directory

可是这句很明显是有问题,检查下python而不是python3之类的,环境变量等等。mac是没问题的,但是环境变量上面要下点功夫

@ZhouYixun ZhouYixun changed the title [Bug] 自定义脚本-无法调用Mac电脑(作为Agent)的python [QUESTION] 自定义脚本-如何调用Mac电脑(作为Agent)的python Mar 12, 2024
@ZhouYixun ZhouYixun added question Further information is requested and removed bug Something isn't working labels Mar 12, 2024
@Ghomeling
Copy link
Author

Ghomeling commented Mar 12, 2024

嗯,我是用的python3,且配置了软链接,可以直接用python执行。如果用你们的ide都是可以执行的呢
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants