From f7b7fcb063be47a1513864f88b2eab1a1964f121 Mon Sep 17 00:00:00 2001 From: yangshiping <43633727+yangshp1987@users.noreply.github.com> Date: Wed, 3 Jun 2020 06:48:07 +0800 Subject: [PATCH] add fec config/show option (#764) Signed-off-by:yangshiping@jd.com --- config/main.py | 19 +++++++++++++++++++ scripts/intfutil | 5 ++++- sonic-utilities-tests/intfutil_test.py | 6 +++--- .../mock_tables/appl_db.json | 1 + 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/config/main.py b/config/main.py index 22dd494854..08747ca62d 100755 --- a/config/main.py +++ b/config/main.py @@ -1954,6 +1954,25 @@ def mtu(ctx, interface_name, interface_mtu, verbose): command += " -vv" run_command(command, display_cmd=verbose) +@interface.command() +@click.pass_context +@click.argument('interface_name', metavar='', required=True) +@click.argument('interface_fec', metavar='', required=True) +@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output") +def fec(ctx, interface_name, interface_fec, verbose): + """Set interface fec""" + if interface_fec not in ["rs", "fc", "none"]: + ctx.fail("'fec not in ['rs', 'fc', 'none']!") + if get_interface_naming_mode() == "alias": + interface_name = interface_alias_to_name(interface_name) + if interface_name is None: + ctx.fail("'interface_name' is None!") + + command = "portconfig -p {} -f {}".format(interface_name, interface_fec) + if verbose: + command += " -vv" + run_command(command, display_cmd=verbose) + # # 'ip' subgroup ('config interface ip ...') # diff --git a/scripts/intfutil b/scripts/intfutil index bdee791122..b0efa0dd38 100755 --- a/scripts/intfutil +++ b/scripts/intfutil @@ -32,6 +32,7 @@ PORT_OPER_STATUS = "oper_status" PORT_ADMIN_STATUS = "admin_status" PORT_SPEED = "speed" PORT_MTU_STATUS = "mtu" +PORT_FEC = "fec" PORT_DESCRIPTION = "description" PORT_OPTICS_TYPE = "type" PORT_PFC_ASYM_STATUS = "pfc_asym" @@ -339,7 +340,7 @@ def appl_db_sub_intf_status_get(appl_db, config_db, front_panel_ports_list, port # ========================== interface-status logic ========================== -header_stat = ['Interface', 'Lanes', 'Speed', 'MTU', 'Alias', 'Vlan', 'Oper', 'Admin', 'Type', 'Asym PFC'] +header_stat = ['Interface', 'Lanes', 'Speed', 'MTU', 'FEC', 'Alias', 'Vlan', 'Oper', 'Admin', 'Type', 'Asym PFC'] header_stat_sub_intf = ['Sub port interface', 'Speed', 'MTU', 'Vlan', 'Admin', 'Type'] class IntfStatus(object): @@ -365,6 +366,7 @@ class IntfStatus(object): appl_db_port_status_get(self.appl_db, key, PORT_LANES_STATUS), appl_db_port_status_get(self.appl_db, key, PORT_SPEED), appl_db_port_status_get(self.appl_db, key, PORT_MTU_STATUS), + appl_db_port_status_get(self.appl_db, key, PORT_FEC), appl_db_port_status_get(self.appl_db, key, PORT_ALIAS), config_db_vlan_port_keys_get(self.combined_int_to_vlan_po_dict, self.front_panel_ports_list, key), appl_db_port_status_get(self.appl_db, key, PORT_OPER_STATUS), @@ -378,6 +380,7 @@ class IntfStatus(object): appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_LANES_STATUS, self.portchannel_speed_dict), appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_SPEED, self.portchannel_speed_dict), appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_MTU_STATUS, self.portchannel_speed_dict), + appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_FEC, self.portchannel_speed_dict), appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_ALIAS, self.portchannel_speed_dict), appl_db_portchannel_status_get(self.appl_db, self.config_db, po, "vlan", self.portchannel_speed_dict), appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_OPER_STATUS, self.portchannel_speed_dict), diff --git a/sonic-utilities-tests/intfutil_test.py b/sonic-utilities-tests/intfutil_test.py index 44791729bb..67f6f9b6a8 100644 --- a/sonic-utilities-tests/intfutil_test.py +++ b/sonic-utilities-tests/intfutil_test.py @@ -27,9 +27,9 @@ def test_intf_status(self): result = self.runner.invoke(show.cli.commands["interfaces"].commands["status"], []) print >> sys.stderr, result.output expected_output = ( - "Interface Lanes Speed MTU Alias Vlan Oper Admin Type Asym PFC\n" - "----------- ------- ------- ----- --------- ------ ------ ------- --------------- ----------\n" - " Ethernet0 0 25G 9100 Ethernet0 routed down up QSFP28 or later off" + "Interface Lanes Speed MTU FEC Alias Vlan Oper Admin Type Asym PFC\n" + "----------- ------- ------- ----- ----- --------- ------ ------ ------- --------------- ----------\n" + " Ethernet0 0 25G 9100 rs Ethernet0 routed down up QSFP28 or later off" ) self.assertEqual(result.output.strip(), expected_output) diff --git a/sonic-utilities-tests/mock_tables/appl_db.json b/sonic-utilities-tests/mock_tables/appl_db.json index 19768f75a2..96c071e3a2 100644 --- a/sonic-utilities-tests/mock_tables/appl_db.json +++ b/sonic-utilities-tests/mock_tables/appl_db.json @@ -7,6 +7,7 @@ "oper_status": "down", "pfc_asym": "off", "mtu": "9100", + "fec": "rs", "admin_status": "up" }, "PORT_TABLE:Ethernet200": {