-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunning_and_editting_a_legacy_config.py
123 lines (102 loc) · 3.31 KB
/
running_and_editting_a_legacy_config.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
import requests
import json
import urllib3
import time
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
base_url = "https://10.36.78.213/ixsuitestore"
apikey = "54278a98db384bd0a46911c9d19e5fc1"
session_id = "1"
headers = {
'content-type': 'application/json; charset=us-ascii',
'X-Api-Key': apikey
}
def wait_for_operation(response):
while True:
state = response.json()["state"]
if state == "IN_PROGRESS":
operation_url = response.json()["url"]
url = base_url + operation_url
time.sleep(0.5)
response = requests.request('GET', url, headers=headers,verify=False)
elif response.json()["state"] == "SUCCESS":
break
else:
print("Operation returned state {c} code and \r\n{b}".format(c=state, b=response.json()))
exit()
return
# Running passed-in [legacy shown here] config
config = {
"runList": [ "samples/testsuite/sleeptest"],
"parameterSets": [{
"path": "samples",
"parameters" : [
{
"name" :"seconds",
"value" : 10
}
]
}]
}
url = base_url + '/api/v1/sessions/' + session_id + '/suitestore/config/operations/start'
print("Starting run")
response = requests.request('POST', url, headers=headers, data=json.dumps(config), verify=False)
# Wait for the start operation to return SUCCESS
wait_for_operation(response)
print("Run started")
# Wait for the run to finish
result_url = response.json()['result']
url = base_url + result_url
while True:
response = requests.request('GET', url, headers=headers, verify=False)
result = response.json()['runState']
if result == 'done':
break
time.sleep(0.5)
print("Run finished")
# Getting entire configuration hierarchy using Select API
url = base_url + '/api/v1/sessions/' + session_id + '/suitestore/operations/select'
body = {
"selects": [
{
"from": "/sessions/" + session_id + "/suitestore/config",
"properties": ["*"],
"children": [
{
"child": ".*",
"properties": ["*"],
"filters": []
}
],
"inlines": []
}
]
}
response = requests.request('POST', url, headers=headers, data=json.dumps(body),verify=False)
# Wait for the select operation to return SUCCESS
wait_for_operation(response)
parameter_url = response.json()['result'][0]['parameterSets'][0]['parameters'][0]['href']
url = base_url + parameter_url
body = {
"name" :"seconds",
"value" : 5
}
print("Changing parameter value")
response = requests.request('PATCH', url, headers=headers, data=json.dumps(body),
verify=False)
# Running existing config
url = base_url + '/api/v1/sessions/' + session_id + '/suitestore/config/operations/start'
print("Starting run")
response = requests.request('POST', url, headers=headers, verify=False)
# Wait for the start operation to return SUCCESS
wait_for_operation(response)
print("Run started")
# Wait for the run to finish
result_url = response.json()['result']
url = base_url + result_url
while True:
response = requests.request('GET', url, headers=headers, verify=False)
result = response.json()['runState']
if result == 'done':
break
time.sleep(0.5)
print("Run finished")