Skip to content

Commit 0f5d02c

Browse files
authored
Merge pull request #5 from qiaoqihu2016/openconn_and_amt
1. for open conn with load type simusers 2. support http/https amt tests 3. fix issue CF-16694 [NSO] results are shown in microseconds, should be milliseconds
2 parents 7908d5e + 7a191f4 commit 0f5d02c

File tree

8 files changed

+582
-63
lines changed

8 files changed

+582
-63
lines changed

cf_common/CfClient.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,32 @@ def fetch_test_template(self, test_type, outfile):
104104
self.requests_error_handler("other", err, None)
105105

106106
dict_response = response.json()
107+
if test_type == "advanced_mixed_traffic":
108+
dict_response["config"]["trafficMix"]["mixer"] = self.fetch_amt_predefinedprotocols()
107109
self.append_log_response('get', response.status_code, url, dict_response)
108110
with open(outfile, "w") as f:
109111
json.dump(dict_response, f, indent=4)
110112
return dict_response
111113

114+
def fetch_amt_predefinedprotocols(self):
115+
self.exception_state = True
116+
url = self.api + "/tests/advanced_mixed_traffic/predefined_protocols"
117+
try:
118+
response = self.__session.get(url)
119+
response.raise_for_status()
120+
except requests.exceptions.HTTPError as errh:
121+
self.requests_error_handler("http", errh, response)
122+
except requests.exceptions.ConnectionError as errc:
123+
self.requests_error_handler("connection", errc, None)
124+
except requests.exceptions.Timeout as errt:
125+
self.requests_error_handler("timeout", errt, None)
126+
except requests.exceptions.RequestException as err:
127+
self.requests_error_handler("other", err, None)
128+
129+
dict_response = response.json()
130+
self.append_log_response('get', response.status_code, url, dict_response)
131+
return dict_response
132+
112133
def post_test(self, test_type, infile):
113134
self.exception_state = True
114135
with open(infile, "r") as f:
@@ -261,6 +282,24 @@ def fetch_test_run_statistics(self, test_run_id):
261282
self.append_log_response('get', response.status_code, url, dict_response)
262283
return dict_response
263284

285+
def fetch_event_logs(self, test_run_id):
286+
self.exception_state = True
287+
url = self.api + "/test_runs/" + test_run_id + "/eventlogs"
288+
try:
289+
response = self.__session.get(url)
290+
except requests.exceptions.HTTPError as errh:
291+
self.requests_error_handler("http", errh, response)
292+
except requests.exceptions.ConnectionError as errc:
293+
self.requests_error_handler("connection", errc, None)
294+
except requests.exceptions.Timeout as errt:
295+
self.requests_error_handler("timeout", errt, None)
296+
except requests.exceptions.RequestException as err:
297+
self.requests_error_handler("other", err, None)
298+
self.exception_continue_check()
299+
dict_response = response.json()
300+
self.append_log_response('get', response.status_code, url, dict_response)
301+
return dict_response
302+
264303
def stop_test(self, test_run_id):
265304
self.exception_state = True
266305
url = self.api + "/test_runs/" + test_run_id + "/stop"

cf_common/CfCreateTest.py

Lines changed: 172 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,23 @@ def __init__(self, base, test_info, test_template, cf_ver):
5757
self.post_size = self.chk_none(test_info["post_size"])
5858
self.name_suffix = test_info["name_suffix"]
5959
self.name = self.name + "_" + self.name_suffix
60+
self.test_template_config = test_template["config"]
6061

6162
self.existing_certificate = self.protocol["supplemental"]["sslTls"][
6263
"certificate"
6364
]
64-
self.protocol = test_template["config"]["protocol"]
65+
if "protocol" in self.test_template_config:
66+
self.protocol = test_template["config"]["protocol"]
6567
self.existing_load_constraints = self.loadSpecification["constraints"]
6668
self.loadSpecification = test_template["config"]["loadSpecification"]
67-
self.test_template_runtimeOptions= test_template["config"]["runtimeOptions"]
69+
if self.type not in ["advanced_mixed_traffic"]:
70+
self.test_template_runtimeOptions = test_template["config"]["runtimeOptions"]
71+
else:
72+
self.test_template_runtimeOptions = test_template["config"]["runTimeOptions"]
73+
self.amt_predefinedprotocols = test_template["config"]["trafficMix"]["mixer"]
74+
self.get_amt_keyinfo()
75+
self.update_amt_mixer()
76+
self.mixer_config = self.mixer[0].get("config",{})
6877

