-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwarm_reboot_stress_mmc0.py
executable file
·62 lines (53 loc) · 1.91 KB
/
warm_reboot_stress_mmc0.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python
import os
import sys
import time
import datetime
import subprocess
import argparse
def main():
fnull = open(os.devnull,"w")
ret = subprocess.call(["which", "sshpass"], stdout=fnull, stderr=subprocess.STDOUT)
if ret == 1:
print "'sshpass' is required."
sys.exit(0)
ret = subprocess.call(["which", "ssh"], stdout=fnull, stderr=subprocess.STDOUT)
if ret == 1:
print "'openssh-client' is required."
sys.exit(0)
fnull.close()
parser = argparse.ArgumentParser(description='perform "HUNG_TASK" test via remote ssh')
parser.add_argument('--remote', dest='remote', type=str, metavar='IP', default='10.5.232.37', help='rermote IP address')
parser.add_argument('--loops', dest='loops', type=int, default=10, help='iterator loops')
parser.add_argument('--sleep', dest='sleep', type=int, default=30, help='sleep seconds per test')
args = parser.parse_args()
print args
prefix = ['sshpass', '-p', 'test0000', 'ssh', '-q',
'-oStrictHostKeyChecking=no', '-oUserKnownHostsFile=/dev/null',
'-oConnectTimeout=10', '-oServerAliveInterval=5' ]
cmd1 = ['lsblk /dev/mmcblk0']
cmd2 = ['reboot']
cmd3 = ['generate_logs']
prefix.append("root@" + args.remote)
for i in range(args.loops):
try:
now = str(datetime.datetime.fromtimestamp(time.time()))
ret = subprocess.call(prefix + cmd1)
print now, ": ", str(i).rjust(3), ": cmd: ", cmd1, ": ret:", ret
now = str(datetime.datetime.fromtimestamp(time.time()))
if ret == 0:
subprocess.call(prefix + cmd2)
elif ret == 32:
subprocess.call(prefix + cmd3)
break
else:
continue
now = str(datetime.datetime.fromtimestamp(time.time()))
print now, ": ", str(i).rjust(3), ": slp: ", args.sleep
time.sleep(args.sleep)
except subprocess.CalledProcessError as err:
now = str(datetime.datetime.fromtimestamp(time.time()))
print now, ": ", str(i).rjust(3), ": error code: ", err.returncode
break;
if __name__ == '__main__':
main()