Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions show/interfaces/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import sys

import subprocess
import click
Expand Down Expand Up @@ -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)
Comment thread
Javier-Tan marked this conversation as resolved.
Comment thread
Javier-Tan marked this conversation as resolved.

ctx = click.get_current_context()

Comment thread
Javier-Tan marked this conversation as resolved.
cmd = ['intfutil', '-c', 'status']
Expand Down
34 changes: 34 additions & 0 deletions tests/remote_show_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading