Skip to content

Commit db61efc

Browse files
authored
[vlan][dhcp_relay] Clear dhcpv6 relay counter while deleting vlan (#2852)
What I did Fix this issue: sonic-net/sonic-buildimage#15047 Show dhcp_relay ipv6 counter will display vlan which has been deleted. How I did it Remove related info in state_db while deleting a vlan How to verify it Add unit test Build utilities and run cmd to verify Signed-off-by: Yaqiang Zhu <[email protected]>
1 parent d5544b4 commit db61efc

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

config/vlan.py

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import click
22
import utilities_common.cli as clicommon
33
import utilities_common.dhcp_relay_util as dhcp_relay_util
4+
from swsscommon.swsscommon import SonicV2Connector
45

56
from jsonpatch import JsonPatchConflict
67
from time import sleep
@@ -65,6 +66,14 @@ def is_dhcpv6_relay_config_exist(db, vlan_name):
6566
return True
6667

6768

69+
def delete_state_db_entry(entry_name):
70+
state_db = SonicV2Connector()
71+
state_db.connect(state_db.STATE_DB)
72+
exists = state_db.exists(state_db.STATE_DB, 'DHCPv6_COUNTER_TABLE|{}'.format(entry_name))
73+
if exists:
74+
state_db.delete(state_db.STATE_DB, 'DHCPv6_COUNTER_TABLE|{}'.format(entry_name))
75+
76+
6877
@vlan.command('del')
6978
@click.argument('vid', metavar='<vid>', required=True, type=int)
7079
@click.option('--no_restart_dhcp_relay', is_flag=True, type=click.BOOL, required=False, default=False,
@@ -109,6 +118,8 @@ def del_vlan(db, vid, no_restart_dhcp_relay):
109118
# set dhcpv4_relay table
110119
set_dhcp_relay_table('VLAN', config_db, vlan, None)
111120

121+
delete_state_db_entry(vlan)
122+
112123
if not no_restart_dhcp_relay and is_dhcpv6_relay_config_exist(db, vlan):
113124
# set dhcpv6_relay table
114125
set_dhcp_relay_table('DHCP_RELAY', config_db, vlan, None)

tests/vlan_test.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,12 @@ def test_config_vlan_del_vlan(self, mock_restart_dhcp_relay_service):
391391
print(result.output)
392392
assert result.exit_code == 0
393393

394-
result = runner.invoke(config.config.commands["vlan"].commands["del"], ["1000"], obj=db)
395-
print(result.exit_code)
396-
print(result.output)
397-
assert result.exit_code == 0
394+
with mock.patch("config.vlan.delete_state_db_entry") as delete_state_db_entry:
395+
result = runner.invoke(config.config.commands["vlan"].commands["del"], ["1000"], obj=db)
396+
print(result.exit_code)
397+
print(result.output)
398+
assert result.exit_code == 0
399+
delete_state_db_entry.assert_called_once_with("Vlan1000")
398400

399401
# show output
400402
result = runner.invoke(show.cli.commands["vlan"].commands["brief"], [], obj=db)

0 commit comments

Comments
 (0)