Skip to content

Commit

Permalink
Enhance "config interface type/advertised-type" to be blocked on RJ45…
Browse files Browse the repository at this point in the history
… ports (#2112)

* Support type check for rj45

Signed-off-by: Stephen Sun <stephens@nvidia.com>

* Add test case for config interface type/advertised-types for RJ45

Signed-off-by: Stephen Sun <stephens@nvidia.com>

* Fix review comments

Signed-off-by: Stephen Sun <stephens@nvidia.com>

* Fix unit test issue in config advertised types

Signed-off-by: Stephen Sun <stephens@nvidia.com>

Co-authored-by: Stephen Sun <stephens@nvidia.com>
  • Loading branch information
keboliu and stephenxs authored Apr 19, 2022
1 parent 3732ac5 commit 154a801
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions scripts/portconfig
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class portconfig(object):
self.is_lag = False
self.is_lag_mbr = False
self.parent = port
self.is_rj45_port = False
# Set up db connections
if namespace is None:
self.db = ConfigDBConnector()
Expand All @@ -90,6 +91,9 @@ class portconfig(object):
lag_tables = self.db.get_table(PORT_CHANNEL_TABLE_NAME)
lag_mbr_tables = self.db.get_table(PORT_CHANNEL_MBR_TABLE_NAME)
if port in port_tables:
port_transceiver_info = self.state_db.get_all(self.state_db.STATE_DB, "TRANSCEIVER_INFO|{}".format(port))
if port_transceiver_info:
self.is_rj45_port = True if port_transceiver_info.get("type") == "RJ45" else False
for key in lag_mbr_tables:
if port == key[1]:
self.parent = key[0]
Expand Down Expand Up @@ -155,6 +159,9 @@ class portconfig(object):
self.db.mod_entry(PORT_TABLE_NAME, port, {PORT_ADV_SPEEDS_CONFIG_FIELD_NAME: adv_speeds})

def set_interface_type(self, port, interface_type):
if self.is_rj45_port:
print("Setting RJ45 ports' type is not supported")
exit(1)
if self.verbose:
print("Setting interface_type %s on port %s" % (interface_type, port))
if interface_type not in VALID_INTERFACE_TYPE_SET:
Expand All @@ -164,6 +171,9 @@ class portconfig(object):
self.db.mod_entry(PORT_TABLE_NAME, port, {PORT_INTERFACE_TYPE_CONFIG_FIELD_NAME: interface_type})

def set_adv_interface_types(self, port, adv_interface_types):
if self.is_rj45_port:
print("Setting RJ45 ports' advertised types is not supported")
exit(1)
if self.verbose:
print("Setting adv_interface_types %s on port %s" % (adv_interface_types, port))

Expand Down
4 changes: 4 additions & 0 deletions tests/config_an_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def test_config_type(self, ctx):
result = self.basic_check("type", ["Ethernet0", "Invalid"], ctx, operator.ne)
assert 'Invalid interface type specified' in result.output
assert 'Valid interface types:' in result.output
result = self.basic_check("type", ["Ethernet16", "Invalid"], ctx, operator.ne)
assert "Setting RJ45 ports' type is not supported" in result.output

def test_config_adv_types(self, ctx):
self.basic_check("advertised-types", ["Ethernet0", "CR4,KR4"], ctx)
Expand All @@ -74,6 +76,8 @@ def test_config_adv_types(self, ctx):
assert 'Invalid interface type specified' in result.output
assert 'duplicate' in result.output
self.basic_check("advertised-types", ["Ethernet0", ""], ctx, operator.ne)
result = self.basic_check("advertised-types", ["Ethernet16", "Invalid"], ctx, operator.ne)
assert "Setting RJ45 ports' advertised types is not supported" in result.output

def basic_check(self, command_name, para_list, ctx, op=operator.eq, expect_result=0):
runner = CliRunner()
Expand Down

0 comments on commit 154a801

Please sign in to comment.