Skip to content

Commit

Permalink
[chassis][supervisor][show][interfaces]show interfaces command warnin…
Browse files Browse the repository at this point in the history
…g on Supervisor card (#1771)

What I did
Fixed #8521

How I did it
Before displaying the warning message, call device_info.is_supervisor() function to check if it is supervisor card, don't display the warning message.

How to verify it
Running the image on supervisor card
Execute the CLI "show interfaces status"
No warning should be seen.

Signed-off-by: mlok <[email protected]>
  • Loading branch information
mlok-nokia authored Nov 4, 2021
1 parent 487b3b7 commit efbe1f4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
26 changes: 25 additions & 1 deletion tests/interfaces_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import traceback

from click.testing import CliRunner
from unittest import mock

import show.main as show

Expand Down Expand Up @@ -292,7 +293,30 @@ def test_show_interfaces_portchannel_in_alias_mode(self):
traceback.print_tb(result.exc_info[2])
assert result.exit_code == 0
assert result.output == show_interfaces_portchannel_in_alias_mode_output


@mock.patch('sonic_py_common.multi_asic.get_port_table', mock.MagicMock(return_value={}))
def test_supervisor_show_interfaces_alias_etp1_with_waring(self):
runner = CliRunner()
os.environ['SONIC_CLI_IFACE_MODE'] = "alias"
result = runner.invoke(show.cli.commands["interfaces"].commands["alias"], ["etp1"])
os.environ['SONIC_CLI_IFACE_MODE'] = "default"
print(result.exit_code)
print(result.output)
assert result.exit_code != 0
assert "Configuration database contains no ports" in result.output

@mock.patch('sonic_py_common.multi_asic.get_port_table', mock.MagicMock(return_value={}))
@mock.patch('sonic_py_common.device_info.is_supervisor', mock.MagicMock(return_value=True))
def test_supervisor_show_interfaces_alias_etp1_without_waring(self):
runner = CliRunner()
os.environ['SONIC_CLI_IFACE_MODE'] = "alias"
result = runner.invoke(show.cli.commands["interfaces"].commands["alias"], ["etp1"])
os.environ['SONIC_CLI_IFACE_MODE'] = "default"
print(result.exit_code)
print(result.output)
assert result.exit_code != 0
assert "Configuration database contains no ports" not in result.output

@classmethod
def teardown_class(cls):
print("TEARDOWN")
5 changes: 3 additions & 2 deletions utilities_common/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import netaddr

from natsort import natsorted
from sonic_py_common import multi_asic
from sonic_py_common import multi_asic, device_info
from utilities_common.db import Db
from utilities_common.general import load_db_config

Expand Down Expand Up @@ -131,7 +131,8 @@ def __init__(self, db=None):


if not self.port_dict:
click.echo(message="Configuration database contains no ports")
if not device_info.is_supervisor():
click.echo(message="Configuration database contains no ports")
self.port_dict = {}

for port_name in self.port_dict:
Expand Down

0 comments on commit efbe1f4

Please sign in to comment.