Skip to content

Commit

Permalink
Change to use rvtysh when calling the show commands (#1572)
Browse files Browse the repository at this point in the history
Change to use rvtysh when calling the show commands
  • Loading branch information
xumia authored May 29, 2021
1 parent 51d6bf5 commit 5f20365
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 24 deletions.
4 changes: 2 additions & 2 deletions show/bgp_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ def show_routes(args, namespace, display, verbose, ipver):
# If not MultiASIC, skip namespace argument
cmd = "show {} route {}".format(ipver, arg_strg)
if multi_asic.is_multi_asic():
output = bgp_util.run_bgp_command(cmd, ns)
output = bgp_util.run_bgp_show_command(cmd, ns)
else:
output = bgp_util.run_bgp_command(cmd)
output = bgp_util.run_bgp_show_command(cmd)
print("{}".format(output))
return

Expand Down
7 changes: 4 additions & 3 deletions show/bgp_quagga_v4.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import click
from show.main import AliasedGroup, ip, run_command
from utilities_common.bgp_util import get_bgp_summary_extended
import utilities_common.constants as constants


###############################################################################
Expand All @@ -21,10 +22,10 @@ def bgp():
def summary():
"""Show summarized information of IPv4 BGP state"""
try:
device_output = run_command('sudo vtysh -c "show ip bgp summary"', return_cmd=True)
device_output = run_command('sudo {} -c "show ip bgp summary"'.format(constants.RVTYSH_COMMAND), return_cmd=True)
get_bgp_summary_extended(device_output)
except Exception:
run_command('sudo vtysh -c "show ip bgp summary"')
run_command('sudo {} -c "show ip bgp summary"'.format(constants.RVTYSH_COMMAND))


# 'neighbors' subcommand ("show ip bgp neighbors")
Expand All @@ -34,7 +35,7 @@ def summary():
def neighbors(ipaddress, info_type):
"""Show IP (IPv4) BGP neighbors"""

command = 'sudo vtysh -c "show ip bgp neighbor'
command = 'sudo {} -c "show ip bgp neighbor'.format(constants.RVTYSH_COMMAND)

if ipaddress is not None:
command += ' {}'.format(ipaddress)
Expand Down
7 changes: 4 additions & 3 deletions show/bgp_quagga_v6.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import click
from show.main import AliasedGroup, ipv6, run_command
from utilities_common.bgp_util import get_bgp_summary_extended
import utilities_common.constants as constants


###############################################################################
Expand All @@ -21,10 +22,10 @@ def bgp():
def summary():
"""Show summarized information of IPv6 BGP state"""
try:
device_output = run_command('sudo vtysh -c "show ipv6 bgp summary"', return_cmd=True)
device_output = run_command('sudo {} -c "show ipv6 bgp summary"'.format(constants.RVTYSH_COMMAND), return_cmd=True)
get_bgp_summary_extended(device_output)
except Exception:
run_command('sudo vtysh -c "show ipv6 bgp summary"')
run_command('sudo {} -c "show ipv6 bgp summary"'.format(constants.RVTYSH_COMMAND))


# 'neighbors' subcommand ("show ipv6 bgp neighbors")
Expand All @@ -33,5 +34,5 @@ def summary():
@click.argument('info_type', type=click.Choice(['routes', 'advertised-routes', 'received-routes']), required=True)
def neighbors(ipaddress, info_type):
"""Show IPv6 BGP neighbors"""
command = 'sudo vtysh -c "show ipv6 bgp neighbor {} {}"'.format(ipaddress, info_type)
command = 'sudo {} -c "show ipv6 bgp neighbor {} {}"'.format(constants.RVTYSH_COMMAND, ipaddress, info_type)
run_command(command)
13 changes: 7 additions & 6 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from tabulate import tabulate
from utilities_common import util_base
from utilities_common.db import Db
import utilities_common.constants as constants

from . import acl
from . import bgp_common
Expand Down Expand Up @@ -725,7 +726,7 @@ def mac(vlan, port, verbose):
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def route_map(route_map_name, verbose):
"""show route-map"""
cmd = 'sudo vtysh -c "show route-map'
cmd = 'sudo {} -c "show route-map'.format(constants.RVTYSH_COMMAND)
if route_map_name is not None:
cmd += ' {}'.format(route_map_name)
cmd += '"'
Expand Down Expand Up @@ -782,7 +783,7 @@ def route(args, namespace, display, verbose):
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def prefix_list(prefix_list_name, verbose):
"""show ip prefix-list"""
cmd = 'sudo vtysh -c "show ip prefix-list'
cmd = 'sudo {} -c "show ip prefix-list'.format(constants.RVTYSH_COMMAND)
if prefix_list_name is not None:
cmd += ' {}'.format(prefix_list_name)
cmd += '"'
Expand All @@ -794,7 +795,7 @@ def prefix_list(prefix_list_name, verbose):
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def protocol(verbose):
"""Show IPv4 protocol information"""
cmd = 'sudo vtysh -c "show ip protocol"'
cmd = 'sudo {} -c "show ip protocol"'.format(constants.RVTYSH_COMMAND)
run_command(cmd, display_cmd=verbose)


Expand All @@ -817,7 +818,7 @@ def ipv6():
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def prefix_list(prefix_list_name, verbose):
"""show ip prefix-list"""
cmd = 'sudo vtysh -c "show ipv6 prefix-list'
cmd = 'sudo {} -c "show ipv6 prefix-list'.format(constants.RVTYSH_COMMAND)
if prefix_list_name is not None:
cmd += ' {}'.format(prefix_list_name)
cmd += '"'
Expand Down Expand Up @@ -865,7 +866,7 @@ def route(args, namespace, display, verbose):
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def protocol(verbose):
"""Show IPv6 protocol information"""
cmd = 'sudo vtysh -c "show ipv6 protocol"'
cmd = 'sudo {} -c "show ipv6 protocol"'.format(constants.RVTYSH_COMMAND)
run_command(cmd, display_cmd=verbose)

#
Expand Down Expand Up @@ -1092,7 +1093,7 @@ def ports(portname, verbose):
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def bgp(verbose):
"""Show BGP running configuration"""
cmd = 'sudo vtysh -c "show running-config"'
cmd = 'sudo {} -c "show running-config"'.format(constants.RVTYSH_COMMAND)
run_command(cmd, display_cmd=verbose)


Expand Down
9 changes: 5 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
mock_show_bgp_network_multi_asic
)
from . import config_int_ip_common
import utilities_common.constants as constants

