Skip to content

Commit

Permalink
Fixed check cases in vlan.py and modified functions in intfutil for v…
Browse files Browse the repository at this point in the history
…lan mode status
  • Loading branch information
MuhammadUmarAsad committed Oct 21, 2022
1 parent fb2921d commit 4e660a2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
46 changes: 24 additions & 22 deletions config/vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ def del_vlan(db, vid, multiple):
for intf_key in intf_table:
if ((type(intf_key) is str and intf_key == 'Vlan{}'.format(vid)) or # TODO: 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))
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)]

Expand All @@ -126,21 +125,20 @@ def del_vlan(db, vid, multiple):


def restart_ndppd():
verify_swss_running_cmd = "docker container inspect -f '{{.State.Status}}' swss"
docker_exec_cmd = "docker exec -i swss {}"
ndppd_config_gen_cmd = "sonic-cfggen -d -t /usr/share/sonic/templates/ndppd.conf.j2,/etc/ndppd.conf"
ndppd_restart_cmd = "supervisorctl restart ndppd"

output = clicommon.run_command(verify_swss_running_cmd, return_cmd=True)

if output and output.strip() != "running":
click.echo(click.style('SWSS container is not running, changes will take effect the next time the SWSS container starts',fg='red'), )
click.echo(click.style('SWSS container is not running, changes will take effect the next time the SWSS container starts', fg='red'),)
return

clicommon.run_command(docker_exec_cmd.format(
ndppd_config_gen_cmd), display_cmd=True)
clicommon.run_command(docker_exec_cmd.format(ndppd_config_gen_cmd), display_cmd=True)
sleep(3)
clicommon.run_command(docker_exec_cmd.format(
ndppd_restart_cmd), display_cmd=True)
clicommon.run_command(docker_exec_cmd.format(ndppd_restart_cmd), display_cmd=True)


@vlan.command('proxy_arp')
Expand Down Expand Up @@ -186,6 +184,9 @@ def add_vlan_member(db, vid, port, untagged, multiple, except_flag):

ctx = click.get_current_context()
config_db = ValidatedConfigDBConnector(db.cfgdb)

port_flag = False
portchannel_flag = False
# parser will parse the vid input if there are syntax errors it will throw error

vid_list = clicommon.vlan_member_input_parser(ctx, db, except_flag, multiple, vid)
Expand All @@ -199,7 +200,7 @@ def add_vlan_member(db, vid, port, untagged, multiple, except_flag):

# default vlan checker
if vid == 1:
ctx.fail("{} is default VLAN. Use switchport command".format(vlan))
ctx.fail("{} is default VLAN".format(vlan))

log.log_info("'vlan member add {} {}' executing...".format(vid, port))

Expand Down Expand Up @@ -250,20 +251,21 @@ def add_vlan_member(db, vid, port, untagged, multiple, except_flag):
ctx.fail("{} is already untagged member!".format(port))

# checking mode status of port if its access, trunk or routed
port_table_data = db.cfgdb.get_table('PORT')
port_data = port_table_data[port]

if "mode" not in port_data:
ctx.fail("{} is in routed mode!\nUse switchport mode command to changes port mode")
else:
existing_mode = port_data["mode"]

mode_type = "access" if untagged else "trunk"
if existing_mode == "access" and mode_type == "trunk": # TODO: MISSING CONSTRAINT IN YANG MODEL
ctx.fail("{} is in access mode! Tagged Members cannot be added".format(existing_mode))

if existing_mode == mode_type or (existing_mode == "trunk" and mode_type == "access"):
pass
if is_port:
port_table_data = db.cfgdb.get_table('PORT')
port_data = port_table_data[port]

if "mode" not in port_data:
ctx.fail("{} is in routed mode!\nUse switchport mode command to changes port mode")
else:
existing_mode = port_data["mode"]

mode_type = "access" if untagged else "trunk"
if existing_mode == "access" and mode_type == "trunk": # TODO: MISSING CONSTRAINT IN YANG MODEL
ctx.fail("{} is in access mode! Tagged Members cannot be added".format(existing_mode))

if existing_mode == mode_type or (existing_mode == "trunk" and mode_type == "access"):
pass

# in case of exception in list last added member will be shown to user
try:
Expand Down
9 changes: 6 additions & 3 deletions scripts/intfutil
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,12 @@ def appl_db_portchannel_status_get(appl_db, config_db, po_name, status_type, por
return status
if status_type == "vlan":
port_table = config_db.get_table('PORT')
port_data = port_table[po_name]
if "mode" in port_data:
status = port_data["mode"]
if po_name in port_table:
port_data = port_table[po_name]
if "mode" in port_data:
status = port_data["mode"]
elif combined_int_to_vlan_po_dict and po_name in combined_int_to_vlan_po_dict.keys():
status = "trunk"
else:
status = "routed"
return status
Expand Down

0 comments on commit 4e660a2

Please sign in to comment.