diff --git a/show/interfaces/__init__.py b/show/interfaces/__init__.py index 7aafbf5f47..4d88a82d95 100644 --- a/show/interfaces/__init__.py +++ b/show/interfaces/__init__.py @@ -360,16 +360,16 @@ def expected(db, interfacename): @click.option('--display', '-d', 'display', default=None, show_default=False, type=str, help='all|frontend') @click.pass_context + def mpls(ctx, interfacename, namespace, display): """Show Interface MPLS status""" - # Edge case: Force show frontend interfaces on single asic if not (multi_asic.is_multi_asic()): - if (display == 'frontend' or display == 'all' or display is None): - display = None - else: - print("Error: Invalid display option command for single asic") - return + if (display == 'frontend' or display == 'all' or display is None): + display = None + else: + print("Error: Invalid display option command for single asic") + return display = "all" if interfacename else display masic = multi_asic_util.MultiAsic(display_option=display, namespace_option=namespace) @@ -945,7 +945,10 @@ def dhcp_mitigation_rate(db, interfacename): def tablelize(keys): table = [] for key in natsorted(keys): - r = [clicommon.get_interface_name_for_display(db, key), clicommon.get_interface_dhcp_mitigation_rate(db.cfgdb, key)] + r = [ + clicommon.get_interface_name_for_display(db, key), + clicommon.get_interface_dhcp_mitigation_rate(db.cfgdb, key) + ] table.append(r) return table diff --git a/tests/dhcp_rate_test.py b/tests/dhcp_rate_test.py index 5b14ff95bb..5da2e3695a 100644 --- a/tests/dhcp_rate_test.py +++ b/tests/dhcp_rate_test.py @@ -266,7 +266,10 @@ def test_config_dhcp_rate_add_on_invalid_interface(self): assert "Error: etp33 does not exist" in result.output @patch("validated_config_db_connector.device_info.is_yang_config_validation_enabled", mock.Mock(return_value=True)) - @patch("config.validated_config_db_connector.ValidatedConfigDBConnector.validated_mod_entry", mock.Mock(side_effect=ValueError)) + @patch( + "config.validated_config_db_connector.ValidatedConfigDBConnector.validated_mod_entry", + mock.Mock(side_effect=ValueError) + ) def test_config_dhcp_rate_add_del_with_value_error(self): db = Db() runner = CliRunner() diff --git a/tests/interfaces_test.py b/tests/interfaces_test.py old mode 100644 new mode 100755 index ec82d9d544..af33fe12be --- a/tests/interfaces_test.py +++ b/tests/interfaces_test.py @@ -263,6 +263,14 @@ PortChannel1001 trunk 4000 """ +show_dhcp_rate_limit_in_alias_mode_output = """\ +Interface DHCP Mitigation Rate +----------- ---------------------- +etp1 300 +etp2 +""" + + class TestInterfaces(object): @classmethod def setup_class(cls): @@ -445,17 +453,14 @@ def test_parse_interface_in_filter(self): 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 @@ -464,17 +469,14 @@ def test_parse_interface_in_filter(self): def test_show_interfaces_switchport_status(self): runner = CliRunner() db = Db() - result = runner.invoke( config.config.commands["switchport"].commands["mode"], ["routed", "PortChannel0001"], obj=db) print(result.exit_code) print(result.output) assert result.exit_code == 0 - result = runner.invoke(show.cli.commands["interfaces"].commands["switchport"].commands["status"]) print(result.exit_code) print(result.output) - assert result.exit_code == 0 assert result.output == show_interfaces_switchport_status_output @@ -483,7 +485,6 @@ def test_show_interfaces_switchport_config(self): result = runner.invoke(show.cli.commands["interfaces"].commands["switchport"].commands["config"]) print(result.exit_code) print(result.output) - assert result.exit_code == 0 assert result.output == show_interfaces_switchport_config_output @@ -494,7 +495,6 @@ def test_show_interfaces_switchport_config_in_alias_mode(self): os.environ['SONIC_CLI_IFACE_MODE'] = "default" print(result.exit_code) print(result.output) - assert result.exit_code == 0 assert result.output == show_interfaces_switchport_config_in_alias_mode_output