From cc450eebe9be5f317ad215f266fb49be9a659cd9 Mon Sep 17 00:00:00 2001 From: yaqiangz Date: Wed, 20 Sep 2023 06:31:19 +0000 Subject: [PATCH] Add ut --- tests/mock_tables/config_db.json | 5 +++++ tests/vlan_test.py | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/tests/mock_tables/config_db.json b/tests/mock_tables/config_db.json index 07fc66db9e..f622184e26 100644 --- a/tests/mock_tables/config_db.json +++ b/tests/mock_tables/config_db.json @@ -2723,5 +2723,10 @@ "alias": "Fabric2", "isolateStatus": "False", "lanes": "2" + }, + "DHCP_RELAY|Vlan1000": { + "dhcpv6_servers": [ + "fc02:2000::1" + ] } } diff --git a/tests/vlan_test.py b/tests/vlan_test.py index 456bb5dd11..5212a7b026 100644 --- a/tests/vlan_test.py +++ b/tests/vlan_test.py @@ -1377,3 +1377,37 @@ def teardown_class(cls): os.environ['UTILITIES_UNIT_TESTING'] = "0" bgp_util.run_bgp_command = cls._old_run_bgp_command print("TEARDOWN") + + def test_config_vlan_del_dhcp_relay_restart(self): + runner = CliRunner() + db = Db() + obj = {"config_db": db.cfgdb} + + # remove vlan IP`s + result = runner.invoke(config.config.commands["interface"].commands["ip"].commands["remove"], + ["Vlan1000", "192.168.0.1/21"], obj=obj) + print(result.exit_code, result.output) + assert result.exit_code != 0 + + result = runner.invoke(config.config.commands["interface"].commands["ip"].commands["remove"], + ["Vlan1000", "fc02:1000::1/64"], obj=obj) + print(result.exit_code, result.output) + assert result.exit_code != 0 + + # remove vlan members + vlan_member = db.cfgdb.get_table("VLAN_MEMBER") + keys = [(k, v) for k, v in vlan_member if k == "Vlan{}".format(1000)] + for _, v in keys: + result = runner.invoke(config.config.commands["vlan"].commands["member"].commands["del"], ["1000", v], obj=db) + print(result.exit_code) + print(result.output) + assert result.exit_code == 0 + + origin_run_command_func = config.vlan.clicommon.run_command + config.vlan.clicommon.run_command = mock.MagicMock(return_value=("active", 0)) + result = runner.invoke(config.config.commands["vlan"].commands["del"], ["1000"], obj=db) + print(result.exit_code) + print(result.output) + assert result.exit_code == 0 + + config.vlan.clicommon.run_command = origin_run_command_func