Skip to content

Commit 154a801

Browse files
keboliustephenxs
andauthored
Enhance "config interface type/advertised-type" to be blocked on RJ45 ports (sonic-net#2112)
* Support type check for rj45 Signed-off-by: Stephen Sun <[email protected]> * Add test case for config interface type/advertised-types for RJ45 Signed-off-by: Stephen Sun <[email protected]> * Fix review comments Signed-off-by: Stephen Sun <[email protected]> * Fix unit test issue in config advertised types Signed-off-by: Stephen Sun <[email protected]> Co-authored-by: Stephen Sun <[email protected]>
1 parent 3732ac5 commit 154a801

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

scripts/portconfig

+10
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class portconfig(object):
7575
self.is_lag = False
7676
self.is_lag_mbr = False
7777
self.parent = port
78+
self.is_rj45_port = False
7879
# Set up db connections
7980
if namespace is None:
8081
self.db = ConfigDBConnector()
@@ -90,6 +91,9 @@ class portconfig(object):
9091
lag_tables = self.db.get_table(PORT_CHANNEL_TABLE_NAME)
9192
lag_mbr_tables = self.db.get_table(PORT_CHANNEL_MBR_TABLE_NAME)
9293
if port in port_tables:
94+
port_transceiver_info = self.state_db.get_all(self.state_db.STATE_DB, "TRANSCEIVER_INFO|{}".format(port))
95+
if port_transceiver_info:
96+
self.is_rj45_port = True if port_transceiver_info.get("type") == "RJ45" else False
9397
for key in lag_mbr_tables:
9498
if port == key[1]:
9599
self.parent = key[0]
@@ -155,6 +159,9 @@ class portconfig(object):
155159
self.db.mod_entry(PORT_TABLE_NAME, port, {PORT_ADV_SPEEDS_CONFIG_FIELD_NAME: adv_speeds})
156160

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

166173
def set_adv_interface_types(self, port, adv_interface_types):
174+
if self.is_rj45_port:
175+
print("Setting RJ45 ports' advertised types is not supported")
176+
exit(1)
167177
if self.verbose:
168178
print("Setting adv_interface_types %s on port %s" % (adv_interface_types, port))
169179

tests/config_an_test.py

+4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def test_config_type(self, ctx):
6262
result = self.basic_check("type", ["Ethernet0", "Invalid"], ctx, operator.ne)
6363
assert 'Invalid interface type specified' in result.output
6464
assert 'Valid interface types:' in result.output
65+
result = self.basic_check("type", ["Ethernet16", "Invalid"], ctx, operator.ne)
66+
assert "Setting RJ45 ports' type is not supported" in result.output
6567

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

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

0 commit comments

Comments
 (0)