-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner.py
75 lines (58 loc) · 2.3 KB
/
runner.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
63
64
65
66
67
68
69
70
71
72
73
74
75
import argparse
import time
import subprocess
import sys
import shlex
WAIT_SEC = 10
parser = argparse.ArgumentParser()
parser.add_argument('--prefix', required=True)
args = parser.parse_args()
rgname = args.prefix + "rg"
depname = args.prefix + "dep"
params = '{"uniqueNamePrefix":{"value":"' + args.prefix + '"},"instanceCount":{"value":"20"},"adminUsername":{"value":"ubuntu"},"adminPassword":{"value":"P4$$w0rd"}}'
deployCommand = ['azure', 'group', 'create', rgname, 'West US', '-d', depname, '-f', 'wait.json', '-p', params]
checkCommand = ['azure', 'group', 'deployment', 'show', rgname, depname]
logCommand = ['azure', 'group', 'log', 'show', rgname, '--all']
destroyCommand = ['azure', 'group', 'delete', '-q', rgname]
numFailures = 0
while True:
start = time.time()
res = subprocess.check_output(deployCommand).strip()
provisioningResult = ""
end = None
while end == None:
time.sleep(WAIT_SEC)
try:
res = subprocess.check_output(checkCommand).strip()
except Exception as e:
continue
for line in res.split('\n'):
if "ProvisioningState" in line:
if "Succeeded" in line:
provisioningResult = "Successful"
end = time.time()
elif "Failed" in line:
provisioningResult = "Failed"
end = time.time()
logOutput = subprocess.check_output(logCommand, stderr=subprocess.STDOUT).strip()
with open(args.prefix + 'FailureLog' + str(numFailures), 'w') as logfile:
logfile.write(logOutput)
numFailures += 1
delta = end - start
print(provisioningResult + ": " + str(delta))
sys.stdout.flush()
deleted = False
while True:
try:
time.sleep(WAIT_SEC)
res = subprocess.check_output(destroyCommand, stderr=subprocess.STDOUT).strip()
break
except Exception as e:
continue
while not deleted:
time.sleep(WAIT_SEC)
try:
res = subprocess.check_output(checkCommand, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
if "could not be found" in str(e.output):
deleted = True