diff --git a/tests/common/fixtures/advanced_reboot.py b/tests/common/fixtures/advanced_reboot.py index ade50b17d5e..4a4d68b3652 100644 --- a/tests/common/fixtures/advanced_reboot.py +++ b/tests/common/fixtures/advanced_reboot.py @@ -15,6 +15,7 @@ from tests.ptf_runner import ptf_runner from tests.common.helpers.assertions import pytest_assert from tests.common.utilities import InterruptableThread +from tests.common.fixtures.duthost_utils import check_bgp_router_id logger = logging.getLogger(__name__) @@ -488,6 +489,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 5ba7d8279b3..762a2fbce72 100644 --- a/tests/common/fixtures/duthost_utils.py +++ b/tests/common/fixtures/duthost_utils.py @@ -514,3 +514,23 @@ def load_dscp_to_queue_map(duthost, port, dut_qos_maps): 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 0c1284b92c6..a45637d5f10 100644 --- a/tests/common/plugins/sanity_check/checks.py +++ b/tests/common/plugins/sanity_check/checks.py @@ -10,6 +10,7 @@ from tests.common.cache import FactsCache 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.fixtures.duthost_utils import check_bgp_router_id logger = logging.getLogger(__name__) SYSTEM_STABILIZE_MAX_TIME = 300 @@ -134,7 +135,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) @@ -216,6 +217,12 @@ 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 tbinfo['topo']['type'] != 't2' 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