From e206e2d3eda67ea31d43c543c71da6b084ae5089 Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Thu, 19 May 2022 07:44:24 -0700 Subject: [PATCH] [portconfig] Allow to configure interface mtu for physical ports only - What I did Allow config interface command to allow mtu only for physical ports. This has been the behavior until sometime back where a change made broke this and allowed the MTU to be passed to orchagent through port table which results in crash. May 13 12:04:12.494964 r-tigon-20 INFO swss#buffermgrd: :- handlePortTable: Port PortChannel101: MTU updated from to 1514 May 13 12:04:12.495984 r-tigon-20 ERR swss#orchagent: :- set: switch id oid:0x0 doesn't exist May 13 12:04:12.495984 r-tigon-20 ERR swss#orchagent: :- setPortMtu: Failed to set MTU 1536 to port pid:0, rv:-5 May 13 12:04:12.495984 r-tigon-20 ERR swss#orchagent: :- handleSaiSetStatus: Encountered failure in set operation, exiting orchagent, SAI API: SAI_API_PORT, status: SAI_STATUS - How I did it Blocked MTU setting if the port is not physical port. - How to verify it Added UT to verify it --- scripts/portconfig | 3 +++ tests/config_an_test.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/scripts/portconfig b/scripts/portconfig index 25647cc45c..bf7829fceb 100755 --- a/scripts/portconfig +++ b/scripts/portconfig @@ -127,6 +127,9 @@ class portconfig(object): self.db.mod_entry(PORT_TABLE_NAME, port, {PORT_FEC_CONFIG_FIELD_NAME: fec}) def set_mtu(self, port, mtu): + port_tables = self.db.get_table(PORT_TABLE_NAME) + if port not in port_tables: + raise Exception("Invalid port %s" % (port)) if self.verbose: print("Setting mtu %s on port %s" % (mtu, port)) self.db.mod_entry(PORT_TABLE_NAME, port, {PORT_MTU_CONFIG_FIELD_NAME: mtu}) diff --git a/tests/config_an_test.py b/tests/config_an_test.py index f16099e40c..2da1879ebd 100644 --- a/tests/config_an_test.py +++ b/tests/config_an_test.py @@ -79,6 +79,11 @@ def test_config_adv_types(self, ctx): result = self.basic_check("advertised-types", ["Ethernet16", "Invalid"], ctx, operator.ne) assert "Setting RJ45 ports' advertised types is not supported" in result.output + def test_config_mtu(self, ctx): + self.basic_check("mtu", ["Ethernet0", "1514"], ctx) + result = self.basic_check("mtu", ["PortChannel0001", "1514"], ctx, operator.ne) + assert 'Invalid port PortChannel0001' in result.output + def basic_check(self, command_name, para_list, ctx, op=operator.eq, expect_result=0): runner = CliRunner() result = runner.invoke(config.config.commands["interface"].commands[command_name], para_list, obj = ctx)