Sleds/buildvm/scat/bot_stop.py

60 lines
1.4 KiB
Python

#!/bin/python3
'''
Created on Mar 30, 2014
author: tpweis
file name: bot_stop.py
'''
import os
import subprocess
import time
import sys
sys.path.insert(0,'/sl/lib')
from sleds_utilities import *
def main():
"function main"
slsetvars()
argv = sys.argv[1:]
USER = argv[0]
URN = argv[1]
print("Enter bot_stop: " +USER+ " " +URN)
VERBOSE=""
BOTLAUNCH="com.sequencelogic.robot.Launcher"
ACTION="--action=stop"
VANID="--van-id=000000"
BOTNAME="--target=" + USER
SLURN="--urn=" + URN
BOTSSTOPPER= "sl_bots.sh"
cmd = slscatget() + "sl_bots.sh"
cmdstr = cmd+ " " +BOTLAUNCH+ " " +VERBOSE+ " " +ACTION+ " " +VANID+ " " +BOTNAME+ " " +SLURN
slscatlog('D', "bots_stop: " + cmdstr)
subprocess.call([cmdstr], shell=True)
# the stop might take a while. Try for up to N seconds, then fail.
rc = "FAIL to stop bot " + USER
botstring = "--user=" + USER
for n in range(5):
time.sleep(1)
p2 = subprocess.Popen(["ps", "-U", "sequencelogic", "a"], stdout=subprocess.PIPE)
data=p2.communicate()[0]
data=data.decode()
data=data.rstrip()
if botstring not in data:
# The process is not running.
rc = "SUCCESS stopped " + USER
break
print(rc)
exit()
if __name__ == '__main__':
# execute only if run as a script
main()