Skip to content
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

[masic support] 'show run bgp' support for multi-asic #2427

Merged
merged 39 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
fe52110
Update main.py
wenyiz2021 Oct 6, 2022
92816b0
remove import bgp_utils
wenyiz2021 Oct 6, 2022
269b53e
Update main.py
wenyiz2021 Oct 6, 2022
5564920
fix indent and constants.RVTYSH_COMMAND
wenyiz2021 Oct 6, 2022
7e6b0b5
refine output, also rctysh doesnt take whole cmd
wenyiz2021 Oct 6, 2022
62eac78
support single-asic case
wenyiz2021 Oct 7, 2022
3646e2f
Update main.py
wenyiz2021 Oct 7, 2022
322aa45
Update main.py
wenyiz2021 Oct 7, 2022
c6b27a9
fix bug multi_asic.is_multi_asic
wenyiz2021 Oct 7, 2022
a3a300f
remove 'callback' argument in option '-n'
wenyiz2021 Oct 7, 2022
c2ad10a
Update multi_asic.py
wenyiz2021 Oct 7, 2022
3dd0302
refine help message
wenyiz2021 Oct 7, 2022
0555e40
ok
wenyiz2021 Nov 17, 2022
fe16855
remove unrelated change for show int counters
wenyiz2021 Nov 17, 2022
cffba1c
multi-asic can run without -n and show all
wenyiz2021 Nov 30, 2022
f900faa
fix typo
wenyiz2021 Nov 30, 2022
377740d
remove debug breakpoint
wenyiz2021 Nov 30, 2022
e6a166c
unit test
wenyiz2021 Nov 30, 2022
ef4dda8
add import importlib
wenyiz2021 Nov 30, 2022
74e8674
Update show_run_bgp_test.py
wenyiz2021 Dec 1, 2022
2f11eac
add teardown
wenyiz2021 Dec 1, 2022
d16e67c
Update show_run_bgp_test.py
wenyiz2021 Dec 1, 2022
66a51f2
Update main.py
wenyiz2021 Dec 16, 2022
823fe87
reuse bgp_util.run_bgp_command
wenyiz2021 Jan 24, 2023
c1c7357
remove separate vector file
wenyiz2021 Jan 24, 2023
d8b557f
Merge branch 'sonic-net:master' into show_run_bgp_masic
wenyiz2021 Jan 24, 2023
533982b
mock for single asic
wenyiz2021 Jan 24, 2023
c87888a
mock multi_asic for 'show run bgp'
wenyiz2021 Jan 24, 2023
5950d09
mock tables for 'show run bgp', test changed
wenyiz2021 Jan 24, 2023
e1cba3d
syntax
wenyiz2021 Jan 24, 2023
d419877
add cmd definition
wenyiz2021 Jan 24, 2023
4fa78f0
fix indent and spaces
wenyiz2021 Jan 24, 2023
400fd00
fix indent
wenyiz2021 Jan 24, 2023
189f598
remove comments, raise issue instead
wenyiz2021 Jan 30, 2023
e22605b
use run_bgp_show_command to run readonly vtysh
wenyiz2021 Jan 30, 2023
b6d058f
Merge branch 'sonic-net:master' into show_run_bgp_masic
wenyiz2021 Jan 31, 2023
11e1d1a
Update conftest.py
wenyiz2021 Jan 31, 2023
3dc5129
add bgp not running tests
wenyiz2021 Jan 31, 2023
3a5bc31
add mock table for not running bgp
wenyiz2021 Jan 31, 2023
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
33 changes: 30 additions & 3 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1385,10 +1385,37 @@ def ports(portname, verbose):
# 'bgp' subcommand ("show runningconfiguration bgp")
@runningconfiguration.command()
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def bgp(verbose):
@click.option('--namespace', '-n', 'namespace', required=False, default=None, type=str, show_default=False,
help='Option needed for multi-asic only - provide namespace name or all')
def bgp(namespace, verbose):
"""Show BGP running configuration"""
cmd = 'sudo {} -c "show running-config"'.format(constants.RVTYSH_COMMAND)
run_command(cmd, display_cmd=verbose)
if multi_asic.is_multi_asic() and (namespace not in multi_asic.get_namespace_list() or namespace != 'all'):
ctx = click.get_current_context()
ctx.fail("-n/--namespace option required. provide namespace from list {}, or give '-n all'".format(multi_asic.get_namespace_list()))
wenyiz2021 marked this conversation as resolved.
Show resolved Hide resolved
if not multi_asic.is_multi_asic() and namespace:
ctx = click.get_current_context()
ctx.fail("-n/--namespace is not available for single asic")

output = ""
#sigle-asic duts will not enter this condition, they cannot take '-n' option
if namespace:
if namespace == 'all':
ns_list = multi_asic.get_namespace_list()
for ns in ns_list:
output += "\n------------Showing running config bgp on {}------------\n".format(ns)
ns_id = " -n {} ".format(multi_asic.get_asic_id_from_name(ns))
cmd = 'sudo {} {} -c "show run bgp"'.format(constants.RVTYSH_COMMAND, ns_id)
output += run_command(cmd, display_cmd = False, return_cmd=True)
else:
output += "\n------------Showing running config bgp on {}------------\n".format(namespace)
ns_id = " -n {} ".format(multi_asic.get_asic_id_from_name(namespace))
cmd = 'sudo {} {} -c "show run bgp"'.format(constants.RVTYSH_COMMAND, ns_id)
output += run_command(cmd, display_cmd = False, return_cmd=True)
# multi-asic duts will not enter this condition, they have to be given '-n' option
else:
cmd = 'sudo {} -c "show run bgp"'.format(constants.RVTYSH_COMMAND)
output += run_command(cmd, display_cmd = False, return_cmd=True)
print(output)


# 'interfaces' subcommand ("show runningconfiguration interfaces")
Expand Down
36 changes: 36 additions & 0 deletions tests/show_run_bgp_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

import os

import pytest

from click.testing import CliRunner

from utilities_common import multi_asic
from utilities_common import constants

from unittest.mock import patch

from sonic_py_common import device_info
from .show_run_commands_input.show_run_bgp_test_vector import *

class TestShowRunCommands(object):
@classmethod
def setup_class(cls):
print("SETUP")
from .mock_tables import dbconnector

@pytest.mark.parametrize('setup_single_bgp_instance', 'test_vector',
[' '], indirect=['setup_single_bgp_instance'])
def test_show_run_bgp_single(
self,
setup_bgp_commands,
setup_single_bgp_instance):
show = setup_bgp_commands
runner = CliRunner()
exec_cmd = show.cli.commands["runningconfiguration"].commands["bgp"]
input = testData['test_vector']
result = runner.invoke(exec_cmd, input['args'])
print("{}".format(result.output))
import pdb; pdb.set_trace()
assert result.exit_code == 0
assert result.output == show_run_bgp_sasic
Loading