Skip to content

Commit

Permalink
Add note for missing constraints in YANG model
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Aug 5, 2022
1 parent b5b15bb commit 405dd9b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions config/vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def add_vlan(db, vid):

config_db = ValidatedConfigDBCOnnector(db.cfgdb, ADHOC_VALIDATION)
try:
config_db.set_entry('VLAN', vlan, {'vlanid': vid})
config_db.set_entry('VLAN', vlan, {'vlanid': str(vid)})
except ValueError:
ctx.fail("Invalid VLAN ID {} (1-4094)".format(vid))

Expand All @@ -64,21 +64,21 @@ def del_vlan(db, vid):

intf_table = db.cfgdb.get_table('VLAN_INTERFACE')
for intf_key in intf_table:
if ((type(intf_key) is str and intf_key == 'Vlan{}'.format(vid)) or
if ((type(intf_key) is str and intf_key == 'Vlan{}'.format(vid)) or # MISSING CONSTRAINT IN YANG MODEL
(type(intf_key) is tuple and intf_key[0] == 'Vlan{}'.format(vid))):
ctx.fail("{} can not be removed. First remove IP addresses assigned to this VLAN".format(vlan))

keys = [ (k, v) for k, v in db.cfgdb.get_table('VLAN_MEMBER') if k == 'Vlan{}'.format(vid) ]

if keys:
if keys: # MISSING CONSTRAINT IN YANG MODEL
ctx.fail("VLAN ID {} can not be removed. First remove all members assigned to this VLAN.".format(vid))

config_db = ValidatedConfigDBConnector(db.cfgdb, ADHOC_VALIDATION)
try:
config_db.set_entry('VLAN', 'Vlan{}'.format(vid), None)
except JsonPatchConflict:
ctx.fail("{} does not exist".format(vlan))
except ValueError:
except ValueError: # GCU prohibits empty table, but it is otherwise allowed. So we temporarily catch GCU error and then directly set empty tabe
config_db = ConfigDBConnector()
config_db.connect()
config_db.set_entry('VLAN', 'Vlan{}'.format(vid), None)
Expand Down

0 comments on commit 405dd9b

Please sign in to comment.