Skip to content

Commit

Permalink
re-add removed adhoc validation
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelmsft authored and Ubuntu committed Aug 12, 2022
1 parent 405dd9b commit 4bcd2d2
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1896,13 +1896,18 @@ def portchannel(db, ctx, namespace):
def add_portchannel(ctx, portchannel_name, min_links, fallback):
"""Add port channel"""

if ADHOC_VALIDATION:
if is_portchannel_name_valid(portchannel_name) != True:
ctx.fail("{} is invalid!, name should have prefix '{}' and sufix '{}'"
.format(portchannel_name, CFG_PORTCHANNEL_PREFIX, CFG_PORTCHANNEL_NO))

db = ValidatedConfigDBConnector(ctx.obj['db'], ADHOC_VALIDATION)

if is_portchannel_present_in_db(db, portchannel_name):
ctx.fail("{} already exists!".format(portchannel_name))

fvs = {'admin_status': 'up',
'mtu': '9100',
'mtu': '9100',
'lacp_key': 'auto'}
if min_links != 0:
fvs['min_links'] = str(min_links)
Expand All @@ -1919,6 +1924,15 @@ def add_portchannel(ctx, portchannel_name, min_links, fallback):
def remove_portchannel(ctx, portchannel_name):
"""Remove port channel"""

if ADHOC_VALIDATION:
if is_portchannel_name_valid(portchannel_name) != True:
ctx.fail("{} is invalid!, name should have prefix '{}' and suffix'{}'"
.format(portchannel_name, CFG_PORTCHANNEL_PREFIX, CFG_PORTCHANNEL_NO))

# Don't proceed if the port channel does not exist
if is_portchannel_present_in_db(db, portchannel_name) is False:
ctx.fail("{} is not present.".format(portchannel_name))

db = ValidatedConfigDBConnector(ctx.obj['db'], ADHOC_VALIDATION)

if len([(k, v) for k, v in db.get_table('PORTCHANNEL_MEMBER') if k == portchannel_name]) != 0:
Expand Down Expand Up @@ -5930,6 +5944,11 @@ def loopback(ctx, redis_unix_socket_path):
def add_loopback(ctx, loopback_name):
config_db = ValidatedConfigDBConnector(ctx.obj['db'], ADHOC_VALIDATION)

if ADHOC_VALIDATION:
if is_loopback_name_valid(loopback_name) is False:
ctx.fail("{} is invalid, name should have prefix '{}' and suffix '{}' "
.format(loopback_name, CFG_LOOPBACK_PREFIX, CFG_LOOPBACK_NO))

lo_intfs = [k for k, v in config_db.get_table('LOOPBACK_INTERFACE').items() if type(k) != tuple]
if loopback_name in lo_intfs:
ctx.fail("{} already exists".format(loopback_name))
Expand All @@ -5944,9 +5963,17 @@ def add_loopback(ctx, loopback_name):
@click.pass_context
def del_loopback(ctx, loopback_name):
config_db = ValidatedConfigDBConnector(ctx.obj['db'], ADHOC_VALIDATION)

lo_config_db = config_db.get_table('LOOPBACK_INTERFACE')

if ADHOC_VALIDATION:
if is_loopback_name_valid(loopback_name) is False:
ctx.fail("{} is invalid, name should have prefix '{}' and suffix '{}' "
.format(loopback_name, CFG_LOOPBACK_PREFIX, CFG_LOOPBACK_NO))
lo_intfs = [k for k, v in lo_config_db.items() if type(k) != tuple]
if loopback_name not in lo_intfs:
ctx.fail("{} does not exist".format(loopback_name))

ips = [ k[1] for k in lo_config_db if type(k) == tuple and k[0] == loopback_name ]
for ip in ips:
config_db.set_entry('LOOPBACK_INTERFACE', (loopback_name, ip), None)
Expand Down

0 comments on commit 4bcd2d2

Please sign in to comment.