test_path = os.path.dirname(os.path.abspath(__file__))
modules_path = os.path.dirname(test_path)
Expand Down Expand Up @@ -128,14 +129,14 @@ def setup_single_bgp_instance(request):
bgp_mocked_json = os.path.join(
test_path, 'mock_tables', 'dummy.json')

def mock_show_bgp_summary(vtysh_cmd, bgp_namespace):
def mock_show_bgp_summary(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVTYSH_COMMAND):
if os.path.isfile(bgp_mocked_json):
with open(bgp_mocked_json) as json_data:
mock_frr_data = json_data.read()
return mock_frr_data
return ""

def mock_run_bgp_command_for_static(vtysh_cmd, bgp_namespace=""):
def mock_run_bgp_command_for_static(vtysh_cmd, bgp_namespace="", vtysh_shell_cmd=constants.RVTYSH_COMMAND):
if vtysh_cmd == "show ip route vrf all static":
return config_int_ip_common.show_ip_route_with_static_expected_output
elif vtysh_cmd == "show ipv6 route vrf all static":
Expand Down Expand Up @@ -217,7 +218,7 @@ def setup_multi_asic_bgp_instance(request):
m_asic_json_file = os.path.join(
test_path, 'mock_tables', 'dummy.json')

def mock_run_bgp_command_for_static(vtysh_cmd, bgp_namespace=""):
def mock_run_bgp_command_for_static(vtysh_cmd, bgp_namespace="", vtysh_shell_cmd=constants.RVTYSH_COMMAND):
if bgp_namespace != 'test_ns':
return ""
if vtysh_cmd == "show ip route vrf all static":
Expand All @@ -227,7 +228,7 @@ def mock_run_bgp_command_for_static(vtysh_cmd, bgp_namespace=""):
else:
return ""

def mock_run_bgp_command(vtysh_cmd, bgp_namespace):
def mock_run_bgp_command(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVTYSH_COMMAND):
if m_asic_json_file.startswith('bgp_v4_network') or \
m_asic_json_file.startswith('bgp_v6_network'):
return mock_show_bgp_network_multi_asic(m_asic_json_file)
Expand Down
12 changes: 7 additions & 5 deletions utilities_common/bgp_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,15 @@ def get_neighbor_dict_from_table(db, table_name):
return neighbor_dict


def run_bgp_command(vtysh_cmd,
bgp_namespace=multi_asic.DEFAULT_NAMESPACE):
def run_bgp_command(vtysh_cmd, bgp_namespace=multi_asic.DEFAULT_NAMESPACE, vtysh_shell_cmd=constants.VTYSH_COMMAND):
bgp_instance_id = ' '
output = None
if bgp_namespace is not multi_asic.DEFAULT_NAMESPACE:
bgp_instance_id = " -n {} ".format(
multi_asic.get_asic_id_from_name(bgp_namespace))

cmd = 'sudo vtysh {} -c "{}"'.format(
bgp_instance_id, vtysh_cmd)
cmd = 'sudo {} {} -c "{}"'.format(
vtysh_shell_cmd, bgp_instance_id, vtysh_cmd)
try:
output = clicommon.run_command(cmd, return_cmd=True)
except Exception:
Expand All @@ -191,6 +190,9 @@ def run_bgp_command(vtysh_cmd,

return output

def run_bgp_show_command(vtysh_cmd, bgp_namespace=multi_asic.DEFAULT_NAMESPACE):
return run_bgp_command(vtysh_cmd, bgp_namespace, constants.RVTYSH_COMMAND)

def get_bgp_summary_from_all_bgp_instances(af, namespace, display):

device = multi_asic_util.MultiAsic(display, namespace)
Expand All @@ -205,7 +207,7 @@ def get_bgp_summary_from_all_bgp_instances(af, namespace, display):
bgp_summary = {}
cmd_output_json = {}
for ns in device.get_ns_list_based_on_options():
cmd_output = run_bgp_command(vtysh_cmd, ns)
cmd_output = run_bgp_show_command(vtysh_cmd, ns)
try:
cmd_output_json = json.loads(cmd_output)
except ValueError:
Expand Down
3 changes: 2 additions & 1 deletion utilities_common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
PORT_OBJ = 'PORT'
IPV4 = 'v4'
IPV6 = 'v6'

VTYSH_COMMAND = 'vtysh'
RVTYSH_COMMAND = 'rvtysh'

0 comments on commit 5f20365

Please sign in to comment.