Skip to content

Commit d1f4413

Browse files
yaqiangzyxieca
authored andcommitted
[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 051f28c commit d1f4413

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 time import sleep
67
from .utils import log
@@ -64,6 +65,14 @@ def is_dhcpv6_relay_config_exist(db, vlan_name):
6465
return True
6566

6667

68+
def delete_state_db_entry(entry_name):
69+
state_db = SonicV2Connector()
70+
state_db.connect(state_db.STATE_DB)
71+
exists = state_db.exists(state_db.STATE_DB, 'DHCPv6_COUNTER_TABLE|{}'.format(entry_name))
72+
if exists:
73+
state_db.delete(state_db.STATE_DB, 'DHCPv6_COUNTER_TABLE|{}'.format(entry_name))
74+
75+
6776
@vlan.command('del')
6877
@click.argument('vid', metavar='<vid>', required=True, type=int)
6978
@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):
106115
# set dhcpv4_relay table
107116
set_dhcp_relay_table('VLAN', db.cfgdb, vlan, None)
108117

118+
delete_state_db_entry(vlan)
119+
109120
if not no_restart_dhcp_relay and is_dhcpv6_relay_config_exist(db, vlan):
110121
# set dhcpv6_relay table
111122
set_dhcp_relay_table(DHCP_RELAY_TABLE, db.cfgdb, 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)