From 6eda965d99fb87dab45932ad8ef2e18fe4ce8527 Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Wed, 23 Mar 2022 15:16:06 -0700 Subject: [PATCH] [vstest]Migrating vs tests from using click commands to direct DB access (#2179) * [vstest]Migrating vs tests from using click commands to direct DB access Signed-off-by: Sudharsan Dhamal Gopalarathnam --- tests/conftest.py | 38 +++ tests/p4rt/test_l3.py | 2 +- tests/p4rt/util.py | 4 +- tests/test_acl.py | 4 +- tests/test_acl_cli.py | 33 --- tests/test_acl_portchannel.py | 4 +- tests/test_buffer_dynamic.py | 66 ++--- tests/test_buffer_traditional.py | 10 +- tests/test_crm.py | 379 ++++------------------------- tests/test_evpn_fdb.py | 4 +- tests/test_evpn_fdb_p2mp.py | 2 +- tests/test_fdb.py | 16 +- tests/test_fdb_update.py | 9 +- tests/test_fgnhg.py | 12 +- tests/test_inband_intf_mgmt_vrf.py | 1 - tests/test_mclag_fdb.py | 2 +- tests/test_mux.py | 4 +- tests/test_nhg.py | 2 +- tests/test_pfcwd.py | 4 +- tests/test_port.py | 16 +- tests/test_port_an.py | 9 +- tests/test_sflow.py | 1 - tests/test_warm_reboot.py | 84 ++++--- tests/test_watermark.py | 30 +-- 24 files changed, 239 insertions(+), 497 deletions(-) delete mode 100644 tests/test_acl_cli.py diff --git a/tests/conftest.py b/tests/conftest.py index 4139cbfa15db..f1e8248a1441 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1157,6 +1157,44 @@ def getCrmCounterValue(self, key, counter): if k[0] == counter: return int(k[1]) + def port_field_set(self, port, field, value): + cdb = swsscommon.DBConnector(4, self.redis_sock, 0) + tbl = swsscommon.Table(cdb, "PORT") + fvs = swsscommon.FieldValuePairs([(field, value)]) + tbl.set(port, fvs) + time.sleep(1) + + def port_admin_set(self, port, status): + self.port_field_set(port, "admin_status", status) + + def interface_ip_add(self, port, ip_address): + cdb = swsscommon.DBConnector(4, self.redis_sock, 0) + tbl = swsscommon.Table(cdb, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL", "NULL")]) + tbl.set(port, fvs) + tbl.set(port + "|" + ip_address, fvs) + time.sleep(1) + + def crm_poll_set(self, value): + cdb = swsscommon.DBConnector(4, self.redis_sock, 0) + tbl = swsscommon.Table(cdb, "CRM") + fvs = swsscommon.FieldValuePairs([("polling_interval", value)]) + tbl.set("Config", fvs) + time.sleep(1) + + def clear_fdb(self): + adb = swsscommon.DBConnector(0, self.redis_sock, 0) + opdata = ["ALL", "ALL"] + msg = json.dumps(opdata,separators=(',',':')) + adb.publish('FLUSHFDBREQUEST', msg) + + def warm_restart_swss(self, enable): + db = swsscommon.DBConnector(6, self.redis_sock, 0) + + tbl = swsscommon.Table(db, "WARM_RESTART_ENABLE_TABLE") + fvs = swsscommon.FieldValuePairs([("enable",enable)]) + tbl.set("swss", fvs) + # deps: acl, crm, fdb def setReadOnlyAttr(self, obj, attr, val): db = swsscommon.DBConnector(swsscommon.ASIC_DB, self.redis_sock, 0) diff --git a/tests/p4rt/test_l3.py b/tests/p4rt/test_l3.py index 42f32facbdfe..4156576bc2a9 100644 --- a/tests/p4rt/test_l3.py +++ b/tests/p4rt/test_l3.py @@ -1328,7 +1328,7 @@ def test_PruneNextHopOnWarmBoot(self, dvs, testlog): util.set_interface_status(dvs, if_name) # Execute the warm reboot. - dvs.runcmd("config warm_restart enable swss") + dvs.warm_restart_swss("true") dvs.stop_swss() dvs.start_swss() diff --git a/tests/p4rt/util.py b/tests/p4rt/util.py index 831c7a5cbec5..778a54960d25 100644 --- a/tests/p4rt/util.py +++ b/tests/p4rt/util.py @@ -84,8 +84,8 @@ def get_port_oid_by_name(dvs, port_name): return port_oid def initialize_interface(dvs, port_name, ip): - dvs.runcmd("config interface startup {}".format(port_name)) - dvs.runcmd("config interface ip add {} {}".format(port_name, ip)) + dvs.port_admin_set(port_name, "up") + dvs.interface_ip_add(port_name, ip) def set_interface_status(dvs, if_name, status = "down", server = 0): dvs.servers[0].runcmd("ip link set {} dev {}".format(status, if_name)) == 0 diff --git a/tests/test_acl.py b/tests/test_acl.py index fb8aecb0ea80..c246eefe53bb 100644 --- a/tests/test_acl.py +++ b/tests/test_acl.py @@ -553,11 +553,11 @@ def test_AclRuleRedirect(self, dvs, dvs_acl, l3_acl_table, setup_teardown_neighb class TestAclCrmUtilization: @pytest.fixture(scope="class", autouse=True) def configure_crm_polling_interval_for_test(self, dvs): - dvs.runcmd("crm config polling interval 1") + dvs.crm_poll_set("1") yield - dvs.runcmd("crm config polling interval 300") + dvs.crm_poll_set("300") def test_ValidateAclTableBindingCrmUtilization(self, dvs, dvs_acl): counter_db = dvs.get_counters_db() diff --git a/tests/test_acl_cli.py b/tests/test_acl_cli.py deleted file mode 100644 index 02785314d28a..000000000000 --- a/tests/test_acl_cli.py +++ /dev/null @@ -1,33 +0,0 @@ -class TestAclCli: - def test_AddTableMultipleTimes(self, dvs, dvs_acl): - dvs.runcmd("config acl add table TEST L3 -p Ethernet0") - - cdb = dvs.get_config_db() - cdb.wait_for_field_match( - "ACL_TABLE", - "TEST", - {"ports": "Ethernet0"} - ) - - # Verify that subsequent updates don't delete "ports" from config DB - dvs.runcmd("config acl add table TEST L3 -p Ethernet4") - cdb.wait_for_field_match( - "ACL_TABLE", - "TEST", - {"ports": "Ethernet4"} - ) - - # Verify that subsequent updates propagate to ASIC DB - L3_BIND_PORTS = ["Ethernet0", "Ethernet4", "Ethernet8", "Ethernet12"] - dvs.runcmd(f"config acl add table TEST L3 -p {','.join(L3_BIND_PORTS)}") - acl_table_id = dvs_acl.get_acl_table_ids(1)[0] - acl_table_group_ids = dvs_acl.get_acl_table_group_ids(len(L3_BIND_PORTS)) - - dvs_acl.verify_acl_table_group_members(acl_table_id, acl_table_group_ids, 1) - dvs_acl.verify_acl_table_port_binding(acl_table_id, L3_BIND_PORTS, 1) - - -# Add Dummy always-pass test at end as workaroud -# for issue when Flaky fail on final test it invokes module tear-down before retrying -def test_nonflaky_dummy(): - pass diff --git a/tests/test_acl_portchannel.py b/tests/test_acl_portchannel.py index 759850d1beca..b912cbea2f20 100644 --- a/tests/test_acl_portchannel.py +++ b/tests/test_acl_portchannel.py @@ -129,7 +129,7 @@ def check_asic_table_absent(self, dvs): # Second create ACL table def test_PortChannelAfterAcl(self, dvs): self.setup_db(dvs) - dvs.runcmd("crm config polling interval 1") + dvs.crm_poll_set("1") time.sleep(2) used_counter = dvs.getCrmCounterValue('ACL_STATS:INGRESS:LAG', 'crm_stats_acl_group_used') @@ -162,7 +162,7 @@ def test_PortChannelAfterAcl(self, dvs): new_new_used_counter = 0 assert new_used_counter - new_new_used_counter == 1 # slow down crm polling - dvs.runcmd("crm config polling interval 10000") + dvs.crm_poll_set("10000") # Frist create ACL table # Second create port channel diff --git a/tests/test_buffer_dynamic.py b/tests/test_buffer_dynamic.py index 76ba36ee1122..2b4367f00db9 100644 --- a/tests/test_buffer_dynamic.py +++ b/tests/test_buffer_dynamic.py @@ -164,14 +164,14 @@ def test_changeSpeed(self, dvs, testlog): self.setup_db(dvs) # Startup interface - dvs.runcmd('config interface startup Ethernet0') + dvs.port_admin_set('Ethernet0', 'up') self.check_queues_after_port_startup(dvs) # Configure lossless PG 3-4 on interface self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'NULL'}) # Change speed to speed1 and verify whether the profile has been updated - dvs.runcmd("config interface speed Ethernet0 " + self.speedToTest1) + dvs.port_field_set("Ethernet0", "speed", self.speedToTest1) expectedProfile = self.make_lossless_profile_name(self.speedToTest1, self.originalCableLen) self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", expectedProfile) @@ -185,7 +185,7 @@ def test_changeSpeed(self, dvs, testlog): self.app_db.wait_for_deleted_entry("BUFFER_PG_TABLE", "Ethernet0:3-4") # Change speed to speed2 and verify - dvs.runcmd("config interface speed Ethernet0 " + self.speedToTest2) + dvs.port_field_set("Ethernet0", "speed", self.speedToTest2) expectedProfile = self.make_lossless_profile_name(self.speedToTest2, self.originalCableLen) # Re-add another lossless PG @@ -197,7 +197,7 @@ def test_changeSpeed(self, dvs, testlog): self.app_db.wait_for_deleted_entry("BUFFER_PG_TABLE", "Ethernet0:6") # Remove the lossless PG 3-4 and revert speed - dvs.runcmd("config interface speed Ethernet0 " + self.originalSpeed) + dvs.port_field_set("Ethernet0", "speed", self.originalSpeed) self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'NULL'}) expectedProfile = self.make_lossless_profile_name(self.originalSpeed, self.originalCableLen) @@ -210,7 +210,7 @@ def test_changeSpeed(self, dvs, testlog): self.app_db.wait_for_deleted_entry("BUFFER_PG_TABLE", "Ethernet0:3-4") # Shutdown interface - dvs.runcmd('config interface shutdown Ethernet0') + dvs.port_admin_set('Ethernet0', 'down') self.cleanup_db(dvs) @@ -219,7 +219,7 @@ def test_changeCableLen(self, dvs, testlog): self.setup_db(dvs) # Startup interface - dvs.runcmd('config interface startup Ethernet0') + dvs.port_admin_set('Ethernet0', 'up') # Configure lossless PG 3-4 on interface self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'NULL'}) @@ -263,7 +263,7 @@ def test_changeCableLen(self, dvs, testlog): self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|3-4') # Shutdown interface - dvs.runcmd('config interface shutdown Ethernet0') + dvs.port_admin_set('Ethernet0', 'down') self.cleanup_db(dvs) @@ -271,7 +271,7 @@ def test_MultipleLosslessPg(self, dvs, testlog): self.setup_db(dvs) # Startup interface - dvs.runcmd('config interface startup Ethernet0') + dvs.port_admin_set('Ethernet0', 'up') # Configure lossless PG 3-4 on interface self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'NULL'}) @@ -282,7 +282,7 @@ def test_MultipleLosslessPg(self, dvs, testlog): self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:6", {"profile": expectedProfile}) # Change speed and check - dvs.runcmd("config interface speed Ethernet0 " + self.speedToTest1) + dvs.port_field_set("Ethernet0", "speed", self.speedToTest1) expectedProfile = self.make_lossless_profile_name(self.speedToTest1, self.originalCableLen) self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", expectedProfile) self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfile}) @@ -299,7 +299,7 @@ def test_MultipleLosslessPg(self, dvs, testlog): # Revert the speed and cable length and check self.change_cable_length(self.originalCableLen) - dvs.runcmd("config interface speed Ethernet0 " + self.originalSpeed) + dvs.port_field_set("Ethernet0", "speed", self.originalSpeed) self.app_db.wait_for_deleted_entry("BUFFER_PROFILE_TABLE", expectedProfile) self.asic_db.wait_for_deleted_entry("ASIC_STATE:SAI_OBJECT_TYPE_BUFFER_PROFILE", self.newProfileInAsicDb) expectedProfile = self.make_lossless_profile_name(self.originalSpeed, self.originalCableLen) @@ -312,7 +312,7 @@ def test_MultipleLosslessPg(self, dvs, testlog): self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|6') # Shutdown interface - dvs.runcmd('config interface shutdown Ethernet0') + dvs.port_admin_set('Ethernet0', 'down') self.cleanup_db(dvs) @@ -320,7 +320,7 @@ def test_headroomOverride(self, dvs, testlog): self.setup_db(dvs) # Startup interface - dvs.runcmd('config interface startup Ethernet0') + dvs.port_admin_set('Ethernet0', 'up') # Configure static profile self.config_db.update_entry('BUFFER_PROFILE', 'test', @@ -397,7 +397,7 @@ def test_headroomOverride(self, dvs, testlog): self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|3-4') # Shutdown interface - dvs.runcmd('config interface shutdown Ethernet0') + dvs.port_admin_set('Ethernet0', 'down') self.cleanup_db(dvs) @@ -405,7 +405,7 @@ def test_mtuUpdate(self, dvs, testlog): self.setup_db(dvs) # Startup interface - dvs.runcmd('config interface startup Ethernet0') + dvs.port_admin_set('Ethernet0', 'up') test_mtu = '1500' default_mtu = '9100' @@ -413,7 +413,7 @@ def test_mtuUpdate(self, dvs, testlog): expectedProfileNormal = self.make_lossless_profile_name(self.originalSpeed, self.originalCableLen) # update the mtu on the interface - dvs.runcmd("config interface mtu Ethernet0 {}".format(test_mtu)) + dvs.port_field_set("Ethernet0", "mtu", test_mtu) # configure lossless PG 3-4 on interface self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'NULL'}) @@ -423,7 +423,7 @@ def test_mtuUpdate(self, dvs, testlog): self.check_new_profile_in_asic_db(dvs, expectedProfileMtu) self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfileMtu}) - dvs.runcmd("config interface mtu Ethernet0 {}".format(default_mtu)) + dvs.port_field_set("Ethernet0", "mtu", default_mtu) self.app_db.wait_for_deleted_entry("BUFFER_PROFILE_TABLE", expectedProfileMtu) self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", expectedProfileNormal) @@ -433,7 +433,7 @@ def test_mtuUpdate(self, dvs, testlog): self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|3-4') # Shutdown interface - dvs.runcmd('config interface shutdown Ethernet0') + dvs.port_admin_set('Ethernet0', 'down') self.cleanup_db(dvs) @@ -441,7 +441,7 @@ def test_nonDefaultAlpha(self, dvs, testlog): self.setup_db(dvs) # Startup interface - dvs.runcmd('config interface startup Ethernet0') + dvs.port_admin_set('Ethernet0', 'up') test_dynamic_th_1 = '1' expectedProfile_th1 = self.make_lossless_profile_name(self.originalSpeed, self.originalCableLen, dynamic_th = test_dynamic_th_1) @@ -477,7 +477,7 @@ def test_nonDefaultAlpha(self, dvs, testlog): self.config_db.delete_entry('BUFFER_PROFILE', 'non-default-dynamic') # Shutdown interface - dvs.runcmd('config interface shutdown Ethernet0') + dvs.port_admin_set('Ethernet0', 'down') self.cleanup_db(dvs) @@ -485,7 +485,7 @@ def test_sharedHeadroomPool(self, dvs, testlog): self.setup_db(dvs) # Startup interface - dvs.runcmd('config interface startup Ethernet0') + dvs.port_admin_set('Ethernet0', 'up') # configure lossless PG 3-4 on interface and start up the interface self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'NULL'}) @@ -574,10 +574,10 @@ def test_sharedHeadroomPool(self, dvs, testlog): # remove lossless PG 3-4 on interface self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|3-4') - dvs.runcmd('config interface shutdown Ethernet0') + dvs.port_admin_set('Ethernet0', 'down') # Shutdown interface - dvs.runcmd('config interface shutdown Ethernet0') + dvs.port_admin_set('Ethernet0', 'down') self.cleanup_db(dvs) @@ -595,7 +595,7 @@ def test_shutdownPort(self, dvs, testlog): lossless_queue_zero_reference = 'egress_lossless_zero_profile' # Startup interface - dvs.runcmd('config interface startup Ethernet0') + dvs.port_admin_set('Ethernet0', 'up') # Configure lossless PG 3-4 on interface self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'NULL'}) @@ -604,7 +604,7 @@ def test_shutdownPort(self, dvs, testlog): # Shutdown port and check whether zero profiles have been applied on queues and the PG 0 maximumQueues = int(self.bufferMaxParameter['max_queues']) - 1 - dvs.runcmd("config interface shutdown Ethernet0") + dvs.port_admin_set('Ethernet0', 'down') self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:0", {"profile": lossy_pg_zero_reference}) self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:0-2", {"profile": lossy_queue_zero_reference}) self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:3-4", {"profile": lossless_queue_zero_reference}) @@ -632,7 +632,7 @@ def test_shutdownPort(self, dvs, testlog): self.app_db.wait_for_deleted_entry("BUFFER_PG_TABLE", "Ethernet0:6") # Startup port and check whether all the PGs have been added - dvs.runcmd("config interface startup Ethernet0") + dvs.port_admin_set('Ethernet0', 'up') self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:0", {"profile": lossy_pg_reference_appl_db}) self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:1", {"profile": lossy_pg_reference_appl_db}) self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfile}) @@ -645,7 +645,7 @@ def test_shutdownPort(self, dvs, testlog): self.app_db.wait_for_deleted_entry("BUFFER_QUEUE_TABLE", "Ethernet0:9-{}".format(maximumQueues)) # Shutdown the port again to verify flow to remove buffer objects from an admin down port - dvs.runcmd("config interface shutdown Ethernet0") + dvs.port_admin_set('Ethernet0', 'down') # First, check whether the objects have been correctly handled self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:0", {"profile": lossy_pg_zero_reference}) self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:0-2", {"profile": lossy_queue_zero_reference}) @@ -671,7 +671,7 @@ def test_shutdownPort(self, dvs, testlog): self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:7-{}".format(maximumQueues), {"profile": lossy_queue_zero_reference}) # Startup again - dvs.runcmd("config interface startup Ethernet0") + dvs.port_admin_set('Ethernet0', 'up') self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:0-2", {"profile": lossy_queue_reference_appl_db}) self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:3-4", {"profile": lossless_queue_reference_appl_db}) self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:5-6", {"profile": lossy_queue_reference_appl_db}) @@ -683,7 +683,7 @@ def test_shutdownPort(self, dvs, testlog): self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|3-4') # Shutdown interface - dvs.runcmd("config interface shutdown Ethernet0") + dvs.port_admin_set('Ethernet0', 'down') self.cleanup_db(dvs) @@ -698,14 +698,14 @@ def test_autoNegPort(self, dvs, testlog): maximum_advertised_speed = '25000' # Startup interfaces - dvs.runcmd('config interface startup Ethernet0') + dvs.port_admin_set('Ethernet0', 'up') # Configure lossless PG 3-4 on the interface self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'NULL'}) # Enable port auto negotiation - dvs.runcmd('config interface autoneg Ethernet0 enabled') - dvs.runcmd('config interface advertised-speeds Ethernet0 {}'.format(advertised_speeds)) + dvs.port_field_set('Ethernet0','autoneg', 'on') + dvs.port_field_set('Ethernet0','adv_speeds', advertised_speeds) # Check the buffer profile. The maximum_advertised_speed should be used expectedProfile = self.make_lossless_profile_name(maximum_advertised_speed, self.originalCableLen) @@ -719,7 +719,7 @@ def test_autoNegPort(self, dvs, testlog): self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:6", {"profile": expectedProfile}) # Disable port auto negotiation - dvs.runcmd('config interface autoneg Ethernet0 disabled') + dvs.port_field_set('Ethernet0','autoneg', 'off') # Check the buffer profile. The configured speed should be used expectedProfile = self.make_lossless_profile_name(self.originalSpeed, self.originalCableLen) @@ -733,7 +733,7 @@ def test_autoNegPort(self, dvs, testlog): self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|6') # Shutdown interface - dvs.runcmd('config interface shutdown Ethernet0') + dvs.port_admin_set('Ethernet0', 'down') self.cleanup_db(dvs) diff --git a/tests/test_buffer_traditional.py b/tests/test_buffer_traditional.py index 3defae0c8061..e955390fde63 100644 --- a/tests/test_buffer_traditional.py +++ b/tests/test_buffer_traditional.py @@ -91,7 +91,7 @@ def test_zero_cable_len_profile_update(self, dvs, setup_teardown_test): test_speed = "100000" test_cable_len = "0m" - dvs.runcmd("config interface startup {}".format(self.INTF)) + dvs.port_admin_set(self.INTF, "up") # Make sure the buffer PG has been created orig_lossless_profile = "pg_lossless_{}_{}_profile".format(orig_speed, cable_len_before_test) self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", orig_lossless_profile) @@ -113,7 +113,7 @@ def test_zero_cable_len_profile_update(self, dvs, setup_teardown_test): self.change_cable_len(test_cable_len) # change intf speed to 'test_speed' - dvs.runcmd("config interface speed {} {}".format(self.INTF, test_speed)) + dvs.port_field_set(self.INTF, "speed", test_speed) test_lossless_profile = "pg_lossless_{}_{}_profile".format(test_speed, test_cable_len) # buffer profile should not get created self.app_db.wait_for_deleted_entry("BUFFER_PROFILE_TABLE", test_lossless_profile) @@ -129,7 +129,7 @@ def test_zero_cable_len_profile_update(self, dvs, setup_teardown_test): self.change_cable_len(cable_len_before_test) # change intf speed to 'test_speed' - dvs.runcmd("config interface speed {} {}".format(self.INTF, test_speed)) + dvs.port_field_set(self.INTF, "speed", test_speed) if profile_exp_cnt_diff != 0: # new profile will get created self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", new_lossless_profile) @@ -150,5 +150,5 @@ def test_zero_cable_len_profile_update(self, dvs, setup_teardown_test): if orig_cable_len: self.change_cable_len(orig_cable_len) if orig_speed: - dvs.runcmd("config interface speed {} {}".format(self.INTF, orig_speed)) - dvs.runcmd("config interface shutdown {}".format(self.INTF)) + dvs.port_field_set(self.INTF, "speed", orig_speed) + dvs.port_admin_set(self.INTF, "down") diff --git a/tests/test_crm.py b/tests/test_crm.py index 200b15cf79dc..e899aff6d3db 100644 --- a/tests/test_crm.py +++ b/tests/test_crm.py @@ -17,29 +17,16 @@ def getCrmCounterValue(dvs, key, counter): return 0 -def getCrmConfigValue(dvs, key, counter): - - config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - crm_stats_table = swsscommon.Table(config_db, 'CRM') - - for k in crm_stats_table.get(key)[1]: - if k[0] == counter: - return int(k[1]) - -def getCrmConfigStr(dvs, key, counter): - - config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - crm_stats_table = swsscommon.Table(config_db, 'CRM') - - for k in crm_stats_table.get(key)[1]: - if k[0] == counter: - return k[1] - return "" - def check_syslog(dvs, marker, err_log, expected_cnt): (exitcode, num) = dvs.runcmd(['sh', '-c', "awk \'/%s/,ENDFILE {print;}\' /var/log/syslog | grep \"%s\" | wc -l" % (marker, err_log)]) assert num.strip() >= str(expected_cnt) +def crm_update(dvs, field, value): + cfg_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + tbl = swsscommon.Table(cfg_db, "CRM") + fvs = swsscommon.FieldValuePairs([(field, value)]) + tbl.set("Config", fvs) + time.sleep(1) class TestCrm(object): def test_CrmFdbEntry(self, dvs, testlog): @@ -48,7 +35,7 @@ def test_CrmFdbEntry(self, dvs, testlog): # configured, server 2 will send packet which can switch to learn another # mac and fail the test. dvs.servers[2].runcmd("sysctl -w net.ipv6.conf.eth0.disable_ipv6=1") - dvs.runcmd("crm config polling interval 1") + crm_update(dvs, "polling_interval", "1") dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000') @@ -99,9 +86,9 @@ def test_CrmFdbEntry(self, dvs, testlog): assert new_avail_counter == avail_counter marker = dvs.add_log_marker() - dvs.runcmd("crm config polling interval 2") - dvs.runcmd("crm config thresholds fdb high 90") - dvs.runcmd("crm config thresholds fdb type free") + crm_update(dvs, "polling_interval", "2") + crm_update(dvs, "fdb_entry_high_threshold", "90") + crm_update(dvs, "fdb_entry_threshold_type", "free") time.sleep(2) check_syslog(dvs, marker, "FDB_ENTRY THRESHOLD_EXCEEDED for TH_FREE", 1) @@ -115,9 +102,9 @@ def test_CrmIpv4Route(self, dvs, testlog): fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) intf_tbl.set("Ethernet0", fvs) intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) - dvs.runcmd("config interface startup Ethernet0") + dvs.port_admin_set("Ethernet0", "up") - dvs.runcmd("crm config polling interval 1") + crm_update(dvs, "polling_interval", "1") dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '1000') @@ -162,9 +149,9 @@ def test_CrmIpv4Route(self, dvs, testlog): assert new_avail_counter == avail_counter marker = dvs.add_log_marker() - dvs.runcmd("crm config polling interval 2") - dvs.runcmd("crm config thresholds ipv4 route high 90") - dvs.runcmd("crm config thresholds ipv4 route type free") + crm_update(dvs, "polling_interval", "2") + crm_update(dvs, "ipv4_route_high_threshold", "90") + crm_update(dvs, "ipv4_route_threshold_type", "free") time.sleep(2) check_syslog(dvs, marker, "IPV4_ROUTE THRESHOLD_EXCEEDED for TH_FREE",1) @@ -182,12 +169,12 @@ def test_CrmIpv6Route(self, dvs, testlog): fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) intf_tbl.set("Ethernet0", fvs) intf_tbl.set("Ethernet0|fc00::1/126", fvs) - dvs.runcmd("config interface startup Ethernet0") + dvs.port_admin_set("Ethernet0", "up") dvs.servers[0].runcmd("ifconfig eth0 inet6 add fc00::2/126") dvs.servers[0].runcmd("ip -6 route add default via fc00::1") - dvs.runcmd("crm config polling interval 1") + crm_update(dvs, "polling_interval", "1") dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '1000') @@ -232,9 +219,9 @@ def test_CrmIpv6Route(self, dvs, testlog): assert new_avail_counter == avail_counter marker = dvs.add_log_marker() - dvs.runcmd("crm config polling interval 2") - dvs.runcmd("crm config thresholds ipv6 route high 90") - dvs.runcmd("crm config thresholds ipv6 route type free") + crm_update(dvs, "polling_interval", "2") + crm_update(dvs, "ipv6_route_high_threshold", "90") + crm_update(dvs, "ipv6_route_threshold_type", "free") time.sleep(2) check_syslog(dvs, marker, "IPV6_ROUTE THRESHOLD_EXCEEDED for TH_FREE",1) @@ -248,9 +235,8 @@ def test_CrmIpv4Nexthop(self, dvs, testlog): fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) intf_tbl.set("Ethernet0", fvs) - dvs.runcmd("config interface startup Ethernet0") - - dvs.runcmd("crm config polling interval 1") + dvs.port_admin_set("Ethernet0", "up") + crm_update(dvs, "polling_interval", "1") dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '1000') @@ -287,9 +273,9 @@ def test_CrmIpv4Nexthop(self, dvs, testlog): assert new_avail_counter == avail_counter marker = dvs.add_log_marker() - dvs.runcmd("crm config polling interval 2") - dvs.runcmd("crm config thresholds ipv4 nexthop high 90") - dvs.runcmd("crm config thresholds ipv4 nexthop type free") + crm_update(dvs, "polling_interval", "2") + crm_update(dvs, "ipv4_nexthop_high_threshold", "90") + crm_update(dvs, "ipv4_nexthop_threshold_type", "free") time.sleep(2) check_syslog(dvs, marker, "IPV4_NEXTHOP THRESHOLD_EXCEEDED for TH_FREE",1) @@ -307,9 +293,9 @@ def test_CrmIpv6Nexthop(self, dvs, testlog): fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) intf_tbl.set("Ethernet0", fvs) intf_tbl.set("Ethernet0|fc00::1/126", fvs) - dvs.runcmd("config interface startup Ethernet0") + dvs.port_admin_set("Ethernet0", "up") - dvs.runcmd("crm config polling interval 1") + crm_update(dvs, "polling_interval", "1") dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '1000') @@ -346,9 +332,9 @@ def test_CrmIpv6Nexthop(self, dvs, testlog): assert new_avail_counter == avail_counter marker = dvs.add_log_marker() - dvs.runcmd("crm config polling interval 2") - dvs.runcmd("crm config thresholds ipv6 nexthop high 90") - dvs.runcmd("crm config thresholds ipv6 nexthop type free") + crm_update(dvs, "polling_interval", "2") + crm_update(dvs, "ipv6_nexthop_high_threshold", "90") + crm_update(dvs, "ipv6_nexthop_threshold_type", "free") time.sleep(2) check_syslog(dvs, marker, "IPV6_NEXTHOP THRESHOLD_EXCEEDED for TH_FREE",1) @@ -362,9 +348,9 @@ def test_CrmIpv4Neighbor(self, dvs, testlog): fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) intf_tbl.set("Ethernet0", fvs) intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) - dvs.runcmd("config interface startup Ethernet0") + dvs.port_admin_set("Ethernet0", "up") - dvs.runcmd("crm config polling interval 1") + crm_update(dvs, "polling_interval", "1") dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '1000') @@ -401,9 +387,9 @@ def test_CrmIpv4Neighbor(self, dvs, testlog): assert new_avail_counter == avail_counter marker = dvs.add_log_marker() - dvs.runcmd("crm config polling interval 2") - dvs.runcmd("crm config thresholds ipv4 neighbor high 90") - dvs.runcmd("crm config thresholds ipv4 neighbor type free") + crm_update(dvs, "polling_interval", "2") + crm_update(dvs, "ipv4_neighbor_high_threshold", "90") + crm_update(dvs, "ipv4_neighbor_threshold_type", "free") time.sleep(2) check_syslog(dvs, marker, "IPV4_NEIGHBOR THRESHOLD_EXCEEDED for TH_FREE",1) @@ -421,9 +407,9 @@ def test_CrmIpv6Neighbor(self, dvs, testlog): fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) intf_tbl.set("Ethernet0", fvs) intf_tbl.set("Ethernet0|fc00::1/126", fvs) - dvs.runcmd("config interface startup Ethernet0") + dvs.port_admin_set("Ethernet0", "up") - dvs.runcmd("crm config polling interval 1") + crm_update(dvs, "polling_interval", "1") dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '1000') @@ -460,9 +446,9 @@ def test_CrmIpv6Neighbor(self, dvs, testlog): assert new_avail_counter == avail_counter marker = dvs.add_log_marker() - dvs.runcmd("crm config polling interval 2") - dvs.runcmd("crm config thresholds ipv6 neighbor high 90") - dvs.runcmd("crm config thresholds ipv6 neighbor type free") + crm_update(dvs, "polling_interval", "2") + crm_update(dvs, "ipv6_neighbor_high_threshold", "90") + crm_update(dvs, "ipv6_neighbor_threshold_type", "free") time.sleep(2) check_syslog(dvs, marker, "IPV6_NEIGHBOR THRESHOLD_EXCEEDED for TH_FREE",1) @@ -478,10 +464,10 @@ def test_CrmNexthopGroup(self, dvs, testlog): intf_tbl.set("Ethernet4", fvs) intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) - dvs.runcmd("config interface startup Ethernet0") - dvs.runcmd("config interface startup Ethernet4") + dvs.port_admin_set("Ethernet0", "up") + dvs.port_admin_set("Ethernet4", "up") - dvs.runcmd("crm config polling interval 1") + crm_update(dvs, "polling_interval", "1") dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '1000') @@ -528,9 +514,9 @@ def test_CrmNexthopGroup(self, dvs, testlog): assert new_avail_counter == avail_counter marker = dvs.add_log_marker() - dvs.runcmd("crm config polling interval 2") - dvs.runcmd("crm config thresholds nexthop group member high 90") - dvs.runcmd("crm config thresholds nexthop group object type free") + crm_update(dvs, "polling_interval", "2") + crm_update(dvs, "nexthop_group_high_threshold", "90") + crm_update(dvs, "nexthop_group_threshold_type", "free") time.sleep(2) check_syslog(dvs, marker, "NEXTHOP_GROUP THRESHOLD_EXCEEDED for TH_FREE",1) @@ -553,10 +539,10 @@ def test_CrmNexthopGroupMember(self, dvs, testlog): intf_tbl.set("Ethernet4", fvs) intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) - dvs.runcmd("config interface startup Ethernet0") - dvs.runcmd("config interface startup Ethernet4") + dvs.port_admin_set("Ethernet0", "up") + dvs.port_admin_set("Ethernet4", "up") - dvs.runcmd("crm config polling interval 1") + crm_update(dvs, "polling_interval", "1") dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '1000') @@ -603,9 +589,9 @@ def test_CrmNexthopGroupMember(self, dvs, testlog): assert new_avail_counter == avail_counter marker = dvs.add_log_marker() - dvs.runcmd("crm config polling interval 2") - dvs.runcmd("crm config thresholds nexthop group member high 90") - dvs.runcmd("crm config thresholds nexthop group member type free") + crm_update(dvs, "polling_interval", "2") + crm_update(dvs, "nexthop_group_member_high_threshold", "90") + crm_update(dvs, "nexthop_group_member_threshold_type", "free") time.sleep(2) check_syslog(dvs, marker, "NEXTHOP_GROUP_MEMBER THRESHOLD_EXCEEDED for TH_FREE",1) @@ -618,7 +604,7 @@ def test_CrmAcl(self, dvs, testlog): db = swsscommon.DBConnector(4, dvs.redis_sock, 0) adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - dvs.runcmd("crm config polling interval 1") + crm_update(dvs, "polling_interval", "1") time.sleep(1) bind_ports = ["Ethernet0", "Ethernet4"] @@ -698,7 +684,7 @@ def test_CrmAclGroup(self, dvs, testlog): db = swsscommon.DBConnector(4, dvs.redis_sock, 0) adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - dvs.runcmd("crm config polling interval 1") + crm_update(dvs, "polling_interval", "1") bind_ports = ["Ethernet0", "Ethernet4", "Ethernet8"] # create ACL table @@ -734,263 +720,6 @@ def test_CrmDnatEntry(self, dvs, testlog): assert used_counter == 0 assert avail_counter != 0 -# commented ipmc test case till vslib is updated -# def test_CrmIpmcEntry(self, dvs, testlog): -# -# # get counters -# used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipmc_entry_used') -# avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipmc_entry_available') -# assert used_counter == 0 -# assert avail_counter != 0 - - def test_Configure(self, dvs, testlog): - - #polling interval - dvs.runcmd("crm config polling interval 10") - time.sleep(2) - polling_interval = getCrmConfigValue(dvs, 'Config', 'polling_interval') - assert polling_interval == 10 - - def test_Configure_ipv4_route(self, dvs, testlog): - - #ipv4 route low/high threshold/type - dvs.runcmd("crm config thresholds ipv4 route low 50") - dvs.runcmd("crm config thresholds ipv4 route high 90") - dvs.runcmd("crm config thresholds ipv4 route type percentage") - - time.sleep(2) - threshold_low = getCrmConfigValue(dvs, 'Config', 'ipv4_route_low_threshold') - assert threshold_low == 50 - threshold_high = getCrmConfigValue(dvs, 'Config', 'ipv4_route_high_threshold') - assert threshold_high == 90 - threshold_type = getCrmConfigStr(dvs, 'Config', 'ipv4_route_threshold_type') - assert threshold_type == 'percentage' - - def test_Configure_ipv6_route(self, dvs, testlog): - - #ipv6 route low/high threshold/type - dvs.runcmd("crm config thresholds ipv6 route low 50") - dvs.runcmd("crm config thresholds ipv6 route high 90") - dvs.runcmd("crm config thresholds ipv6 route type used") - - time.sleep(2) - threshold_low = getCrmConfigValue(dvs, 'Config', 'ipv6_route_low_threshold') - assert threshold_low == 50 - threshold_high = getCrmConfigValue(dvs, 'Config', 'ipv6_route_high_threshold') - assert threshold_high == 90 - threshold_type = getCrmConfigStr(dvs, 'Config', 'ipv6_route_threshold_type') - assert threshold_type == 'used' - - def test_Configure_ipv4_nexthop(self, dvs, testlog): - - #ipv4 nexthop low/high threshold/type - dvs.runcmd("crm config thresholds ipv4 nexthop low 50") - dvs.runcmd("crm config thresholds ipv4 nexthop high 90") - dvs.runcmd("crm config thresholds ipv4 nexthop type 'percentage'") - - time.sleep(2) - threshold_low = getCrmConfigValue(dvs, 'Config', 'ipv4_nexthop_low_threshold') - assert threshold_low == 50 - threshold_high = getCrmConfigValue(dvs, 'Config', 'ipv4_nexthop_high_threshold') - assert threshold_high == 90 - threshold_type = getCrmConfigStr(dvs, 'Config', 'ipv4_nexthop_threshold_type') - assert threshold_type == 'percentage' - - def test_Configure_ipv6_nexthop(self, dvs, testlog): - - #ipv6 nexthop low/high threshold/type - dvs.runcmd("crm config thresholds ipv6 nexthop low 50") - dvs.runcmd("crm config thresholds ipv6 nexthop high 90") - dvs.runcmd("crm config thresholds ipv6 nexthop type free") - - time.sleep(2) - threshold_low = getCrmConfigValue(dvs, 'Config', 'ipv6_nexthop_low_threshold') - assert threshold_low == 50 - threshold_high = getCrmConfigValue(dvs, 'Config', 'ipv6_nexthop_high_threshold') - assert threshold_high == 90 - threshold_type = getCrmConfigStr(dvs, 'Config', 'ipv6_nexthop_threshold_type') - assert threshold_type == 'free' - - def test_Configure_ipv4_neighbor(self, dvs, testlog): - - #ipv4 neighbor low/high threshold/type - dvs.runcmd("crm config thresholds ipv4 neighbor low 50") - dvs.runcmd("crm config thresholds ipv4 neighbor high 90") - dvs.runcmd("crm config thresholds ipv4 neighbor type percentage") - - time.sleep(2) - threshold_low = getCrmConfigValue(dvs, 'Config', 'ipv4_neighbor_low_threshold') - assert threshold_low == 50 - threshold_high = getCrmConfigValue(dvs, 'Config', 'ipv4_neighbor_high_threshold') - assert threshold_high == 90 - threshold_type = getCrmConfigStr(dvs, 'Config', 'ipv4_neighbor_threshold_type') - assert threshold_type == 'percentage' - - def test_Configure_ipv6_neighbor(self, dvs, testlog): - - #ipv6 neighbor low/high threshold/type - dvs.runcmd("crm config thresholds ipv6 neighbor low 50") - dvs.runcmd("crm config thresholds ipv6 neighbor high 90") - dvs.runcmd("crm config thresholds ipv6 neighbor type used") - - time.sleep(2) - threshold_low = getCrmConfigValue(dvs, 'Config', 'ipv6_neighbor_low_threshold') - assert threshold_low == 50 - threshold_high = getCrmConfigValue(dvs, 'Config', 'ipv6_neighbor_high_threshold') - assert threshold_high == 90 - threshold_type = getCrmConfigStr(dvs, 'Config', 'ipv6_neighbor_threshold_type') - assert threshold_type == 'used' - - def test_Configure_group_member(self, dvs, testlog): - - #nexthop group member low/high threshold/type - dvs.runcmd("crm config thresholds nexthop group member low 50") - dvs.runcmd("crm config thresholds nexthop group member high 90") - dvs.runcmd("crm config thresholds nexthop group member type percentage") - - time.sleep(2) - threshold_low = getCrmConfigValue(dvs, 'Config', 'nexthop_group_member_low_threshold') - assert threshold_low == 50 - threshold_high = getCrmConfigValue(dvs, 'Config', 'nexthop_group_member_high_threshold') - assert threshold_high == 90 - threshold_type = getCrmConfigStr(dvs, 'Config', 'nexthop_group_member_threshold_type') - assert threshold_type == 'percentage' - - def test_Configure_group_object(self, dvs, testlog): - - #nexthop group object low/high threshold/type - dvs.runcmd("crm config thresholds nexthop group object low 50") - dvs.runcmd("crm config thresholds nexthop group object high 90") - dvs.runcmd("crm config thresholds nexthop group object type free") - - time.sleep(2) - threshold_low = getCrmConfigValue(dvs, 'Config', 'nexthop_group_low_threshold') - assert threshold_low == 50 - threshold_high = getCrmConfigValue(dvs, 'Config', 'nexthop_group_high_threshold') - assert threshold_high == 90 - threshold_type = getCrmConfigStr(dvs, 'Config', 'nexthop_group_threshold_type') - assert threshold_type == 'free' - - def test_Configure_acl_table(self, dvs, testlog): - - #thresholds acl table low/high threshold/type - dvs.runcmd("crm config thresholds acl table low 50") - dvs.runcmd("crm config thresholds acl table high 90") - dvs.runcmd("crm config thresholds acl table type percentage") - - time.sleep(2) - threshold_low = getCrmConfigValue(dvs, 'Config', 'acl_table_low_threshold') - assert threshold_low == 50 - threshold_high = getCrmConfigValue(dvs, 'Config', 'acl_table_high_threshold') - assert threshold_high == 90 - threshold_type = getCrmConfigStr(dvs, 'Config', 'acl_table_threshold_type') - assert threshold_type == 'percentage' - - def test_Configure_acl_group(self, dvs, testlog): - - #thresholds acl group low/high threshold/type - dvs.runcmd("crm config thresholds acl group low 50") - dvs.runcmd("crm config thresholds acl group high 90") - dvs.runcmd("crm config thresholds acl group type used") - - time.sleep(2) - threshold_low = getCrmConfigValue(dvs, 'Config', 'acl_group_low_threshold') - assert threshold_low == 50 - threshold_high = getCrmConfigValue(dvs, 'Config', 'acl_group_high_threshold') - assert threshold_high == 90 - threshold_type = getCrmConfigStr(dvs, 'Config', 'acl_group_threshold_type') - assert threshold_type == 'used' - - def test_Configure_acl_group_entry(self, dvs, testlog): - - #thresholds acl group entry low/high threshold/type - dvs.runcmd("crm config thresholds acl group entry low 50") - dvs.runcmd("crm config thresholds acl group entry high 90") - dvs.runcmd("crm config thresholds acl group entry type percentage") - - time.sleep(2) - threshold_low = getCrmConfigValue(dvs, 'Config', 'acl_entry_low_threshold') - assert threshold_low == 50 - threshold_high = getCrmConfigValue(dvs, 'Config', 'acl_entry_high_threshold') - assert threshold_high == 90 - threshold_type = getCrmConfigStr(dvs, 'Config', 'acl_entry_threshold_type') - assert threshold_type == 'percentage' - - def test_Configure_acl_group_counter(self, dvs, testlog): - - #thresholds acl group counter low/high threshold/type - dvs.runcmd("crm config thresholds acl group counter low 50") - dvs.runcmd("crm config thresholds acl group counter high 90") - dvs.runcmd("crm config thresholds acl group counter type free") - - time.sleep(2) - threshold_low = getCrmConfigValue(dvs, 'Config', 'acl_counter_low_threshold') - assert threshold_low == 50 - threshold_high = getCrmConfigValue(dvs, 'Config', 'acl_counter_high_threshold') - assert threshold_high == 90 - threshold_type = getCrmConfigStr(dvs, 'Config', 'acl_counter_threshold_type') - assert threshold_type == 'free' - - def test_Configure_fdb(self, dvs, testlog): - - #thresholds fdb low/high threshold/type - dvs.runcmd("crm config thresholds fdb low 50") - dvs.runcmd("crm config thresholds fdb high 90") - dvs.runcmd("crm config thresholds fdb type percentage") - - time.sleep(2) - threshold_low = getCrmConfigValue(dvs, 'Config', 'fdb_entry_low_threshold') - assert threshold_low == 50 - threshold_high = getCrmConfigValue(dvs, 'Config', 'fdb_entry_high_threshold') - assert threshold_high == 90 - threshold_type = getCrmConfigStr(dvs, 'Config', 'fdb_entry_threshold_type') - assert threshold_type == 'percentage' - - def test_Configure_snat(self, dvs, testlog): - - #thresholds snat low/high threshold/type - dvs.runcmd("crm config thresholds snat low 50") - dvs.runcmd("crm config thresholds snat high 90") - dvs.runcmd("crm config thresholds snat type percentage") - - time.sleep(2) - threshold_low = getCrmConfigValue(dvs, 'Config', 'snat_entry_low_threshold') - assert threshold_low == 50 - threshold_high = getCrmConfigValue(dvs, 'Config', 'snat_entry_high_threshold') - assert threshold_high == 90 - threshold_type = getCrmConfigStr(dvs, 'Config', 'snat_entry_threshold_type') - assert threshold_type == 'percentage' - - def test_Configure_dnat(self, dvs, testlog): - - #thresholds dnat low/high threshold/type - dvs.runcmd("crm config thresholds dnat low 50") - dvs.runcmd("crm config thresholds dnat high 90") - dvs.runcmd("crm config thresholds dnat type percentage") - - time.sleep(2) - threshold_low = getCrmConfigValue(dvs, 'Config', 'dnat_entry_low_threshold') - assert threshold_low == 50 - threshold_high = getCrmConfigValue(dvs, 'Config', 'dnat_entry_high_threshold') - assert threshold_high == 90 - threshold_type = getCrmConfigStr(dvs, 'Config', 'dnat_entry_threshold_type') - assert threshold_type == 'percentage' - - def test_Configure_ipmc(self, dvs, testlog): - - #thresholds ipmc low/high threshold/type - dvs.runcmd("crm config thresholds ipmc low 50") - dvs.runcmd("crm config thresholds ipmc high 90") - dvs.runcmd("crm config thresholds ipmc type percentage") - - time.sleep(2) - threshold_low = getCrmConfigValue(dvs, 'Config', 'ipmc_entry_low_threshold') - assert threshold_low == 50 - threshold_high = getCrmConfigValue(dvs, 'Config', 'ipmc_entry_high_threshold') - assert threshold_high == 90 - threshold_type = getCrmConfigStr(dvs, 'Config', 'ipmc_entry_threshold_type') - assert threshold_type == 'percentage' - # Add Dummy always-pass test at end as workaroud # for issue when Flaky fail on final test it invokes module tear-down before retrying def test_nonflaky_dummy(): diff --git a/tests/test_evpn_fdb.py b/tests/test_evpn_fdb.py index 31d75535c7e7..3c9a2177475d 100644 --- a/tests/test_evpn_fdb.py +++ b/tests/test_evpn_fdb.py @@ -51,7 +51,7 @@ def test_evpnFdb(dvs, testlog): helper = VxlanEvpnHelper() dvs.setup_db() - dvs.runcmd("sonic-clear fdb all") + dvs.clear_fdb() time.sleep(2) #Find switch_id @@ -62,7 +62,6 @@ def test_evpnFdb(dvs, testlog): # create vlan print("Creating Vlan3") - #dvs.runcmd("config vlan add 3") dvs.create_vlan("3") time.sleep(2) @@ -79,7 +78,6 @@ def test_evpnFdb(dvs, testlog): vm_before = helper.how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") print("Making Ethernet0 as a member of Vlan3") - #dvs.runcmd("config vlan member add 3 Ethernet0") dvs.create_vlan_member("3", "Ethernet0") time.sleep(2) diff --git a/tests/test_evpn_fdb_p2mp.py b/tests/test_evpn_fdb_p2mp.py index 7929bc862f6f..8c1cfbf1d619 100644 --- a/tests/test_evpn_fdb_p2mp.py +++ b/tests/test_evpn_fdb_p2mp.py @@ -54,7 +54,7 @@ def test_evpnFdbP2MP(dvs, testlog): helper = VxlanEvpnHelper() dvs.setup_db() - dvs.runcmd("sonic-clear fdb all") + dvs.clear_fdb() time.sleep(2) #Find switch_id diff --git a/tests/test_fdb.py b/tests/test_fdb.py index 9893a4e3b001..2f9067a5999c 100644 --- a/tests/test_fdb.py +++ b/tests/test_fdb.py @@ -31,9 +31,10 @@ class TestFdb(object): def test_FdbWarmRestartNotifications(self, dvs, testlog): dvs.setup_db() - dvs.runcmd("sonic-clear fdb all") + dvs.clear_fdb() - dvs.runcmd("crm config polling interval 1") + dvs.crm_poll_set("1") + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000') time.sleep(2) @@ -225,8 +226,7 @@ def test_FdbWarmRestartNotifications(self, dvs, testlog): assert ok, str(extra) # enable warm restart - (exitcode, result) = dvs.runcmd("config warm_restart enable swss") - assert exitcode == 0 + dvs.warm_restart_swss("true") # freeze orchagent for warm restart (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check") @@ -317,14 +317,14 @@ def test_FdbWarmRestartNotifications(self, dvs, testlog): finally: # disable warm restart - dvs.runcmd("config warm_restart disable swss") + dvs.warm_restart_swss("false") # slow down crm polling - dvs.runcmd("crm config polling interval 10000") + dvs.crm_poll_set("10000") def test_FdbAddedAfterMemberCreated(self, dvs, testlog): dvs.setup_db() - dvs.runcmd("sonic-clear fdb all") + dvs.clear_fdb() time.sleep(2) # create a FDB entry in Application DB @@ -377,7 +377,7 @@ def test_FdbAddedAfterMemberCreated(self, dvs, testlog): ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet0"])]) assert ok, str(extra) - dvs.runcmd("sonic-clear fdb all") + dvs.clear_fdb() dvs.remove_vlan_member("2", "Ethernet0") dvs.remove_vlan("2") diff --git a/tests/test_fdb_update.py b/tests/test_fdb_update.py index 5daf27804e82..128dc3773b10 100644 --- a/tests/test_fdb_update.py +++ b/tests/test_fdb_update.py @@ -56,8 +56,7 @@ def get_mac_by_bridge_id(self, dvs, bridge_id): def test_FDBAddedAndUpdated(self, dvs, testlog): dvs.setup_db() - - dvs.runcmd("sonic-clear fdb all") + dvs.clear_fdb() time.sleep(2) # create a FDB entry in Application DB @@ -173,7 +172,7 @@ def test_FDBAddedAndUpdated(self, dvs, testlog): def test_FDBLearnedAndUpdated(self, dvs, testlog): dvs.setup_db() - dvs.runcmd("sonic-clear fdb all") + dvs.clear_fdb() # create vlan; create vlan member dvs.create_vlan("6") @@ -261,12 +260,12 @@ def test_FDBLearnedAndUpdated(self, dvs, testlog): dvs.remove_vlan("6") # clear fdb - dvs.runcmd("sonic-clear fdb all") + dvs.clear_fdb() def test_FDBLearnedAndFlushed(self, dvs, testlog): dvs.setup_db() - dvs.runcmd("sonic-clear fdb all") + dvs.clear_fdb() VLAN = "9" VLAN_NAME = "Vlan9" diff --git a/tests/test_fgnhg.py b/tests/test_fgnhg.py index 2fa8a9d89090..645853e24cfb 100644 --- a/tests/test_fgnhg.py +++ b/tests/test_fgnhg.py @@ -216,7 +216,7 @@ def startup_link(dvs, db, port): db.wait_for_field_match("PORT_TABLE", "Ethernet%d" % (port * 4), {"oper_status": "up"}) def run_warm_reboot(dvs): - dvs.runcmd("config warm_restart enable swss") + dvs.warm_restart_swss("true") # Stop swss before modifing the configDB dvs.stop_swss() @@ -280,7 +280,7 @@ def create_interface_n_fg_ecmp_config(dvs, nh_range_start, nh_range_end, fg_nhg_ ip_pref_key = "Ethernet" + str(i*4) + "|10.0.0." + str(i*2) + "/31" create_entry(config_db, IF_TB, if_name_key, fvs_nul) create_entry(config_db, IF_TB, ip_pref_key, fvs_nul) - dvs.runcmd("config interface startup " + if_name_key) + dvs.port_admin_set(if_name_key, "up") shutdown_link(dvs, app_db, i) startup_link(dvs, app_db, i) bank = 1 @@ -300,7 +300,7 @@ def remove_interface_n_fg_ecmp_config(dvs, nh_range_start, nh_range_end, fg_nhg_ ip_pref_key = "Ethernet" + str(i*4) + "|10.0.0." + str(i*2) + "/31" remove_entry(config_db, IF_TB, if_name_key) remove_entry(config_db, IF_TB, ip_pref_key) - dvs.runcmd("config interface shutdown " + if_name_key) + dvs.port_admin_set(if_name_key, "down") shutdown_link(dvs, app_db, i) remove_entry(config_db, FG_NHG_MEMBER, "10.0.0." + str(1 + i*2)) remove_entry(config_db, FG_NHG, fg_nhg_name) @@ -334,7 +334,7 @@ def fine_grained_ecmp_base_test(dvs, match_mode): create_entry(config_db, VLAN_MEMB_TB, vlan_name_key + "|" + if_name_key, fvs) create_entry(config_db, VLAN_IF_TB, vlan_name_key, fvs_nul) create_entry(config_db, VLAN_IF_TB, ip_pref_key, fvs_nul) - dvs.runcmd("config interface startup " + if_name_key) + dvs.port_admin_set(if_name_key, "up") dvs.servers[i].runcmd("ip link set down dev eth0") == 0 dvs.servers[i].runcmd("ip link set up dev eth0") == 0 bank = 0 @@ -619,7 +619,7 @@ def fine_grained_ecmp_base_test(dvs, match_mode): remove_entry(config_db, VLAN_IF_TB, vlan_name_key) remove_entry(config_db, VLAN_MEMB_TB, vlan_name_key + "|" + if_name_key) remove_entry(config_db, VLAN_TB, vlan_name_key) - dvs.runcmd("config interface shutdown " + if_name_key) + dvs.port_admin_set(if_name_key, "down") dvs.servers[i].runcmd("ip link set down dev eth0") == 0 remove_entry(config_db, "FG_NHG_MEMBER", "10.0.0." + str(1 + i*2)) @@ -770,7 +770,7 @@ def test_fgnhg_matchmode_nexthop_multi_route(self, dvs, testlog): ip_pref_key = "Ethernet" + str(i*4) + "|10.0.0." + str(i*2) + "/31" create_entry(config_db, IF_TB, if_name_key, fvs_nul) create_entry(config_db, IF_TB, ip_pref_key, fvs_nul) - dvs.runcmd("config interface startup " + if_name_key) + dvs.port_admin_set(if_name_key, "up") shutdown_link(dvs, app_db, i) startup_link(dvs, app_db, i) dvs.runcmd("arp -s 10.0.0." + str(1 + i*2) + " 00:00:00:00:00:" + str(1 + i*2)) diff --git a/tests/test_inband_intf_mgmt_vrf.py b/tests/test_inband_intf_mgmt_vrf.py index 05aa1f7389b4..4b1b8c86edad 100644 --- a/tests/test_inband_intf_mgmt_vrf.py +++ b/tests/test_inband_intf_mgmt_vrf.py @@ -14,7 +14,6 @@ def setup_db(self, dvs): def add_mgmt_vrf(self, dvs): initial_entries = set(self.asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_VIRTUAL_ROUTER")) - #dvs.runcmd("config vrf add mgmt") dvs.runcmd("ip link add mgmt type vrf table 5000") dvs.runcmd("ifconfig mgmt up") time.sleep(2) diff --git a/tests/test_mclag_fdb.py b/tests/test_mclag_fdb.py index 5049859437d9..a4e5ff0f9dbc 100644 --- a/tests/test_mclag_fdb.py +++ b/tests/test_mclag_fdb.py @@ -76,7 +76,7 @@ def how_many_entries_exist(db, table): @pytest.mark.dev_sanity def test_mclagFdb_basic_config_add(dvs, testlog): dvs.setup_db() - dvs.runcmd("sonic-clear fdb all") + dvs.clear_fdb() time.sleep(2) vlan_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") diff --git a/tests/test_mux.py b/tests/test_mux.py index e9eb027a9d1b..20ac1832c165 100644 --- a/tests/test_mux.py +++ b/tests/test_mux.py @@ -61,8 +61,8 @@ def create_vlan_interface(self, confdb, asicdb, dvs): confdb.create_entry("VLAN_INTERFACE", "Vlan1000|192.168.0.1/24", fvs) confdb.create_entry("VLAN_INTERFACE", "Vlan1000|fc02:1000::1/64", fvs) - dvs.runcmd("config interface startup Ethernet0") - dvs.runcmd("config interface startup Ethernet4") + dvs.port_admin_set("Ethernet0", "up") + dvs.port_admin_set("Ethernet4", "up") def create_mux_cable(self, confdb): diff --git a/tests/test_nhg.py b/tests/test_nhg.py index 2d004f6c1ba2..94d581b47cf4 100644 --- a/tests/test_nhg.py +++ b/tests/test_nhg.py @@ -135,7 +135,7 @@ def config_intf(self, i): self.config_db.create_entry("INTERFACE", self.port_name(i), fvs) self.config_db.create_entry("INTERFACE", "{}|{}".format(self.port_name(i), self.port_ipprefix(i)), fvs) - self.dvs.runcmd("config interface startup " + self.port_name(i)) + self.dvs.port_admin_set(self.port_name(i), "up") self.dvs.runcmd("arp -s {} {}".format(self.peer_ip(i), self.port_mac(i))) assert self.dvs.servers[i].runcmd("ip link set down dev eth0") == 0 assert self.dvs.servers[i].runcmd("ip link set up dev eth0") == 0 diff --git a/tests/test_pfcwd.py b/tests/test_pfcwd.py index 78cd8515741f..2707588580e8 100644 --- a/tests/test_pfcwd.py +++ b/tests/test_pfcwd.py @@ -103,7 +103,7 @@ def setup_test(self, dvs): # set cable len to non zero value. if port is down, default cable len is 0 self.set_cable_len(port, "5m") # startup port - dvs.runcmd("config interface startup {}".format(port)) + dvs.port_admin_set(port, "up") # enable pfcwd self.set_flex_counter_status("PFCWD", "enable") @@ -120,7 +120,7 @@ def teardown_test(self, dvs): if self.orig_cable_len: self.set_cable_len(port, self.orig_cable_len[port]) # shutdown port - dvs.runcmd("config interface shutdown {}".format(port)) + dvs.port_admin_set(port, "down") def get_db_handle(self, dvs): self.app_db = dvs.get_app_db() diff --git a/tests/test_port.py b/tests/test_port.py index 4766c87debec..c63dae5c57d1 100644 --- a/tests/test_port.py +++ b/tests/test_port.py @@ -59,11 +59,11 @@ def test_PortMtu(self, dvs, testlog): assert fv[1] == "9100" def test_PortNotification(self, dvs, testlog): - dvs.runcmd("config interface startup Ethernet0") - dvs.runcmd("config interface ip add Ethernet0 10.0.0.0/31") + dvs.port_admin_set("Ethernet0", "up") + dvs.interface_ip_add("Ethernet0", "10.0.0.0/31") - dvs.runcmd("config interface startup Ethernet4") - dvs.runcmd("config interface ip add Ethernet4 10.0.0.2/31") + dvs.port_admin_set("Ethernet4", "up") + dvs.interface_ip_add("Ethernet4", "10.0.0.2/31") dvs.servers[0].runcmd("ip link set down dev eth0") == 0 @@ -126,11 +126,11 @@ def test_PortFecForce(self, dvs, testlog): adb.wait_for_field_match("ASIC_STATE:SAI_OBJECT_TYPE_PORT", port_oid, expected_fields) def test_PortFec(self, dvs, testlog): - dvs.runcmd("config interface startup Ethernet0") - dvs.runcmd("config interface ip add Ethernet0 10.0.0.0/31") + dvs.port_admin_set("Ethernet0", "up") + dvs.interface_ip_add("Ethernet0", "10.0.0.0/31") - dvs.runcmd("config interface startup Ethernet4") - dvs.runcmd("config interface ip add Ethernet4 10.0.0.2/31") + dvs.port_admin_set("Ethernet4", "up") + dvs.interface_ip_add("Ethernet4", "10.0.0.2/31") dvs.servers[0].runcmd("ip link set down dev eth0") == 0 diff --git a/tests/test_port_an.py b/tests/test_port_an.py index 93add09b9ab2..dc98f43d0e40 100644 --- a/tests/test_port_an.py +++ b/tests/test_port_an.py @@ -254,9 +254,8 @@ def test_PortAutoNegWarm(self, dvs, testlog): cfvs = swsscommon.FieldValuePairs([("admin_status", "up")]) ctbl.set("Ethernet0", cfvs) - # enable warm restart - (exitcode, result) = dvs.runcmd("config warm_restart enable swss") - assert exitcode == 0 + + dvs.warm_restart_swss("true") # freeze orchagent for warm restart (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check") @@ -290,9 +289,9 @@ def test_PortAutoNegWarm(self, dvs, testlog): finally: # disable warm restart - dvs.runcmd("config warm_restart disable swss") + dvs.warm_restart_swss("disable") # slow down crm polling - dvs.runcmd("crm config polling interval 10000") + dvs.crm_poll_set("10000") # Add Dummy always-pass test at end as workaroud diff --git a/tests/test_sflow.py b/tests/test_sflow.py index e3c95a694657..f6ab6a3c1344 100644 --- a/tests/test_sflow.py +++ b/tests/test_sflow.py @@ -146,7 +146,6 @@ def test_SamplingRatePortCfgUpdate(self, dvs, testlog): ''' self.setup_sflow(dvs) appldb = dvs.get_app_db() - #dvs.runcmd("portconfig -p {} -s {}".format("Ethernet0", "25000")) self.cdb.update_entry("PORT", "Ethernet0", {'speed' : "25000"}) expected_fields = {"sample_rate": self.speed_rate_table["25000"]} appldb.wait_for_field_match("SFLOW_SESSION_TABLE", "Ethernet0", expected_fields) diff --git a/tests/test_warm_reboot.py b/tests/test_warm_reboot.py index 1a10c9455a3b..cf525a64f33b 100644 --- a/tests/test_warm_reboot.py +++ b/tests/test_warm_reboot.py @@ -237,6 +237,20 @@ def ping_new_ips(dvs): dvs.runcmd(['sh', '-c', "ping -c 1 -W 0 -q {}.0.0.{} > /dev/null 2>&1".format(i*4, j+NUM_NEIGH_PER_INTF+2)]) dvs.runcmd(['sh', '-c', "ping6 -c 1 -W 0 -q {}00::{} > /dev/null 2>&1".format(i*4, j+NUM_NEIGH_PER_INTF+2)]) +def warm_restart_set(dvs, app, enable): + db = swsscommon.DBConnector(6, dvs.redis_sock, 0) + tbl = swsscommon.Table(db, "WARM_RESTART_ENABLE_TABLE") + fvs = swsscommon.FieldValuePairs([("enable",enable)]) + tbl.set(app, fvs) + time.sleep(1) + + +def warm_restart_timer_set(dvs, app, timer, val): + db = swsscommon.DBConnector(4, dvs.redis_sock, 0) + tbl = swsscommon.Table(db, "WARM_RESTART") + fvs = swsscommon.FieldValuePairs([(timer, val)]) + tbl.set(app, fvs) + time.sleep(1) class TestWarmReboot(object): def test_PortSyncdWarmRestart(self, dvs, testlog): @@ -245,10 +259,10 @@ def test_PortSyncdWarmRestart(self, dvs, testlog): appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) - dvs.runcmd("config warm_restart enable swss") + dvs.warm_restart_swss("true") - dvs.runcmd("config interface startup Ethernet16") - dvs.runcmd("config interface startup Ethernet20") + dvs.port_admin_set("Ethernet16", "up") + dvs.port_admin_set("Ethernet20", "up") time.sleep(1) @@ -259,8 +273,8 @@ def test_PortSyncdWarmRestart(self, dvs, testlog): intf_tbl.set("Ethernet20|11.0.0.9/29", fvs) intf_tbl.set("Ethernet16", fvs) intf_tbl.set("Ethernet20", fvs) - dvs.runcmd("config interface startup Ethernet16") - dvs.runcmd("config interface startup Ethernet20") + dvs.port_admin_set("Ethernet16", "up") + dvs.port_admin_set("Ethernet20", "up") dvs.servers[4].runcmd("ip link set down dev eth0") == 0 dvs.servers[4].runcmd("ip link set up dev eth0") == 0 @@ -339,12 +353,12 @@ def test_VlanMgrdWarmRestart(self, dvs, testlog): dvs.runcmd("ifconfig Ethernet16 0") dvs.runcmd("ifconfig Ethernet20 0") - dvs.runcmd("config interface startup Ethernet16 ") - dvs.runcmd("config interface startup Ethernet20 ") + dvs.port_admin_set("Ethernet16", "up") + dvs.port_admin_set("Ethernet20", "up") time.sleep(1) - dvs.runcmd("config warm_restart enable swss") + dvs.warm_restart_swss("true") # create vlan create_entry_tbl( @@ -387,8 +401,6 @@ def test_VlanMgrdWarmRestart(self, dvs, testlog): intf_tbl.set("Vlan20|11.0.0.9/29", fvs) intf_tbl.set("Vlan16", fvs) intf_tbl.set("Vlan20", fvs) - dvs.runcmd("config interface startup Vlan16") - dvs.runcmd("config interface startup Vlan20") dvs.servers[4].runcmd("ifconfig eth0 11.0.0.2/29") dvs.servers[4].runcmd("ip route add default via 11.0.0.1") @@ -453,7 +465,7 @@ def test_IntfMgrdWarmRestartNoInterfaces(self, dvs, testlog): state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) restore_count = swss_get_RestoreCount(dvs, state_db) - dvs.runcmd("config warm_restart enable swss") + dvs.warm_restart_swss("true") dvs.runcmd("supervisorctl restart intfmgrd") reached_desired_state = False @@ -474,7 +486,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) - dvs.runcmd("config warm_restart enable swss") + dvs.warm_restart_swss("true") # # Testcase1: @@ -503,8 +515,8 @@ def test_swss_neighbor_syncup(self, dvs, testlog): intf_tbl.set("{}".format(intfs[1]), fvs) intf_tbl.set("{}".format(intfs[0]), fvs) intf_tbl.set("{}".format(intfs[1]), fvs) - dvs.runcmd("config interface startup {}".format(intfs[0])) - dvs.runcmd("config interface startup {}".format(intfs[1])) + dvs.port_admin_set(intfs[0], "up") + dvs.port_admin_set(intfs[1], "up") ips = ["24.0.0.2", "24.0.0.3", "28.0.0.2", "28.0.0.3"] v6ips = ["2400::2", "2400::3", "2800::2", "2800::3"] @@ -748,7 +760,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): # setup timer in configDB timer_value = "15" - dvs.runcmd("config warm_restart neighsyncd_timer {}".format(timer_value)) + warm_restart_timer_set(dvs, "swss", "neighsyncd_timer", timer_value) # get restore_count restore_count = swss_get_RestoreCount(dvs, state_db) @@ -847,7 +859,7 @@ def test_OrchagentWarmRestartReadyCheck(self, dvs, testlog): time.sleep(1) - dvs.runcmd("config warm_restart enable swss") + dvs.warm_restart_swss("true") config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) intf_tbl = swsscommon.Table(config_db, "INTERFACE") @@ -856,8 +868,8 @@ def test_OrchagentWarmRestartReadyCheck(self, dvs, testlog): intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) intf_tbl.set("Ethernet0", fvs) intf_tbl.set("Ethernet4", fvs) - dvs.runcmd("config interface startup Ethernet0") - dvs.runcmd("config interface startup Ethernet4") + dvs.port_admin_set("Ethernet0", "up") + dvs.port_admin_set("Ethernet4", "up") dvs.servers[0].runcmd("ifconfig eth0 10.0.0.1/31") dvs.servers[0].runcmd("ip route add default via 10.0.0.0") @@ -916,7 +928,7 @@ def test_swss_port_state_syncup(self, dvs, testlog): conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) - dvs.runcmd("config warm_restart enable swss") + dvs.warm_restart_swss("true") tbl = swsscommon.Table(appl_db, swsscommon.APP_PORT_TABLE_NAME) @@ -931,9 +943,9 @@ def test_swss_port_state_syncup(self, dvs, testlog): intf_tbl.set("Ethernet0", fvs) intf_tbl.set("Ethernet4", fvs) intf_tbl.set("Ethernet8", fvs) - dvs.runcmd("config interface startup Ethernet0") - dvs.runcmd("config interface startup Ethernet4") - dvs.runcmd("config interface startup Ethernet8") + dvs.port_admin_set("Ethernet0", "up") + dvs.port_admin_set("Ethernet4", "up") + dvs.port_admin_set("Ethernet8", "up") dvs.runcmd("arp -s 10.0.0.1 00:00:00:00:00:01") dvs.runcmd("arp -s 10.0.0.3 00:00:00:00:00:02") @@ -1102,9 +1114,9 @@ def test_routing_WarmRestart(self, dvs, testlog): intf_tbl.set("{}".format(intfs[1]), fvs) intf_tbl.set("{}".format(intfs[2]), fvs) intf_tbl.set("{}".format(intfs[2]), fvs) - dvs.runcmd("config interface startup {}".format(intfs[0])) - dvs.runcmd("config interface startup {}".format(intfs[1])) - dvs.runcmd("config interface startup {}".format(intfs[2])) + dvs.port_admin_set(intfs[0], "up") + dvs.port_admin_set(intfs[1], "up") + dvs.port_admin_set(intfs[2], "up") time.sleep(1) @@ -1199,8 +1211,8 @@ def test_routing_WarmRestart(self, dvs, testlog): # The following two instructions will be substituted by the commented ones # once the later ones are added to sonic-utilities repo. - dvs.runcmd("config warm_restart enable bgp") - dvs.runcmd("config warm_restart bgp_timer {}".format(restart_timer)) + warm_restart_set(dvs, "bgp", "true") + warm_restart_timer_set(dvs, "bgp", "bgp_timer", str(restart_timer)) time.sleep(1) @@ -1711,7 +1723,7 @@ def test_routing_WarmRestart(self, dvs, testlog): del_entry_tbl(state_db, "BGP_STATE_TABLE", "IPv4|eoiu") del_entry_tbl(state_db, "BGP_STATE_TABLE", "IPv6|eoiu") - dvs.runcmd("config warm_restart bgp_timer {}".format(restart_timer)) + warm_restart_timer_set(dvs, "bgp", "bgp_timer", str(restart_timer)) # Restart zebra dvs.stop_zebra() dvs.start_zebra() @@ -1854,7 +1866,7 @@ def test_system_warmreboot_neighbor_syncup(self, dvs, testlog): flush_neigh_entries(dvs) time.sleep(5) - dvs.runcmd("config warm_restart enable system") + warm_restart_set(dvs, "system", "true") # Test neighbors on NUM_INTF (e,g 8) interfaces # Ethernet32/36/.../60, with ip: 32.0.0.1/24... 60.0.0.1/24 @@ -1877,7 +1889,7 @@ def test_system_warmreboot_neighbor_syncup(self, dvs, testlog): intf_tbl.set("Ethernet{}|{}00::1/64".format(i*4, i*4), fvs) intf_tbl.set("Ethernet{}".format(i*4, i*4), fvs) intf_tbl.set("Ethernet{}".format(i*4, i*4), fvs) - dvs.runcmd("config interface startup Ethernet{}".format(i*4, i*4)) + dvs.port_admin_set("Ethernet{}".format(i*4), "up") dvs.servers[i].runcmd("ip link set up dev eth0") dvs.servers[i].runcmd("ip addr flush dev eth0") #result = dvs.servers[i].runcmd_output("ifconfig eth0 | grep HWaddr | awk '{print $NF}'") @@ -2103,7 +2115,7 @@ def test_system_warmreboot_neighbor_syncup(self, dvs, testlog): swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") # disable system warm restart - dvs.runcmd("config warm_restart disable system") + warm_restart_set(dvs, "system", "false") for i in range(8, 8+NUM_INTF): intf_tbl._del("Ethernet{}|{}.0.0.1/24".format(i*4, i*4)) @@ -2117,11 +2129,11 @@ def test_VrfMgrdWarmRestart(self, dvs, testlog): appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) - dvs.runcmd("config warm_restart enable swss") + dvs.warm_restart_swss("true") # bring up interface - dvs.runcmd("config interface startup Ethernet0 ") - dvs.runcmd("config interface startup Ethernet4 ") + dvs.port_admin_set("Ethernet0", "up") + dvs.port_admin_set("Ethernet4", "up") # create vrf create_entry_tbl(conf_db, "VRF", "Vrf_1", [('empty', 'empty')]) @@ -2285,7 +2297,7 @@ def test_MirrorSessionWarmReboot(self, dvs): # Monitor port should not change b/c routes are ECMP state_db.wait_for_field_match("MIRROR_SESSION_TABLE", "test_session", {"monitor_port": "Ethernet12"}) - dvs.runcmd("config warm_restart enable swss") + dvs.warm_restart_swss("true") dvs.stop_swss() dvs.start_swss() @@ -2332,7 +2344,7 @@ def test_EverflowWarmReboot(self, dvs, dvs_acl): asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_ACL_ENTRY", 1 + len(asic_db.default_acl_entries)) # Execute the warm reboot - dvs.runcmd("config warm_restart enable swss") + dvs.warm_restart_swss("true") dvs.stop_swss() dvs.start_swss() diff --git a/tests/test_watermark.py b/tests/test_watermark.py index 6d7c993125dc..23efedcb42df 100644 --- a/tests/test_watermark.py +++ b/tests/test_watermark.py @@ -172,6 +172,12 @@ def set_up(self, dvs): tbl.set('', [(q, "SAI_QUEUE_TYPE_ALL")]) self.all_q.append(q) + def clear_watermark(self, dvs, data): + adb = swsscommon.DBConnector(0, dvs.redis_sock, 0) + msg = json.dumps(data, separators=(',',':')) + adb.publish('WATERMARK_CLEAR_REQUEST', msg) + time.sleep(1) + def test_telemetry_period(self, dvs): self.setup_dbs(dvs) self.set_up(dvs) @@ -191,7 +197,10 @@ def test_telemetry_period(self, dvs): self.populate_asic_all(dvs, "123") - dvs.runcmd("config watermark telemetry interval {}".format(5)) + interval = {"interval": "5"} + self.config_db.create_entry("WATERMARK_TABLE", + "TELEMETRY_INTERVAL", + interval) time.sleep(self.DEFAULT_TELEMETRY_INTERVAL + 1) time.sleep(self.NEW_INTERVAL + 1) @@ -257,10 +266,7 @@ def test_clear(self, dvs): # clear pg shared watermark, and verify that headroom watermark and persistent watermarks are not affected - exitcode, output = dvs.runcmd("sonic-clear priority-group watermark shared") - time.sleep(1) - assert exitcode == 0, "CLI failure: %s" % output - # make sure it cleared + self.clear_watermark(dvs, ["USER", "PG_SHARED"]) self.verify_value(dvs, self.pgs, WmTables.user, SaiWmStats.pg_shared, "0") # make sure the rest is untouched @@ -271,9 +277,7 @@ def test_clear(self, dvs): # clear queue unicast persistent watermark, and verify that multicast watermark and user watermarks are not affected - exitcode, output = dvs.runcmd("sonic-clear queue persistent-watermark unicast") - time.sleep(1) - assert exitcode == 0, "CLI failure: %s" % output + self.clear_watermark(dvs, ["PERSISTENT", "Q_SHARED_UNI"]) # make sure it cleared self.verify_value(dvs, self.uc_q, WmTables.persistent, SaiWmStats.queue_shared, "0") @@ -289,16 +293,14 @@ def test_clear(self, dvs): # clear queue all watermark, and verify that multicast and unicast watermarks are not affected # clear persistent all watermark - exitcode, output = dvs.runcmd("sonic-clear queue persistent-watermark all") - time.sleep(1) - assert exitcode == 0, "CLI failure: %s" % output + self.clear_watermark(dvs, ["PERSISTENT", "Q_SHARED_ALL"]) + # make sure it cleared self.verify_value(dvs, self.all_q, WmTables.persistent, SaiWmStats.queue_shared, "0") # clear user all watermark - exitcode, output = dvs.runcmd("sonic-clear queue watermark all") - time.sleep(1) - assert exitcode == 0, "CLI failure: %s" % output + self.clear_watermark(dvs, ["USER", "Q_SHARED_ALL"]) + # make sure it cleared self.verify_value(dvs, self.all_q, WmTables.user, SaiWmStats.queue_shared, "0")