Skip to content

Commit

Permalink
[cherry-pick][202311] Show running config when bgp is down (sonic-net…
Browse files Browse the repository at this point in the history
…#3315)

* [202311] Show running config when bgp is down
  • Loading branch information
wen587 authored May 21, 2024
1 parent 34f01f9 commit 673da6b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1437,11 +1437,11 @@ def all(verbose):
ns_list = multi_asic.get_namespace_list()
for ns in ns_list:
ns_config = get_config_json_by_namespace(ns)
ns_config['bgpraw'] = bgp_util.run_bgp_show_command(bgpraw_cmd, ns)
ns_config['bgpraw'] = bgp_util.run_bgp_show_command(bgpraw_cmd, ns, exit_on_fail=False)
output[ns] = ns_config
click.echo(json.dumps(output, indent=4))
else:
host_config['bgpraw'] = bgp_util.run_bgp_show_command(bgpraw_cmd)
host_config['bgpraw'] = bgp_util.run_bgp_show_command(bgpraw_cmd, exit_on_fail=False)
click.echo(json.dumps(output['localhost'], indent=4))


Expand Down
11 changes: 7 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def mock_run_bgp_command_for_static(vtysh_cmd, bgp_namespace="", vtysh_shell_cmd
else:
return ""

def mock_run_bgp_command(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVTYSH_COMMAND):
def mock_run_bgp_command(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVTYSH_COMMAND, exit_on_fail=True):
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 All @@ -328,7 +328,8 @@ def mock_run_bgp_command(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVT
else:
return ""

def mock_run_show_sum_bgp_command(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.VTYSH_COMMAND):
def mock_run_show_sum_bgp_command(
vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.VTYSH_COMMAND, exit_on_fail=True):
if vtysh_cmd == "show ip bgp summary json":
m_asic_json_file = 'no_bgp_neigh.json'
else:
Expand All @@ -343,7 +344,8 @@ def mock_run_show_sum_bgp_command(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=cons
else:
return ""

def mock_run_show_summ_bgp_command_no_ext_neigh_on_all_asic(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.VTYSH_COMMAND):
def mock_run_show_summ_bgp_command_no_ext_neigh_on_all_asic(
vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.VTYSH_COMMAND, exit_on_fail=True):
if vtysh_cmd == "show ip bgp summary json":
m_asic_json_file = 'no_ext_bgp_neigh.json'
else:
Expand All @@ -358,7 +360,8 @@ def mock_run_show_summ_bgp_command_no_ext_neigh_on_all_asic(vtysh_cmd, bgp_names
else:
return ""

def mock_run_show_summ_bgp_command_no_ext_neigh_on_asic1(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.VTYSH_COMMAND):
def mock_run_show_summ_bgp_command_no_ext_neigh_on_asic1(
vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.VTYSH_COMMAND, exit_on_fail=True):
if vtysh_cmd == "show ip bgp summary json":
if bgp_namespace == "asic1":
m_asic_json_file = 'no_ext_bgp_neigh.json'
Expand Down
11 changes: 6 additions & 5 deletions utilities_common/bgp_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ def get_neighbor_dict_from_table(db, table_name):
return neighbor_dict


def run_bgp_command(vtysh_cmd, bgp_namespace=multi_asic.DEFAULT_NAMESPACE, vtysh_shell_cmd=constants.VTYSH_COMMAND):
def run_bgp_command(vtysh_cmd, bgp_namespace=multi_asic.DEFAULT_NAMESPACE,
vtysh_shell_cmd=constants.VTYSH_COMMAND, exit_on_fail=True):
bgp_instance_id = []
output = None
if bgp_namespace is not multi_asic.DEFAULT_NAMESPACE:
Expand All @@ -199,16 +200,16 @@ def run_bgp_command(vtysh_cmd, bgp_namespace=multi_asic.DEFAULT_NAMESPACE, vtysh
output, ret = clicommon.run_command(cmd, return_cmd=True)
if ret != 0:
click.echo(output.rstrip('\n'))
sys.exit(ret)
output = "" if not exit_on_fail else sys.exit(ret)
except Exception:
ctx = click.get_current_context()
ctx.fail("Unable to get summary from bgp {}".format(bgp_instance_id))
ctx.fail("Unable to get summary from bgp {}".format(bgp_instance_id)) if exit_on_fail else None

return output


def run_bgp_show_command(vtysh_cmd, bgp_namespace=multi_asic.DEFAULT_NAMESPACE):
output = run_bgp_command(vtysh_cmd, bgp_namespace, constants.RVTYSH_COMMAND)
def run_bgp_show_command(vtysh_cmd, bgp_namespace=multi_asic.DEFAULT_NAMESPACE, exit_on_fail=True):
output = run_bgp_command(vtysh_cmd, bgp_namespace, constants.RVTYSH_COMMAND, exit_on_fail)
# handle the the alias mode in the following code
if output is not None:
if clicommon.get_interface_naming_mode() == "alias" and re.search("show ip|ipv6 route", vtysh_cmd):
Expand Down

0 comments on commit 673da6b

Please sign in to comment.