6978
self.cf_version = int("".join(i for i in cf_ver if i.isdigit()))
7079
self.cf_version = str(self.cf_version)
@@ -76,25 +85,146 @@ def complete_test(self):
7685
comp_test = {}
7786
comp_test["name"] = self.name
7887
comp_test["projectId"] = self.projectId
79-
comp_test["config"] = {}
80-
comp_test["config"]["queue"] = self.queue
81-
comp_test["config"]["debug"] = self.debug
82-
comp_test["config"]["subnets"] = self.subnets
83-
comp_test["config"]["criteria"] = self.criteria
84-
comp_test["config"]["networks"] = self.networks
85-
comp_test["config"]["interfaces"] = self.interfaces
86-
comp_test["config"]["protocol"] = self.protocol
87-
comp_test["config"]["virtualRouters"] = self.virtualRouters
88-
comp_test["config"]["trafficPattern"] = self.trafficPattern
89-
comp_test["config"]["testType"] = self.testType
90-
comp_test["config"]["loadSpecification"] = self.loadSpecification
91-
comp_test["config"]["runtimeOptions"] = self.test_template_runtimeOptions
88+
if self.type in ["advanced_mixed_traffic"]:
89+
comp_test["config"] = self.test_template_config
90+
comp_test["config"]["queue"] = self.queue
91+
comp_test["config"]["subnets"] = self.subnets
92+
comp_test["config"]["networks"] = self.networks
93+
comp_test["config"]["relationships"] = self.relationships
94+
comp_test["config"]["virtualRouters"] = self.virtualRouters
95+
comp_test["config"]["virtualRoutersToPorts"] = self.virtualRoutersToPorts
96+
comp_test["config"]["trafficMix"]["mixer"] = self.mixer
97+
comp_test["config"]["trafficMix"]["mixer"][0]["config"] = self.mixer_config
98+
comp_test["config"]["loadSpecification"] = self.loadSpecification
99+
comp_test["config"]["runtimeOptions"] = self.test_template_runtimeOptions
100+
else:
101+
comp_test["config"] = {}
102+
comp_test["config"]["queue"] = self.queue
103+
comp_test["config"]["debug"] = self.debug
104+
comp_test["config"]["subnets"] = self.subnets
105+
comp_test["config"]["criteria"] = self.criteria
106+
comp_test["config"]["networks"] = self.networks
107+
comp_test["config"]["interfaces"] = self.interfaces
108+
comp_test["config"]["protocol"] = self.protocol
109+
comp_test["config"]["virtualRouters"] = self.virtualRouters
110+
comp_test["config"]["trafficPattern"] = self.trafficPattern
111+
comp_test["config"]["testType"] = self.testType
112+
comp_test["config"]["loadSpecification"] = self.loadSpecification
113+
comp_test["config"]["runtimeOptions"] = self.test_template_runtimeOptions
92114
return comp_test
93115

94116
def save_test(self, outfile):
95117
with open(outfile, "w") as f:
96118
json.dump(self.complete_test(), f, indent=4)
97119

120+
def get_amt_keyinfo(self):
121+
testname = self.name.lower()
122+
self.amt_protocol = []
123+
self.amt_keyinfo = []
124+
if self.connection_type.lower() == "separate" and self.keep_alive.lower() == "false":
125+
test_type = "CPS"
126+
elif self.http_method.lower() == "post" and self.keep_alive.lower() == "true":
127+
test_type = "POST"
128+
elif self.connection_type.lower() == "keepalive" and self.keep_alive.lower() == "true":
129+
test_type = "TPUT"
130+
else:
131+
test_type = "TPUT"
132+
if self.tls.lower() == "true":
133+
self.amt_protocol.append("HTTPS")
134+
self.amt_keyinfo.append({"HTTPS": test_type})
135+
else:
136+
self.amt_protocol.append("HTTP")
137+
self.amt_keyinfo.append({"HTTP": test_type})
138+
139+
def get_amt_actions(self, keyinfo):
140+
action = []
141+
action_http = "1 GET http://<AUTO_ASSIGN_HOST>:80"
142+
action_https = "1 GET https://<AUTO_ASSIGN_HOST>:443"
143+
action_http_post = f"1 POST http://<AUTO_ASSIGN_HOST>:80/<POST_BODY: URLENC KEY=spirent, \
144+
LENGTH={self.post_size}, FIXED>"
145+
action_https_post = f"1 POST https://<AUTO_ASSIGN_HOST>:443/<POST_BODY: URLENC KEY=spirent, \
146+
LENGTH={self.post_size}, FIXED>"
147+
actions = {"HTTP": {"TPUT": ["LOOP NewLoop START COUNT=10", action_http, "LOOP NewLoop STOP"],
148+
"POST": ["LOOP NewLoop START COUNT=10", action_http_post, "LOOP NewLoop STOP"],
149+
"CPS": [action_http, action_http, action_http, action_http]
150+
},
151+
"HTTPS": {"TPUT": ["LOOP NewLoop START COUNT=10", action_https, "LOOP NewLoop STOP"],
152+
"POST": ["LOOP NewLoop START COUNT=10", action_https_post, "LOOP NewLoop STOP"],
153+
"CPS": [action_https, action_https, action_https, action_https]
154+
},
155+
"HTTP2": {"TPUT": ["LOOP NewLoop START COUNT=10", action_http, "LOOP NewLoop STOP"],
156+
"CPS": [action_http, action_http, action_http, action_http]
157+
},
158+
"FTP": []
159+
}
160+
if type(keyinfo) == dict:
161+
for key, value in keyinfo.items():
162+
if key in ["HTTP", "HTTPS", "HTTP2"]:
163+
action = actions[key][value]
164+
else:
165+
action = actions[keyinfo]
166+
return action
167+
168+
def update_amt_mixer(self):
169+
self.mixer = []
170+
try:
171+
for i in range(0, len(self.amt_protocol)):
172+
predefinedprotocols = self.amt_protocol[i]
173+
if self.amt_protocol[i] == "HTTPS":
174+
predefinedprotocols = "HTTP"
175+
for j in range(0, len(self.amt_predefinedprotocols)):
176+
if predefinedprotocols == self.amt_predefinedprotocols[j].get("name", ""):
177+
template = self.amt_predefinedprotocols[j]
178+
action = self.get_amt_actions(self.amt_keyinfo[i])
179+
template["config"]["client"]["actionList"]["actions"] = action
180+
if self.amt_protocol[i] == "HTTPS":
181+
template["name"] = self.amt_protocol[i]
182+
template["config"]["client"]["actionList"]["name"] = self.amt_protocol[i]
183+
template["config"]["server"]["port"] = 443
184+
self.mixer.append(template)
185+
break
186+
length = len(self.mixer)
187+
percentage = round(100 / length, 1)
188+
for i in range(0, length):
189+
self.mixer[i]["percentage"] = percentage
190+
except Exception as e:
191+
print(f"\nUnable to set mixer\n{e}")
192+
193+
def configure_amt_relationships(self):
194+
self.relationships = []
195+
length = len(self.interfaces["client"])
196+
if length == 0:
197+
return
198+
try:
199+
for i in range(0, length):
200+
length_subnets = len(self.interfaces["client"][i]["subnetIds"])
201+
for j in range(0, length_subnets):
202+
for protocol in self.amt_protocol:
203+
relationship = {"server": {}, "protocols": "", "client": {}}
204+
relationship["protocols"] = [protocol]
205+
for side in ["server", "client"]:
206+
relationship[side]["subnetId"] = self.interfaces[side][i]["subnetIds"][j]
207+
relationship[side]["portSystemId"] = self.interfaces[side][i]["portSystemId"]
208+
self.relationships.append(relationship)
209+
except Exception as e:
210+
print(f"\nUnable to set relationships\n{e}")
211+
212+
def configure_amt_virtualrouterstoports(self):
213+
if not self.virtualRouters:
214+
self.virtualRoutersToPorts = {}
215+
return
216+
self.virtualRoutersToPorts = {"client": [], "server": []}
217+
length = len(self.interfaces["client"])
218+
try:
219+
for i in range(0, length):
220+
for side in ["client", "server"]:
221+
vr_to_port = {}
222+
vr_to_port["portSystemId"] = self.relationships[i][side]["portSystemId"]
223+
vr_to_port["virtualRouterId"] = self.virtualRouters[side][i]["id"]
224+
self.virtualRoutersToPorts[side].append(vr_to_port)
225+
except Exception as e:
226+
print(f"\nUnable to set virtualrouterstoports\n{e}")
227+
98228
def update_runtimeOptions(self):
99229
try:
100230
keys = self.runtimeOptions.keys()
@@ -178,6 +308,11 @@ def update_transactions(
178308
self.protocol["keepAlive"]["delayTimeUnit"] = delay_time_unit
179309
except Exception as e:
180310
print(f"\nUnable to set per request delay_time and unit \n{e}")
311+
if self.type == "open_connections" and self.protocol["keepAlive"]["enabled"] == True:
312+
try:
313+
self.protocol["keepAlive"]["delayType"] = "perTransaction"
314+
except Exception as e:
315+
print(f"\nUnable to set per request delay_type \n{e}")
181316

182317
def update_http_method(self, http_method, post_size):
183318
if http_method.lower() == "post":
@@ -410,14 +545,18 @@ def chk_none(value):
410545
return value
411546

412547
def update_config_changes(self):
548+
if self.type == "advanced_mixed_traffic":
549+
self.configure_amt_relationships()
550+
self.configure_amt_virtualrouterstoports()
551+
self.protocol = self.mixer_config["client"]
552+
if self.type != "advanced_mixed_traffic":
553+
self.update_runtimeOptions()
554+
self.update_close_with_fin()
413555
self.update_network_settings()
414556
self.update_criteria_settings()
415557
# self.update_load_constraints()
416-
self.update_close_with_fin()
417-
if 19300000 < self.cf_version:
558+
if 19300000 < self.cf_version and self.type != "advanced_mixed_traffic":
418559
self.update_http_method(self.http_method, self.post_size)
419-
if self.object_size is not None:
420-
self.update_object_size(self.object_type, self.object_size)
421560
if self.keep_alive is not None:
422561
self.update_transactions(
423562
self.connection_type,
@@ -426,6 +565,15 @@ def update_config_changes(self):
426565
self.delay_time,
427566
self.delay_time_unit,
428567
)
568+
if self.type == "advanced_mixed_traffic":
569+
self.mixer_config["client"] = self.protocol
570+
self.protocol = self.mixer_config["server"]
571+
self.update_close_with_fin()
572+
if self.object_size is not None:
573+
self.update_object_size(self.object_type, self.object_size)
574+
if self.type == "advanced_mixed_traffic":
575+
self.mixer_config["server"] = self.protocol
576+
self.protocol = self.mixer_config
429577
if self.tls is not None:
430578
self.update_tls(
431579
self.tls,
@@ -437,7 +585,8 @@ def update_config_changes(self):
437585
self.tls_record,
438586
self.payload_encryption_offload,
439587
)
440-
588+
if self.type == "advanced_mixed_traffic":
589+
self.mixer_config = self.protocol
441590

442591
class TestsToRun:
443592
def __init__(self, reference_to_run_csv_file, test_to_run_csv_file):
@@ -453,8 +602,10 @@ def __init__(self, reference_to_run_csv_file, test_to_run_csv_file):
453602

454603
def add_test(self, new_test_dict, test_type):
455604
test_ref_match = False
605+
new_test_name = new_test_dict["name"].rsplit("_", 1)[0]
456606
for test in self.reference_tests:
457-
if new_test_dict["name"].startswith(test["name"]):
607+
#if new_test_dict["name"].startswith(test["name"]):
608+
if new_test_name == test["name"]:
458609
test_csv_info = self.test_csv_line_values(
459610
test, new_test_dict, test_type
460611
)

0 commit comments

Comments
 (0)