Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix enable ipv6-link-local-only fail on VLAN interface without IP #3526

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5829,8 +5829,12 @@ def enable_use_link_local_only(ctx, interface_name):
ctx.fail("Interface name %s is invalid. Please enter a valid interface name!!" %(interface_name))

if (interface_type == "VLAN_INTERFACE"):
if not clicommon.is_valid_vlan_interface(db, interface_name):
ctx.fail("Interface name %s is invalid. Please enter a valid interface name!!" %(interface_name))
if not clicommon.check_if_vlanid_exist(db, interface_name):
ctx.fail("{} is nonexistent. Please create vlan first!!"
.format(interface_name))
if not clicommon.has_vlan_member(db, interface_name):
ctx.fail("{} has no member joined. Please make sure at least one vlan member joined the vlan!!"
.format(interface_name))

portchannel_member_table = db.get_table('PORTCHANNEL_MEMBER')

Expand Down Expand Up @@ -5882,8 +5886,12 @@ def disable_use_link_local_only(ctx, interface_name):
ctx.fail("Interface name %s is invalid. Please enter a valid interface name!!" %(interface_name))

if (interface_type == "VLAN_INTERFACE"):
if not clicommon.is_valid_vlan_interface(db, interface_name):
ctx.fail("Interface name %s is invalid. Please enter a valid interface name!!" %(interface_name))
if not clicommon.check_if_vlanid_exist(db, interface_name):
ctx.fail("{} is nonexistent. Please create vlan first!!"
.format(interface_name))
if not clicommon.has_vlan_member(db, interface_name):
ctx.fail("{} has no member joined. Please make sure at least one vlan member joined the vlan!!"
.format(interface_name))

portchannel_member_table = db.get_table('PORTCHANNEL_MEMBER')

Expand Down
50 changes: 49 additions & 1 deletion tests/ipv6_link_local_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def test_config_enable_disable_ipv6_link_local_on_interface_which_is_member_of_p
runner = CliRunner()
db = Db()
obj = {'db':db.cfgdb}

# Enable ipv6 link local on Ethernet32
result = runner.invoke(config.config.commands["interface"].commands["ipv6"].commands["enable"].commands["use-link-local-only"], ["Ethernet32"], obj=obj)
print(result.exit_code)
Expand Down Expand Up @@ -234,6 +234,54 @@ def test_vlan_member_add_on_link_local_interface(self):
assert result.exit_code != 0
assert 'Error: Ethernet40 is a router interface!' in result.output

def test_config_enable_disable_ipv6_link_local_on_nonexistent_vlan(self):
runner = CliRunner()
db = Db()
obj = {'db': db.cfgdb}

# Enable ipv6 link local on nonexistent Vlan10
result = runner.invoke(
config.config.commands["interface"].commands["ipv6"].commands["enable"].commands["use-link-local-only"],
["Vlan10"], obj=obj)
print(result.exit_code)
print(result.output)
assert result.exit_code != 0
assert 'Error: Vlan10 is nonexistent. Please create vlan first!!' in result.output

# Disable ipv6 link local on nonexistent Vlan10
result = runner.invoke(
config.config.commands["interface"].commands["ipv6"].commands["disable"].commands["use-link-local-only"],
["Vlan10"], obj=obj)
print(result.exit_code)
print(result.output)
assert result.exit_code != 0
assert 'Error: Vlan10 is nonexistent. Please create vlan first!!' in result.output

def test_config_enable_disable_ipv6_link_local_on_vlan_no_member_joined(self):
runner = CliRunner()
db = Db()
obj = {'db': db.cfgdb}

# Enable ipv6 link local on Vlan3000 no member joined
result = runner.invoke(
config.config.commands["interface"].commands["ipv6"].commands["enable"].commands["use-link-local-only"],
["Vlan3000"], obj=obj)
print(result.exit_code)
print(result.output)
assert result.exit_code != 0
assert 'Error: Vlan3000 has no member joined. Please make sure at least one vlan member joined the vlan!!' \
in result.output

# Disable ipv6 link local on Vlan3000 no member joined
result = runner.invoke(
config.config.commands["interface"].commands["ipv6"].commands["disable"].commands["use-link-local-only"],
["Vlan3000"], obj=obj)
print(result.exit_code)
print(result.output)
assert result.exit_code != 0
assert 'Error: Vlan3000 has no member joined. Please make sure at least one vlan member joined the vlan!!' \
in result.output

@classmethod
def teardown_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "0"
Expand Down
13 changes: 12 additions & 1 deletion utilities_common/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,25 @@ def is_vlanid_in_range(vid):


def check_if_vlanid_exist(config_db, vlan, table_name='VLAN'):
"""Check if vlan id exits in the config db or ot"""
"""Check if vlan id exists in the config db or not"""

if len(config_db.get_entry(table_name, vlan)) != 0:
return True

return False


def has_vlan_member(config_db, vlan):
"""Check if vlan has any member joined"""

vlan_ports_data = config_db.get_table('VLAN_MEMBER')
for key in vlan_ports_data:
if key[0] == vlan:
return True

return False


def is_port_vlan_member(config_db, port, vlan):
"""Check if port is a member of vlan"""

Expand Down
Loading