diff options
| author | dongxiaoyan <[email protected]> | 2024-11-06 19:46:55 +0800 |
|---|---|---|
| committer | dongxiaoyan <[email protected]> | 2024-11-06 19:46:55 +0800 |
| commit | f8b2dd4759d60604e16ead53616bca7023680644 (patch) | |
| tree | 615e079040ce2578ca2f6b9e17c271068a43ee3f | |
| parent | 8d34b2695bc33d70ee9982fe6c81f8dc27661c3e (diff) | |
1、新增Device用例
12 files changed, 2575 insertions, 1 deletions
diff --git a/support/api_utils/organize_config.py b/support/api_utils/organize_config.py index 234baa0d7..063c14af6 100644 --- a/support/api_utils/organize_config.py +++ b/support/api_utils/organize_config.py @@ -175,7 +175,7 @@ class OrganizeConfig: if "trex" == config["traffic"]["type"]: traffic_radom_ip_flag = True sub_id_flag = False - if "sub_id" in config["rule_name"]: + if "sub_id" in config["rule_name"] or "_imsi_" in config["rule_name"] or "_imei_" in config["rule_name"] or "_phone_number_" in config["rule_name"] or "_apn_" in config["rule_name"]: sub_id_flag = True for obj in config["condition"]: if "source_ip" == obj and len(config["condition"]["source_ip"]) > 0:# or "destination_ip" in obj: diff --git a/tests/statistics/stats_srcip_multi_sub_phone_number_dstip_http_table_session_dim_sled_ip.py b/tests/statistics/stats_srcip_multi_sub_phone_number_dstip_http_table_session_dim_sled_ip.py new file mode 100644 index 000000000..94cc46c0a --- /dev/null +++ b/tests/statistics/stats_srcip_multi_sub_phone_number_dstip_http_table_session_dim_sled_ip.py @@ -0,0 +1,234 @@ +# -*- coding: UTF-8 -*- +import time +import os +import sys + +from support.ui_utils.element_position.map_element_position_library import replace_paras + +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +import traceback +from datetime import datetime +from support.common_utils.create_policy import CreatePolicy +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "statistics", + "rule_name": parameter["test_case_name"], + "rule_action": "statistics", + "rule_type": "create", + "debug_flag": "local", + "test_subcriber_id": "test6489", + "script_type": "ui", + "condition": { + "source_ip": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": "10.64.224.31", + }, + ] + } + ], + "source_port": [], + "destination_ip": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": "2.1.1.6", + }, + ] + }], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [ + { + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "object_type": "mobile_identity", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "imei", + "item_value": parameter['test_phone_number'][1:9] + '&' +parameter['test_phone_number'][9], + } + ] + } + ], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [ + ], + "protocol_filed": [], + "sub_action_override": True, + "sub_action": [ + ], + "packet_capture": [] + }, + "action_parameter": { + "statistics_template": [{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "profile_type": "statistics_template", + "charts": [ + { + "chart_name": "default name", + "visualization_type": "Table", + "metrics": [ + "new_sessions_for_this_rule:SUM:new sessions", + "closed_sessions_for_this_rule:SUM:closed sessions" + ], + "dimensions": ["sled_ip"], + "order_by": "new sessions", + "row_limit": "20", + "min_in_size": "0", + "min_out_size": "0" + }, + { + "chart_name": "default name", + "visualization_type": "Table", + "metrics": [ + "new_sessions_for_this_rule:RATE:new sessions", + "closed_sessions_for_this_rule:RATE:closed sessions" + ], + "dimensions": ["sled_ip"], + "order_by": "closed sessions", + "row_limit": "20", + "min_in_size": "0", + "min_out_size": "0" + } + ] + }] + }, + "expected_return": "reset", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], + "traffic": { + "protocol": "", + "type": "trex", + "clients_start_ip": "10.64.224.6", + "clients_end_ip": "10.64.224.6", + "servers_start_ip": "2.1.1.6", + "servers_end_ip": "2.1.1.6", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + }, + "statists_metric_results": [#如果Bytes Aggregate为:BITRATE则Bytes*8 + {"app_category_id": "255","in_bytes": 1140, "out_bytes": 93218, "bytes": 94358} + ], + # "traffic": { + # "type": "trex", + # "clients_start_ip": "192.168.64.86", + # "clients_end_ip": "192.168.64.86", + # "servers_start_ip": "2.1.1.1", + # "servers_end_ip": "2.1.1.2", + # "m": 1, + # "d": 1, + # "yaml_name": "test", + # "pcap_name": "test_https" + # }, + # "traffic": { + # "type": "nslookup", + # "command": "nslookup www.facebook.com" + # }, + # "traffic": { + # "type": "wget", + # "command": "wget -q -O- http://open.node.com:180" + # }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + # 脚本结束时间和耗时 + end_time = time.time() + duration = end_time - start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Finish test case: " + parameter["test_case_name"], flush=True) + return result + + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, + flush=True) + traceback.print_exc() + return "Error: " + str(e) + finally: + # 清理环境 + if isinstance(create, CreatePolicy): + create.clean_up() + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.73", + "api_server": "http://192.168.44.72", + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, # 6 + "root_path": "D:/tsgcode/tsg_test", + "path": "tsgcode/tsg_test/testcase/ui", + "module_name": "statistics", + "test_case_name": os.path.basename(__file__)[:-3], + "debug_flag": "local", + "test_subcriber_id": "test6489", + "script_type": "ui", + "policy_type": "statistics" + } + parameter = replace_paras(parameter) + run(parameter) + """ + # 在测试文件的当前路径执行如下命令执行测试用例: + pytest –cache-clear -v pytest_json.py --alluredir ./allure + + # 执行如下命令生成测试报告(自动打开浏览器): + allure serve allure + """
\ No newline at end of file diff --git a/tests/statistics/stats_srcip_pre_imei_dstip_http_table_session_dim_sled_ip.py b/tests/statistics/stats_srcip_pre_imei_dstip_http_table_session_dim_sled_ip.py new file mode 100644 index 000000000..04cb8b7f4 --- /dev/null +++ b/tests/statistics/stats_srcip_pre_imei_dstip_http_table_session_dim_sled_ip.py @@ -0,0 +1,234 @@ +# -*- coding: UTF-8 -*- +import time +import os +import sys + +from support.ui_utils.element_position.map_element_position_library import replace_paras + +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +import traceback +from datetime import datetime +from support.common_utils.create_policy import CreatePolicy +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "statistics", + "rule_name": parameter["test_case_name"], + "rule_action": "statistics", + "rule_type": "create", + "debug_flag": "local", + "test_subcriber_id": "test6489", + "script_type": "ui", + "condition": { + "source_ip": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": "10.64.224.31", + }, + ] + } + ], + "source_port": [], + "destination_ip": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": "2.1.1.6", + }, + ] + }], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [ + { + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "object_type": "mobile_identity", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "imei", + "item_value": '^' + parameter['test_imei'][0:12] + '$', + } + ] + } + ], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [ + ], + "protocol_filed": [], + "sub_action_override": True, + "sub_action": [ + ], + "packet_capture": [] + }, + "action_parameter": { + "statistics_template": [{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "profile_type": "statistics_template", + "charts": [ + { + "chart_name": "default name", + "visualization_type": "Table", + "metrics": [ + "new_sessions_for_this_rule:SUM:new sessions", + "closed_sessions_for_this_rule:SUM:closed sessions" + ], + "dimensions": ["sled_ip"], + "order_by": "new sessions", + "row_limit": "20", + "min_in_size": "0", + "min_out_size": "0" + }, + { + "chart_name": "default name", + "visualization_type": "Table", + "metrics": [ + "new_sessions_for_this_rule:RATE:new sessions", + "closed_sessions_for_this_rule:RATE:closed sessions" + ], + "dimensions": ["sled_ip"], + "order_by": "closed sessions", + "row_limit": "20", + "min_in_size": "0", + "min_out_size": "0" + } + ] + }] + }, + "expected_return": "reset", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], + "traffic": { + "protocol": "", + "type": "trex", + "clients_start_ip": "10.64.224.6", + "clients_end_ip": "10.64.224.6", + "servers_start_ip": "2.1.1.6", + "servers_end_ip": "2.1.1.6", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + }, + "statists_metric_results": [#如果Bytes Aggregate为:BITRATE则Bytes*8 + {"app_category_id": "255","in_bytes": 1140, "out_bytes": 93218, "bytes": 94358} + ], + # "traffic": { + # "type": "trex", + # "clients_start_ip": "192.168.64.86", + # "clients_end_ip": "192.168.64.86", + # "servers_start_ip": "2.1.1.1", + # "servers_end_ip": "2.1.1.2", + # "m": 1, + # "d": 1, + # "yaml_name": "test", + # "pcap_name": "test_https" + # }, + # "traffic": { + # "type": "nslookup", + # "command": "nslookup www.facebook.com" + # }, + # "traffic": { + # "type": "wget", + # "command": "wget -q -O- http://open.node.com:180" + # }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + # 脚本结束时间和耗时 + end_time = time.time() + duration = end_time - start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Finish test case: " + parameter["test_case_name"], flush=True) + return result + + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, + flush=True) + traceback.print_exc() + return "Error: " + str(e) + finally: + # 清理环境 + if isinstance(create, CreatePolicy): + create.clean_up() + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.73", + "api_server": "http://192.168.44.72", + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, # 6 + "root_path": "D:/tsgcode/tsg_test", + "path": "tsgcode/tsg_test/testcase/ui", + "module_name": "statistics", + "test_case_name": os.path.basename(__file__)[:-3], + "debug_flag": "local", + "test_subcriber_id": "test6489", + "script_type": "ui", + "policy_type": "statistics" + } + parameter = replace_paras(parameter) + run(parameter) + """ + # 在测试文件的当前路径执行如下命令执行测试用例: + pytest –cache-clear -v pytest_json.py --alluredir ./allure + + # 执行如下命令生成测试报告(自动打开浏览器): + allure serve allure + """
\ No newline at end of file diff --git a/tests/statistics/stats_srcip_pre_imsi_dstip_http_table_session_dim_sled_ip.py b/tests/statistics/stats_srcip_pre_imsi_dstip_http_table_session_dim_sled_ip.py new file mode 100644 index 000000000..ff4722195 --- /dev/null +++ b/tests/statistics/stats_srcip_pre_imsi_dstip_http_table_session_dim_sled_ip.py @@ -0,0 +1,234 @@ +# -*- coding: UTF-8 -*- +import time +import os +import sys + +from support.ui_utils.element_position.map_element_position_library import replace_paras + +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +import traceback +from datetime import datetime +from support.common_utils.create_policy import CreatePolicy +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "statistics", + "rule_name": parameter["test_case_name"], + "rule_action": "statistics", + "rule_type": "create", + "debug_flag": "local", + "test_subcriber_id": "test6489", + "script_type": "ui", + "condition": { + "source_ip": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": "10.64.224.31", + }, + ] + } + ], + "source_port": [], + "destination_ip": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": "2.1.1.6", + }, + ] + }], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [ + { + "name": "sec_imsi", + "object_type": "mobile_identity", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "imsi", + "item_value": '^' + parameter['test_imsi'][0:12], + } + ] + } + ], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [ + ], + "protocol_filed": [], + "sub_action_override": True, + "sub_action": [ + ], + "packet_capture": [] + }, + "action_parameter": { + "statistics_template": [{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "profile_type": "statistics_template", + "charts": [ + { + "chart_name": "default name", + "visualization_type": "Table", + "metrics": [ + "new_sessions_for_this_rule:SUM:new sessions", + "closed_sessions_for_this_rule:SUM:closed sessions" + ], + "dimensions": ["sled_ip"], + "order_by": "new sessions", + "row_limit": "20", + "min_in_size": "0", + "min_out_size": "0" + }, + { + "chart_name": "default name", + "visualization_type": "Table", + "metrics": [ + "new_sessions_for_this_rule:RATE:new sessions", + "closed_sessions_for_this_rule:RATE:closed sessions" + ], + "dimensions": ["sled_ip"], + "order_by": "closed sessions", + "row_limit": "20", + "min_in_size": "0", + "min_out_size": "0" + } + ] + }] + }, + "expected_return": "reset", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], + "traffic": { + "protocol": "", + "type": "trex", + "clients_start_ip": "10.64.224.6", + "clients_end_ip": "10.64.224.6", + "servers_start_ip": "2.1.1.6", + "servers_end_ip": "2.1.1.6", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + }, + "statists_metric_results": [#如果Bytes Aggregate为:BITRATE则Bytes*8 + {"app_category_id": "255","in_bytes": 1140, "out_bytes": 93218, "bytes": 94358} + ], + # "traffic": { + # "type": "trex", + # "clients_start_ip": "192.168.64.86", + # "clients_end_ip": "192.168.64.86", + # "servers_start_ip": "2.1.1.1", + # "servers_end_ip": "2.1.1.2", + # "m": 1, + # "d": 1, + # "yaml_name": "test", + # "pcap_name": "test_https" + # }, + # "traffic": { + # "type": "nslookup", + # "command": "nslookup www.facebook.com" + # }, + # "traffic": { + # "type": "wget", + # "command": "wget -q -O- http://open.node.com:180" + # }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + # 脚本结束时间和耗时 + end_time = time.time() + duration = end_time - start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Finish test case: " + parameter["test_case_name"], flush=True) + return result + + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, + flush=True) + traceback.print_exc() + return "Error: " + str(e) + finally: + # 清理环境 + if isinstance(create, CreatePolicy): + create.clean_up() + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.73", + "api_server": "http://192.168.44.72", + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, # 6 + "root_path": "D:/tsgcode/tsg_test", + "path": "tsgcode/tsg_test/testcase/ui", + "module_name": "statistics", + "test_case_name": os.path.basename(__file__)[:-3], + "debug_flag": "local", + "test_subcriber_id": "test6489", + "script_type": "ui", + "policy_type": "statistics" + } + parameter = replace_paras(parameter) + run(parameter) + """ + # 在测试文件的当前路径执行如下命令执行测试用例: + pytest –cache-clear -v pytest_json.py --alluredir ./allure + + # 执行如下命令生成测试报告(自动打开浏览器): + allure serve allure + """
\ No newline at end of file diff --git a/tests/statistics/stats_srcip_pre_phone_number_dstip_http_table_session_dim_sled_ip.py b/tests/statistics/stats_srcip_pre_phone_number_dstip_http_table_session_dim_sled_ip.py new file mode 100644 index 000000000..bcb557f13 --- /dev/null +++ b/tests/statistics/stats_srcip_pre_phone_number_dstip_http_table_session_dim_sled_ip.py @@ -0,0 +1,234 @@ +# -*- coding: UTF-8 -*- +import time +import os +import sys + +from support.ui_utils.element_position.map_element_position_library import replace_paras + +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +import traceback +from datetime import datetime +from support.common_utils.create_policy import CreatePolicy +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "statistics", + "rule_name": parameter["test_case_name"], + "rule_action": "statistics", + "rule_type": "create", + "debug_flag": "local", + "test_subcriber_id": "test6489", + "script_type": "ui", + "condition": { + "source_ip": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": "10.64.224.31", + }, + ] + } + ], + "source_port": [], + "destination_ip": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": "2.1.1.6", + }, + ] + }], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [ + { + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "object_type": "mobile_identity", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "phone_number", + "item_value": '^' + parameter['test_phone_number'][0:10] + '$', + } + ] + } + ], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [ + ], + "protocol_filed": [], + "sub_action_override": True, + "sub_action": [ + ], + "packet_capture": [] + }, + "action_parameter": { + "statistics_template": [{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "profile_type": "statistics_template", + "charts": [ + { + "chart_name": "default name", + "visualization_type": "Table", + "metrics": [ + "new_sessions_for_this_rule:SUM:new sessions", + "closed_sessions_for_this_rule:SUM:closed sessions" + ], + "dimensions": ["sled_ip"], + "order_by": "new sessions", + "row_limit": "20", + "min_in_size": "0", + "min_out_size": "0" + }, + { + "chart_name": "default name", + "visualization_type": "Table", + "metrics": [ + "new_sessions_for_this_rule:RATE:new sessions", + "closed_sessions_for_this_rule:RATE:closed sessions" + ], + "dimensions": ["sled_ip"], + "order_by": "closed sessions", + "row_limit": "20", + "min_in_size": "0", + "min_out_size": "0" + } + ] + }] + }, + "expected_return": "reset", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], + "traffic": { + "protocol": "", + "type": "trex", + "clients_start_ip": "10.64.224.6", + "clients_end_ip": "10.64.224.6", + "servers_start_ip": "2.1.1.6", + "servers_end_ip": "2.1.1.6", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + }, + "statists_metric_results": [#如果Bytes Aggregate为:BITRATE则Bytes*8 + {"app_category_id": "255","in_bytes": 1140, "out_bytes": 93218, "bytes": 94358} + ], + # "traffic": { + # "type": "trex", + # "clients_start_ip": "192.168.64.86", + # "clients_end_ip": "192.168.64.86", + # "servers_start_ip": "2.1.1.1", + # "servers_end_ip": "2.1.1.2", + # "m": 1, + # "d": 1, + # "yaml_name": "test", + # "pcap_name": "test_https" + # }, + # "traffic": { + # "type": "nslookup", + # "command": "nslookup www.facebook.com" + # }, + # "traffic": { + # "type": "wget", + # "command": "wget -q -O- http://open.node.com:180" + # }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + # 脚本结束时间和耗时 + end_time = time.time() + duration = end_time - start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Finish test case: " + parameter["test_case_name"], flush=True) + return result + + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, + flush=True) + traceback.print_exc() + return "Error: " + str(e) + finally: + # 清理环境 + if isinstance(create, CreatePolicy): + create.clean_up() + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.73", + "api_server": "http://192.168.44.72", + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, # 6 + "root_path": "D:/tsgcode/tsg_test", + "path": "tsgcode/tsg_test/testcase/ui", + "module_name": "statistics", + "test_case_name": os.path.basename(__file__)[:-3], + "debug_flag": "local", + "test_subcriber_id": "test6489", + "script_type": "ui", + "policy_type": "statistics" + } + parameter = replace_paras(parameter) + run(parameter) + """ + # 在测试文件的当前路径执行如下命令执行测试用例: + pytest –cache-clear -v pytest_json.py --alluredir ./allure + + # 执行如下命令生成测试报告(自动打开浏览器): + allure serve allure + """
\ No newline at end of file diff --git a/tests/statistics/stats_srcip_sub_phone_number_dstip_http_table_session_dim_sled_ip.py b/tests/statistics/stats_srcip_sub_phone_number_dstip_http_table_session_dim_sled_ip.py new file mode 100644 index 000000000..efea59611 --- /dev/null +++ b/tests/statistics/stats_srcip_sub_phone_number_dstip_http_table_session_dim_sled_ip.py @@ -0,0 +1,234 @@ +# -*- coding: UTF-8 -*- +import time +import os +import sys + +from support.ui_utils.element_position.map_element_position_library import replace_paras + +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +import traceback +from datetime import datetime +from support.common_utils.create_policy import CreatePolicy +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "statistics", + "rule_name": parameter["test_case_name"], + "rule_action": "statistics", + "rule_type": "create", + "debug_flag": "local", + "test_subcriber_id": "test6489", + "script_type": "ui", + "condition": { + "source_ip": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": "10.64.224.31", + }, + ] + } + ], + "source_port": [], + "destination_ip": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": "2.1.1.6", + }, + ] + }], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [ + { + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "object_type": "mobile_identity", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "phone_number", + "item_value": parameter['test_phone_number'][2:10], + } + ] + } + ], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [ + ], + "protocol_filed": [], + "sub_action_override": True, + "sub_action": [ + ], + "packet_capture": [] + }, + "action_parameter": { + "statistics_template": [{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "profile_type": "statistics_template", + "charts": [ + { + "chart_name": "default name", + "visualization_type": "Table", + "metrics": [ + "new_sessions_for_this_rule:SUM:new sessions", + "closed_sessions_for_this_rule:SUM:closed sessions" + ], + "dimensions": ["sled_ip"], + "order_by": "new sessions", + "row_limit": "20", + "min_in_size": "0", + "min_out_size": "0" + }, + { + "chart_name": "default name", + "visualization_type": "Table", + "metrics": [ + "new_sessions_for_this_rule:RATE:new sessions", + "closed_sessions_for_this_rule:RATE:closed sessions" + ], + "dimensions": ["sled_ip"], + "order_by": "closed sessions", + "row_limit": "20", + "min_in_size": "0", + "min_out_size": "0" + } + ] + }] + }, + "expected_return": "reset", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], + "traffic": { + "protocol": "", + "type": "trex", + "clients_start_ip": "10.64.224.6", + "clients_end_ip": "10.64.224.6", + "servers_start_ip": "2.1.1.6", + "servers_end_ip": "2.1.1.6", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + }, + "statists_metric_results": [#如果Bytes Aggregate为:BITRATE则Bytes*8 + {"app_category_id": "255","in_bytes": 1140, "out_bytes": 93218, "bytes": 94358} + ], + # "traffic": { + # "type": "trex", + # "clients_start_ip": "192.168.64.86", + # "clients_end_ip": "192.168.64.86", + # "servers_start_ip": "2.1.1.1", + # "servers_end_ip": "2.1.1.2", + # "m": 1, + # "d": 1, + # "yaml_name": "test", + # "pcap_name": "test_https" + # }, + # "traffic": { + # "type": "nslookup", + # "command": "nslookup www.facebook.com" + # }, + # "traffic": { + # "type": "wget", + # "command": "wget -q -O- http://open.node.com:180" + # }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + # 脚本结束时间和耗时 + end_time = time.time() + duration = end_time - start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Finish test case: " + parameter["test_case_name"], flush=True) + return result + + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, + flush=True) + traceback.print_exc() + return "Error: " + str(e) + finally: + # 清理环境 + if isinstance(create, CreatePolicy): + create.clean_up() + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.73", + "api_server": "http://192.168.44.72", + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, # 6 + "root_path": "D:/tsgcode/tsg_test", + "path": "tsgcode/tsg_test/testcase/ui", + "module_name": "statistics", + "test_case_name": os.path.basename(__file__)[:-3], + "debug_flag": "local", + "test_subcriber_id": "test6489", + "script_type": "ui", + "policy_type": "statistics" + } + parameter = replace_paras(parameter) + run(parameter) + """ + # 在测试文件的当前路径执行如下命令执行测试用例: + pytest –cache-clear -v pytest_json.py --alluredir ./allure + + # 执行如下命令生成测试报告(自动打开浏览器): + allure serve allure + """
\ No newline at end of file diff --git a/tests/statistics/stats_srcip_suff_apn_dstip_http_table_session_dim_sled_ip.py b/tests/statistics/stats_srcip_suff_apn_dstip_http_table_session_dim_sled_ip.py new file mode 100644 index 000000000..8810fc9fd --- /dev/null +++ b/tests/statistics/stats_srcip_suff_apn_dstip_http_table_session_dim_sled_ip.py @@ -0,0 +1,234 @@ +# -*- coding: UTF-8 -*- +import time +import os +import sys + +from support.ui_utils.element_position.map_element_position_library import replace_paras + +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +import traceback +from datetime import datetime +from support.common_utils.create_policy import CreatePolicy +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "statistics", + "rule_name": parameter["test_case_name"], + "rule_action": "statistics", + "rule_type": "create", + "debug_flag": "local", + "test_subcriber_id": "test6489", + "script_type": "ui", + "condition": { + "source_ip": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": "10.64.224.31", + }, + ] + } + ], + "source_port": [], + "destination_ip": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": "2.1.1.6", + }, + ] + }], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [ + { + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "object_type": "apn", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "apn", + "item_value": parameter['test_apn'][2] + '$', + } + ] + } + ], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [ + ], + "protocol_filed": [], + "sub_action_override": True, + "sub_action": [ + ], + "packet_capture": [] + }, + "action_parameter": { + "statistics_template": [{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "profile_type": "statistics_template", + "charts": [ + { + "chart_name": "default name", + "visualization_type": "Table", + "metrics": [ + "new_sessions_for_this_rule:SUM:new sessions", + "closed_sessions_for_this_rule:SUM:closed sessions" + ], + "dimensions": ["sled_ip"], + "order_by": "new sessions", + "row_limit": "20", + "min_in_size": "0", + "min_out_size": "0" + }, + { + "chart_name": "default name", + "visualization_type": "Table", + "metrics": [ + "new_sessions_for_this_rule:RATE:new sessions", + "closed_sessions_for_this_rule:RATE:closed sessions" + ], + "dimensions": ["sled_ip"], + "order_by": "closed sessions", + "row_limit": "20", + "min_in_size": "0", + "min_out_size": "0" + } + ] + }] + }, + "expected_return": "reset", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], + "traffic": { + "protocol": "", + "type": "trex", + "clients_start_ip": "10.64.224.6", + "clients_end_ip": "10.64.224.6", + "servers_start_ip": "2.1.1.6", + "servers_end_ip": "2.1.1.6", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + }, + "statists_metric_results": [#如果Bytes Aggregate为:BITRATE则Bytes*8 + {"app_category_id": "255","in_bytes": 1140, "out_bytes": 93218, "bytes": 94358} + ], + # "traffic": { + # "type": "trex", + # "clients_start_ip": "192.168.64.86", + # "clients_end_ip": "192.168.64.86", + # "servers_start_ip": "2.1.1.1", + # "servers_end_ip": "2.1.1.2", + # "m": 1, + # "d": 1, + # "yaml_name": "test", + # "pcap_name": "test_https" + # }, + # "traffic": { + # "type": "nslookup", + # "command": "nslookup www.facebook.com" + # }, + # "traffic": { + # "type": "wget", + # "command": "wget -q -O- http://open.node.com:180" + # }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + # 脚本结束时间和耗时 + end_time = time.time() + duration = end_time - start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Finish test case: " + parameter["test_case_name"], flush=True) + return result + + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, + flush=True) + traceback.print_exc() + return "Error: " + str(e) + finally: + # 清理环境 + if isinstance(create, CreatePolicy): + create.clean_up() + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.73", + "api_server": "http://192.168.44.72", + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, # 6 + "root_path": "D:/tsgcode/tsg_test", + "path": "tsgcode/tsg_test/testcase/ui", + "module_name": "statistics", + "test_case_name": os.path.basename(__file__)[:-3], + "debug_flag": "local", + "test_subcriber_id": "test6489", + "script_type": "ui", + "policy_type": "statistics" + } + parameter = replace_paras(parameter) + run(parameter) + """ + # 在测试文件的当前路径执行如下命令执行测试用例: + pytest –cache-clear -v pytest_json.py --alluredir ./allure + + # 执行如下命令生成测试报告(自动打开浏览器): + allure serve allure + """
\ No newline at end of file diff --git a/tests/statistics/stats_srcip_suff_phone_number_dstip_http_table_session_dim_sled_ip.py b/tests/statistics/stats_srcip_suff_phone_number_dstip_http_table_session_dim_sled_ip.py new file mode 100644 index 000000000..adc8a3fa9 --- /dev/null +++ b/tests/statistics/stats_srcip_suff_phone_number_dstip_http_table_session_dim_sled_ip.py @@ -0,0 +1,234 @@ +# -*- coding: UTF-8 -*- +import time +import os +import sys + +from support.ui_utils.element_position.map_element_position_library import replace_paras + +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +import traceback +from datetime import datetime +from support.common_utils.create_policy import CreatePolicy +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "statistics", + "rule_name": parameter["test_case_name"], + "rule_action": "statistics", + "rule_type": "create", + "debug_flag": "local", + "test_subcriber_id": "test6489", + "script_type": "ui", + "condition": { + "source_ip": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": "10.64.224.31", + }, + ] + } + ], + "source_port": [], + "destination_ip": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": "2.1.1.6", + }, + ] + }], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [ + { + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "object_type": "mobile_identity", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "phone_number", + "item_value": parameter['test_phone_number'][5] + '$', + } + ] + } + ], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [ + ], + "protocol_filed": [], + "sub_action_override": True, + "sub_action": [ + ], + "packet_capture": [] + }, + "action_parameter": { + "statistics_template": [{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "profile_type": "statistics_template", + "charts": [ + { + "chart_name": "default name", + "visualization_type": "Table", + "metrics": [ + "new_sessions_for_this_rule:SUM:new sessions", + "closed_sessions_for_this_rule:SUM:closed sessions" + ], + "dimensions": ["sled_ip"], + "order_by": "new sessions", + "row_limit": "20", + "min_in_size": "0", + "min_out_size": "0" + }, + { + "chart_name": "default name", + "visualization_type": "Table", + "metrics": [ + "new_sessions_for_this_rule:RATE:new sessions", + "closed_sessions_for_this_rule:RATE:closed sessions" + ], + "dimensions": ["sled_ip"], + "order_by": "closed sessions", + "row_limit": "20", + "min_in_size": "0", + "min_out_size": "0" + } + ] + }] + }, + "expected_return": "reset", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], + "traffic": { + "protocol": "", + "type": "trex", + "clients_start_ip": "10.64.224.6", + "clients_end_ip": "10.64.224.6", + "servers_start_ip": "2.1.1.6", + "servers_end_ip": "2.1.1.6", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + }, + "statists_metric_results": [#如果Bytes Aggregate为:BITRATE则Bytes*8 + {"app_category_id": "255","in_bytes": 1140, "out_bytes": 93218, "bytes": 94358} + ], + # "traffic": { + # "type": "trex", + # "clients_start_ip": "192.168.64.86", + # "clients_end_ip": "192.168.64.86", + # "servers_start_ip": "2.1.1.1", + # "servers_end_ip": "2.1.1.2", + # "m": 1, + # "d": 1, + # "yaml_name": "test", + # "pcap_name": "test_https" + # }, + # "traffic": { + # "type": "nslookup", + # "command": "nslookup www.facebook.com" + # }, + # "traffic": { + # "type": "wget", + # "command": "wget -q -O- http://open.node.com:180" + # }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + # 脚本结束时间和耗时 + end_time = time.time() + duration = end_time - start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Finish test case: " + parameter["test_case_name"], flush=True) + return result + + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, + flush=True) + traceback.print_exc() + return "Error: " + str(e) + finally: + # 清理环境 + if isinstance(create, CreatePolicy): + create.clean_up() + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.73", + "api_server": "http://192.168.44.72", + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, # 6 + "root_path": "D:/tsgcode/tsg_test", + "path": "tsgcode/tsg_test/testcase/ui", + "module_name": "statistics", + "test_case_name": os.path.basename(__file__)[:-3], + "debug_flag": "local", + "test_subcriber_id": "test6489", + "script_type": "ui", + "policy_type": "statistics" + } + parameter = replace_paras(parameter) + run(parameter) + """ + # 在测试文件的当前路径执行如下命令执行测试用例: + pytest –cache-clear -v pytest_json.py --alluredir ./allure + + # 执行如下命令生成测试报告(自动打开浏览器): + allure serve allure + """
\ No newline at end of file diff --git a/tests/statistics/stats_srcip_xly_apn_dstip_http_table_session_dim_device_group.py b/tests/statistics/stats_srcip_xly_apn_dstip_http_table_session_dim_device_group.py new file mode 100644 index 000000000..7b59616c9 --- /dev/null +++ b/tests/statistics/stats_srcip_xly_apn_dstip_http_table_session_dim_device_group.py @@ -0,0 +1,234 @@ +# -*- coding: UTF-8 -*- +import time +import os +import sys + +from support.ui_utils.element_position.map_element_position_library import replace_paras + +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +import traceback +from datetime import datetime +from support.common_utils.create_policy import CreatePolicy +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "statistics", + "rule_name": parameter["test_case_name"], + "rule_action": "statistics", + "rule_type": "create", + "debug_flag": "local", + "test_subcriber_id": "test6489", + "script_type": "ui", + "condition": { + "source_ip": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": "10.64.224.31", + }, + ] + } + ], + "source_port": [], + "destination_ip": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": "2.1.1.6", + }, + ] + }], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [ + { + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "object_type": "apn", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "apn", + "item_value": '^' + parameter['test_apn'] + '$', + } + ] + } + ], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [ + ], + "protocol_filed": [], + "sub_action_override": True, + "sub_action": [ + ], + "packet_capture": [] + }, + "action_parameter": { + "statistics_template": [{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "profile_type": "statistics_template", + "charts": [ + { + "chart_name": "default name", + "visualization_type": "Table", + "metrics": [ + "new_sessions_for_this_rule:SUM:new sessions", + "closed_sessions_for_this_rule:SUM:closed sessions" + ], + "dimensions": ["device_group"], + "order_by": "new sessions", + "row_limit": "20", + "min_in_size": "0", + "min_out_size": "0" + }, + { + "chart_name": "default name", + "visualization_type": "Table", + "metrics": [ + "new_sessions_for_this_rule:RATE:new sessions", + "closed_sessions_for_this_rule:RATE:closed sessions" + ], + "dimensions": ["device_group"], + "order_by": "closed sessions", + "row_limit": "20", + "min_in_size": "0", + "min_out_size": "0" + } + ] + }] + }, + "expected_return": "reset", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], + "traffic": { + "protocol": "", + "type": "trex", + "clients_start_ip": "10.64.224.6", + "clients_end_ip": "10.64.224.6", + "servers_start_ip": "2.1.1.6", + "servers_end_ip": "2.1.1.6", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + }, + "statists_metric_results": [#如果Bytes Aggregate为:BITRATE则Bytes*8 + {"app_category_id": "255","in_bytes": 1140, "out_bytes": 93218, "bytes": 94358} + ], + # "traffic": { + # "type": "trex", + # "clients_start_ip": "192.168.64.86", + # "clients_end_ip": "192.168.64.86", + # "servers_start_ip": "2.1.1.1", + # "servers_end_ip": "2.1.1.2", + # "m": 1, + # "d": 1, + # "yaml_name": "test", + # "pcap_name": "test_https" + # }, + # "traffic": { + # "type": "nslookup", + # "command": "nslookup www.facebook.com" + # }, + # "traffic": { + # "type": "wget", + # "command": "wget -q -O- http://open.node.com:180" + # }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + # 脚本结束时间和耗时 + end_time = time.time() + duration = end_time - start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Finish test case: " + parameter["test_case_name"], flush=True) + return result + + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, + flush=True) + traceback.print_exc() + return "Error: " + str(e) + finally: + # 清理环境 + if isinstance(create, CreatePolicy): + create.clean_up() + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.73", + "api_server": "http://192.168.44.72", + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, # 6 + "root_path": "D:/tsgcode/tsg_test", + "path": "tsgcode/tsg_test/testcase/ui", + "module_name": "statistics", + "test_case_name": os.path.basename(__file__)[:-3], + "debug_flag": "local", + "test_subcriber_id": "test6489", + "script_type": "ui", + "policy_type": "statistics" + } + parameter = replace_paras(parameter) + run(parameter) + """ + # 在测试文件的当前路径执行如下命令执行测试用例: + pytest –cache-clear -v pytest_json.py --alluredir ./allure + + # 执行如下命令生成测试报告(自动打开浏览器): + allure serve allure + """
\ No newline at end of file diff --git a/tests/statistics/stats_srcip_xly_imei_dstip_http_table_session_dim_device_group.py b/tests/statistics/stats_srcip_xly_imei_dstip_http_table_session_dim_device_group.py new file mode 100644 index 000000000..8d7d2cfac --- /dev/null +++ b/tests/statistics/stats_srcip_xly_imei_dstip_http_table_session_dim_device_group.py @@ -0,0 +1,234 @@ +# -*- coding: UTF-8 -*- +import time +import os +import sys + +from support.ui_utils.element_position.map_element_position_library import replace_paras + +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +import traceback +from datetime import datetime +from support.common_utils.create_policy import CreatePolicy +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "statistics", + "rule_name": parameter["test_case_name"], + "rule_action": "statistics", + "rule_type": "create", + "debug_flag": "local", + "test_subcriber_id": "test6489", + "script_type": "ui", + "condition": { + "source_ip": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": "10.64.224.31", + }, + ] + } + ], + "source_port": [], + "destination_ip": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": "2.1.1.6", + }, + ] + }], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [ + { + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "object_type": "mobile_identity", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "imei", + "item_value": '^' + parameter['test_imei'] + '$', + } + ] + } + ], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [ + ], + "protocol_filed": [], + "sub_action_override": True, + "sub_action": [ + ], + "packet_capture": [] + }, + "action_parameter": { + "statistics_template": [{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "profile_type": "statistics_template", + "charts": [ + { + "chart_name": "default name", + "visualization_type": "Table", + "metrics": [ + "new_sessions_for_this_rule:SUM:new sessions", + "closed_sessions_for_this_rule:SUM:closed sessions" + ], + "dimensions": ["device_group"], + "order_by": "new sessions", + "row_limit": "20", + "min_in_size": "0", + "min_out_size": "0" + }, + { + "chart_name": "default name", + "visualization_type": "Table", + "metrics": [ + "new_sessions_for_this_rule:RATE:new sessions", + "closed_sessions_for_this_rule:RATE:closed sessions" + ], + "dimensions": ["device_group"], + "order_by": "closed sessions", + "row_limit": "20", + "min_in_size": "0", + "min_out_size": "0" + } + ] + }] + }, + "expected_return": "reset", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], + "traffic": { + "protocol": "", + "type": "trex", + "clients_start_ip": "10.64.224.6", + "clients_end_ip": "10.64.224.6", + "servers_start_ip": "2.1.1.6", + "servers_end_ip": "2.1.1.6", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + }, + "statists_metric_results": [#如果Bytes Aggregate为:BITRATE则Bytes*8 + {"app_category_id": "255","in_bytes": 1140, "out_bytes": 93218, "bytes": 94358} + ], + # "traffic": { + # "type": "trex", + # "clients_start_ip": "192.168.64.86", + # "clients_end_ip": "192.168.64.86", + # "servers_start_ip": "2.1.1.1", + # "servers_end_ip": "2.1.1.2", + # "m": 1, + # "d": 1, + # "yaml_name": "test", + # "pcap_name": "test_https" + # }, + # "traffic": { + # "type": "nslookup", + # "command": "nslookup www.facebook.com" + # }, + # "traffic": { + # "type": "wget", + # "command": "wget -q -O- http://open.node.com:180" + # }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + # 脚本结束时间和耗时 + end_time = time.time() + duration = end_time - start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Finish test case: " + parameter["test_case_name"], flush=True) + return result + + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, + flush=True) + traceback.print_exc() + return "Error: " + str(e) + finally: + # 清理环境 + if isinstance(create, CreatePolicy): + create.clean_up() + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.73", + "api_server": "http://192.168.44.72", + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, # 6 + "root_path": "D:/tsgcode/tsg_test", + "path": "tsgcode/tsg_test/testcase/ui", + "module_name": "statistics", + "test_case_name": os.path.basename(__file__)[:-3], + "debug_flag": "local", + "test_subcriber_id": "test6489", + "script_type": "ui", + "policy_type": "statistics" + } + parameter = replace_paras(parameter) + run(parameter) + """ + # 在测试文件的当前路径执行如下命令执行测试用例: + pytest –cache-clear -v pytest_json.py --alluredir ./allure + + # 执行如下命令生成测试报告(自动打开浏览器): + allure serve allure + """
\ No newline at end of file diff --git a/tests/statistics/stats_srcip_xly_imsi_dstip_http_table_session_dim_device_group.py b/tests/statistics/stats_srcip_xly_imsi_dstip_http_table_session_dim_device_group.py new file mode 100644 index 000000000..0f346db70 --- /dev/null +++ b/tests/statistics/stats_srcip_xly_imsi_dstip_http_table_session_dim_device_group.py @@ -0,0 +1,234 @@ +# -*- coding: UTF-8 -*- +import time +import os +import sys + +from support.ui_utils.element_position.map_element_position_library import replace_paras + +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +import traceback +from datetime import datetime +from support.common_utils.create_policy import CreatePolicy +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "statistics", + "rule_name": parameter["test_case_name"], + "rule_action": "statistics", + "rule_type": "create", + "debug_flag": "local", + "test_subcriber_id": "test6489", + "script_type": "ui", + "condition": { + "source_ip": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": "10.64.224.31", + }, + ] + } + ], + "source_port": [], + "destination_ip": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": "2.1.1.6", + }, + ] + }], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [ + { + "name": "sec_imsi", + "object_type": "mobile_identity", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "imsi", + "item_value": '^' + parameter['test_imsi'] + '$', + } + ] + } + ], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [ + ], + "protocol_filed": [], + "sub_action_override": True, + "sub_action": [ + ], + "packet_capture": [] + }, + "action_parameter": { + "statistics_template": [{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "profile_type": "statistics_template", + "charts": [ + { + "chart_name": "default name", + "visualization_type": "Table", + "metrics": [ + "new_sessions_for_this_rule:SUM:new sessions", + "closed_sessions_for_this_rule:SUM:closed sessions" + ], + "dimensions": ["device_group"], + "order_by": "new sessions", + "row_limit": "20", + "min_in_size": "0", + "min_out_size": "0" + }, + { + "chart_name": "default name", + "visualization_type": "Table", + "metrics": [ + "new_sessions_for_this_rule:RATE:new sessions", + "closed_sessions_for_this_rule:RATE:closed sessions" + ], + "dimensions": ["device_group"], + "order_by": "closed sessions", + "row_limit": "20", + "min_in_size": "0", + "min_out_size": "0" + } + ] + }] + }, + "expected_return": "reset", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], + "traffic": { + "protocol": "", + "type": "trex", + "clients_start_ip": "10.64.224.6", + "clients_end_ip": "10.64.224.6", + "servers_start_ip": "2.1.1.6", + "servers_end_ip": "2.1.1.6", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + }, + "statists_metric_results": [#如果Bytes Aggregate为:BITRATE则Bytes*8 + {"app_category_id": "255","in_bytes": 1140, "out_bytes": 93218, "bytes": 94358} + ], + # "traffic": { + # "type": "trex", + # "clients_start_ip": "192.168.64.86", + # "clients_end_ip": "192.168.64.86", + # "servers_start_ip": "2.1.1.1", + # "servers_end_ip": "2.1.1.2", + # "m": 1, + # "d": 1, + # "yaml_name": "test", + # "pcap_name": "test_https" + # }, + # "traffic": { + # "type": "nslookup", + # "command": "nslookup www.facebook.com" + # }, + # "traffic": { + # "type": "wget", + # "command": "wget -q -O- http://open.node.com:180" + # }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + # 脚本结束时间和耗时 + end_time = time.time() + duration = end_time - start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Finish test case: " + parameter["test_case_name"], flush=True) + return result + + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, + flush=True) + traceback.print_exc() + return "Error: " + str(e) + finally: + # 清理环境 + if isinstance(create, CreatePolicy): + create.clean_up() + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.73", + "api_server": "http://192.168.44.72", + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, # 6 + "root_path": "D:/tsgcode/tsg_test", + "path": "tsgcode/tsg_test/testcase/ui", + "module_name": "statistics", + "test_case_name": os.path.basename(__file__)[:-3], + "debug_flag": "local", + "test_subcriber_id": "test6489", + "script_type": "ui", + "policy_type": "statistics" + } + parameter = replace_paras(parameter) + run(parameter) + """ + # 在测试文件的当前路径执行如下命令执行测试用例: + pytest –cache-clear -v pytest_json.py --alluredir ./allure + + # 执行如下命令生成测试报告(自动打开浏览器): + allure serve allure + """
\ No newline at end of file diff --git a/tests/statistics/stats_srcip_xly_phone_number_dstip_http_table_session_dim_device_group.py b/tests/statistics/stats_srcip_xly_phone_number_dstip_http_table_session_dim_device_group.py new file mode 100644 index 000000000..9d906d012 --- /dev/null +++ b/tests/statistics/stats_srcip_xly_phone_number_dstip_http_table_session_dim_device_group.py @@ -0,0 +1,234 @@ +# -*- coding: UTF-8 -*- +import time +import os +import sys + +from support.ui_utils.element_position.map_element_position_library import replace_paras + +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +import traceback +from datetime import datetime +from support.common_utils.create_policy import CreatePolicy +from support.report_update import ReportUpdate + +def run(parameter): + try: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Begin to run test case: " + parameter["test_case_name"], flush=True) + # 参数初始化 + exception_result = "" + result = {} + + # 脚本启动时间 + start_time = time.time() + + # 测试数据 + test_data = { + "is_multi_priority": False, + "rule_num": 1, + "policy_type": "statistics", + "rule_name": parameter["test_case_name"], + "rule_action": "statistics", + "rule_type": "create", + "debug_flag": "local", + "test_subcriber_id": "test6489", + "script_type": "ui", + "condition": { + "source_ip": [ + { + "name": parameter["test_case_name"].replace("_dstip", "", 1), + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": "10.64.224.31", + }, + ] + } + ], + "source_port": [], + "destination_ip": [ + { + "name": parameter["test_case_name"].replace("_srcip", "", 1), + "object_type": "ip", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "ipv4", + "item_value": "2.1.1.6", + }, + ] + }], + "destination_port": [], + "internal_ip": [], + "internal_port": [], + "external_ip": [], + "external_port": [], + "source_geography": [], + "destination_geography": [], + "sub_id": [], + "device": [ + { + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "object_type": "mobile_identity", + "select_type": False, + "negate": False, + "item": [ + { + "item_operation": "add", + "item_type": "phone_number", + "item_value": '^' + parameter['test_phone_number'] + '$', + } + ] + } + ], + "tunnel": [], + "tunnel_level": [], + "flag": [], + "application": [ + { + "name": "http", # + "object_type": "application", + "negate": False + } + ], + "server_fqdn": [ + ], + "protocol_filed": [], + "sub_action_override": True, + "sub_action": [ + ], + "packet_capture": [] + }, + "action_parameter": { + "statistics_template": [{ + "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1), + "profile_type": "statistics_template", + "charts": [ + { + "chart_name": "default name", + "visualization_type": "Table", + "metrics": [ + "new_sessions_for_this_rule:SUM:new sessions", + "closed_sessions_for_this_rule:SUM:closed sessions" + ], + "dimensions": ["device_group"], + "order_by": "new sessions", + "row_limit": "20", + "min_in_size": "0", + "min_out_size": "0" + }, + { + "chart_name": "default name", + "visualization_type": "Table", + "metrics": [ + "new_sessions_for_this_rule:RATE:new sessions", + "closed_sessions_for_this_rule:RATE:closed sessions" + ], + "dimensions": ["device_group"], + "order_by": "closed sessions", + "row_limit": "20", + "min_in_size": "0", + "min_out_size": "0" + } + ] + }] + }, + "expected_return": "reset", + "counters": {"hits": 1}, + "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}], + "traffic": { + "protocol": "", + "type": "trex", + "clients_start_ip": "10.64.224.6", + "clients_end_ip": "10.64.224.6", + "servers_start_ip": "2.1.1.6", + "servers_end_ip": "2.1.1.6", + "m": 1, + "d": 1, + "yaml_name": "test", + "pcap_name": "http_87pkts" + }, + "statists_metric_results": [#如果Bytes Aggregate为:BITRATE则Bytes*8 + {"app_category_id": "255","in_bytes": 1140, "out_bytes": 93218, "bytes": 94358} + ], + # "traffic": { + # "type": "trex", + # "clients_start_ip": "192.168.64.86", + # "clients_end_ip": "192.168.64.86", + # "servers_start_ip": "2.1.1.1", + # "servers_end_ip": "2.1.1.2", + # "m": 1, + # "d": 1, + # "yaml_name": "test", + # "pcap_name": "test_https" + # }, + # "traffic": { + # "type": "nslookup", + # "command": "nslookup www.facebook.com" + # }, + # "traffic": { + # "type": "wget", + # "command": "wget -q -O- http://open.node.com:180" + # }, + "token": "" + } + # 测试用例实例化 + create = CreatePolicy(test_data, parameter) + result = create.create_policy() + + # 脚本结束时间和耗时 + end_time = time.time() + duration = end_time - start_time + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Finish test case: " + parameter["test_case_name"], flush=True) + return result + + except Exception as e: + exception_result = str(e) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Error: ", e, + flush=True) + traceback.print_exc() + return "Error: " + str(e) + finally: + # 清理环境 + if isinstance(create, CreatePolicy): + create.clean_up() + # 生成csv报告 + update = ReportUpdate() + update.write_result(parameter, result, exception_result) + +if __name__ == '__main__': + parameter = { + + "username": "zhaokun", + "password": "zhaokun1", + "test_pc_ip": "192.168.64.73", + "api_server": "http://192.168.44.72", + "is_log": 1, + "env": "tsgx", + "vsys_id": 1, # 6 + "root_path": "D:/tsgcode/tsg_test", + "path": "tsgcode/tsg_test/testcase/ui", + "module_name": "statistics", + "test_case_name": os.path.basename(__file__)[:-3], + "debug_flag": "local", + "test_subcriber_id": "test6489", + "script_type": "ui", + "policy_type": "statistics" + } + parameter = replace_paras(parameter) + run(parameter) + """ + # 在测试文件的当前路径执行如下命令执行测试用例: + pytest –cache-clear -v pytest_json.py --alluredir ./allure + + # 执行如下命令生成测试报告(自动打开浏览器): + allure serve allure + """
\ No newline at end of file |
