How to use execWithCaptureStatus method in autotest

Best Python code snippet using autotest_python

fence_apc_snmp.py

Source:fence_apc_snmp.py Github

copy

Full Screen

...202 fd = open("/tmp/apclog", "w")203 fd.write("Attempting the following command: %s\n" % cmdstr_off)204 strr = os.system(cmdstr_off)205 time.sleep(1)206 strr, code = execWithCaptureStatus("/usr/bin/snmpget", args_status)207 if verbose:208 fd.write("Result: %s\n" % strr)209 fd.close()210 if strr.find(POWER_OFF) >= 0:211 print "Success. Outlet off"212 sys.exit(0)213 else:214 if verbose:215 fd.write("Unable to power off apc outlet")216 fd.close()217 sys.exit(1)218 elif action == POWER_ON:219 if verbose:220 fd = open("/tmp/apclog", "w")221 fd.write("Attempting the following command: %s\n" % cmdstr_on)222 strr = os.system(cmdstr_on)223 time.sleep(1)224 strr, code = execWithCaptureStatus("/usr/bin/snmpget", args_status)225 #strr = os.system(cmdstr_status)226 if verbose:227 fd.write("Result: %s\n" % strr)228 if strr.find(POWER_ON) >= 0:229 if verbose:230 fd.close()231 print "Success. Outlet On."232 sys.exit(0)233 else:234 print "Unable to power on apc outlet"235 if verbose:236 fd.write("Unable to power on apc outlet")237 fd.close()238 sys.exit(1)239 elif action == POWER_REBOOT:240 if verbose:241 fd = open("/tmp/apclog", "w")242 fd.write("Attempting the following command: %s\n" % cmdstr_off)243 strr = os.system(cmdstr_off)244 time.sleep(1)245 strr, code = execWithCaptureStatus("/usr/bin/snmpget", args_status)246 #strr = os.system(cmdstr_status)247 if verbose:248 fd.write("Result: %s\n" % strr)249 if strr.find(POWER_OFF) < 0:250 print "Unable to power off apc outlet"251 if verbose:252 fd.write("Unable to power off apc outlet")253 fd.close()254 sys.exit(1)255 if verbose:256 fd.write("Attempting the following command: %s\n" % cmdstr_on)257 strr = os.system(cmdstr_on)258 time.sleep(1)259 strr, code = execWithCaptureStatus("/usr/bin/snmpget", args_status)260 #strr = os.system(cmdstr_status)261 if verbose:262 fd.write("Result: %s\n" % strr)263 if strr.find(POWER_ON) >= 0:264 if verbose:265 fd.close()266 print "Success: Outlet Rebooted."267 sys.exit(0)268 else:269 print "Unable to power on apc outlet"270 if verbose:271 fd.write("Unable to power on apc outlet")272 fd.close()273 sys.exit(1)274def execWithCaptureStatus(command, argv, searchPath=0, root='/', stdin=0,275 catchfd=1, closefd=-1):276 if not os.access(root + command, os.X_OK):277 raise RuntimeError(command + " cannot be run")278 (read, write) = os.pipe()279 childpid = os.fork()280 if (not childpid):281 if (root and root != '/'):282 os.chroot(root)283 if isinstance(catchfd, tuple):284 for fd in catchfd:285 os.dup2(write, fd)286 else:287 os.dup2(write, catchfd)288 os.close(write)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful