From a26b30c1a80eba4f4a804995b3992f91f1e69479 Mon Sep 17 00:00:00 2001 From: kellyyeh <42761586+kellyyeh@users.noreply.github.com> Date: Fri, 21 Jul 2023 10:01:12 -0700 Subject: [PATCH] Check if BGP has Loopback0 IP as its router ID (#8576) --- tests/common/fixtures/advanced_reboot.py | 4 ++++ tests/common/fixtures/duthost_utils.py | 20 ++++++++++++++++++++ tests/common/plugins/sanity_check/checks.py | 8 +++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/common/fixtures/advanced_reboot.py b/tests/common/fixtures/advanced_reboot.py index 4fd3bf95d1a..a4d1d055dea 100644 --- a/tests/common/fixtures/advanced_reboot.py +++ b/tests/common/fixtures/advanced_reboot.py @@ -17,6 +17,7 @@ from tests.common.utilities import InterruptableThread from tests.common.dualtor.data_plane_utils import get_peerhost from tests.common.dualtor.dual_tor_utils import show_muxcable_status +from tests.common.fixtures.duthost_utils import check_bgp_router_id logger = logging.getLogger(__name__) @@ -524,6 +525,9 @@ def runRebootTest(self): try: if self.preboot_setup: self.preboot_setup() + if self.duthost.num_asics() == 1 and not check_bgp_router_id(self.duthost, self.mgFacts): + test_results[test_case_name].append("Failed to verify BGP router identifier is Loopback0 on %s" % + self.duthost.hostname) if self.advanceboot_loganalyzer: pre_reboot_analysis, post_reboot_analysis = self.advanceboot_loganalyzer marker = pre_reboot_analysis() diff --git a/tests/common/fixtures/duthost_utils.py b/tests/common/fixtures/duthost_utils.py index 794c9d11ebe..67a4cb5645c 100644 --- a/tests/common/fixtures/duthost_utils.py +++ b/tests/common/fixtures/duthost_utils.py @@ -562,3 +562,23 @@ def load_dscp_to_queue_map(duthost, port, dut_qos_maps_module): except: logger.error("Failed to retrieve dscp to queue map for port {} on {}".format(port, duthost.hostname)) return {} + + +def check_bgp_router_id(duthost, mgFacts): + """ + Check bgp router ID is same as Loopback0 + """ + check_bgp_router_id_cmd = r'vtysh -c "show ip bgp summary json"' + bgp_summary = duthost.shell(check_bgp_router_id_cmd, module_ignore_errors=True) + try: + bgp_summary_json = json.loads(bgp_summary['stdout']) + router_id = str(bgp_summary_json['ipv4Unicast']['routerId']) + loopback0 = str(mgFacts['minigraph_lo_interfaces'][0]['addr']) + if router_id == loopback0: + logger.info("BGP router identifier: %s == Loopback0 address %s" % (router_id, loopback0)) + return True + else: + logger.info("BGP router identifier %s != Loopback0 address %s" % (router_id, loopback0)) + return False + except Exception as e: + logger.error("Error loading BGP routerID - {}".format(e)) diff --git a/tests/common/plugins/sanity_check/checks.py b/tests/common/plugins/sanity_check/checks.py index 5a6fd708c4f..d41eb1d44ea 100644 --- a/tests/common/plugins/sanity_check/checks.py +++ b/tests/common/plugins/sanity_check/checks.py @@ -13,6 +13,7 @@ from tests.common.plugins.sanity_check.constants import STAGE_PRE_TEST, STAGE_POST_TEST from tests.common.helpers.parallel import parallel_run, reset_ansible_local_tmp from tests.common.dualtor.mux_simulator_control import _probe_mux_ports +from tests.common.fixtures.duthost_utils import check_bgp_router_id logger = logging.getLogger(__name__) SYSTEM_STABILIZE_MAX_TIME = 300 @@ -144,7 +145,7 @@ def _check_interfaces_on_dut(*args, **kwargs): @pytest.fixture(scope="module") -def check_bgp(duthosts): +def check_bgp(duthosts, tbinfo): init_result = {"failed": False, "check_item": "bgp"} def _check(*args, **kwargs): result = parallel_run(_check_bgp_on_dut, args, kwargs, duthosts.frontend_nodes, timeout=600, init_result=init_result) @@ -226,6 +227,11 @@ def _check_bgp_status_helper(): else: logger.info('No BGP neighbors are down on %s' % dut.hostname) + mgFacts = dut.get_extended_minigraph_facts(tbinfo) + if dut.num_asics() == 1 and not wait_until(timeout, interval, 0, check_bgp_router_id, dut, mgFacts): + check_result['failed'] = True + logger.info("Failed to verify BGP router identifier is Loopback0 address on %s" % dut.hostname) + logger.info("Done checking bgp status on %s" % dut.hostname) results[dut.hostname] = check_result