-
Notifications
You must be signed in to change notification settings - Fork 689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Draft] Add remote compatible show ip bgp and -n all for show ip bgp network #3413
Closed
BYGX-wcr
wants to merge
16
commits into
sonic-net:master
from
BYGX-wcr:remote-compatible-show-ip-bgp
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9579a8c
enable direct exec of show ip bgp on supervisor and enable -n all for…
BYGX-wcr 9cf9ccf
add unit test for remote show ip bgp and show ip bgp -n all
BYGX-wcr 729e715
fix for pre-commit check
BYGX-wcr a15c3b3
fix test suites
BYGX-wcr 146c6b4
fix for unit test suite
BYGX-wcr 2f101b5
fix for test suites
BYGX-wcr 069e047
fix output mismatch for bgp_v4_network_all_asic test vector
BYGX-wcr da871c2
fix remote show test
BYGX-wcr 74cd5d9
fix rexec in show ip bgp and the corresponding tests
BYGX-wcr 3d816d8
add mechanism to reset subprocess.run
BYGX-wcr 71c17c0
twist to try
BYGX-wcr 80b57fb
twist expected outputs
BYGX-wcr 2f946f8
increase test coverage
BYGX-wcr c5a3829
small fix
BYGX-wcr 7352a97
small fix
BYGX-wcr 17bf9d0
remove test for show.main
BYGX-wcr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import mock | ||
import subprocess | ||
from io import BytesIO | ||
from click.testing import CliRunner | ||
|
||
|
||
def mock_rexec_command(*args): | ||
mock_stdout = BytesIO(b"""hello world""") | ||
print(mock_stdout.getvalue().decode()) | ||
return subprocess.CompletedProcess(args=[], returncode=0, stdout=mock_stdout, stderr=BytesIO()) | ||
|
||
|
||
def mock_rexec_error_cmd(*args): | ||
mock_stderr = BytesIO(b"""Error""") | ||
print(mock_stderr.getvalue().decode()) | ||
return subprocess.CompletedProcess(args=[], returncode=1, stdout=BytesIO(), stderr=mock_stderr) | ||
|
||
|
||
MULTI_LC_REXEC_OUTPUT = '''Since the current device is a chassis supervisor, this command will be executed remotely on all linecards | ||
hello world | ||
''' | ||
|
||
MULTI_LC_ERR_OUTPUT = '''Since the current device is a chassis supervisor, this command will be executed remotely on all linecards | ||
Error | ||
''' | ||
|
||
class TestRexecBgpNetwork(object): | ||
@classmethod | ||
def setup_class(cls): | ||
pass | ||
|
||
@mock.patch("sonic_py_common.device_info.is_supervisor", mock.MagicMock(return_value=True)) | ||
def test_show_ip_bgp_rexec(self, setup_bgp_commands): | ||
show = setup_bgp_commands | ||
runner = CliRunner() | ||
|
||
_old_subprocess_run = subprocess.run | ||
subprocess.run = mock_rexec_command | ||
result = runner.invoke(show.cli.commands["ip"].commands["bgp"], args=["summary"]) | ||
print(result.output) | ||
subprocess.run = _old_subprocess_run | ||
assert result.exit_code == 0 | ||
assert MULTI_LC_REXEC_OUTPUT == result.output | ||
|
||
@mock.patch("sonic_py_common.device_info.is_supervisor", mock.MagicMock(return_value=True)) | ||
def test_show_ip_bgp_error_rexec(self, setup_bgp_commands): | ||
show = setup_bgp_commands | ||
runner = CliRunner() | ||
|
||
_old_subprocess_run = subprocess.run | ||
subprocess.run = mock_rexec_error_cmd | ||
result = runner.invoke(show.cli.commands["ip"].commands["bgp"], args=["summary"]) | ||
print(result.output) | ||
subprocess.run = _old_subprocess_run | ||
assert result.exit_code == 1 | ||
assert MULTI_LC_ERR_OUTPUT == result.output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you are just keeping original logic here, that if it is multi-asic, and namespace is not provided, error out.
but I think original logic may not be updated, can you change to: if multi asic, and namespace is not provided, print for all asics?
refer to: #2427
another pros for this is, you are running this cmd on sup, if one chassis has both multi/single-asic LCs,
show ip bgp sum
will output for all LCs, instead of having multi-asic LC error out, in this case we could have at least cmd working for both multi/single-asic.