From abbd8ce62ba662cd2659589a9996e827d13ad061 Mon Sep 17 00:00:00 2001 From: yuyang Date: Tue, 20 Dec 2016 00:37:59 +0800 Subject: Add flake8 style config and for POSCA JIRA: BOTTLENECK-100 Adding flake8 configuration and fix for POSCA Change-Id: Ib822d5abde535263a4473d67c15cc17995f1417b Signed-off-by: yuyang --- testsuites/posca/testcase_script/common_script.py | 83 ++++++++++++----------- 1 file changed, 42 insertions(+), 41 deletions(-) (limited to 'testsuites/posca/testcase_script/common_script.py') diff --git a/testsuites/posca/testcase_script/common_script.py b/testsuites/posca/testcase_script/common_script.py index 2ca9f68b..a0114644 100644 --- a/testsuites/posca/testcase_script/common_script.py +++ b/testsuites/posca/testcase_script/common_script.py @@ -19,38 +19,38 @@ headers = {"Content-Type": "application/json"} def posca_tran_data(ES_ip, file_name): - p = sub.Popen(['curl', '-s', '-XPOST', "%s/_bulk" % ES_ip, - '--data-binary', "@" + file_name], stdout=sub.PIPE) - for line in iter(p.stdout.readline, b''): - ret_dict = json.loads(line) - if not ret_dict['errors']: - print("INFO: %6s lines no errors, total cost %d ms." - % (len(ret_dict['items']), ret_dict['took'])) - return len(ret_dict['items']) - else: - print("ERROR: %6s lines have errors, total cost %d ms." - % (len(ret_dict['items']), ret_dict['took'])) + p = sub.Popen(['curl', '-s', '-XPOST', "%s/_bulk" % ES_ip, + '--data-binary', "@" + file_name], stdout=sub.PIPE) + for line in iter(p.stdout.readline, b''): + ret_dict = json.loads(line) + if not ret_dict['errors']: + print("INFO: %6s lines no errors, total cost %d ms." + % (len(ret_dict['items']), ret_dict['took'])) + return len(ret_dict['items']) + else: + print("ERROR: %6s lines have errors, total cost %d ms." + % (len(ret_dict['items']), ret_dict['took'])) def posca_config_read(config_str, con_str, config): print("========== posca system bandwidth config read ===========") con_dic = {} - print("Configuration file is %s" %(config_str)) + print("Configuration file is %s" % (config_str)) idx = 0 with open(config_str, "rd") as cfgfile: config.readfp(cfgfile) while idx < len(con_str): con_dic[str(con_str[idx])] = \ - config.get("config", str(con_str[idx])) + config.get("config", str(con_str[idx])) idx += 1 with IPDB() as ip: GATEWAY_IP = ip.routes['default'].gateway if str(con_dic["test_ip"]) is "": - con_dic["test_ip"] = GATEWAY_IP+":8888" - print("test_ip is null get local ip is %s" %(con_dic["test_ip"])) + con_dic["test_ip"] = GATEWAY_IP + ":8888" + print("test_ip is null get local ip is %s" % (con_dic["test_ip"])) if con_dic["ES_ip"] is "": - con_dic["ES_ip"] = GATEWAY_IP+":9200" - print("ES_ip is null get local ip is %s" %(con_dic["ES_ip"])) + con_dic["ES_ip"] = GATEWAY_IP + ":9200" + print("ES_ip is null get local ip is %s" % (con_dic["ES_ip"])) return con_dic @@ -81,44 +81,46 @@ def posca_get_reply(con_dic, task_id, time_test=1): time.sleep(float(con_dic["test_time"])) reply_response = requests.get(reply_url) reply_data = json.loads(reply_response.text) - print("return data is %s" %(reply_data)) + print("return data is %s" % (reply_data)) if reply_data["status"] == 1: return(reply_data["result"][0]) if reply_data["status"] == 0: if time_test == 10: print("yardstick time out") sys.exit() - reply_result_data = posca_get_reply(con_dic, task_id, time_test=time_test+1) + reply_result_data = posca_get_reply( + con_dic, task_id, time_test=time_test + 1) return(reply_result_data) - posca_get_reply(con_dic, task_id, time_test=time_test+1) + posca_get_reply(con_dic, task_id, time_test=time_test + 1) if reply_data["status"] == 2: print("yardstick error exit") sys.exit() def posca_send_data(con_dic, test_config, file_config): - base_url = "http://%s/yardstick/testcases/samples/action" % (con_dic['test_ip']) - print("test ip addr is %s" %(base_url)) + base_url = "http://%s/yardstick/testcases/samples/action" % (con_dic[ + 'test_ip']) + print("test ip addr is %s" % (base_url)) test_dict = { - "action":"runTestCase", - "args":{ - "opts": { - "task-args": { - 'tx_msg_size': '%s' % str(test_config["tx_msg_size"]), - 'rx_msg_size': '%s' % str(test_config["rx_msg_size"]), - 'test_time': '%s' % str(int(con_dic["test_time"]) - 20), - 'host': 'node3.LF', - 'target': 'node4.LF' - } - }, - "testcase":"netperf_bottlenecks" - } + "action": "runTestCase", + "args": { + "opts": { + "task-args": { + 'tx_msg_size': '%s' % str(test_config["tx_msg_size"]), + 'rx_msg_size': '%s' % str(test_config["rx_msg_size"]), + 'test_time': '%s' % str(int(con_dic["test_time"]) - 20), + 'host': 'node3.LF', + 'target': 'node4.LF' + } + }, + "testcase": "netperf_bottlenecks" + } } reponse = requests.post( - base_url, data=json.dumps(test_dict), headers=headers) + base_url, data=json.dumps(test_dict), headers=headers) ask_data = json.loads(reponse.text) task_id = ask_data["result"] - print("yardstick task id is: %s" %(task_id)) + print("yardstick task id is: %s" % (task_id)) data_reply = posca_get_reply(con_dic, task_id) data_reply.update(test_config) posca_output_result(file_config, data_reply) @@ -128,11 +130,10 @@ def posca_send_data(con_dic, test_config, file_config): def posca_create_incluxdb(con_dic): base_url = "http://%s/yardstick/env/action" % (con_dic['test_ip']) test_dict = { - "action":"createInfluxDBContainer", + "action": "createInfluxDBContainer", } - reponse = requests.post( - base_url, data=json.dumps(test_dict), headers=headers) + requests.post( + base_url, data=json.dumps(test_dict), headers=headers) print("waiting for creating InfluxDB") time.sleep(30) print("Done, creating InflxDB Container") - -- cgit 1.2.3-korg