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

Fixed admin state config CLI for Backport interfaces #2557

Merged
merged 3 commits into from
Jan 30, 2023
Merged
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
22 changes: 22 additions & 0 deletions tests/interfaces_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from click.testing import CliRunner
from unittest import mock
from utilities_common.intf_filter import parse_interface_in_filter

import show.main as show

Expand Down Expand Up @@ -315,6 +316,27 @@ def test_supervisor_show_interfaces_alias_etp1_without_waring(self):
print(result.output)
assert result.exit_code != 0

def test_parse_interface_in_filter(self):
intf_filter = "Ethernet0"
intf_list = parse_interface_in_filter(intf_filter)
assert len(intf_list) == 1
assert intf_list[0] == "Ethernet0"

intf_filter = "Ethernet1-3"
intf_list = parse_interface_in_filter(intf_filter)
assert len(intf_list) == 3
assert intf_list == ["Ethernet1", "Ethernet2", "Ethernet3"]

intf_filter = "Ethernet-BP10"
intf_list = parse_interface_in_filter(intf_filter)
assert len(intf_list) == 1
assert intf_list[0] == "Ethernet-BP10"

intf_filter = "Ethernet-BP10-12"
intf_list = parse_interface_in_filter(intf_filter)
assert len(intf_list) == 3
assert intf_list == ["Ethernet-BP10", "Ethernet-BP11", "Ethernet-BP12"]

@classmethod
def teardown_class(cls):
print("TEARDOWN")
16 changes: 14 additions & 2 deletions utilities_common/intf_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

SONIC_PORT_NAME_PREFIX = "Ethernet"
SONIC_LAG_NAME_PREFIX = "PortChannel"
SONIC_BACK_PORT_NAME_PREFIX = "Ethernet-BP"

def parse_interface_in_filter(intf_filter):
intf_fs = []
Expand All @@ -11,7 +12,19 @@ def parse_interface_in_filter(intf_filter):

fs = intf_filter.split(',')
for x in fs:
if '-' in x:
if x.startswith(SONIC_BACK_PORT_NAME_PREFIX):
intf = SONIC_BACK_PORT_NAME_PREFIX
x = x.split(intf)[1]
if '-' in x:
start = x.split('-')[0]
end = x.split('-')[1]
if not start.isdigit() or not end.isdigit():
continue
for i in range(int(start), int(end)+1):
intf_fs.append(intf+str(i))
else:
intf_fs.append(intf+x)
elif '-' in x:
# handle range
if not x.startswith(SONIC_PORT_NAME_PREFIX) and not x.startswith(SONIC_LAG_NAME_PREFIX):
continue
Expand Down Expand Up @@ -40,4 +53,3 @@ def interface_in_filter(intf, filter):
return True

return False