-
Notifications
You must be signed in to change notification settings - Fork 809
[show] Add bgpraw to show run all #2537
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
Changes from 8 commits
be4aa05
4bc7e7b
bcdfe21
80d63dc
ed1cce3
a69380d
f5fc969
1070c59
3c5b6f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| from datetime import datetime | ||
| import utilities_common.constants as constants | ||
| from utilities_common.general import load_db_config | ||
| from json.decoder import JSONDecodeError | ||
|
|
||
| # mock the redis for unit test purposes # | ||
| try: | ||
|
|
@@ -129,6 +130,10 @@ def run_command(command, display_cmd=False, return_cmd=False): | |
| if rc != 0: | ||
| sys.exit(rc) | ||
|
|
||
| def get_cmd_output(cmd): | ||
| proc = subprocess.Popen(cmd, text=True, stdout=subprocess.PIPE) | ||
| return proc.communicate()[0] | ||
|
|
||
| # Lazy global class instance for SONiC interface name to alias conversion | ||
| iface_alias_converter = lazy_object_proxy.Proxy(lambda: clicommon.InterfaceAliasConverter()) | ||
|
|
||
|
|
@@ -1383,8 +1388,20 @@ def runningconfiguration(): | |
| @click.option('--verbose', is_flag=True, help="Enable verbose output") | ||
| def all(verbose): | ||
| """Show full running configuration""" | ||
| cmd = "sonic-cfggen -d --print-data" | ||
| run_command(cmd, display_cmd=verbose) | ||
| cmd = ['sonic-cfggen', '-d', '--print-data'] | ||
| stdout = get_cmd_output(cmd) | ||
|
||
|
|
||
| try: | ||
| output = json.loads(stdout) | ||
| except JSONDecodeError as e: | ||
| click.echo("Failed to load output '{}':{}".format(cmd, e)) | ||
| raise click.Abort() | ||
|
|
||
| if 'bgpraw' in output or not multi_asic.is_multi_asic(): | ||
| bgpraw_cmd = [constants.RVTYSH_COMMAND, '-c', 'show running-config'] | ||
| bgpraw = get_cmd_output(bgpraw_cmd) | ||
|
||
| output['bgpraw'] = bgpraw | ||
wen587 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| click.echo(json.dumps(output, indent=4)) | ||
wen587 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| # 'acl' subcommand ("show runningconfiguration acl") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import os | ||
| import sys | ||
| import show.main as show | ||
| from click.testing import CliRunner | ||
| from unittest import mock | ||
| from unittest.mock import call, MagicMock | ||
|
|
||
| test_path = os.path.dirname(os.path.abspath(__file__)) | ||
| modules_path = os.path.dirname(test_path) | ||
| sys.path.insert(0, test_path) | ||
| sys.path.insert(0, modules_path) | ||
|
|
||
|
|
||
| class TestShowRunAllCommands(object): | ||
| @classmethod | ||
| def setup_class(cls): | ||
| print("SETUP") | ||
| os.environ["UTILITIES_UNIT_TESTING"] = "1" | ||
|
|
||
| def test_show_runningconfiguration_all_json_loads_failure(self): | ||
| def get_cmd_output_side_effect(*args, **kwargs): | ||
| return "" | ||
| with mock.patch('show.main.get_cmd_output', | ||
| mock.MagicMock(side_effect=get_cmd_output_side_effect)) as mock_get_cmd_output: | ||
| result = CliRunner().invoke(show.cli.commands['runningconfiguration'].commands['all'], []) | ||
| assert result.exit_code != 0 | ||
|
|
||
| def test_show_runningconfiguration_all(self): | ||
| def get_cmd_output_side_effect(*args, **kwargs): | ||
| return "{}" | ||
| with mock.patch('show.main.get_cmd_output', | ||
| mock.MagicMock(side_effect=get_cmd_output_side_effect)) as mock_get_cmd_output: | ||
| result = CliRunner().invoke(show.cli.commands['runningconfiguration'].commands['all'], []) | ||
| assert mock_get_cmd_output.call_count == 2 | ||
| assert mock_get_cmd_output.call_args_list == [ | ||
| call(['sonic-cfggen', '-d', '--print-data']), | ||
| call(['rvtysh', '-c', 'show running-config'])] | ||
|
|
||
| @classmethod | ||
| def teardown_class(cls): | ||
| print("TEARDOWN") | ||
| os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1]) | ||
| os.environ["UTILITIES_UNIT_TESTING"] = "0" |
Uh oh!
There was an error while loading. Please reload this page.