Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sabakram committed May 6, 2024
1 parent 3f43e37 commit bdc536b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
16 changes: 9 additions & 7 deletions config/vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#
# 'vlan' group ('config vlan ...')
#


@click.group(cls=clicommon.AbbreviationGroup, name='vlan')
def vlan():
"""VLAN-related configuration tasks"""
Expand Down Expand Up @@ -52,7 +54,6 @@ def add_vlan(db, vid, multiple):
ctx.fail("{} is not integer".format(vid))
vid_list.append(int(vid))


if ADHOC_VALIDATION:

# loop will execute till an exception occurs
Expand Down Expand Up @@ -182,6 +183,7 @@ def del_vlan(db, vid, multiple, no_restart_dhcp_relay):
docker_exec_cmd + ['rm', '-f', '/etc/supervisor/conf.d/ndppd.conf'], ignore_error=True, return_cmd=True)
clicommon.run_command(docker_exec_cmd + ['supervisorctl', 'update'], return_cmd=True)


def restart_ndppd():
verify_swss_running_cmd = ['docker', 'container', 'inspect', '-f', '{{.State.Status}}', 'swss']
docker_exec_cmd = ['docker', 'exec', '-i', 'swss']
Expand Down Expand Up @@ -209,6 +211,7 @@ def restart_ndppd():
sleep(3)
clicommon.run_command(docker_exec_cmd + ndppd_restart_cmd, return_cmd=True)


@vlan.command('proxy_arp')
@click.argument('vid', metavar='<vid>', required=True, type=int)
@click.argument('mode', metavar='<mode>', required=True, type=click.Choice(["enabled", "disabled"]))
Expand All @@ -231,10 +234,13 @@ def config_proxy_arp(db, vid, mode):
#
# 'member' group ('config vlan member ...')
#


@vlan.group(cls=clicommon.AbbreviationGroup, name='member')
def vlan_member():
pass


@vlan_member.command('add')
@click.argument('vid', metavar='<vid>', required=True)
@click.argument('port', metavar='port', required=True)
Expand All @@ -247,7 +253,6 @@ def add_vlan_member(db, vid, port, untagged, multiple, except_flag):

ctx = click.get_current_context()


# parser will parse the vid input if there are syntax errors it will throw error
vid_list = clicommon.vlan_member_input_parser(ctx, "add", db, except_flag, multiple, vid, port)
# multiple vlan command cannot be used to add multiple untagged vlan members
Expand Down Expand Up @@ -306,11 +311,8 @@ def add_vlan_member(db, vid, port, untagged, multiple, except_flag):
ctx.fail("{} is in access mode! Tagged Members cannot be added".format(port))
elif 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:
config_db.set_entry('VLAN_MEMBER', (vlan, port), {'tagging_mode': "untagged" if untagged else "tagged"})
except ValueError:
ctx.fail("{} invalid VLAN ID , or {} invalid port , cannot add VLAN member".format(vlan, port))
config_db.set_entry('VLAN_MEMBER', (vlan, port), {'tagging_mode': "untagged" if untagged else "tagged"})


@vlan_member.command('del')
@click.argument('vid', metavar='<vid>', required=True)
Expand Down
1 change: 0 additions & 1 deletion tests/vlan_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,6 @@ def test_config_vlan_add_member_yang_validation(self):
["4098", "Ethernet1"], obj=obj)
print(result.exit_code)
assert result.exit_code != 0
assert "Error: Vlan4098 invalid VLAN ID , or Ethernet1 invalid port , cannot add VLAN member" in result.output

@patch("validated_config_db_connector.device_info.is_yang_config_validation_enabled", mock.Mock(return_value=True))
@patch("config.validated_config_db_connector.ValidatedConfigDBConnector.validated_mod_entry",
Expand Down

0 comments on commit bdc536b

Please sign in to comment.