Skip to content

Commit 3197f39

Browse files
authored
Add check to not allow deleting PO if its member of vlan. (sonic-net#2141)
* Added check to not allow deleting PO if its member of vlan.
1 parent 2513da1 commit 3197f39

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

.DS_Store

8 KB
Binary file not shown.

config/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,11 @@ def remove_portchannel(ctx, portchannel_name):
19261926
if is_portchannel_present_in_db(db, portchannel_name) is False:
19271927
ctx.fail("{} is not present.".format(portchannel_name))
19281928

1929+
# Dont let to remove port channel if vlan membership exists
1930+
for k,v in db.get_table('VLAN_MEMBER'):
1931+
if v == portchannel_name:
1932+
ctx.fail("{} has vlan {} configured, remove vlan membership to proceed".format(portchannel_name, str(k)))
1933+
19291934
if len([(k, v) for k, v in db.get_table('PORTCHANNEL_MEMBER') if k == portchannel_name]) != 0:
19301935
click.echo("Error: Portchannel {} contains members. Remove members before deleting Portchannel!".format(portchannel_name))
19311936
else:

tests/portchannel_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,18 @@ def test_add_portchannel_member_with_pbh_bindngs(self):
179179
assert result.exit_code != 0
180180
assert "Error: Port Ethernet60 is already bound to following PBH_TABLES:" in result.output
181181

182+
def test_delete_portchannel_which_is_member_of_a_vlan(self):
183+
runner = CliRunner()
184+
db = Db()
185+
obj = {'db':db.cfgdb}
186+
187+
# try to delete the portchannel when its member of a vlan
188+
result = runner.invoke(config.config.commands["portchannel"].commands["del"], ["PortChannel1001"], obj=obj)
189+
print(result.exit_code)
190+
print(result.output)
191+
assert result.exit_code != 0
192+
assert "PortChannel1001 has vlan Vlan4000 configured, remove vlan membership to proceed" in result.output
193+
182194
@classmethod
183195
def teardown_class(cls):
184196
os.environ['UTILITIES_UNIT_TESTING'] = "0"

0 commit comments

Comments
 (0)