summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordongxiaoyan <[email protected]>2024-11-27 15:39:36 +0800
committerdongxiaoyan <[email protected]>2024-11-27 15:39:36 +0800
commitd4e53ebf6e07c62be7433917b38af88859b415e9 (patch)
tree6b156042be7733998d60fc8c1f97d7727a88ba8a
parenta9d6d36eea397f465f322961509410030b42bf7b (diff)
1、测试数据适配重构代码
2、注释掉Case中的打印
-rw-r--r--tests/statistics/stats_srcip_dstip_http_bar_sessions_dim_s2c_link_id.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_bar_sessions_dim_sub_id.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_appcategory.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c2s_link_id.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c2s_ttl.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c_ip.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c_ip_object.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c_port.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_decoded_as.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_device_group.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_direction.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_domain.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_flags.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_fqdn.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_http_host.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s2c_link_id.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s2c_ttl.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s_ip.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s_ip_object.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s_port.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_sled_ip.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_sub_id.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_appcategory.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c2s_link_id.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c2s_ttl.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c_country.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c_ip.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c_ip_object.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c_port.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_decoded_as.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_device_group.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_direction.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_domain.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_flags.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_fqdn.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_http_host.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_s2c_link_id.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_s2c_ttl.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_s_country.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_s_ip_object.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_sled_ip.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_app.py16
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_appcategory.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c2s_link_id.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c2s_ttl.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c_country.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c_ip.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c_ip_object.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c_port.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_decoded_as.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_device_group.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_direction.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_domain.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_flags.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_fqdn.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_http_host.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s2c_link_id.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s2c_ttl.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s_country.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s_ip.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s_ip_object.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s_port.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_sled_ip.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_sub_id.py4
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_app.py10
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_app_category.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c2s_link_id.py6
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c2s_ttl.py6
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c_country.py6
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c_ip.py6
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c_ip_object.py6
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c_port.py6
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_decoded_as.py6
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_device_group.py6
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_direction.py6
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_domain.py6
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_flags.py6
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_fqdn.py6
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_http_host.py6
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s2c_link_id.py6
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s2c_ttl.py6
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s_country.py6
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s_ip.py6
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s_ip_object.py6
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s_port.py6
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_sled_ip.py6
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_sub_id.py6
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_app.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_app_category.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c2s_link_id.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c2s_ttl.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c_country.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c_ip.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c_ip_object.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c_port.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_decoded_as.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_device_group.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_direction.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_domain.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_flags.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_fqdn.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_http_host.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s2c_link_id.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s2c_ttl.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s_country.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s_ip.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s_ip_object.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s_port.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_sled_ip.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_sub_id.py2
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_app.py493
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_appcategory.py496
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c2s_link_id.py492
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c2s_ttl.py493
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c_country.py493
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c_ip.py493
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c_ip_object.py494
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c_port.py493
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_decoded_as.py493
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_device_group.py493
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_direction.py493
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_domain.py493
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_flags.py493
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_fqdn.py493
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_http_host.py493
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s2c_link_id.py493
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s2c_ttl.py493
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s_country.py493
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s_ip.py493
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s_ip_object.py494
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s_port.py493
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_sled_ip.py493
-rw-r--r--tests/statistics/stats_srcip_dstip_http_line_pkts_dim_sub_id.py493
134 files changed, 7841 insertions, 3958 deletions
diff --git a/tests/statistics/stats_srcip_dstip_http_bar_sessions_dim_s2c_link_id.py b/tests/statistics/stats_srcip_dstip_http_bar_sessions_dim_s2c_link_id.py
index 3c1117d47..9202466eb 100644
--- a/tests/statistics/stats_srcip_dstip_http_bar_sessions_dim_s2c_link_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_bar_sessions_dim_s2c_link_id.py
@@ -236,8 +236,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
diff --git a/tests/statistics/stats_srcip_dstip_http_bar_sessions_dim_sub_id.py b/tests/statistics/stats_srcip_dstip_http_bar_sessions_dim_sub_id.py
index ddb30a347..d68ccdf17 100644
--- a/tests/statistics/stats_srcip_dstip_http_bar_sessions_dim_sub_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_bar_sessions_dim_sub_id.py
@@ -354,8 +354,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_appcategory.py b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_appcategory.py
index 2d9d91ba7..b2e2976ef 100644
--- a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_appcategory.py
+++ b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_appcategory.py
@@ -296,8 +296,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c2s_link_id.py b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c2s_link_id.py
index dbe3c1097..4d9f6efa7 100644
--- a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c2s_link_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c2s_link_id.py
@@ -296,8 +296,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c2s_ttl.py b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c2s_ttl.py
index 36604d13d..486fa8912 100644
--- a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c2s_ttl.py
+++ b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c2s_ttl.py
@@ -296,8 +296,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c_ip.py b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c_ip.py
index 3ef673811..767349882 100644
--- a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c_ip.py
@@ -296,8 +296,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c_ip_object.py b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c_ip_object.py
index b32acd7aa..0580a4d44 100644
--- a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c_ip_object.py
+++ b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c_ip_object.py
@@ -296,8 +296,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c_port.py b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c_port.py
index 5171d56aa..e3f2c0d37 100644
--- a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c_port.py
+++ b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_c_port.py
@@ -296,8 +296,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_decoded_as.py b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_decoded_as.py
index 5c9a54327..0989c2e22 100644
--- a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_decoded_as.py
+++ b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_decoded_as.py
@@ -296,8 +296,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_device_group.py b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_device_group.py
index 13bdc371b..311e83720 100644
--- a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_device_group.py
+++ b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_device_group.py
@@ -296,8 +296,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_direction.py b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_direction.py
index 7951700b9..aa7097649 100644
--- a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_direction.py
+++ b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_direction.py
@@ -296,8 +296,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_domain.py b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_domain.py
index 71d7c3120..658a58259 100644
--- a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_domain.py
+++ b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_domain.py
@@ -296,8 +296,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_flags.py b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_flags.py
index f56354922..0a5e96451 100644
--- a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_flags.py
+++ b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_flags.py
@@ -296,8 +296,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_fqdn.py b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_fqdn.py
index 5acc0a94e..fcc67c70f 100644
--- a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_fqdn.py
+++ b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_fqdn.py
@@ -296,8 +296,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_http_host.py b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_http_host.py
index 5315c2579..2e1a2edf9 100644
--- a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_http_host.py
+++ b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_http_host.py
@@ -296,8 +296,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s2c_link_id.py b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s2c_link_id.py
index 62507b1da..dc707b095 100644
--- a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s2c_link_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s2c_link_id.py
@@ -296,8 +296,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s2c_ttl.py b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s2c_ttl.py
index e87e39305..842626d0f 100644
--- a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s2c_ttl.py
+++ b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s2c_ttl.py
@@ -296,8 +296,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s_ip.py b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s_ip.py
index fa95359ba..ea8998917 100644
--- a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s_ip.py
@@ -296,8 +296,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s_ip_object.py b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s_ip_object.py
index c6d3a1cc6..7ec133ca2 100644
--- a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s_ip_object.py
+++ b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s_ip_object.py
@@ -296,8 +296,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s_port.py b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s_port.py
index 96227b313..576f523c8 100644
--- a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s_port.py
+++ b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_s_port.py
@@ -296,8 +296,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_sled_ip.py b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_sled_ip.py
index 4d7c5004b..f0e9bbb39 100644
--- a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_sled_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_sled_ip.py
@@ -296,8 +296,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_sub_id.py b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_sub_id.py
index 6eea7fb23..be2797e62 100644
--- a/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_sub_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_bar_syn_pkts_dim_sub_id.py
@@ -296,8 +296,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_appcategory.py b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_appcategory.py
index d84c35111..de58a5f0e 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_appcategory.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_appcategory.py
@@ -323,8 +323,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c2s_link_id.py b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c2s_link_id.py
index 758f4dc26..d52050203 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c2s_link_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c2s_link_id.py
@@ -323,8 +323,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c2s_ttl.py b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c2s_ttl.py
index aab957130..073a4552b 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c2s_ttl.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c2s_ttl.py
@@ -323,8 +323,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c_country.py b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c_country.py
index ad26a144c..ba9834698 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c_country.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c_country.py
@@ -323,8 +323,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c_ip.py b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c_ip.py
index 58ac72265..263c5a96b 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c_ip.py
@@ -323,8 +323,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c_ip_object.py b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c_ip_object.py
index b64cdbf81..1bc8f210d 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c_ip_object.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c_ip_object.py
@@ -323,8 +323,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c_port.py b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c_port.py
index 0ee84c176..f025fd3f9 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c_port.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_c_port.py
@@ -323,8 +323,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_decoded_as.py b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_decoded_as.py
index 36dad9e10..7283c362e 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_decoded_as.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_decoded_as.py
@@ -323,8 +323,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_device_group.py b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_device_group.py
index 2adfaba2b..f4a93c5cd 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_device_group.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_device_group.py
@@ -323,8 +323,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_direction.py b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_direction.py
index a15da1b2c..635946d91 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_direction.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_direction.py
@@ -323,8 +323,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_domain.py b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_domain.py
index 68db22602..a768b88d7 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_domain.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_domain.py
@@ -323,8 +323,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_flags.py b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_flags.py
index df51e551f..bc0c50d90 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_flags.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_flags.py
@@ -323,8 +323,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_fqdn.py b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_fqdn.py
index b1af67685..43dc1a7cf 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_fqdn.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_fqdn.py
@@ -323,8 +323,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_http_host.py b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_http_host.py
index a85237890..9bd9d7b74 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_http_host.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_http_host.py
@@ -323,8 +323,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_s2c_link_id.py b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_s2c_link_id.py
index a0758895a..162922476 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_s2c_link_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_s2c_link_id.py
@@ -323,8 +323,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_s2c_ttl.py b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_s2c_ttl.py
index a18dfd8fb..0fe89ebd0 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_s2c_ttl.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_s2c_ttl.py
@@ -323,8 +323,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_s_country.py b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_s_country.py
index 25ebb60f8..a2d63f2fd 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_s_country.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_s_country.py
@@ -323,8 +323,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_s_ip_object.py b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_s_ip_object.py
index 023346bae..9c6aca9bb 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_s_ip_object.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_s_ip_object.py
@@ -323,8 +323,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_sled_ip.py b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_sled_ip.py
index 6c16d220f..f37375b05 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_sled_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_closed_sessions_dim_sled_ip.py
@@ -323,8 +323,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes.py
index 699346452..80f33ec1f 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes.py
@@ -451,8 +451,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_app.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_app.py
index ba0c5dc27..bb7b23830 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_app.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_app.py
@@ -86,8 +86,8 @@ def run(parameter):
{
"id": "",
"display": {
- "page_x": null,
- "page_y": null,
+ "page_x": None,
+ "page_y": None,
"height": "",
"width": "",
"type": "line",
@@ -158,8 +158,8 @@ def run(parameter):
{
"id": "",
"display": {
- "page_x": null,
- "page_y": null,
+ "page_x": None,
+ "page_y": None,
"height": "",
"width": "",
"type": "line",
@@ -229,8 +229,8 @@ def run(parameter):
{
"id": "",
"display": {
- "page_x": null,
- "page_y": null,
+ "page_x": None,
+ "page_y": None,
"height": "",
"width": "",
"type": "line",
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_appcategory.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_appcategory.py
index b336b14d4..13f3e771a 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_appcategory.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_appcategory.py
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c2s_link_id.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c2s_link_id.py
index c2fc5aa37..d98ef4c9f 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c2s_link_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c2s_link_id.py
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c2s_ttl.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c2s_ttl.py
index 258747848..8d303bea0 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c2s_ttl.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c2s_ttl.py
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c_country.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c_country.py
index fb18a151b..1fc2a4479 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c_country.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c_country.py
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c_ip.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c_ip.py
index 28e9f0724..1dbf0ebee 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c_ip.py
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c_ip_object.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c_ip_object.py
index a08e7527a..57e8ccc52 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c_ip_object.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c_ip_object.py
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c_port.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c_port.py
index 8dd2c6a33..7480c2fdd 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c_port.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_c_port.py
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_decoded_as.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_decoded_as.py
index 325c9aa19..ef25bfade 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_decoded_as.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_decoded_as.py
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_device_group.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_device_group.py
index 18b5c3f65..504d2c9ca 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_device_group.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_device_group.py
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_direction.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_direction.py
index a0d35b878..1cd580b66 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_direction.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_direction.py
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_domain.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_domain.py
index a73e961f0..e4db166d9 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_domain.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_domain.py
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_flags.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_flags.py
index def46aaea..23dc2f079 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_flags.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_flags.py
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_fqdn.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_fqdn.py
index 1a54f9297..5af134fc3 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_fqdn.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_fqdn.py
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_http_host.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_http_host.py
index 329a0a138..cde4d5d29 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_http_host.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_http_host.py
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s2c_link_id.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s2c_link_id.py
index 8dea08b1a..082963860 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s2c_link_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s2c_link_id.py
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s2c_ttl.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s2c_ttl.py
index 105568f81..b4eda3e57 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s2c_ttl.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s2c_ttl.py
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s_country.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s_country.py
index ba46ad344..981d19e99 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s_country.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s_country.py
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s_ip.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s_ip.py
index 7e3c11d8d..2c6361b21 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s_ip.py
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s_ip_object.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s_ip_object.py
index 940479ffb..f92da959d 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s_ip_object.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s_ip_object.py
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s_port.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s_port.py
index 6214b0383..d53e05b09 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s_port.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_s_port.py
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_sled_ip.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_sled_ip.py
index cac6359d6..bea99f130 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_sled_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_sled_ip.py
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_sub_id.py b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_sub_id.py
index c9332e383..0bea0e94a 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_sub_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_in_out_bytes_dim_sub_id.py
@@ -395,8 +395,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_app.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_app.py
index f8edcefa9..133c78eb2 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_app.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_app.py
@@ -86,8 +86,8 @@ def run(parameter):
{
"id": "",
"display": {
- "page_x": null,
- "page_y": null,
+ "page_x": None,
+ "page_y": None,
"height": "",
"width": "",
"type": "line",
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "10"
}
}
]
@@ -252,8 +252,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_app_category.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_app_category.py
index a15fc5785..e2aee409c 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_app_category.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_app_category.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "5"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c2s_link_id.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c2s_link_id.py
index cc6a227f6..c1189b2af 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c2s_link_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c2s_link_id.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "5"
}
}
]
@@ -252,8 +252,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c2s_ttl.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c2s_ttl.py
index e769d60a8..0dedd73b6 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c2s_ttl.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c2s_ttl.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "5"
}
}
]
@@ -252,8 +252,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c_country.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c_country.py
index e5324a08b..aca292d32 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c_country.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c_country.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "5"
}
}
]
@@ -252,8 +252,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c_ip.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c_ip.py
index 53fc80db0..78e782e81 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c_ip.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "5"
}
}
]
@@ -252,8 +252,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c_ip_object.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c_ip_object.py
index 8bb0b9e6b..e407eec8a 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c_ip_object.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c_ip_object.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
@@ -252,8 +252,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c_port.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c_port.py
index 730603042..938ca0490 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c_port.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_c_port.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
@@ -252,8 +252,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_decoded_as.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_decoded_as.py
index b3d9c798d..002eedb2d 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_decoded_as.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_decoded_as.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
@@ -252,8 +252,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_device_group.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_device_group.py
index 4041ab537..0df382d13 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_device_group.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_device_group.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "10"
}
}
]
@@ -252,8 +252,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_direction.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_direction.py
index dc9bfaf78..403216640 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_direction.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_direction.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
@@ -252,8 +252,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_domain.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_domain.py
index 5b2c9ad91..3f17bb0e5 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_domain.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_domain.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
@@ -252,8 +252,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_flags.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_flags.py
index 3383bf258..8e1f2773e 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_flags.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_flags.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
@@ -252,8 +252,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_fqdn.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_fqdn.py
index 91ddb8019..88ed6fc4b 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_fqdn.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_fqdn.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
@@ -252,8 +252,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_http_host.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_http_host.py
index 29c7152d4..24edb826e 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_http_host.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_http_host.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
@@ -252,8 +252,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s2c_link_id.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s2c_link_id.py
index beaa1b05e..91e217888 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s2c_link_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s2c_link_id.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
@@ -252,8 +252,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s2c_ttl.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s2c_ttl.py
index 6443c1039..285afe477 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s2c_ttl.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s2c_ttl.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
@@ -252,8 +252,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s_country.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s_country.py
index 2a2dd4fea..6c96b9d47 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s_country.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s_country.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
@@ -252,8 +252,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s_ip.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s_ip.py
index aba783966..11d33cae9 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s_ip.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
@@ -252,8 +252,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s_ip_object.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s_ip_object.py
index 23f13b4ab..8ae56101d 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s_ip_object.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s_ip_object.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
@@ -252,8 +252,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s_port.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s_port.py
index e89c7811c..5eb34f28c 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s_port.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_s_port.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
@@ -252,8 +252,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_sled_ip.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_sled_ip.py
index 414618ccc..a24fced2a 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_sled_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_sled_ip.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
@@ -252,8 +252,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_sub_id.py b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_sub_id.py
index 54b2d78fd..fdf87ad6b 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_sub_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_c2s_flows_dim_sub_id.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
@@ -252,8 +252,8 @@ def run(parameter):
test_summary["metric"] = "The failure reason: the returned metric is empty."
elif len(metric_result) > 0:
test_summary["metric"] = metric_result
- if rules_tuple:
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
return test_summary
except Exception as e:
exception_result = str(e)
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_app.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_app.py
index 28e8b09b1..7da75539a 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_app.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_app.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "5"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_app_category.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_app_category.py
index dc671889c..c2ba4d6ad 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_app_category.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_app_category.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c2s_link_id.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c2s_link_id.py
index 5f9fbc520..01cc3af8b 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c2s_link_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c2s_link_id.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c2s_ttl.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c2s_ttl.py
index 745011247..8f2750bc5 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c2s_ttl.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c2s_ttl.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c_country.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c_country.py
index e6582698a..9d96b17a6 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c_country.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c_country.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c_ip.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c_ip.py
index 3fa98ed33..9aa6ede0c 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c_ip.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c_ip_object.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c_ip_object.py
index b0100e4a1..1f800aa4b 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c_ip_object.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c_ip_object.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c_port.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c_port.py
index e0d979874..9f2cc9273 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c_port.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_c_port.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "15"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_decoded_as.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_decoded_as.py
index 85d777ee5..d4f018640 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_decoded_as.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_decoded_as.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "20"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_device_group.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_device_group.py
index 2afe37f3c..2dd878d6f 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_device_group.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_device_group.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "20"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_direction.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_direction.py
index d51e916b8..d9b153a5f 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_direction.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_direction.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "20"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_domain.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_domain.py
index e33d6d89b..934a54f30 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_domain.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_domain.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "20"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_flags.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_flags.py
index 812f146e2..7ffea53e5 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_flags.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_flags.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "20"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_fqdn.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_fqdn.py
index 15540800e..20da62340 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_fqdn.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_fqdn.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "20"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_http_host.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_http_host.py
index 23d71f3dc..d3a31c2ac 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_http_host.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_http_host.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "20"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s2c_link_id.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s2c_link_id.py
index 291b85551..12a7a5b6e 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s2c_link_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s2c_link_id.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "20"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s2c_ttl.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s2c_ttl.py
index e8c248f3d..bdb90fd89 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s2c_ttl.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s2c_ttl.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "20"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s_country.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s_country.py
index 24b858dcb..baf5a47c2 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s_country.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s_country.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "20"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s_ip.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s_ip.py
index 30e409f63..572342cbb 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s_ip.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "20"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s_ip_object.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s_ip_object.py
index 5033953b3..6fa6447a7 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s_ip_object.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s_ip_object.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "20"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s_port.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s_port.py
index 24086d857..75ec66668 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s_port.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_s_port.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "20"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_sled_ip.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_sled_ip.py
index c7b55f1ec..d3dfbc4d4 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_sled_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_sled_ip.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "20"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_sub_id.py b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_sub_id.py
index 56a8a4a6f..ec28e8765 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_sub_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_new_s2c_flows_dim_sub_id.py
@@ -151,7 +151,7 @@ def run(parameter):
],
"order_by": "",
"source": "statistics_rule",
- "series_limit": ""
+ "series_limit": "20"
}
}
]
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_app.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_app.py
index b2661f2b5..cd17a81f7 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_app.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_app.py
@@ -1,209 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, Application",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "app"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "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.22",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, Application",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "app"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": "Line",
- "metrics": [
- "sent_pkts+received_pkts:RATE:pkts"
- ],
- "dimensions": ["app"],
- "order_by": "pkts",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "sent_pkts+received_pkts:SUM:pkts"
- ],
- "dimensions": ["app"],
- "order_by": "",
- "row_limit": "5",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
- },
- "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.22",
- "clients_end_ip": "10.64.224.22",
- "servers_start_ip": "2.1.1.22",
- "servers_end_ip": "2.1.1.22",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ },
+ "vsys": 1
+ }
},
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_appcategory.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_appcategory.py
index 191803b8e..efb5046f9 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_appcategory.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_appcategory.py
@@ -1,212 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, Application Category",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "app_category"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application Category",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "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.23",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, Application Category",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "app_category"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application Category",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": "Line",
- "metrics": [
- "sent_pkts+received_pkts:RATE:pkts"
- ],
- "dimensions": ["app_category"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "sent_pkts+received_pkts:SUM:pkts"
- ],
- "dimensions": ["app_category"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
+ },
+ "vsys": 1
+ }
},
- "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.23",
- "clients_end_ip": "10.64.224.23",
- "servers_start_ip": "2.1.1.23",
- "servers_end_ip": "2.1.1.23",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"app_category": "4", "pkts": 83}
- ],
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c2s_link_id.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c2s_link_id.py
index 2c3a7b030..a62232dfa 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c2s_link_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c2s_link_id.py
@@ -1,208 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, Client-to-Server Link ID",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "c2s_link_id"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Client-to-Server Link ID",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "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.23",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, Client-to-Server Link ID",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "c2s_link_id"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Client-to-Server Link ID",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "tunnel": [],
- "tunnel_level": [],
- "flag": [],
- "application": [
- {
- "name": "http", #
- "object_type": "application",
- "negate": False
- }
- ],
- "server_fqdn": [
- ],
- "protocol_filed": [],
- "sub_action_override": True,
- "sub_action": [
- ],
- "packet_capture": []
+ },
+ "vsys": 1
+ }
},
- "action_parameter": {
- "statistics_template": [{
- "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
- "profile_type": "statistics_template",
- "charts": [
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "sent_pkts+received_pkts:RATE:pkts"
- ],
- "dimensions": ["c2s_link_id"],
- "order_by": "",
- "row_limit": "5",
- "min_in_size": "1",
- "min_out_size": "1"
- },{
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "sent_pkts+received_pkts:SUM:pkts"
- ],
- "dimensions": ["c2s_link_id"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
- },
- "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.23",
- "clients_end_ip": "10.64.224.23",
- "servers_start_ip": "2.1.1.23",
- "servers_end_ip": "2.1.1.23",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c2s_ttl.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c2s_ttl.py
index 7aba7bcff..37f02d338 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c2s_ttl.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c2s_ttl.py
@@ -1,209 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, Client-to-Server TTL",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "c2s_ttl"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Client-to-Server TTL",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "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.23",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, Client-to-Server TTL",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "c2s_ttl"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Client-to-Server TTL",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": "Line",
- "metrics": [
- "sent_pkts+received_pkts:RATE:pkts"
- ],
- "dimensions": ["c2s_ttl"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "sent_pkts+received_pkts:SUM:pkts"
- ],
- "dimensions": ["c2s_ttl"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
- },
- "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.23",
- "clients_end_ip": "10.64.224.23",
- "servers_start_ip": "2.1.1.23",
- "servers_end_ip": "2.1.1.23",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ },
+ "vsys": 1
+ }
},
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c_country.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c_country.py
index dc0da7d35..d561afa4b 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c_country.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c_country.py
@@ -1,209 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, Client Country",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "client_country"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Client Country",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "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.22",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, Client Country",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "client_country"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Client Country",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": "Line",
- "metrics": [
- "sent_pkts+received_pkts:RATE:pkts"
- ],
- "dimensions": ["client_country"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "sent_pkts+received_pkts:SUM:pkts"
- ],
- "dimensions": ["client_country"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
- },
- "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.22",
- "clients_end_ip": "10.64.224.22",
- "servers_start_ip": "2.1.1.22",
- "servers_end_ip": "2.1.1.22",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ },
+ "vsys": 1
+ }
},
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c_ip.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c_ip.py
index 086afbc0e..967daf073 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c_ip.py
@@ -1,209 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, Client IP",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "client_ip"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Client IP",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "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.23",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, Client IP",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "client_ip"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Client IP",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": "Line",
- "metrics": [
- "sent_pkts+received_pkts:RATE:pkts"
- ],
- "dimensions": ["client_ip"],
- "order_by": "",
- "row_limit": "15",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "sent_pkts+received_pkts:SUM:pkts"
- ],
- "dimensions": ["client_ip"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
- },
- "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.23",
- "clients_end_ip": "10.64.224.23",
- "servers_start_ip": "2.1.1.23",
- "servers_end_ip": "2.1.1.23",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ },
+ "vsys": 1
+ }
},
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c_ip_object.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c_ip_object.py
index db13a20c1..4a281b6f5 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c_ip_object.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c_ip_object.py
@@ -1,210 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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",
- "statistics_option": "Brief",
- "select_type": False,
- "negate": False,
- "item": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, Client IP Object List",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "client_ip_object_list"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Client IP Object List",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "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.23",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, Client IP Object List",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "client_ip_object_list"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Client IP Object List",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": "Line",
- "metrics": [
- "sent_pkts+received_pkts:RATE:pkts"
- ],
- "dimensions": ["client_ip_object_list"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "sent_pkts+received_pkts:SUM:pkts"
- ],
- "dimensions": ["client_ip_object_list"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
- },
- "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.23",
- "clients_end_ip": "10.64.224.23",
- "servers_start_ip": "2.1.1.23",
- "servers_end_ip": "2.1.1.23",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ },
+ "vsys": 1
+ }
},
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c_port.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c_port.py
index f1cdfaf84..52a29c480 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c_port.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_c_port.py
@@ -1,209 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, Client Port'",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "client_port"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Client Port'",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "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.23",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, Client Port'",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "client_port"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Client Port'",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": "Line",
- "metrics": [
- "sent_pkts+received_pkts:RATE:pkts"
- ],
- "dimensions": ["client_port"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "sent_pkts+received_pkts:SUM:pkts"
- ],
- "dimensions": ["client_port"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
- },
- "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.23",
- "clients_end_ip": "10.64.224.23",
- "servers_start_ip": "2.1.1.23",
- "servers_end_ip": "2.1.1.23",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ },
+ "vsys": 1
+ }
},
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_decoded_as.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_decoded_as.py
index d091421c6..b780f0f4e 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_decoded_as.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_decoded_as.py
@@ -1,209 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, Decoded AS",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "decoded_as"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Decoded AS",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "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.23",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, Decoded AS",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "decoded_as"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Decoded AS",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": "Line",
- "metrics": [
- "sent_pkts+received_pkts:RATE:pkts"
- ],
- "dimensions": ["decoded_as"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "sent_pkts+received_pkts:SUM:pkts"
- ],
- "dimensions": ["decoded_as"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
- },
- "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.23",
- "clients_end_ip": "10.64.224.23",
- "servers_start_ip": "2.1.1.23",
- "servers_end_ip": "2.1.1.23",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ },
+ "vsys": 1
+ }
},
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_device_group.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_device_group.py
index ac5a6426d..b759e5afe 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_device_group.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_device_group.py
@@ -1,209 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, Device Group",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "device_group"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Device Group",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "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.23",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, Device Group",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "device_group"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Device Group",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": "Line",
- "metrics": [
- "sent_pkts+received_pkts:RATE:pkts"
- ],
- "dimensions": ["device_group"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "sent_pkts+received_pkts:SUM:pkts"
- ],
- "dimensions": ["device_group"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
- },
- "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.23",
- "clients_end_ip": "10.64.224.23",
- "servers_start_ip": "2.1.1.23",
- "servers_end_ip": "2.1.1.23",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ },
+ "vsys": 1
+ }
},
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_direction.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_direction.py
index 49abb8ce8..f4bb3b5b0 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_direction.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_direction.py
@@ -1,209 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, Direction",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "direction"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Direction",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "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.23",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, Direction",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "direction"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Direction",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": "Line",
- "metrics": [
- "sent_pkts+received_pkts:RATE:pkts"
- ],
- "dimensions": ["direction"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "sent_pkts+received_pkts:SUM:pkts"
- ],
- "dimensions": ["direction"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
- },
- "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.23",
- "clients_end_ip": "10.64.224.23",
- "servers_start_ip": "2.1.1.23",
- "servers_end_ip": "2.1.1.23",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ },
+ "vsys": 1
+ }
},
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_domain.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_domain.py
index 252cb8cc5..8ebd6256f 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_domain.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_domain.py
@@ -1,209 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, Server Domain",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "server_domain"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server Domain",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "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": "10.64.0.1",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, Server Domain",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "server_domain"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server Domain",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": "Line",
- "metrics": [
- "sent_pkts+received_pkts:RATE:pkts"
- ],
- "dimensions": ["server_domain"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "sent_pkts+received_pkts:SUM:pkts"
- ],
- "dimensions": ["server_domain"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
- },
- "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.23",
- "clients_end_ip": "10.64.224.23",
- "servers_start_ip": "10.64.0.1",
- "servers_end_ip": "10.64.0.1",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ },
+ "vsys": 1
+ }
},
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_flags.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_flags.py
index eae112e3c..0cd6b1bcc 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_flags.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_flags.py
@@ -1,209 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, Flags",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "flags"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Flags",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "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.23",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, Flags",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "flags"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Flags",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": "Line",
- "metrics": [
- "sent_pkts+received_pkts:RATE:pkts"
- ],
- "dimensions": ["flags"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "sent_pkts+received_pkts:SUM:pkts"
- ],
- "dimensions": ["flags"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
- },
- "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.23",
- "clients_end_ip": "10.64.224.23",
- "servers_start_ip": "2.1.1.23",
- "servers_end_ip": "2.1.1.23",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ },
+ "vsys": 1
+ }
},
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_fqdn.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_fqdn.py
index 320805ad6..47512601c 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_fqdn.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_fqdn.py
@@ -1,209 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, Server FQDN",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "server_fqdn"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server FQDN",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "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.23",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, Server FQDN",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "server_fqdn"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server FQDN",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": "Line",
- "metrics": [
- "sent_pkts+received_pkts:RATE:pkts"
- ],
- "dimensions": ["server_fqdn"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "sent_pkts+received_pkts:SUM:pkts"
- ],
- "dimensions": ["server_fqdn"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
- },
- "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.23",
- "clients_end_ip": "10.64.224.23",
- "servers_start_ip": "2.1.1.23",
- "servers_end_ip": "2.1.1.23",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ },
+ "vsys": 1
+ }
},
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_http_host.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_http_host.py
index 369450682..6b0cd4db3 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_http_host.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_http_host.py
@@ -1,209 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, HTTP Host",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "http_host"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "HTTP Host",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "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.23",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, HTTP Host",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "http_host"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "HTTP Host",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": "Line",
- "metrics": [
- "sent_pkts+received_pkts:RATE:pkts"
- ],
- "dimensions": ["http_host"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "sent_pkts+received_pkts:SUM:pkts"
- ],
- "dimensions": ["http_host"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
- },
- "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.23",
- "clients_end_ip": "10.64.224.23",
- "servers_start_ip": "2.1.1.23",
- "servers_end_ip": "2.1.1.23",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ },
+ "vsys": 1
+ }
},
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s2c_link_id.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s2c_link_id.py
index df06a8eb6..a30006542 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s2c_link_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s2c_link_id.py
@@ -1,209 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, Server-to-Client Link ID",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "s2c_link_id"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server-to-Client Link ID",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "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.23",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, Server-to-Client Link ID",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "s2c_link_id"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server-to-Client Link ID",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": "Line",
- "metrics": [
- "sent_pkts+received_pkts:RATE:pkts"
- ],
- "dimensions": ["s2c_link_id"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "sent_pkts+received_pkts:SUM:pkts"
- ],
- "dimensions": ["s2c_link_id"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
- },
- "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.23",
- "clients_end_ip": "10.64.224.23",
- "servers_start_ip": "2.1.1.23",
- "servers_end_ip": "2.1.1.23",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ },
+ "vsys": 1
+ }
},
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s2c_ttl.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s2c_ttl.py
index df426da22..a74069937 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s2c_ttl.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s2c_ttl.py
@@ -1,209 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, Server-to-Client TTL",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "s2c_ttl"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server-to-Client TTL",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "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.23",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, Server-to-Client TTL",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "s2c_ttl"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server-to-Client TTL",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": "Line",
- "metrics": [
- "sent_pkts+received_pkts:RATE:pkts"
- ],
- "dimensions": ["s2c_ttl"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "sent_pkts+received_pkts:SUM:pkts"
- ],
- "dimensions": ["s2c_ttl"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
- },
- "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.23",
- "clients_end_ip": "10.64.224.23",
- "servers_start_ip": "2.1.1.23",
- "servers_end_ip": "2.1.1.23",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ },
+ "vsys": 1
+ }
},
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s_country.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s_country.py
index d85c9c6d9..e44ae317c 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s_country.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s_country.py
@@ -1,209 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, Server Country",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "server_country"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server Country",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "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.22",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, Server Country",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "server_country"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server Country",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": "Line",
- "metrics": [
- "sent_pkts+received_pkts:RATE:pkts"
- ],
- "dimensions": ["server_country"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "sent_pkts+received_pkts:SUM:pkts"
- ],
- "dimensions": ["server_country"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
- },
- "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.22",
- "clients_end_ip": "10.64.224.22",
- "servers_start_ip": "2.1.1.22",
- "servers_end_ip": "2.1.1.22",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ },
+ "vsys": 1
+ }
},
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s_ip.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s_ip.py
index e9e0fddc5..d5185895d 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s_ip.py
@@ -1,209 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, Server IP",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "server_ip"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server IP",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "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.23",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, Server IP",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "server_ip"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server IP",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": "Line",
- "metrics": [
- "sent_pkts+received_pkts:RATE:pkts"
- ],
- "dimensions": ["server_ip"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "sent_pkts+received_pkts:SUM:pkts"
- ],
- "dimensions": ["server_ip"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
- },
- "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.23",
- "clients_end_ip": "10.64.224.23",
- "servers_start_ip": "2.1.1.23",
- "servers_end_ip": "2.1.1.23",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ },
+ "vsys": 1
+ }
},
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s_ip_object.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s_ip_object.py
index 0b22be33e..11159eab9 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s_ip_object.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s_ip_object.py
@@ -1,210 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, Server IP Object List",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "server_ip_object_list"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server IP Object List",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "statistics_option": "Brief",
- "select_type": False,
- "negate": False,
- "item": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.23",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, Server IP Object List",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "server_ip_object_list"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server IP Object List",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": "Line",
- "metrics": [
- "sent_pkts+received_pkts:RATE:pkts"
- ],
- "dimensions": ["server_ip_object_list"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "sent_pkts+received_pkts:SUM:pkts"
- ],
- "dimensions": ["server_ip_object_list"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
- },
- "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.23",
- "clients_end_ip": "10.64.224.23",
- "servers_start_ip": "2.1.1.23",
- "servers_end_ip": "2.1.1.23",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ },
+ "vsys": 1
+ }
},
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s_port.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s_port.py
index 3bdc31d85..9016bc0b5 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s_port.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_s_port.py
@@ -1,209 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, Server Port",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "server_port"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server Port",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "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.23",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, Server Port",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "server_port"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server Port",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": "Line",
- "metrics": [
- "sent_pkts+received_pkts:RATE:pkts"
- ],
- "dimensions": ["server_port"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "sent_pkts+received_pkts:SUM:pkts"
- ],
- "dimensions": ["server_port"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
- },
- "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.23",
- "clients_end_ip": "10.64.224.23",
- "servers_start_ip": "2.1.1.23",
- "servers_end_ip": "2.1.1.23",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ },
+ "vsys": 1
+ }
},
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_sled_ip.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_sled_ip.py
index f163d9551..e6adf8b4b 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_sled_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_sled_ip.py
@@ -1,209 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, Sled IP",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "sled_ip"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Sled IP",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "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.23",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, Sled IP",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "sled_ip"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Sled IP",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": "Line",
- "metrics": [
- "in_pkts+out_pkts:RATE:pkts"
- ],
- "dimensions": ["sled_ip"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "in_pkts+out_pkts:SUM:pkts"
- ],
- "dimensions": ["sled_ip"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
- },
- "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.23",
- "clients_end_ip": "10.64.224.23",
- "servers_start_ip": "2.1.1.23",
- "servers_end_ip": "2.1.1.23",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ },
+ "vsys": 1
+ }
},
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""
diff --git a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_sub_id.py b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_sub_id.py
index 38e78f207..122f91dfb 100644
--- a/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_sub_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_line_pkts_dim_sub_id.py
@@ -1,209 +1,378 @@
# -*- coding: UTF-8 -*-
-import time
import os
import sys
+import time
+import pytz
+from support.organize_config import OrganizeConfig
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
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+from support.ui_utils.ui_client import UIClient
+from support.api_utils.api_client import APIClient
+from support.packet_generator.traffic_generator import *
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 = {}
+ result, exception_result = "", ""
+ test_summary = {}
# 脚本启动时间
script_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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_dstip", "", 1),
+ "attribute_name": "ATTR_SOURCE_IP",
+ "type": "ip",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "10.64.224.31",
+ "interval": "1-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "name": parameter["test_case_name"].replace("_srcip", "", 1),
+ "attribute_name": "ATTR_DESTINATION_IP",
+ "type": "ip",
+ "sub_type": "ip",
+ "statistics_option": "none",
+ "member_type": "item",
+ "items": [
+ {
+ "op": "add",
+ "ip": "2.1.1.9",
+ "interval": "0-65535"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "negate_option": False,
+ "or_conditions": [
+ {
+ "attribute_name": "ATTR_APP_ID",
+ "type": "application",
+ "items": ["http"]
+ }
+ ]
+ },
+ ],
+ "action_parameter": {
+ "template_profile":{
+ "name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
+ "uuid": "",
+ "dataview": {
+ "charts": [
{
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received) Distributed by Time, Subscriber ID",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "subscriber_id"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Subscriber ID",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "RATE(Packets Sent, Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "5"
+ }
},
- ]
- }
- ],
- "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.23",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "line",
+ "table_type": ""
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received) Distributed by Time, Subscriber ID",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "subscriber_id"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Subscriber ID",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "__time"
+ ],
+ "function": {
+ "name": "DATETIME_FLOOR_WITH_FILL",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Time",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": 65536,
+ "metrics": [
+ {
+ "source_fields": [
+ "sent_pkts",
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(Packets Sent, Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "",
+ "source": "statistics_rule",
+ "series_limit": "20"
+ }
+ }
]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": "Line",
- "metrics": [
- "in_pkts+out_pkts:RATE:pkts"
- ],
- "dimensions": ["subscriber_id"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Line",
- "metrics": [
- "in_pkts+out_pkts:SUM:pkts"
- ],
- "dimensions": ["subscriber_id"],
- "order_by": "",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
- }
- ]
- }]
- },
- "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.23",
- "clients_end_ip": "10.64.224.23",
- "servers_start_ip": "2.1.1.23",
- "servers_end_ip": "2.1.1.23",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ },
+ "vsys": 1
+ }
},
- # "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": ""
+ "is_enabled": 1,
+ "log_option": "metadata"
}
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_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
+ traffic_generation = {
+ "tool": "trex", # or trex/http
+ "clients_start_ip": "10.64.224.9",
+ "clients_end_ip": "10.64.224.9",
+ "servers_start_ip": "2.1.1.9",
+ "servers_end_ip": "2.1.1.9",
+ "m": 1,
+ "d": 1,
+ "yaml_name": "test",
+ "pcap_name": "http_87pkts"
+ }
+
+ verification_result = {
+ "excepted_traffic_result": {"total_bytes": 94679, "total_bytes_received": 93284, "total_bytes_sent": 1395, "total_packets": 87, "total_packets_received": 65, "total_packets_sent": 22, "total_syn_pkt": 1},
+ "expected_query": {"hits": 1},
+ "expected_log": [
+ {"query_field_key": "decoded_as", "query_value": "HTTP"},
+ {"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}
+ ]
+ }
+ # 创建
+ if parameter["initiation_method"] == "ui":
+ ui_client = UIClient()
+ rules_tuple, ui_error = ui_client.create_rules(policy_configuration)
+ if len(ui_error) > 0:
+ return ui_error
+ elif parameter["initiation_method"] == "api":
+ api_client = APIClient(parameter)
+
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token,())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+ # {uuid, type}, i.e., {"12341-232-a21", "ip"}
+ objects_tuple, api_error = api_client.create_objects(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ # 处理Profiles
+ profiles_tuple, api_error = api_client.create_profiles(policy_configuration)
+ if len(api_error) > 0:
+ return api_error
+ rules_tuple, api_error = api_client.create_rules(policy_configuration, objects_tuple, "", profiles_tuple)
+ if len(api_error) > 0:
+ return api_error
+ # 等待下发配置生效
+ time.sleep(3)
+
+ # 类实例化
+ generator = TrafficGenerator()
+
+ # 获取当前时间
+ utc_tz = pytz.timezone('UTC')
+ current_utc_time = datetime.now(utc_tz)
+ start_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
+
+ # 触发流量
+ traffic_result = generator.run(policy_configuration, traffic_generation)
+
+ # 验证流量生成器的返回值是否符合策略执行的预期
+ excepted_traffic_result, error = generator.result(verification_result, traffic_result)
+ if excepted_traffic_result == False:
+ return error
+
+ # 验证tsg的日志是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ log_result = ui_client.query_rule_log(verification_result, rules_tuple, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ log_result = api_client.query_rule_log(traffic_generation, verification_result, rules_tuple, start_time, traffic_result)
+ if log_result == True:
+ test_summary["log"] = "Pass."
+ elif log_result == False:
+ test_summary["log"] = "The failure reason: the returned log does not match the expected result."
+ elif log_result == None:
+ test_summary["log"] = "The failure reason: the returned log is empty."
+ elif len(log_result) > 0:
+ test_summary["log"] = log_result
+
+ # 验证tsg的metric是否符合策略执行的预期
+ if parameter["initiation_method"] == "ui":
+ metric_result = ui_client.query_rule_metric(verification_result, traffic_result)
+ elif parameter["initiation_method"] == "api":
+ metric_result = api_client.query_rule_metric(verification_result, rules_tuple, start_time, traffic_result)
+ if metric_result == True:
+ test_summary["metric"] = "Pass."
+ elif metric_result == False:
+ test_summary["metric"] = "The failure reason: the returned metric does not match the expected result."
+ elif metric_result == None:
+ test_summary["metric"] = "The failure reason: the returned metric is empty."
+ elif len(metric_result) > 0:
+ test_summary["metric"] = metric_result
+ #if rules_tuple:
+ # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "DEBUG:Case:{},rule:{},log_result:{},excepted_traffic_result:{},metric_result:{}".format(os.path.basename(__file__)[:-3], list(rules_tuple)[0]["uuid"], log_result, excepted_traffic_result, metric_result), flush=True)
+ return test_summary
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)
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
+ "When running test case, the exception error: ", str(e), flush=True)
+ return "When running test case, the exception error: " + str(e)
finally:
- # 清理环境
- if isinstance(create, CreatePolicy):
- create.clean_up()
+ # 删除
+ if parameter["initiation_method"] == "ui":
+ if rules_tuple:
+ ui_client.delete_rules(parameter, policy_configuration)
+ elif parameter["initiation_method"] == "api":
+ if rules_tuple:
+ api_client.delete_rules(rules_tuple)
+ if profiles_tuple:
+ api_client.delete_profiles(profiles_tuple)
+ if objects_tuple:
+ api_client.delete_objects(objects_tuple)
+ # 脚本结束时间和耗时
+ script_end_time = time.time()
+ duration = script_end_time - script_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)
+
# 生成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,
+ "is_log": 0,
"env": "tsgx",
- "vsys_id": 1, # 6
+ "vsys": 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",
+ "initiation_method": "api",
"policy_type": "statistics"
- }
+ }
parameter = replace_paras(parameter)
run(parameter)
"""