summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhaokun <[email protected]>2024-11-28 11:59:45 +0800
committerzhaokun <[email protected]>2024-11-28 11:59:45 +0800
commitf1f96a7c7668f069f8cb29cc7df8b01b934bed74 (patch)
tree58970197fa646df299826b0c645f8a510fded780
parentfe38c49f8fb819e5fee6d61897e6ca7059bdb2e6 (diff)
parent88d32fa8bae14c2c76b3407e7aa9ecc7195bb305 (diff)
merge
-rw-r--r--support/api_utils/query_rule_metric.py8
-rw-r--r--tests/service_chaining/sc_decrypted_scrip_fqdn_ssl_mirror_block_disabled_vxlan_activeip_bfd.py2
-rw-r--r--tests/service_chaining/sc_raw_dstip_dstport_range_mirror_bypass_vlan_none.py9
-rw-r--r--tests/service_chaining/sc_raw_dstip_dstport_range_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_dstip_external_port_range_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_dstip_external_port_range_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_imsi_fqdn_http_url_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_imsi_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_multiple_port_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_negate_apn_fqdn_ssl_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_negate_apn_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_negate_imei_fqdn_http_url_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_negate_imei_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_negate_imsi_fqdn_http_url_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_negate_imsi_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_negate_pn_fqdn_http_url_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_negate_pn_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_negate_srcip_dstip_fqdn_ssl_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_negate_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_negate_subid_fqdn_http_url_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_negate_subid_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_pn_fqdn_http_url_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_pn_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_rtp_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_rtp_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_scrip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_src_compliance_risk_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_src_geoip_asn_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_src_geoip_city_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_src_geoip_country_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_src_internet_service_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_src_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_src_security_threat_library_iprange_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_src_website_classification_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dst_compliance_risk_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dst_geoip_asn_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dst_geoip_city_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dst_geoip_country_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dst_internet_service_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dst_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dst_security_threat_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dst_website_classification_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py1
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_dns_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_dns_qname_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_dns_qname_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_dns_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_exact_fqdn_category_library_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_exact_fqdn_geoip_city_library_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_exact_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_exact_fqdn_security_threat_library_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_all_ipproto_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_all_ipproto_quic_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_http_url_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ipprototcp_http_url_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ipprototcp_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_extport_ssl_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_extport_ssl_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_intport_ssl_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_intport_ssl_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_quic_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_quic_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_false_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_false_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_true_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_true_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_esni_false_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_esni_false_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_disabled_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_activeip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_inactiveip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_inactiveip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_activeip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_inactiveip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_global_bypass_diff_device_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_nearby_bypass_diff_device_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_disabled_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_activeip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_inactiveip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_inactiveip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_unavailableip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_unavailableip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_disabled_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_activeip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_inactiveip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_inactiveip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_unavailableip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_unavailableip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_no_sni_false_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_no_sni_false_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_activeip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_inactiveip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_inactiveip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_unavailableip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_unavailableip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_inactiveip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_inactiveip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_unavailableip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_unavailableip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_activeip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_inactiveip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_inactiveip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_unavailableip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_unavailableip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_activeip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_inactiveip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_inactiveip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_unavailableip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_unavailableip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_ftp_account_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_ftp_account_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_ipprototcp_ftp_account_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_ipprotoudp_dns_qname_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_mail_from_to_account_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_mail_from_to_account_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_mirror_block_vxlan_activeip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_disabled_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_vxlan_activeip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_multiple_port_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_negate_dstport_dns_qname_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_negate_dstport_dns_qname_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_negate_fqdn_ssl_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_negate_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_openvpn_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_openvpn_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_quic_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_quic_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_rdp_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_rdp_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_ssl_esni_true_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_ssl_esni_true_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_activeip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_inactiveip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_inactiveip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_unavailableip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_unavailableip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_bypass_disabled_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_ssl_no_sni_true_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_ssl_no_sni_true_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_steer_bypass_disabled_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_compliance_risk_library_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_geoip_asn_library_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_internet_geoip_country_library_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_internet_service_library_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstport_external_port_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstport_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstport_range_external_port_range_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dstport_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_dtsip_mirror_bypass_vxlan_inactiveip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_fqdn_ipprototcp_ssl_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_block_disabled_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_bypass_disabled_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_global_bypass_diff_device_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_nearby_bypass_diff_device_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_internal_port_range_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_internal_port_range_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_inactiveip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_inactiveip_none.py33
-rw-r--r--tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_unavailableip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_unavailableip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_mirror_bypass_vxlan_unavailableip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_mirror_redispatch_block_vxlan_inactiveip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_negate_dstip_fqdn_ssl_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_negate_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_negate_srcport_range_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_negate_srcport_range_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_steer_block_vxlan_inactiveip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_steer_block_vxlan_inactiveip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_steer_block_vxlan_unavailableip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_steer_block_vxlan_unavailableip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_inactiveip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_unavailableip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_unavailableip_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_steer_redispatch_block_vxlan_inactiveip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcip_steer_redispatch_bypass_vxlan_inactiveip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcport_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcport_range_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_srcport_range_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_srcport_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_subid_fqdn_http_url_mirror_bypass_vlan_none.py5
-rw-r--r--tests/service_chaining/sc_raw_subid_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py5
-rw-r--r--tests/service_chaining/sc_raw_subid_imei_apn_fqdn_http_url_mirror_bypass_vlan_none.py9
-rw-r--r--tests/service_chaining/sc_raw_subid_imei_apn_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py169
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_app.py441
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_app_appcategories.py458
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_appcategories.py443
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c2s_link_id.py441
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c2s_s2c_link_id.py458
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c2s_s2c_ttl.py458
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c2s_ttl.py441
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_country.py443
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_ip.py443
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_ip_object.py443
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_port.py443
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_country.py458
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_country_app.py473
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_ip.py458
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_ip_object.py458
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_port.py458
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_decoded_as.py443
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_device_group.py443
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_domain.py443
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_flags.py443
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_fqdn.py443
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_fqdn_domain.py458
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_http_host.py443
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s2c_link_id.py441
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s2c_ttl.py441
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s_country.py443
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s_ip.py443
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s_ip_object.py443
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s_port.py443
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_sled_ip.py443
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_sub_id.py443
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_app.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_app_appcategory.py578
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_app_c_s_country.py608
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_app_fqdn.py578
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_appcategory.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c2s_link_id.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c2s_s2c_link_id.py578
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c2s_s2c_ttl.py578
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c2s_ttl.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_country.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_ip.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_ip_object.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_port.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_s_country_app_appcategory.py638
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_s_ip.py578
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_s_ip_objects.py580
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_s_port.py578
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_decoded_as.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_device_group.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_device_group_decoded_as.py578
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_direction.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_domain.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_flags.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_fqdn.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_fqdn_domain.py578
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_http_host.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s2c_link_id.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s2c_ttl.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_country.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_ip.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_ip_app.py578
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_ip_fqdn.py578
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_ip_object.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_port.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_sled_ip.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_sub_id.py548
-rw-r--r--tests/statistics/stats_srcip_dstip_http_table_all_sessions_dim_app.py541
272 files changed, 24268 insertions, 11572 deletions
diff --git a/support/api_utils/query_rule_metric.py b/support/api_utils/query_rule_metric.py
index c4dfdd9c4..97b3473d8 100644
--- a/support/api_utils/query_rule_metric.py
+++ b/support/api_utils/query_rule_metric.py
@@ -114,9 +114,9 @@ class QueryRuleMetric:
negate_option = self.get_negate_option_from_configration()
if metric_result == 333:
if sf_configuration[0]["connectivity"]["method"] == "vxlan_g":
- if sf_configuration[0]["connectivity"]["sf_dest_ip"] not in active_dst_ip_list:
+ if sf_configuration[0]["connectivity"]["dest_ip"] not in active_dst_ip_list:
metric_result = True
- elif sf_configuration[0]["connectivity"]["sf_dest_ip"] in active_dst_ip_list and sf_configuration[0]["admin_status"] == 0:
+ elif sf_configuration[0]["connectivity"]["dest_ip"] in active_dst_ip_list and sf_configuration[0]["admin_status"] == 0:
metric_result = True
elif sf_configuration[0]["device_group"]["tag"] not in effective_device_tag_list and sff_configuration[0]["load_balance_localization"] == "nearby":
metric_result = True
@@ -817,7 +817,7 @@ class QueryRuleMetric:
if self.policy_configuration["action_parameter"]["targeted_traffic"] == "raw":
byte_value = traffic_result["total_bytes"]
pkt_value = traffic_result["total_packets"]
- if sf_configuration[0]["connectivity"]["method"] == "vxlan_g" and sf_configuration[0]["connectivity"]["sf_dest_ip"] in active_dst_ip_list:
+ if sf_configuration[0]["connectivity"]["method"] == "vxlan_g" and sf_configuration[0]["connectivity"]["dest_ip"] in active_dst_ip_list:
if len(application) > 0 :
if application[0] == "http" or application[0] == "ssl" or application[0] == "rdp" or application[0] == "OPENVPN":
lost_pkt = 3
@@ -873,7 +873,7 @@ class QueryRuleMetric:
else:
metric_result = False
elif self.policy_configuration["action_parameter"]["targeted_traffic"] == "decrypted":
- if sf_configuration[0]["connectivity"]["method"] == "vxlan_g" and sf_configuration[0]["connectivity"]["sf_dest_ip"] in active_dst_ip_list:
+ if sf_configuration[0]["connectivity"]["method"] == "vxlan_g" and sf_configuration[0]["connectivity"]["dest_ip"] in active_dst_ip_list:
if sff_configuration[0]["type"] == 1:
if metric_dict["sent_bytes"] == metric_dict["received_bytes"] and metric_dict["sent_packets"] == metric_dict["received_packets"]:
metric_result = True
diff --git a/tests/service_chaining/sc_decrypted_scrip_fqdn_ssl_mirror_block_disabled_vxlan_activeip_bfd.py b/tests/service_chaining/sc_decrypted_scrip_fqdn_ssl_mirror_block_disabled_vxlan_activeip_bfd.py
index b09dd965c..a1da35286 100644
--- a/tests/service_chaining/sc_decrypted_scrip_fqdn_ssl_mirror_block_disabled_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_decrypted_scrip_fqdn_ssl_mirror_block_disabled_vxlan_activeip_bfd.py
@@ -143,7 +143,7 @@ def run(parameter):
return api_error
# 等待下发配置生效
- time.sleep(3)
+ time.sleep(20)
# 类实例化
generator = TrafficGenerator()
diff --git a/tests/service_chaining/sc_raw_dstip_dstport_range_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_dstip_dstport_range_mirror_bypass_vlan_none.py
index d5a3132b9..ab9211d3a 100644
--- a/tests/service_chaining/sc_raw_dstip_dstport_range_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_dstip_dstport_range_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -128,6 +129,14 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_dstip_dstport_range_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_dstip_dstport_range_steer_bypass_vxlan_activeip_bfd.py
index c9f3e8ac3..8873daeb5 100644
--- a/tests/service_chaining/sc_raw_dstip_dstport_range_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_dstip_dstport_range_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -127,6 +128,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_dstip_external_port_range_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_dstip_external_port_range_mirror_bypass_vlan_none.py
index fb7306a87..2d13dfae8 100644
--- a/tests/service_chaining/sc_raw_dstip_external_port_range_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_dstip_external_port_range_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -148,6 +149,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_dstip_external_port_range_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_dstip_external_port_range_steer_bypass_vxlan_activeip_bfd.py
index c7cd3c8ec..2f89caff1 100644
--- a/tests/service_chaining/sc_raw_dstip_external_port_range_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_dstip_external_port_range_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -127,6 +128,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_imsi_fqdn_http_url_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_imsi_fqdn_http_url_mirror_bypass_vlan_none.py
index d4220642a..ad498864d 100644
--- a/tests/service_chaining/sc_raw_imsi_fqdn_http_url_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_imsi_fqdn_http_url_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -162,6 +163,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_imsi_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_imsi_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index 6ff20e73c..7e35d8dfd 100644
--- a/tests/service_chaining/sc_raw_imsi_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_imsi_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -161,6 +162,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_multiple_port_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_multiple_port_steer_bypass_vxlan_activeip_bfd.py
index 8444f4ca1..dabbff435 100644
--- a/tests/service_chaining/sc_raw_multiple_port_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_multiple_port_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -161,6 +162,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_negate_apn_fqdn_ssl_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_negate_apn_fqdn_ssl_mirror_bypass_vlan_none.py
index ef331800f..f7e2db53d 100644
--- a/tests/service_chaining/sc_raw_negate_apn_fqdn_ssl_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_negate_apn_fqdn_ssl_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -131,6 +132,10 @@ def run(parameter):
"expected_metric": {"hits": 0},
"expected_log": []
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_negate_apn_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_negate_apn_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py
index f072fdfa6..118349854 100644
--- a/tests/service_chaining/sc_raw_negate_apn_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_negate_apn_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -129,6 +130,10 @@ def run(parameter):
"expected_metric": {"hits": 0},
"expected_log": []
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_negate_imei_fqdn_http_url_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_negate_imei_fqdn_http_url_mirror_bypass_vlan_none.py
index 844ff62ee..25c8fbf36 100644
--- a/tests/service_chaining/sc_raw_negate_imei_fqdn_http_url_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_negate_imei_fqdn_http_url_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -151,6 +152,10 @@ def run(parameter):
"expected_log": []
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_negate_imei_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_negate_imei_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index 58b8d0ff4..9e62fb0e1 100644
--- a/tests/service_chaining/sc_raw_negate_imei_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_negate_imei_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -150,6 +151,10 @@ def run(parameter):
"expected_log": []
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_negate_imsi_fqdn_http_url_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_negate_imsi_fqdn_http_url_mirror_bypass_vlan_none.py
index c1c872cd6..6670d55ef 100644
--- a/tests/service_chaining/sc_raw_negate_imsi_fqdn_http_url_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_negate_imsi_fqdn_http_url_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -152,6 +153,10 @@ def run(parameter):
"expected_log": []
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_negate_imsi_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_negate_imsi_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index 4156ebaa5..8df9f759b 100644
--- a/tests/service_chaining/sc_raw_negate_imsi_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_negate_imsi_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -150,6 +151,10 @@ def run(parameter):
"expected_log": []
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_negate_pn_fqdn_http_url_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_negate_pn_fqdn_http_url_mirror_bypass_vlan_none.py
index 67c4bb9ab..9c6111eb2 100644
--- a/tests/service_chaining/sc_raw_negate_pn_fqdn_http_url_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_negate_pn_fqdn_http_url_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -151,6 +152,10 @@ def run(parameter):
"expected_log": []
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_negate_pn_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_negate_pn_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index af541e739..2d69fd85a 100644
--- a/tests/service_chaining/sc_raw_negate_pn_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_negate_pn_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -150,6 +151,10 @@ def run(parameter):
"expected_log": []
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_negate_srcip_dstip_fqdn_ssl_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_negate_srcip_dstip_fqdn_ssl_mirror_bypass_vlan_none.py
index 819cd585a..6394c6cc6 100644
--- a/tests/service_chaining/sc_raw_negate_srcip_dstip_fqdn_ssl_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_negate_srcip_dstip_fqdn_ssl_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -154,6 +155,10 @@ def run(parameter):
"expected_log": []
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_negate_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_negate_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py
index 664e492ff..a2ccf46d7 100644
--- a/tests/service_chaining/sc_raw_negate_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_negate_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -153,6 +154,10 @@ def run(parameter):
"expected_log": []
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_negate_subid_fqdn_http_url_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_negate_subid_fqdn_http_url_mirror_bypass_vlan_none.py
index 502d68f01..40abd4e13 100644
--- a/tests/service_chaining/sc_raw_negate_subid_fqdn_http_url_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_negate_subid_fqdn_http_url_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -149,6 +150,10 @@ def run(parameter):
"expected_log": []
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_negate_subid_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_negate_subid_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index b981e7808..738a3cb2e 100644
--- a/tests/service_chaining/sc_raw_negate_subid_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_negate_subid_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -148,6 +149,10 @@ def run(parameter):
"expected_log": []
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_pn_fqdn_http_url_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_pn_fqdn_http_url_mirror_bypass_vlan_none.py
index e18ca7473..14956322e 100644
--- a/tests/service_chaining/sc_raw_pn_fqdn_http_url_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_pn_fqdn_http_url_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -162,6 +163,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_pn_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_pn_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index de98cde3c..52bd0b8eb 100644
--- a/tests/service_chaining/sc_raw_pn_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_pn_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -161,6 +162,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_rtp_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_rtp_mirror_bypass_vlan_none.py
index 3b0104fe4..3ca5f56f2 100644
--- a/tests/service_chaining/sc_raw_rtp_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_rtp_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -98,6 +99,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_rtp_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_rtp_steer_bypass_vxlan_activeip_bfd.py
index b7aab7474..65e7bc358 100644
--- a/tests/service_chaining/sc_raw_rtp_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_rtp_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -97,6 +98,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_scrip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_scrip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_none.py
index 9efb38591..b1f585162 100644
--- a/tests/service_chaining/sc_raw_scrip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_none.py
+++ b/tests/service_chaining/sc_raw_scrip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -158,6 +159,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_src_compliance_risk_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_src_compliance_risk_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index 186225636..0f6d333a6 100644
--- a/tests/service_chaining/sc_raw_src_compliance_risk_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_src_compliance_risk_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -192,6 +193,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_src_geoip_asn_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_src_geoip_asn_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index e7a2f8299..dac3e2026 100644
--- a/tests/service_chaining/sc_raw_src_geoip_asn_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_src_geoip_asn_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -191,6 +192,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_src_geoip_city_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_src_geoip_city_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index ba02cb095..4d8666ebe 100644
--- a/tests/service_chaining/sc_raw_src_geoip_city_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_src_geoip_city_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -186,6 +187,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_src_geoip_country_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_src_geoip_country_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index 1af5a68e3..8fab03ed1 100644
--- a/tests/service_chaining/sc_raw_src_geoip_country_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_src_geoip_country_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -190,6 +191,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_src_internet_service_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_src_internet_service_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index 50b8af759..f2e7c8aaa 100644
--- a/tests/service_chaining/sc_raw_src_internet_service_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_src_internet_service_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -192,6 +193,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_src_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_src_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index a7aaffa70..ebb266ccd 100644
--- a/tests/service_chaining/sc_raw_src_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_src_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -185,6 +186,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_src_security_threat_library_iprange_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_src_security_threat_library_iprange_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index e0e4c4a75..5880c0cf7 100644
--- a/tests/service_chaining/sc_raw_src_security_threat_library_iprange_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_src_security_threat_library_iprange_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -185,6 +186,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_src_website_classification_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_src_website_classification_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index 1efe2b6f2..aa5512c46 100644
--- a/tests/service_chaining/sc_raw_src_website_classification_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_src_website_classification_library_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -190,6 +191,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dst_compliance_risk_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dst_compliance_risk_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index 4870725f8..592b6999f 100644
--- a/tests/service_chaining/sc_raw_srcip_dst_compliance_risk_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dst_compliance_risk_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -185,6 +186,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dst_geoip_asn_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dst_geoip_asn_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index 5f7244526..1e2b8fecb 100644
--- a/tests/service_chaining/sc_raw_srcip_dst_geoip_asn_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dst_geoip_asn_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -185,6 +186,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dst_geoip_city_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dst_geoip_city_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index 6bd8f6d2c..38af788dd 100644
--- a/tests/service_chaining/sc_raw_srcip_dst_geoip_city_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dst_geoip_city_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -185,6 +186,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dst_geoip_country_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dst_geoip_country_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index 06cbb009f..d04c219cb 100644
--- a/tests/service_chaining/sc_raw_srcip_dst_geoip_country_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dst_geoip_country_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -185,6 +186,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dst_internet_service_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dst_internet_service_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index 5ccca6d17..e1c30979b 100644
--- a/tests/service_chaining/sc_raw_srcip_dst_internet_service_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dst_internet_service_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -185,6 +186,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dst_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dst_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index 3cbe146d4..5e3e58184 100644
--- a/tests/service_chaining/sc_raw_srcip_dst_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dst_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -185,6 +186,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dst_security_threat_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dst_security_threat_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index 00cdd671d..6ae56f736 100644
--- a/tests/service_chaining/sc_raw_srcip_dst_security_threat_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dst_security_threat_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -185,6 +186,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dst_website_classification_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dst_website_classification_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index 912eb308a..935ad86ed 100644
--- a/tests/service_chaining/sc_raw_srcip_dst_website_classification_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dst_website_classification_library_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_dns_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_dns_mirror_bypass_vlan_none.py
index 382cf5c5f..2625f7f36 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_dns_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_dns_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -142,6 +143,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_dns_qname_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_dns_qname_mirror_bypass_vlan_none.py
index 591ce5b42..41e3ba2bd 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_dns_qname_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_dns_qname_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -160,6 +161,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_dns_qname_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_dns_qname_steer_bypass_vxlan_activeip_bfd.py
index e7d56bd0e..656e92280 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_dns_qname_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_dns_qname_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -159,6 +160,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_dns_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_dns_steer_bypass_vxlan_activeip_bfd.py
index d65838e6f..24cc5c0bf 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_dns_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_dns_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -141,6 +142,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_exact_fqdn_category_library_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_exact_fqdn_category_library_http_url_steer_bypass_vxlan_activeip_bfd.py
index e443fdaef..299e10374 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_exact_fqdn_category_library_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_exact_fqdn_category_library_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -187,6 +188,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_exact_fqdn_geoip_city_library_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_exact_fqdn_geoip_city_library_http_url_steer_bypass_vxlan_activeip_bfd.py
index dd92eafad..c8306c58d 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_exact_fqdn_geoip_city_library_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_exact_fqdn_geoip_city_library_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -186,6 +187,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_exact_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_exact_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py
index 3e9842b50..30d56fc24 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_exact_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_exact_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -186,6 +187,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_exact_fqdn_security_threat_library_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_exact_fqdn_security_threat_library_http_url_steer_bypass_vxlan_activeip_bfd.py
index 108b7bfff..3a2670cb9 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_exact_fqdn_security_threat_library_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_exact_fqdn_security_threat_library_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -186,6 +187,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_all_ipproto_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_all_ipproto_http_url_steer_bypass_vxlan_activeip_bfd.py
index fb1176e78..f18c9ca00 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_all_ipproto_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_all_ipproto_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -187,6 +188,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_all_ipproto_quic_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_all_ipproto_quic_steer_bypass_vxlan_activeip_bfd.py
index fcfbe8243..eb2823401 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_all_ipproto_quic_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_all_ipproto_quic_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -171,6 +172,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_http_url_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_http_url_mirror_bypass_vlan_none.py
index 5ac948885..a7610b70f 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_http_url_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_http_url_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -178,6 +179,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index e5770b6e8..4a874644b 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -177,6 +178,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ipprototcp_http_url_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ipprototcp_http_url_mirror_bypass_vlan_none.py
index 3ea6985a6..4f85fd341 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ipprototcp_http_url_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ipprototcp_http_url_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -188,6 +189,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ipprototcp_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ipprototcp_http_url_steer_bypass_vxlan_activeip_bfd.py
index 1a62e4608..55d3e3491 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ipprototcp_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ipprototcp_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -187,6 +188,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py
index 7992afcab..756e7421b 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -193,6 +194,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_extport_ssl_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_extport_ssl_mirror_bypass_vlan_none.py
index b1ac57a56..3cf2f8f5b 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_extport_ssl_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_extport_ssl_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -177,6 +178,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_extport_ssl_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_extport_ssl_steer_bypass_vxlan_activeip_bfd.py
index a44b01f66..5456f3edb 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_extport_ssl_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_extport_ssl_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -176,6 +177,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_intport_ssl_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_intport_ssl_mirror_bypass_vlan_none.py
index 38d015639..f701d1e3c 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_intport_ssl_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_intport_ssl_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -177,6 +178,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_intport_ssl_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_intport_ssl_steer_bypass_vxlan_activeip_bfd.py
index 38d015639..d0c2d87ba 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_intport_ssl_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_negate_intport_ssl_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -177,6 +178,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_quic_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_quic_mirror_bypass_vlan_none.py
index 4c384dc59..319f177eb 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_quic_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_quic_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -159,6 +160,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_quic_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_quic_steer_bypass_vxlan_activeip_bfd.py
index 11b029d3e..03978045d 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_quic_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_quic_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -158,6 +159,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_false_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_false_mirror_bypass_vlan_none.py
index 3911a74c5..340f1b8ac 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_false_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_false_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -171,6 +172,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_false_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_false_steer_bypass_vxlan_activeip_bfd.py
index 196c37c8f..07ff947a1 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_false_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_false_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -170,6 +171,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_true_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_true_mirror_bypass_vlan_none.py
index 456b7a9f5..0075fe382 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_true_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_true_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -171,6 +172,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_true_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_true_steer_bypass_vxlan_activeip_bfd.py
index 703831b5e..c35405338 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_true_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_ech_true_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -170,6 +171,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_esni_false_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_esni_false_mirror_bypass_vlan_none.py
index 16dc2859c..9a531c88f 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_esni_false_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_esni_false_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -171,6 +172,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_esni_false_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_esni_false_steer_bypass_vxlan_activeip_bfd.py
index 18b9b9a4d..c160b953b 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_esni_false_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_esni_false_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -170,6 +171,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_disabled_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_disabled_vxlan_activeip_bfd.py
index 644e1d764..4b0bd2cdd 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_disabled_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_disabled_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -157,6 +158,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_activeip_bfd.py
index 30b7f0880..5c12d6868 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -155,6 +156,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_activeip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_activeip_none.py
index 5e0c6d365..3f945f5e9 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_activeip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_activeip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -157,6 +158,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_inactiveip_bfd.py
index 5cbf10275..1872b456e 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_inactiveip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_inactiveip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -154,6 +155,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_inactiveip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_inactiveip_none.py
index 9dfe86694..950d54462 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_inactiveip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_block_vxlan_inactiveip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -156,6 +157,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vlan_none.py
index dae907bec..aa302fd48 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -160,6 +161,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_activeip_bfd.py
index f1cf64ed5..8599c5515 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -154,6 +155,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_activeip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_activeip_none.py
index f4db56a32..ec711f360 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_activeip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_activeip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -159,6 +160,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_inactiveip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_inactiveip_none.py
index 7b6d63ba4..6f384a1c4 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_inactiveip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_inactiveip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -157,6 +158,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_bfd.py
index a80ed259b..38ae5b7a5 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -151,6 +152,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_none.py
index c47eea873..18f094549 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_bypass_vxlan_unavailableip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -153,6 +154,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_global_bypass_diff_device_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_global_bypass_diff_device_vlan_none.py
index 0c834f3b9..b83b58bd4 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_global_bypass_diff_device_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_global_bypass_diff_device_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -158,6 +159,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_nearby_bypass_diff_device_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_nearby_bypass_diff_device_vlan_none.py
index baa657ca8..feb9d0f90 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_nearby_bypass_diff_device_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_nearby_bypass_diff_device_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -157,6 +158,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_disabled_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_disabled_vxlan_activeip_bfd.py
index 68787d0a2..16018797f 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_disabled_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_disabled_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -162,6 +163,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vlan_none.py
index 226b8efd6..2a960a601 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vlan_none.py
@@ -9,6 +9,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -164,6 +165,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_activeip_bfd.py
index 3161dd3a3..eaae270b8 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -162,6 +163,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_activeip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_activeip_none.py
index 05467a3b5..e4626e340 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_activeip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_activeip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -159,6 +160,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_inactiveip_bfd.py
index 0d988c023..4670d28c5 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_inactiveip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_inactiveip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -162,6 +163,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_inactiveip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_inactiveip_none.py
index fedcfd458..31812389d 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_inactiveip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_inactiveip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -162,6 +163,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_unavailableip_bfd.py
index c24ba18f0..539c16cd3 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_unavailableip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_unavailableip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -155,6 +156,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_unavailableip_none.py
index 05295c4ea..acdbb6fb4 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_unavailableip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_block_vxlan_unavailableip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -162,6 +163,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_disabled_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_disabled_vxlan_activeip_bfd.py
index fbf52e88e..0375f39c0 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_disabled_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_disabled_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -163,6 +164,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vlan_none.py
index f592a1ef7..08173223c 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -164,6 +165,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_activeip_bfd.py
index 1acbc1549..fa099d038 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -163,6 +164,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_activeip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_activeip_none.py
index 3410a65c1..860363828 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_activeip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_activeip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -163,6 +164,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_inactiveip_bfd.py
index 0df21e9c1..6e73b526b 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_inactiveip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_inactiveip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -163,6 +164,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_inactiveip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_inactiveip_none.py
index d78a38ac3..38a6e96a4 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_inactiveip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_inactiveip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -163,6 +164,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_unavailableip_bfd.py
index 24a6e5bde..b6e50369b 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_unavailableip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_unavailableip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -163,6 +164,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_unavailableip_none.py
index decef4d50..c3b50b6f2 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_unavailableip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_mirror_redispatch_bypass_vxlan_unavailableip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -163,6 +164,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_no_sni_false_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_no_sni_false_mirror_bypass_vlan_none.py
index a80d9e0b4..e434cb599 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_no_sni_false_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_no_sni_false_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -171,6 +172,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_no_sni_false_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_no_sni_false_steer_bypass_vxlan_activeip_bfd.py
index 7ede22333..856268476 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_no_sni_false_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_no_sni_false_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -169,6 +170,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_activeip_bfd.py
index 022614734..0e91bc1a5 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -156,6 +157,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_activeip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_activeip_none.py
index ca5657df9..2311650fa 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_activeip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_activeip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -156,6 +157,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_inactiveip_bfd.py
index 0c8c057bc..382544851 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_inactiveip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_inactiveip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -150,6 +151,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_inactiveip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_inactiveip_none.py
index 84545124e..005da4999 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_inactiveip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_inactiveip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -156,6 +157,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_unavailableip_bfd.py
index f9704ad26..3c1ad3930 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_unavailableip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_unavailableip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -149,6 +150,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_unavailableip_none.py
index 8c8a824bd..88e6c36af 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_unavailableip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_block_vxlan_unavailableip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -153,6 +154,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py
index 0357d2ae0..6ca695ee0 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -159,6 +160,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_none.py
index 912659de2..3c2085ab8 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -156,6 +157,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_inactiveip_bfd.py
index 98d4f5fb9..6a018240f 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_inactiveip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_inactiveip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -150,6 +151,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_inactiveip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_inactiveip_none.py
index 4745af726..1894cd46e 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_inactiveip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_inactiveip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -156,6 +157,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_unavailableip_bfd.py
index c2c3e1063..5d9539bde 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_unavailableip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_unavailableip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -147,6 +148,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_unavailableip_none.py
index 39270ccb7..571e948c1 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_unavailableip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_bypass_vxlan_unavailableip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -154,6 +155,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_activeip_bfd.py
index 08690d28f..5c3efe0ce 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -154,6 +155,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_activeip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_activeip_none.py
index eea66beb3..00d616a64 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_activeip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_activeip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -159,6 +160,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_inactiveip_bfd.py
index 969c0d1f4..34d241f13 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_inactiveip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_inactiveip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -153,6 +154,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_inactiveip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_inactiveip_none.py
index a37957db9..4b2e56597 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_inactiveip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_inactiveip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -159,6 +160,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_unavailableip_bfd.py
index ffff12be7..2f78d7e05 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_unavailableip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_unavailableip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -154,6 +155,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_unavailableip_none.py
index 80384cbf2..2b90918b7 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_unavailableip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_block_vxlan_unavailableip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -156,6 +157,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_activeip_bfd.py
index 0bad09896..c7cd6522e 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -154,6 +155,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_activeip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_activeip_none.py
index 4553c35f5..27ad46a83 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_activeip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_activeip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -160,6 +161,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_inactiveip_bfd.py
index 38ac9db30..98cfbe356 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_inactiveip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_inactiveip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -154,6 +155,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_inactiveip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_inactiveip_none.py
index 34c909844..6a4baa2d8 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_inactiveip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_inactiveip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -160,6 +161,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_unavailableip_bfd.py
index 65945707e..2e064ea51 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_unavailableip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_unavailableip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -156,6 +157,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_unavailableip_none.py
index e5ed85cca..1325255a4 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_unavailableip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_fqdn_ssl_steer_redispatch_bypass_vxlan_unavailableip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -157,6 +158,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ftp_account_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_ftp_account_mirror_bypass_vlan_none.py
index 4c9e15407..0f0afbff0 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_ftp_account_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_ftp_account_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -156,6 +157,10 @@ def run(parameter):
{"query_field_key": "received_bytes", "query_value": ""}
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ftp_account_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_ftp_account_steer_bypass_vxlan_activeip_bfd.py
index 1ac4c66c0..f5e5000e1 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_ftp_account_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_ftp_account_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -153,6 +154,10 @@ def run(parameter):
{"query_field_key": "received_bytes", "query_value": ""}
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ipprototcp_ftp_account_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_ipprototcp_ftp_account_steer_bypass_vxlan_activeip_bfd.py
index 798523248..5b3008433 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_ipprototcp_ftp_account_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_ipprototcp_ftp_account_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -166,6 +167,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ipprotoudp_dns_qname_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_ipprotoudp_dns_qname_steer_bypass_vxlan_activeip_bfd.py
index 333bb7e2a..636ebfcf7 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_ipprotoudp_dns_qname_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_ipprotoudp_dns_qname_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -170,6 +171,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_mail_from_to_account_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_mail_from_to_account_mirror_bypass_vlan_none.py
index f8754b728..6b8a04f50 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_mail_from_to_account_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_mail_from_to_account_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -196,6 +197,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_mail_from_to_account_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_mail_from_to_account_steer_bypass_vxlan_activeip_bfd.py
index ce271e71d..47f0132f5 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_mail_from_to_account_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_mail_from_to_account_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -190,6 +191,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_mirror_block_vxlan_activeip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_mirror_block_vxlan_activeip_none.py
index 924e4cd17..958f9d464 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_mirror_block_vxlan_activeip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_mirror_block_vxlan_activeip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -128,6 +129,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_disabled_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_disabled_vxlan_activeip_bfd.py
index d1f6ace49..0de1ea85a 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_disabled_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_disabled_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -126,6 +127,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_vxlan_activeip_bfd.py
index c571a7dae..02e32ffdb 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -126,6 +127,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_vxlan_activeip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_vxlan_activeip_none.py
index 16fa2dd4d..10e17a811 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_vxlan_activeip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_mirror_bypass_vxlan_activeip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -128,6 +129,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_multiple_port_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_multiple_port_mirror_bypass_vlan_none.py
index 93d7c0b5e..161763025 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_multiple_port_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_multiple_port_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -202,6 +203,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_negate_dstport_dns_qname_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_negate_dstport_dns_qname_mirror_bypass_vlan_none.py
index e072b6466..97a8658fb 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_negate_dstport_dns_qname_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_negate_dstport_dns_qname_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -179,6 +180,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_negate_dstport_dns_qname_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_negate_dstport_dns_qname_steer_bypass_vxlan_activeip_bfd.py
index 45bc32dcc..b8e21aa4a 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_negate_dstport_dns_qname_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_negate_dstport_dns_qname_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -178,6 +179,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_negate_fqdn_ssl_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_negate_fqdn_ssl_mirror_bypass_vlan_none.py
index b15c0530b..213a850fb 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_negate_fqdn_ssl_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_negate_fqdn_ssl_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -160,6 +161,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_negate_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_negate_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py
index 29521daf9..cf1784660 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_negate_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_negate_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -159,6 +160,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_openvpn_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_openvpn_mirror_bypass_vlan_none.py
index 27fe9a664..53261ba5a 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_openvpn_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_openvpn_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -142,6 +143,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_openvpn_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_openvpn_steer_bypass_vxlan_activeip_bfd.py
index d31d4b860..948714645 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_openvpn_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_openvpn_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -142,6 +143,10 @@ def run(parameter):
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_quic_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_quic_mirror_bypass_vlan_none.py
index d7ebb6549..7faee998e 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_quic_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_quic_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -141,6 +142,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_quic_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_quic_steer_bypass_vxlan_activeip_bfd.py
index d6bb46894..fbda86344 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_quic_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_quic_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -140,6 +141,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_rdp_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_rdp_mirror_bypass_vlan_none.py
index 9382fee7a..d372a6410 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_rdp_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_rdp_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -142,6 +143,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_rdp_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_rdp_steer_bypass_vxlan_activeip_bfd.py
index d32711cf5..44dd02739 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_rdp_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_rdp_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -141,6 +142,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_esni_true_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_esni_true_mirror_bypass_vlan_none.py
index 6bd4ed4a1..e82792c19 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_esni_true_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_esni_true_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -153,6 +154,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_esni_true_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_esni_true_steer_bypass_vxlan_activeip_bfd.py
index f521b6bb4..26befb1bd 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_esni_true_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_esni_true_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -152,6 +153,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vlan_none.py
index ba731db8b..f98a5f03a 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -140,6 +141,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_activeip_bfd.py
index cc7f10b6a..df5879375 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -132,6 +133,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_activeip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_activeip_none.py
index 98e043666..e4593b2ec 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_activeip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_activeip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -138,6 +139,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_inactiveip_bfd.py
index aab19f1d1..792142197 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_inactiveip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_inactiveip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -132,6 +133,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_inactiveip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_inactiveip_none.py
index 4c2042a5d..3b9890c02 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_inactiveip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_inactiveip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -139,6 +140,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_unavailableip_bfd.py
index 5b6d289eb..7feff6364 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_unavailableip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_unavailableip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -129,6 +130,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_unavailableip_none.py
index 3244eb509..ae654951c 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_unavailableip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_block_vxlan_unavailableip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -135,6 +136,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_bypass_disabled_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_bypass_disabled_vlan_none.py
index 946c3bfab..b1b8b80b2 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_bypass_disabled_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_bypass_disabled_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -140,6 +141,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_bypass_vlan_none.py
index e0c607735..47a62945a 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -142,6 +143,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_no_sni_true_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_no_sni_true_mirror_bypass_vlan_none.py
index 622b35aa5..150c2a2b5 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_no_sni_true_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_no_sni_true_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -152,6 +153,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_ssl_no_sni_true_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_ssl_no_sni_true_steer_bypass_vxlan_activeip_bfd.py
index ee5e52b91..f8f468dbc 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_ssl_no_sni_true_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_ssl_no_sni_true_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -151,6 +152,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_steer_bypass_disabled_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_steer_bypass_disabled_vxlan_activeip_bfd.py
index 9d2a8b822..e346053c3 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_steer_bypass_disabled_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_steer_bypass_disabled_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -125,6 +126,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_steer_bypass_vxlan_activeip_bfd.py
index b58461cd6..0ad42aa02 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -122,6 +123,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_compliance_risk_library_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_compliance_risk_library_http_url_steer_bypass_vxlan_activeip_bfd.py
index 785bfe0b9..acad63da3 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_compliance_risk_library_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_compliance_risk_library_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -186,6 +187,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_geoip_asn_library_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_geoip_asn_library_http_url_steer_bypass_vxlan_activeip_bfd.py
index 6391d3706..0e01d187f 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_geoip_asn_library_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_geoip_asn_library_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -193,6 +194,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_internet_geoip_country_library_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_internet_geoip_country_library_http_url_steer_bypass_vxlan_activeip_bfd.py
index 4349ef884..efd548698 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_internet_geoip_country_library_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_internet_geoip_country_library_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -187,6 +188,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_internet_service_library_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_internet_service_library_http_url_steer_bypass_vxlan_activeip_bfd.py
index 47451e393..bfd39826c 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_internet_service_library_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_internet_service_library_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -186,6 +187,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py
index 02805fc65..37e6ba636 100644
--- a/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstip_suff_fqdn_library_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -192,6 +193,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstport_external_port_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstport_external_port_steer_bypass_vxlan_activeip_bfd.py
index 5ff8a247c..26062faaa 100644
--- a/tests/service_chaining/sc_raw_srcip_dstport_external_port_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstport_external_port_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -146,6 +147,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstport_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstport_mirror_bypass_vlan_none.py
index 71b733519..af003a0d9 100644
--- a/tests/service_chaining/sc_raw_srcip_dstport_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstport_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -129,6 +130,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstport_range_external_port_range_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_dstport_range_external_port_range_mirror_bypass_vlan_none.py
index 1a1a11922..7a143c37e 100644
--- a/tests/service_chaining/sc_raw_srcip_dstport_range_external_port_range_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_dstport_range_external_port_range_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -147,6 +148,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dstport_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_dstport_steer_bypass_vxlan_activeip_bfd.py
index 57cd25db7..fa4a13d47 100644
--- a/tests/service_chaining/sc_raw_srcip_dstport_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dstport_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -129,6 +130,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_dtsip_mirror_bypass_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_dtsip_mirror_bypass_vxlan_inactiveip_bfd.py
index 0b08d1e9b..329042e40 100644
--- a/tests/service_chaining/sc_raw_srcip_dtsip_mirror_bypass_vxlan_inactiveip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_dtsip_mirror_bypass_vxlan_inactiveip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -123,6 +124,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_fqdn_ipprototcp_ssl_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_fqdn_ipprototcp_ssl_steer_bypass_vxlan_activeip_bfd.py
index cabfa0226..e4382d78a 100644
--- a/tests/service_chaining/sc_raw_srcip_fqdn_ipprototcp_ssl_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_fqdn_ipprototcp_ssl_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -148,6 +149,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_block_disabled_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_block_disabled_vxlan_activeip_bfd.py
index a1de210c0..2a6063632 100644
--- a/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_block_disabled_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_block_disabled_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -138,6 +139,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_bypass_disabled_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_bypass_disabled_vxlan_activeip_bfd.py
index d5def1442..5aff11594 100644
--- a/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_bypass_disabled_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_bypass_disabled_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -137,6 +138,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_global_bypass_diff_device_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_global_bypass_diff_device_vxlan_activeip_bfd.py
index 99dce68e9..9307b0388 100644
--- a/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_global_bypass_diff_device_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_global_bypass_diff_device_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -135,6 +136,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_nearby_bypass_diff_device_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_nearby_bypass_diff_device_vxlan_activeip_bfd.py
index 28f5fa232..84f6028bc 100644
--- a/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_nearby_bypass_diff_device_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_fqdn_ssl_steer_nearby_bypass_diff_device_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -134,6 +135,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_internal_port_range_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_internal_port_range_mirror_bypass_vlan_none.py
index 518703277..f86ed8041 100644
--- a/tests/service_chaining/sc_raw_srcip_internal_port_range_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_internal_port_range_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -129,6 +130,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_internal_port_range_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_internal_port_range_steer_bypass_vxlan_activeip_bfd.py
index c72f9da73..b6af6f70b 100644
--- a/tests/service_chaining/sc_raw_srcip_internal_port_range_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_internal_port_range_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -128,6 +129,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_inactiveip_bfd.py
index 1239686f3..a8d398f6b 100644
--- a/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_inactiveip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_inactiveip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -111,6 +112,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_inactiveip_none.py b/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_inactiveip_none.py
index 7c37f1a23..362839fa5 100644
--- a/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_inactiveip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_inactiveip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -49,34 +50,6 @@ def run(parameter):
]
}
],
- "log_query_param": [{"query_field_key": "sc_rsp_raw_uuid_list", "query_value": ""},
- {"query_field_key": "sent_pkts", "query_value": ""},
- {"query_field_key": "received_pkts", "query_value": ""},
- {"query_field_key": "sent_bytes", "query_value": ""},
- {"query_field_key": "received_bytes", "query_value": ""}],
- "traffic":{
- "protocol": "",
- "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"
- },
- "expected_return":"",
- "token": ""
- }
-
- # 测试用例实例化
- create = CreatePolicy(test_data, parameter)
- result = create.create_policy()
-
- # 脚本结束时间和耗时
- script_end_time = time.time()
- duration = script_end_time - script_start_time
"action_parameter": {
"targeted_traffic": "raw",
"sff_profiles":
@@ -139,6 +112,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_unavailableip_bfd.py
index 0796b2ae3..95bf52c03 100644
--- a/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_unavailableip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_unavailableip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -111,6 +112,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_unavailableip_none.py
index ff4d83a29..cbf2fc262 100644
--- a/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_unavailableip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_mirror_block_vxlan_unavailableip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -111,6 +112,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_mirror_bypass_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_mirror_bypass_vxlan_unavailableip_bfd.py
index 21c239b74..81e5f2d04 100644
--- a/tests/service_chaining/sc_raw_srcip_mirror_bypass_vxlan_unavailableip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_mirror_bypass_vxlan_unavailableip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -109,6 +110,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_mirror_redispatch_block_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_mirror_redispatch_block_vxlan_inactiveip_bfd.py
index b3a3cd4fe..34e21d886 100644
--- a/tests/service_chaining/sc_raw_srcip_mirror_redispatch_block_vxlan_inactiveip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_mirror_redispatch_block_vxlan_inactiveip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -114,6 +115,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_negate_dstip_fqdn_ssl_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_negate_dstip_fqdn_ssl_mirror_bypass_vlan_none.py
index 963effa70..aca432558 100644
--- a/tests/service_chaining/sc_raw_srcip_negate_dstip_fqdn_ssl_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_negate_dstip_fqdn_ssl_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -160,6 +161,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_negate_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_negate_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py
index b067508a2..38f7198cf 100644
--- a/tests/service_chaining/sc_raw_srcip_negate_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_negate_dstip_fqdn_ssl_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -159,6 +160,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_negate_srcport_range_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcip_negate_srcport_range_mirror_bypass_vlan_none.py
index 6289c09be..80d370416 100644
--- a/tests/service_chaining/sc_raw_srcip_negate_srcport_range_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcip_negate_srcport_range_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -129,6 +130,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_negate_srcport_range_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcip_negate_srcport_range_steer_bypass_vxlan_activeip_bfd.py
index 6289c09be..80d370416 100644
--- a/tests/service_chaining/sc_raw_srcip_negate_srcport_range_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_negate_srcport_range_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -129,6 +130,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_inactiveip_bfd.py
index 922b9b7b1..ca411aa34 100644
--- a/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_inactiveip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_inactiveip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -109,6 +110,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_inactiveip_none.py b/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_inactiveip_none.py
index 4d2a217b7..5e924f61b 100644
--- a/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_inactiveip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_inactiveip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -109,6 +110,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_unavailableip_bfd.py
index 2a27a9074..c08ee9e43 100644
--- a/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_unavailableip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_unavailableip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -109,6 +110,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_unavailableip_none.py
index 9eeb54d65..831ec6f24 100644
--- a/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_unavailableip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_steer_block_vxlan_unavailableip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -109,6 +110,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_inactiveip_bfd.py
index 1e35d2473..27f65e295 100644
--- a/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_inactiveip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_inactiveip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -109,6 +110,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_unavailableip_bfd.py b/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_unavailableip_bfd.py
index 8e6baae47..9e93d803f 100644
--- a/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_unavailableip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_unavailableip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -109,6 +110,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_unavailableip_none.py b/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_unavailableip_none.py
index d08c0e521..63e2158a0 100644
--- a/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_unavailableip_none.py
+++ b/tests/service_chaining/sc_raw_srcip_steer_bypass_vxlan_unavailableip_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -109,6 +110,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_steer_redispatch_block_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_steer_redispatch_block_vxlan_inactiveip_bfd.py
index 89227bb76..05a79daf2 100644
--- a/tests/service_chaining/sc_raw_srcip_steer_redispatch_block_vxlan_inactiveip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_steer_redispatch_block_vxlan_inactiveip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -112,6 +113,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcip_steer_redispatch_bypass_vxlan_inactiveip_bfd.py b/tests/service_chaining/sc_raw_srcip_steer_redispatch_bypass_vxlan_inactiveip_bfd.py
index d88a0e352..ba83b5397 100644
--- a/tests/service_chaining/sc_raw_srcip_steer_redispatch_bypass_vxlan_inactiveip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcip_steer_redispatch_bypass_vxlan_inactiveip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -113,6 +114,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcport_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcport_mirror_bypass_vlan_none.py
index b5f98eb92..4ce9c1645 100644
--- a/tests/service_chaining/sc_raw_srcport_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcport_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -109,6 +110,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcport_range_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_srcport_range_mirror_bypass_vlan_none.py
index 820addc6e..c4665b2cd 100644
--- a/tests/service_chaining/sc_raw_srcport_range_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_srcport_range_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -109,6 +110,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcport_range_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcport_range_steer_bypass_vxlan_activeip_bfd.py
index 59abc58a8..88cee1429 100644
--- a/tests/service_chaining/sc_raw_srcport_range_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcport_range_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -116,6 +117,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_srcport_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_srcport_steer_bypass_vxlan_activeip_bfd.py
index b9fd9a3a0..f47cbda65 100644
--- a/tests/service_chaining/sc_raw_srcport_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_srcport_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -104,6 +105,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_subid_fqdn_http_url_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_subid_fqdn_http_url_mirror_bypass_vlan_none.py
index 03cdc09f1..32a569bdc 100644
--- a/tests/service_chaining/sc_raw_subid_fqdn_http_url_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_subid_fqdn_http_url_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -160,6 +161,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_subid_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_subid_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index cc9615c0f..4d6e7dbf1 100644
--- a/tests/service_chaining/sc_raw_subid_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_subid_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -159,6 +160,10 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_subid_imei_apn_fqdn_http_url_mirror_bypass_vlan_none.py b/tests/service_chaining/sc_raw_subid_imei_apn_fqdn_http_url_mirror_bypass_vlan_none.py
index 18010cc91..7980fae90 100644
--- a/tests/service_chaining/sc_raw_subid_imei_apn_fqdn_http_url_mirror_bypass_vlan_none.py
+++ b/tests/service_chaining/sc_raw_subid_imei_apn_fqdn_http_url_mirror_bypass_vlan_none.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -197,6 +198,14 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/service_chaining/sc_raw_subid_imei_apn_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py b/tests/service_chaining/sc_raw_subid_imei_apn_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
index 14333cffa..8fb783200 100644
--- a/tests/service_chaining/sc_raw_subid_imei_apn_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
+++ b/tests/service_chaining/sc_raw_subid_imei_apn_fqdn_http_url_steer_bypass_vxlan_activeip_bfd.py
@@ -8,6 +8,7 @@ from support.ui_utils.workpath import workdir
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.organize_config import OrganizeConfig
from support.report_update import ReportUpdate
def run(parameter):
@@ -196,6 +197,174 @@ def run(parameter):
]
}
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
+ # 替换condition中的ip为随机ip
+ organize_config = OrganizeConfig(parameter, policy_configuration, api_client.token, ())
+ organize_config.generate_random_ip(parameter, policy_configuration, traffic_generation)
+
# 创建
if parameter["initiation_method"] == "ui":
ui_client = UIClient()
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_app.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_app.py
index ae21c4e3e..9849640d6 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_app.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_app.py
@@ -1,201 +1,326 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": "default name",
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": ["app"],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by Application",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "app"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -204,4 +329,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_app_appcategories.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_app_appcategories.py
index 3bad04ecf..ad40af06e 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_app_appcategories.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_app_appcategories.py
@@ -1,204 +1,340 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "app",
- "app_category"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by Application, Application Category",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "app"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "app_category"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application Category",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -207,4 +343,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_appcategories.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_appcategories.py
index 276da9d80..5930e5d2b 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_appcategories.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_appcategories.py
@@ -1,203 +1,326 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "app_category"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -206,4 +329,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c2s_link_id.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c2s_link_id.py
index cede88712..4038491cf 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c2s_link_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c2s_link_id.py
@@ -1,201 +1,326 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": "default name",
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": ["s2c_link_id"],
- "order_by": "all flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -204,4 +329,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c2s_s2c_link_id.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c2s_s2c_link_id.py
index 0dea223da..30b344b86 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c2s_s2c_link_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c2s_s2c_link_id.py
@@ -1,204 +1,340 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "c2s_link_id",
- "s2c_link_id"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by Client-to-Server Link ID, Server-to-Client 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": [
+ "s2c_link_id"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server-to-Client Link ID",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -207,4 +343,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c2s_s2c_ttl.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c2s_s2c_ttl.py
index 2c745d32d..d8049db91 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c2s_s2c_ttl.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c2s_s2c_ttl.py
@@ -1,204 +1,340 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": "stats_http_table_all_flows_dim_c2s_s2c_ttl",
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "c2s_ttl",
- "s2c_ttl"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by Client-to-Server TTL, Server-to-Client 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": [
+ "s2c_ttl"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server-to-Client TTL",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -207,4 +343,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c2s_ttl.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c2s_ttl.py
index a177631a7..27ab8eb40 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c2s_ttl.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c2s_ttl.py
@@ -1,201 +1,326 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": "default name",
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": ["c2s_ttl"],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -204,4 +329,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_country.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_country.py
index c55573f90..9047c531b 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_country.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_country.py
@@ -1,203 +1,326 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "client_ip"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -206,4 +329,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_ip.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_ip.py
index c55573f90..2c47828e8 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_ip.py
@@ -1,203 +1,326 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "client_ip"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -206,4 +329,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_ip_object.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_ip_object.py
index 2b29b79fa..6faa07309 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_ip_object.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_ip_object.py
@@ -1,205 +1,326 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.6",
- },
- ]
- }
- ],
- "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.6",
- },
- ]
- }],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "client_ip_object_list"
- ],
- "order_by": "new c2s flows",
- "row_limit": "10",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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": 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)
"""
@@ -208,4 +329,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_port.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_port.py
index 05c2a9fb1..2c47828e8 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_port.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_port.py
@@ -1,203 +1,326 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "new_c2s_flows_for_this_rule:RATE:new c2s flows",
- "new_s2c_flows_for_this_rule:RATE:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:RATE:all flows"
- ],
- "dimensions": [
- "client_port"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -206,4 +329,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_country.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_country.py
index 394c1fa49..b46800872 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_country.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_country.py
@@ -1,204 +1,340 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "client_country",
- "server_country"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by Client Country, Server 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": [
+ "server_country"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server Country",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -207,4 +343,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_country_app.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_country_app.py
index 6d7b4a78e..ec3ad0ad3 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_country_app.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_country_app.py
@@ -1,205 +1,354 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "client_country",
- "server_country",
- "app"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by Client Country, Server Country, Application",
+ "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": [
+ "server_country"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server Country",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "app"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -208,4 +357,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_ip.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_ip.py
index 307700fa8..b3680afb7 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_ip.py
@@ -1,204 +1,340 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "client_ip",
- "server_ip"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by Client IP, Server 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": [
+ "server_ip"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server IP",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -207,4 +343,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_ip_object.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_ip_object.py
index 436e9f1f1..42f922b0f 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_ip_object.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_ip_object.py
@@ -1,206 +1,340 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.6",
- },
- ]
- }
- ],
- "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.6",
- },
- ]
- }],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "client_ip_object_list",
- "server_ip_object_list"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by Client IP Object List, Server 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": [
+ "server_ip_object_list"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server IP Object List",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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": 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)
"""
@@ -209,4 +343,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_port.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_port.py
index 9e30391d9..b26bcca43 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_port.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_c_s_port.py
@@ -1,204 +1,340 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "client_port",
- "server_port"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by Client Port, Server 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": [
+ "server_port"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server Port",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -207,4 +343,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_decoded_as.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_decoded_as.py
index 9871f18a0..eafc3d656 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_decoded_as.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_decoded_as.py
@@ -1,203 +1,326 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "decoded_as"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -206,4 +329,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_device_group.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_device_group.py
index 2de729f54..633e2e028 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_device_group.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_device_group.py
@@ -1,203 +1,326 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "device_group"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -206,4 +329,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_domain.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_domain.py
index 41a5fa927..692e7c4fe 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_domain.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_domain.py
@@ -1,203 +1,326 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "server_fqdn"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -206,4 +329,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_flags.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_flags.py
index f916f46fd..b1f1f7217 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_flags.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_flags.py
@@ -1,203 +1,326 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "flags"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by Flags",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "flags"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Flags",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -206,4 +329,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_fqdn.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_fqdn.py
index e070bc5a5..e288de633 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_fqdn.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_fqdn.py
@@ -1,203 +1,326 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "server_domain"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -206,4 +329,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_fqdn_domain.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_fqdn_domain.py
index f522fe3ed..cd0a4411e 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_fqdn_domain.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_fqdn_domain.py
@@ -1,204 +1,340 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "server_fqdn",
- "server_domain"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by Server FQDN, Server Domain",
+ "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": [
+ "server_domain"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server Domain",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -207,4 +343,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_http_host.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_http_host.py
index 572e2211f..b29563a9c 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_http_host.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_http_host.py
@@ -1,203 +1,326 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "http_host"
- ],
- "order_by": "new s2c flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -206,4 +329,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s2c_link_id.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s2c_link_id.py
index cede88712..6fa62a5d1 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s2c_link_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s2c_link_id.py
@@ -1,201 +1,326 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": "default name",
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": ["s2c_link_id"],
- "order_by": "all flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -204,4 +329,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s2c_ttl.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s2c_ttl.py
index b1a5fc5dd..6ba97fd20 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s2c_ttl.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s2c_ttl.py
@@ -1,201 +1,326 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": "default name",
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": ["s2c_ttl"],
- "order_by": "all flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -204,4 +329,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s_country.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s_country.py
index c55573f90..492a47431 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s_country.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s_country.py
@@ -1,203 +1,326 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "client_ip"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -206,4 +329,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s_ip.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s_ip.py
index f5c388136..323c727bf 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s_ip.py
@@ -1,203 +1,326 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "server_ip"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -206,4 +329,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s_ip_object.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s_ip_object.py
index 2d2d629dc..6b9bbb9fb 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s_ip_object.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s_ip_object.py
@@ -1,205 +1,326 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.6",
- },
- ]
- }
- ],
- "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.6",
- },
- ]
- }],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": parameter["test_case_name"].replace("_srcip_dstip", "", 1),
- "visualization_type": "table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "server_ip_object_list"
- ],
- "order_by": "new c2s flows",
- "row_limit": "20",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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": 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)
"""
@@ -208,4 +329,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s_port.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s_port.py
index 12024a364..5c22fb3ba 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s_port.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_s_port.py
@@ -1,203 +1,326 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "server_port"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -206,4 +329,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_sled_ip.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_sled_ip.py
index dcb4f4cfc..f5c1dc24b 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_sled_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_sled_ip.py
@@ -1,203 +1,326 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "sled_ip"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -206,4 +329,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_sub_id.py b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_sub_id.py
index 449e838c6..84a081587 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_sub_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_flows_dim_sub_id.py
@@ -1,203 +1,326 @@
# -*- 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)
+ 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": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "10.64.224.31",
- },
- ]
- }
- ],
- "source_port": [],
- "destination_ip": [
- {
- "name": parameter["test_case_name"].replace("_srcip", "", 1),
- "object_type": "ip",
- "select_type": False,
- "negate": False,
- "item": [
- {
- "item_operation": "add",
- "item_type": "ipv4",
- "item_value": "2.1.1.6",
- },
- ]
- }],
- "destination_port": [],
- "internal_ip": [],
- "internal_port": [],
- "external_ip": [],
- "external_port": [],
- "source_geography": [],
- "destination_geography": [],
- "sub_id": [],
- "device": [],
- "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": [
+ policy_configuration = {
+ "name": parameter["test_case_name"],
+ "type": "statistics",
+ "action": "statistics",
+ "and_conditions": [
+ {
+ "negate_option": False,
+ "or_conditions": [
{
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "new_c2s_flows_for_this_rule:SUM:new c2s flows",
- "new_s2c_flows_for_this_rule:SUM:new s2c flows",
- "new_c2s_flows_for_this_rule+new_s2c_flows_for_this_rule:SUM:all flows"
- ],
- "dimensions": [
- "subscriber_id"
- ],
- "order_by": "new c2s flows",
- "row_limit": "1000",
- "min_in_size": "1",
- "min_out_size": "1"
+ "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"
+ }
+ ]
}
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.6",
- "clients_end_ip": "10.64.224.6",
- "servers_start_ip": "2.1.1.6",
- "servers_end_ip": "2.1.1.6",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
+ ]
+ },
+ {
+ "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": [
+ {
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(New Client-to-Server Flows, New Server-to-Client Flows), SUM(New Client-to-Server Flows) and SUM(New Server-to-Client Flows) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "metrics": [
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule",
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_1",
+ "label": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_c2s_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(New Client-to-Server Flows)",
+ "unit": "flows"
+ },
+ {
+ "source_fields": [
+ "new_s2c_flows_for_this_rule"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(New Server-to-Client Flows)",
+ "unit": "flows"
+ }
+ ],
+ "order_by": "SUM(New Client-to-Server Flows, New Server-to-Client Flows)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
+ ]
+ },
+ "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)
"""
@@ -206,4 +329,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_app.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_app.py
index 1e42bd26a..3ea77c9e1 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_app.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_app.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by Application",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "app"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by Application",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "app"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "app"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "app"
- ],
- "order_by": "Packets",
- "row_limit": "5",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"app": "123","app_category": "234", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_app_appcategory.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_app_appcategory.py
index 6d1676c35..26b59210d 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_app_appcategory.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_app_appcategory.py
@@ -1,224 +1,444 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by Application, Application Category",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "app"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "app_category"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application Category",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by Application, Application Category",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "app"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "app_category"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application Category",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "app",
- "app_category"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "app",
- "app_category"
- ],
- "order_by": "Packets Received",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"app": "123","app_category": "234", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -227,4 +447,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_app_c_s_country.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_app_c_s_country.py
index 0e83026ac..d85ad7f2a 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_app_c_s_country.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_app_c_s_country.py
@@ -1,226 +1,472 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by Application, Client Country, Server Country",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "app"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "client_country"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Client Country",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "server_country"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server Country",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by Application, Client Country, Server Country",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "app"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "client_country"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Client Country",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "server_country"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server Country",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "app",
- "client_country",
- "server_country"
- ],
- "order_by": "Packets",
- "row_limit": "1000",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "app",
- "client_country",
- "server_country"
- ],
- "order_by": "Packets Sent",
- "row_limit": "500",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"app": "123","app_category": "234", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -229,4 +475,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_app_fqdn.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_app_fqdn.py
index 5afe2a2e7..8715f526e 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_app_fqdn.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_app_fqdn.py
@@ -1,224 +1,444 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by Application, Server FQDN",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "app"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "server_fqdn"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server FQDN",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by Application, Server FQDN",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "app"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "server_fqdn"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server FQDN",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "app",
- "server_fqdn"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "app",
- "server_fqdn"
- ],
- "order_by": "Packets Received",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"app": "123","app_category": "234", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -227,4 +447,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_appcategory.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_appcategory.py
index 896c8b3a9..5ae1b58cf 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_appcategory.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_appcategory.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "app_category"
- ],
- "order_by": "Packets",
- "row_limit": "500",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "app_category"
- ],
- "order_by": "Packets",
- "row_limit": "200",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"app": "123","app_category": "234", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c2s_link_id.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c2s_link_id.py
index 31095eae7..cb510e20f 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c2s_link_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c2s_link_id.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "c2s_link_id"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "c2s_link_id"
- ],
- "order_by": "Packets Received",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"c2s_link_id": "702","s2c_link_id": "702", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c2s_s2c_link_id.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c2s_s2c_link_id.py
index 6fb8c32d2..3244ce3ce 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c2s_s2c_link_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c2s_s2c_link_id.py
@@ -1,224 +1,444 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by Client-to-Server Link ID, Server-to-Client 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": [
+ "s2c_link_id"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server-to-Client Link ID",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by Client-to-Server Link ID, Server-to-Client 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": [
+ "s2c_link_id"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server-to-Client Link ID",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "c2s_link_id",
- "s2c_link_id"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "c2s_link_id",
- "s2c_link_id"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"c2s_link_id": "702","s2c_link_id": "702", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -227,4 +447,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c2s_s2c_ttl.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c2s_s2c_ttl.py
index 602151613..7c1a928c6 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c2s_s2c_ttl.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c2s_s2c_ttl.py
@@ -1,224 +1,444 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by Client-to-Server TTL, Server-to-Client 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": [
+ "s2c_ttl"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server-to-Client TTL",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by Client-to-Server TTL, Server-to-Client 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": [
+ "s2c_ttl"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server-to-Client TTL",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "c2s_ttl",
- "s2c_ttl"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "c2s_ttl",
- "s2c_ttl"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"c2s_ttl": "60","s2c_ttl": "20", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -227,4 +447,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c2s_ttl.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c2s_ttl.py
index b65f57bfe..1d2bbfcc3 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c2s_ttl.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c2s_ttl.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "c2s_ttl"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "c2s_ttl"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"c2s_ttl": "60","s2c_ttl": "20", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_country.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_country.py
index 65effc4c7..146d29ae0 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_country.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_country.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "client_country"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "client_country"
- ],
- "order_by": "Packets",
- "row_limit": "5",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"app": "123","app_category": "234", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_ip.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_ip.py
index 839376bb7..3f9f0bb42 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_ip.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "client_ip"
- ],
- "order_by": "Packets",
- "row_limit": "200",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "client_ip"
- ],
- "order_by": "Packets",
- "row_limit": "500",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"app": "123","app_category": "234", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_ip_object.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_ip_object.py
index dbd65126d..43d5849c4 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_ip_object.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_ip_object.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "client_ip_object_list"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "client_ip_object_list"
- ],
- "order_by": "Packets",
- "row_limit": "5",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"app": "123","app_category": "234", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_port.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_port.py
index e50349c9d..85d6fd1f4 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_port.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_port.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "client_port"
- ],
- "order_by": "Packets",
- "row_limit": "20",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "client_port"
- ],
- "order_by": "Packets",
- "row_limit": "50",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"app": "123","app_category": "234", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_s_country_app_appcategory.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_s_country_app_appcategory.py
index 95768fac3..a9885f3b8 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_s_country_app_appcategory.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_s_country_app_appcategory.py
@@ -1,228 +1,500 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by Client Country, Server Country, Application, Application Category",
+ "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": [
+ "server_country"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server Country",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "app"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "app_category"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application Category",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by Client Country, Server Country, Application, Application Category",
+ "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": [
+ "server_country"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server Country",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "app"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application",
+ "is_drill_down": 0
+ },
+ {
+ "source_fields": [
+ "app_category"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application Category",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "app",
- "app_category",
- "client_country",
- "server_country"
- ],
- "order_by": "Packets",
- "row_limit": "1000",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "app",
- "app_category",
- "client_country",
- "server_country"
- ],
- "order_by": "Packets Sent",
- "row_limit": "500",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"app": "123","app_category": "234", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -231,4 +503,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_s_ip.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_s_ip.py
index 7e4ff608b..cd13e1ac9 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_s_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_s_ip.py
@@ -1,224 +1,444 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by Client IP, Server 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": [
+ "server_ip"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server IP",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by Client IP, Server 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": [
+ "server_ip"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server IP",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "client_ip",
- "server_ip"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "client_ip",
- "server_ip"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"client_ip": "1.1.1.1","server_ip": "2.2.2.2", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -227,4 +447,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_s_ip_objects.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_s_ip_objects.py
index 69c479ccb..60bb702df 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_s_ip_objects.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_s_ip_objects.py
@@ -1,226 +1,444 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by Client IP Object List, Server 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": [
+ "server_ip_object_list"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server IP Object List",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by Client IP Object List, Server 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": [
+ "server_ip_object_list"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server IP Object List",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "client_ip_object_list",
- "server_ip_object_list"
- ],
- "order_by": "pkts",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "client_ip_object_list",
- "server_ip_object_list"
- ],
- "order_by": "pkts",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"client_ip_object_list": "1573552","server_ip_object_list": "1573552", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -229,4 +447,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_s_port.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_s_port.py
index 257a6f902..f73d784fa 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_s_port.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_c_s_port.py
@@ -1,224 +1,444 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by Client Port, Server 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": [
+ "server_port"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server Port",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by Client Port, Server 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": [
+ "server_port"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server Port",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "client_port",
- "server_port"
- ],
- "order_by": "Packets",
- "row_limit": "1000",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "client_port",
- "server_port"
- ],
- "order_by": "Packets",
- "row_limit": "100",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"server_port": "80", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -227,4 +447,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_decoded_as.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_decoded_as.py
index f13c4db68..0d637a8a5 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_decoded_as.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_decoded_as.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "decoded_as"
- ],
- "order_by": "Packets",
- "row_limit": "1000",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "decoded_as"
- ],
- "order_by": "Packets",
- "row_limit": "500",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"c2s_ttl": "60","s2c_ttl": "20", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_device_group.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_device_group.py
index 1856466a3..22850e1e4 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_device_group.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_device_group.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.25",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "device_group"
- ],
- "order_by": "Packets",
- "row_limit": "500",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "device_group"
- ],
- "order_by": "Packets",
- "row_limit": "500",
- "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.25",
- "clients_end_ip": "10.64.224.25",
- "servers_start_ip": "2.1.1.25",
- "servers_end_ip": "2.1.1.25",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"device_group": "tsgx", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_device_group_decoded_as.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_device_group_decoded_as.py
index 1791895b2..c667ea316 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_device_group_decoded_as.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_device_group_decoded_as.py
@@ -1,224 +1,444 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by Device Group, Decoded AS",
+ "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": [
+ "decoded_as"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Decoded AS",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by Device Group, Decoded AS",
+ "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": [
+ "decoded_as"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Decoded AS",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "decoded_as",
- "device_group"
- ],
- "order_by": "Packets",
- "row_limit": "1000",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "decoded_as",
- "device_group"
- ],
- "order_by": "Packets",
- "row_limit": "500",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"c2s_ttl": "60","s2c_ttl": "20", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -227,4 +447,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_direction.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_direction.py
index d1d3193f2..fa896e237 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_direction.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_direction.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by Direction",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "direction"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Direction",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by Direction",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "direction"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Direction",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "direction"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "direction"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"server_port": "80", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_domain.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_domain.py
index c0c3a822f..991f968a1 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_domain.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_domain.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "server_domain"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "server_domain"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"server_port": "80", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_flags.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_flags.py
index 2d2a2ebbc..3e7955dac 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_flags.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_flags.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by Flags",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "flags"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Flags",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by Flags",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "flags"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Flags",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "flags"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "flags"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"server_port": "80", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_fqdn.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_fqdn.py
index f950ba8cc..c894e256c 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_fqdn.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_fqdn.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "server_fqdn"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "server_fqdn"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"app": "123","app_category": "234", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_fqdn_domain.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_fqdn_domain.py
index 606102b98..4695adc81 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_fqdn_domain.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_fqdn_domain.py
@@ -1,224 +1,444 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by Server FQDN, Server Domain",
+ "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": [
+ "server_domain"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server Domain",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by Server FQDN, Server Domain",
+ "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": [
+ "server_domain"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server Domain",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "server_fqdn",
- "server_domain"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "server_fqdn",
- "server_domain"
- ],
- "order_by": "Packets Received",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"server_fqdm": "www.yumi.com", "server_domain": "yumi.com", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -227,4 +447,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_http_host.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_http_host.py
index f1b13210f..866048cce 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_http_host.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_http_host.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "http_host"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "http_host"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"app": "123","app_category": "234", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s2c_link_id.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s2c_link_id.py
index 01cea3914..f418c8bd4 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s2c_link_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s2c_link_id.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "s2c_link_id"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "s2c_link_id"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"c2s_link_id": "702","s2c_link_id": "702", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s2c_ttl.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s2c_ttl.py
index 49c03ff7c..b70eb88da 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s2c_ttl.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s2c_ttl.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "s2c_ttl"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "s2c_ttl"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"c2s_ttl": "60","s2c_ttl": "20", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_country.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_country.py
index e89ca41f0..15b0ed3ed 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_country.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_country.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "server_country"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "server_country"
- ],
- "order_by": "Packets",
- "row_limit": "5",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"app": "123","app_category": "234", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_ip.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_ip.py
index 48c338cf7..f37c2c94b 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_ip.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "server_ip"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "server_ip"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"client_ip": "1.1.1.1","server_ip": "2.2.2.2", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_ip_app.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_ip_app.py
index 4285f7e97..e2c911433 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_ip_app.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_ip_app.py
@@ -1,224 +1,444 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by Server IP, Application",
+ "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": [
+ "app"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by Server IP, Application",
+ "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": [
+ "app"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "app",
- "server_ip"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "app",
- "server_ip"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"client_ip": "1.1.1.1","server_ip": "2.2.2.2", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -227,4 +447,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_ip_fqdn.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_ip_fqdn.py
index 2308f9c86..931dc5592 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_ip_fqdn.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_ip_fqdn.py
@@ -1,224 +1,444 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by Server IP, Server FQDN",
+ "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": [
+ "server_fqdn"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server FQDN",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by Server IP, Server FQDN",
+ "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": [
+ "server_fqdn"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Server FQDN",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "server_ip",
- "server_fqdn"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "server_ip",
- "server_fqdn"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"client_ip": "1.1.1.1","server_ip": "2.2.2.2", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -227,4 +447,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_ip_object.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_ip_object.py
index 82452af74..9764c1abe 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_ip_object.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_ip_object.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "server_ip_object_list"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "server_ip_object_list"
- ],
- "order_by": "Packets",
- "row_limit": "10",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"client_ip": "1.1.1.1","server_ip": "2.2.2.2", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_port.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_port.py
index c97dc6e0c..55728514e 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_port.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_s_port.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "server_port"
- ],
- "order_by": "Packets",
- "row_limit": "20",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "server_port"
- ],
- "order_by": "Packets",
- "row_limit": "50",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"app": "123","app_category": "234", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_sled_ip.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_sled_ip.py
index 70e1e2703..7fe80ea48 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_sled_ip.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_sled_ip.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "sled_ip"
- ],
- "order_by": "Packets",
- "row_limit": "20",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "sled_ip"
- ],
- "order_by": "Packets",
- "row_limit": "50",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"app": "123","app_category": "234", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_sub_id.py b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_sub_id.py
index e2766bb8e..703cb7723 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_sub_id.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_pkts_dim_sub_id.py
@@ -1,222 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by 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
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "sent_pkts:SUM:Packets Sent",
- "received_pkts:SUM:Packets Received",
- "sent_pkts+received_pkts:SUM:Packets"
- ],
- "dimensions": [
- "subscriber_id"
- ],
- "order_by": "Packets",
- "row_limit": "20",
- "min_in_size": "0",
- "min_out_size": "0"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "sent_pkts:RATE:Packets Sent",
- "received_pkts:RATE:Packets Received",
- "sent_pkts+received_pkts:RATE:Packets"
- ],
- "dimensions": [
- "subscriber_id"
- ],
- "order_by": "Packets",
- "row_limit": "50",
- "min_in_size": "0",
- "min_out_size": "0"
- }
- ]
- }]
- },
- "expected_return": "reset",
- "counters": {"hits": 1},
- "log_query_param": [{"query_field_key": "server_fqdn", "query_value": "www.yumi.com"}],
- "traffic": {
- "protocol": "",
- "type": "trex",
- "clients_start_ip": "10.64.224.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "m": 1,
- "d": 1,
- "yaml_name": "test",
- "pcap_name": "http_87pkts"
- },
- "statists_metric_results": [
- {"app": "123","app_category": "234", "in_pkts": 19, "out_pkts": 64, "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)
"""
@@ -225,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """
diff --git a/tests/statistics/stats_srcip_dstip_http_table_all_sessions_dim_app.py b/tests/statistics/stats_srcip_dstip_http_table_all_sessions_dim_app.py
index 076bfddc9..3ea77c9e1 100644
--- a/tests/statistics/stats_srcip_dstip_http_table_all_sessions_dim_app.py
+++ b/tests/statistics/stats_srcip_dstip_http_table_all_sessions_dim_app.py
@@ -1,215 +1,416 @@
# -*- 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)
+ 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": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "SUM(Packets Sent, Packets Received), SUM(Packets Sent) and SUM(Packets Received) Distributed by Application",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "app"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "SUM(Packets Sent)",
+ "unit": "packets"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "SUM",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "SUM(Packets Received)",
+ "unit": "packets"
+ }
+ ],
+ "order_by": "SUM(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
},
- ]
- }
- ],
- "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.31",
- },
+ "id": "",
+ "display": {
+ "page_x": None,
+ "page_y": None,
+ "height": "",
+ "width": "",
+ "type": "table",
+ "table_type": "regular"
+ },
+ "uuid": "",
+ "name": "RATE(Packets Sent, Packets Received), RATE(Packets Sent) and RATE(Packets Received) Distributed by Application",
+ "threshold": {
+ "in_bytes": 0,
+ "out_bytes": 0
+ },
+ "query": {
+ "dimensions": [
+ {
+ "source_fields": [
+ "app"
+ ],
+ "function": {
+ "name": "",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "label": "Application",
+ "is_drill_down": 0
+ }
+ ],
+ "limit": "20",
+ "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"
+ },
+ {
+ "source_fields": [
+ "sent_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_2",
+ "label": "RATE(Packets Sent)",
+ "unit": "pps"
+ },
+ {
+ "source_fields": [
+ "received_pkts"
+ ],
+ "function": {
+ "name": "RATE",
+ "expression": "",
+ "variables": [
+
+ ]
+ },
+ "metric_type": "count",
+ "metric_name": "count_3",
+ "label": "RATE(Packets Received)",
+ "unit": "pps"
+ }
+ ],
+ "order_by": "RATE(Packets Sent, Packets Received)",
+ "source": "statistics_rule",
+ "series_limit": ""
+ }
+ }
]
- }],
- "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": "Table",
- "metrics": [
- "new_sessions_for_this_rule:SUM:sessions"
- ],
- "dimensions": [
- "app"
- ],
- "order_by": "sessions",
- "row_limit": "20",
- "min_in_size": "1",
- "min_out_size": "1"
- },
- {
- "chart_name": "default name",
- "visualization_type": "Table",
- "metrics": [
- "new_sessions_for_this_rule:RATE:sessions"
- ],
- "dimensions": [
- "app"
- ],
- "order_by": "sessions",
- "row_limit": "50",
- "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.31",
- "clients_end_ip": "10.64.224.31",
- "servers_start_ip": "2.1.1.31",
- "servers_end_ip": "2.1.1.31",
- "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)
"""
@@ -218,4 +419,4 @@ if __name__ == '__main__':
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
- """ \ No newline at end of file
+ """