diff --git a/show/interfaces/__init__.py b/show/interfaces/__init__.py index b0fd79105f5..cb00755a75a 100644 --- a/show/interfaces/__init__.py +++ b/show/interfaces/__init__.py @@ -1,5 +1,6 @@ import json import os +import sys import subprocess import click @@ -148,6 +149,13 @@ def naming_mode(verbose): def status(interfacename, namespace, display, verbose): """Show Interface status information""" + if device_info.is_supervisor(): + # the command will be executed directly by rexec + click.echo("Since the current device is a chassis supervisor, " + "this command will be executed remotely on all linecards") + proc = subprocess.run(["rexec", "all"] + ["-c", " ".join(sys.argv)]) + sys.exit(proc.returncode) + ctx = click.get_current_context() cmd = ['intfutil', '-c', 'status'] diff --git a/tests/remote_show_test.py b/tests/remote_show_test.py index e1be3d0302c..ee16a38f7fe 100644 --- a/tests/remote_show_test.py +++ b/tests/remote_show_test.py @@ -25,6 +25,40 @@ def mock_rexec_error_cmd(*args): ''' +class TestRexecInterfacesStatus(object): + @classmethod + def setup_class(cls): + pass + + @mock.patch("show.interfaces.device_info.is_supervisor", mock.MagicMock(return_value=True)) + @mock.patch("sys.argv", ["show", "interfaces", "status"]) + def test_show_interfaces_status_rexec(self): + import show.main as show + runner = CliRunner() + + _old_subprocess_run = subprocess.run + subprocess.run = mock_rexec_command + result = runner.invoke(show.cli.commands["interfaces"].commands["status"]) + print(result.output) + subprocess.run = _old_subprocess_run + assert result.exit_code == 0 + assert MULTI_LC_REXEC_OUTPUT == result.output + + @mock.patch("show.interfaces.device_info.is_supervisor", mock.MagicMock(return_value=True)) + @mock.patch("sys.argv", ["show", "interfaces", "status"]) + def test_show_interfaces_status_error_rexec(self): + import show.main as show + runner = CliRunner() + + _old_subprocess_run = subprocess.run + subprocess.run = mock_rexec_error_cmd + result = runner.invoke(show.cli.commands["interfaces"].commands["status"]) + print(result.output) + subprocess.run = _old_subprocess_run + assert result.exit_code == 1 + assert MULTI_LC_ERR_OUTPUT == result.output + + class TestRexecBgp(object): @classmethod def setup_class(cls):