diff --git a/config/vlan.py b/config/vlan.py index b60be30363..cc11d496ee 100644 --- a/config/vlan.py +++ b/config/vlan.py @@ -1,6 +1,7 @@ import click import utilities_common.cli as clicommon import utilities_common.dhcp_relay_util as dhcp_relay_util +from swsscommon.swsscommon import SonicV2Connector from time import sleep from .utils import log @@ -64,6 +65,14 @@ def is_dhcpv6_relay_config_exist(db, vlan_name): return True +def delete_state_db_entry(entry_name): + state_db = SonicV2Connector() + state_db.connect(state_db.STATE_DB) + exists = state_db.exists(state_db.STATE_DB, 'DHCPv6_COUNTER_TABLE|{}'.format(entry_name)) + if exists: + state_db.delete(state_db.STATE_DB, 'DHCPv6_COUNTER_TABLE|{}'.format(entry_name)) + + @vlan.command('del') @click.argument('vid', metavar='', required=True, type=int) @click.option('--no_restart_dhcp_relay', is_flag=True, type=click.BOOL, required=False, default=False, @@ -106,6 +115,8 @@ def del_vlan(db, vid, no_restart_dhcp_relay): # set dhcpv4_relay table set_dhcp_relay_table('VLAN', db.cfgdb, vlan, None) + delete_state_db_entry(vlan) + if not no_restart_dhcp_relay and is_dhcpv6_relay_config_exist(db, vlan): # set dhcpv6_relay table set_dhcp_relay_table(DHCP_RELAY_TABLE, db.cfgdb, vlan, None) diff --git a/tests/vlan_test.py b/tests/vlan_test.py index ce1271024b..56ac18383c 100644 --- a/tests/vlan_test.py +++ b/tests/vlan_test.py @@ -391,10 +391,12 @@ def test_config_vlan_del_vlan(self, mock_restart_dhcp_relay_service): print(result.output) assert result.exit_code == 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 + with mock.patch("config.vlan.delete_state_db_entry") as delete_state_db_entry: + result = runner.invoke(config.config.commands["vlan"].commands["del"], ["1000"], obj=db) + print(result.exit_code) + print(result.output) + assert result.exit_code == 0 + delete_state_db_entry.assert_called_once_with("Vlan1000") # show output result = runner.invoke(show.cli.commands["vlan"].commands["brief"], [], obj=db)