[QUESTION] 自定义脚本-如何调用Mac电脑(作为Agent)的python
Opened this issue · 4 comments
Ghomeling commented
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
- 自定义python脚本如下:
if name == 'main':
print("success") - 执行自定义脚本报错,本地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!
ZhouYixun commented
你直接终端使用 python xxx.py可以?
Ghomeling commented
ZhouYixun commented
Cannot run program "python": error=2, No such file or directory
可是这句很明显是有问题,检查下python而不是python3之类的,环境变量等等。mac是没问题的,但是环境变量上面要下点功夫
Ghomeling commented