This repository has been archived by the owner on Feb 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
runTest.py
166 lines (140 loc) · 4.64 KB
/
runTest.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import requests
import argparse
import json
import time
import threading
import sys
def getConfig(config):
f = open(config, "r")
return json.loads(f.read(), strict=False)
def appendPR(buildRequest, pullRepo, pullId):
if (pullRepo != False):
buildRequest.update( { "pullRepo": pullRepo } )
buildRequest.update( { "pullId": pullId } )
return buildRequest
def appendOutputRepo(buildRequest, pullRepo, pullId):
if (pullRepo != False):
buildRequest.update( { "pullRepo": pullRepo } )
buildRequest.update( { "pullId": pullId } )
return buildRequest
def triggerBuild(buildRequests, code):
url = "https://blimpfunc.azurewebsites.net/api/HttpBuildPipeline_HttpStart"
querystring = {"code": code}
payload = json.dumps(buildRequests)
headers = {
'Content-Type': "application/json",
'cache-control': "no-cache"
}
response = requests.request("POST", url, data=payload, headers=headers, params=querystring)
print(response.content.decode('utf-8'))
return json.loads(response.content.decode('utf-8'), strict=False)
def getStatusQueryGetUri(jsonResponse):
return jsonResponse["statusQueryGetUri"]
def pollPipeline(statusQueryGetUri):
url = statusQueryGetUri
headers = {
'cache-control': "no-cache"
}
response = requests.request("GET", url, headers=headers)
print(response.content.decode('utf-8'))
return json.loads(response.content.decode('utf-8'), strict=False)
def buildImage(br, code, results, outputMessage):
tries = 0
success = False
webAppName = ""
while tries < 1:
try:
tries = tries + 1
print("building")
print(br)
statusQueryGetUri = getStatusQueryGetUri(triggerBuild(br, code))
print(statusQueryGetUri)
while True:
time.sleep(60)
content = pollPipeline(statusQueryGetUri)
runtimeStatus = content["runtimeStatus"]
if runtimeStatus == "Completed":
print("build completed")
print(content["output"].replace("\\", "/"))
output = json.loads(content["output"].replace("\\", "/"), strict=False)
webAppName = output["input"]["webAppName"].replace("\\", "/")
print("webAppName: "+ webAppName)
status = output["status"]
if (status == "success"):
print("pass")
success = True
break
else:
print("failed")
break
elif runtimeStatus == "Running":
print("running")
continue
else:
print("failed")
break
if success:
break
else:
print("trying again")
print(br)
continue
except:
print(sys.exc_info())
if success:
results.append(True)
outputMessage.append(
"Build request Succeed on following input: \n" + json.dumps(br) + "\n" +
"webAppName: " + webAppName)
sys.exit(0)
else:
results.append(False)
outputMessage.append(
"Build request Failed on following input: \n" + json.dumps(br) + "\n" +
"failure message: \n" + content["output"].replace("\\", "/"))
sys.exit(1)
parser = argparse.ArgumentParser()
parser.add_argument('--config', help='config file')
parser.add_argument('--code', help='code')
parser.add_argument('--pullId', help='pullId')
parser.add_argument('--pullRepo', help='pullRepo')
args = parser.parse_args()
config = args.config
code = args.code
pullRepo = args.pullRepo
pullId = args.pullId
print("config")
print(config)
print("pullRepo")
print(pullRepo)
print("pullId")
print(pullId)
threads = []
results = []
outputMessage = []
buildRequests = getConfig(config)
for br in buildRequests:
br = appendPR(br, pullRepo, pullId)
print(br)
t = threading.Thread(target=buildImage, args=((br, code, results, outputMessage)))
threads.append(t)
t.start()
time.sleep(60)
# Wait for all of them to finish
for t in threads:
t.join()
print("------------------------------------------------------------------------")
withfailures = False
for r in results:
if r == False:
withfailures = True
if (withfailures):
print("Runs completed with Failures")
else:
print("Runs completed with no Failures")
for msg in outputMessage:
print(msg)
if (withfailures):
sys.exit(1)
else:
sys.exit(0)