-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperftemp.py
More file actions
205 lines (177 loc) · 6.92 KB
/
perftemp.py
File metadata and controls
205 lines (177 loc) · 6.92 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
__author__ = "Matteo De Marie"
__email__ = "de.marie.matteo@gmail.com"
from testagent.probe import Probe
import paramiko
from datetime import datetime
import time
class perftemp(Probe):
#------------Exec tests and parse logs----------------------------
def core(self,inputs):
def test_scenario(client, scen_name):
#Check number of next test
cmin, cmout, cmerr = client.exec_command("cat /opt/stack/tempest/.testrepository/next-stream")
num = cmout.read()
#Start test
cmin, cmout, cmerr = client.exec_command("/opt/stack/tempest/run_tempest.sh -t tempest." + scen_name)
#Wait for result
while not cmout.channel.exit_status_ready():
pass
#Check results based on test number
cmin, cmout, cmerr = client.exec_command("cat /opt/stack/tempest/.testrepository/"+num)
results = [] #list of test with detail
elem = {} #detail of test
start = False #timestamp test started found
test = False #name test found
result = False #result's test found
for line in cmout.readlines():
#Checked al details about one test
if start and test and result:
results.append(elem)
print "--------------------"
elem = {}
start = False
test = False
result = False
#First 'time' time before start test
elif line.startswith("time") and start==False:
elem['start'] = datetime.strptime(line[6:-2],"%Y-%m-%d %H:%M:%S.%f")
print "start: " + (datetime.strptime(line[6:-2],"%Y-%m-%d %H:%M:%S.%f")).ctime()
start = True
#Second 'time' time after test is done
elif line.startswith("time") and start==True:
elem['end'] = datetime.strptime(line[6:-2],"%Y-%m-%d %H:%M:%S.%f")
print "end: " + (datetime.strptime(line[6:-2],"%Y-%m-%d %H:%M:%S.%f")).ctime()
#Result of test SUCCESS
elif line.startswith("successful:"):
elem['result'] = "success"
result = True
#Result of test SKIPPED
elif line.startswith("skip:"):
elem['result'] = "skipped"
result = True
#Result of test FAILED
elif line.startswith("failure:"):
elem['result'] = "failed"
result = True
#Name of test
elif line.startswith("test:"):
elem['test'] = line[6:].split("[")[0]
print "nome: " + line[6:].split("[")[0]
test = True
return results
#----Type of times regroup-------------------------------------
#Type 'sum': Sum times all tests
#Type 'par': Sum times all subtests
#Type 'det': Show times all subtests
def calc_time(data, tipo="par"):
total = []
if tipo == "sum":
temp = None
for test in data:
for sub in test:
if sub.get("result") == "skipped":
skip_all = []
skip_all.append("skipped")
return skip_all
elif sub.get("result") == "failed":
all_failed = []
all_failed.append("failed")
return all_failed
else:
if temp is None:
temp = (sub.get("end")-sub.get("start"))
else:
temp = temp + (sub.get("end")-sub.get("start"))
total.append(temp)
elif tipo == "par":
temp = None
for test in data:
for sub in test:
if sub.get("result") == "skipped":
temp = "skipped"
break
elif sub.get("result") == "failed":
temp = "failed"
break
else:
if temp is None:
temp = (sub.get("end")-sub.get("start"))
else:
temp = temp + (sub.get("end")-sub.get("start"))
total.append(temp)
temp = None
elif tipo == "det":
for test in data:
for sub in test:
if sub.get("result") == "skipped":
total.append("skipped")
break
elif sub.get("result") == "failed":
total.append("failed")
break
else:
total.append(sub.get("end")-sub.get("start"))
else:
return False
return total
#-----Compare results with goal--------------------------------
def compare_result(tested, goal):
results = []
for i in range(0,len(goal)):
if tested[i] == "failed":
#results.append("Failed")
results.append(False)
continue
elif tested[i] == "skipped":
#results.append("False*")
results.append(False)
continue
elif tested[i].total_seconds() <= goal.get(str(i+1)):
results.append(True)
else:
results.append(False)
return results
#-----Configure tempest.conf----------------------------------------
def configure(client, param):
total = ""
for key, value in param.iteritems():
if key != "Tempest" or key != "Aspected" or key != "Tests":
if type(value) == type({}):
total += "\n[" + key + "]\n"
for key2, value2 in value.iteritems():
if value2 != "":
total += key2 + " = " + unicode(value2) + "\n"
stdin, stdout, stderr = client.exec_command("echo '%s' > /opt/stack/tempest/etc/tempest.conf" %total)
#-------------MAIN--------------------------------------------
xml = self.testinstances
if len(xml["Tests"]) != len(xml["Aspected"]):
return "Quantita di valori attesi diversa dal numero di test"
try:
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(xml["Tempest"]["host"], username=xml["Tempest"]["user"], password=xml["Tempest"]["psw"])
except:
print "Impossibile connettersi al server Tempest"
if client:
client.close()
return "Impossibile connettersi al server Tempest"
results = []
print "Start configuration"
configure(client,xml)
print "Finish configuration"
print "Start testing"
for i in range(1,len(xml["Tests"])+1):
results.append(test_scenario(client,xml["Tests"][str(i)]))
print "Finish testing"
client.close()
print "Regroup results"
times = calc_time(results)
print "Regroupped"
print "Comparing results"
return compare_result(times,xml["Aspected"])
def corer (self, inputs):
return
def appendAtomics(self):
self.appendAtomic(self.core, self.corer)
probe = perftemp