From 4b80d0db761b282a7af2495ade94e85ea9c988b8 Mon Sep 17 00:00:00 2001 From: Dmitrii Shcherbakov Date: Tue, 20 Jun 2023 22:16:04 +0400 Subject: [PATCH] Add a workaround for LP: #2024481 Due to the race condition described in LP: #2024481, before adding networks to the speaker we need to wait until it gets scheduled, otherwise it may not advertise some routes that are attempted to be advertised before the speaker is scheduled to a dragent service causing a non-fatal service error. --- zaza/openstack/configure/bgp_speaker.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/zaza/openstack/configure/bgp_speaker.py b/zaza/openstack/configure/bgp_speaker.py index 6144474..5ac3156 100755 --- a/zaza/openstack/configure/bgp_speaker.py +++ b/zaza/openstack/configure/bgp_speaker.py @@ -19,6 +19,9 @@ import argparse import logging import sys +import tenacity +import zaza.model + from zaza.openstack.utilities import ( cli as cli_utils, openstack as openstack_utils, @@ -29,6 +32,20 @@ from zaza.openstack.utilities import ( NDR_TEST_FIP = "NDR_TEST_FIP" +@tenacity.retry(wait=tenacity.wait_exponential(multiplier=1, max=60), + reraise=True, stop=tenacity.stop_after_attempt(10)) +def _assert_speaker_added(local_as): + logging.debug(f"Checking that a BGP speaker for {local_as} has been added") + # As soon as this message appears in the log on a pristine machine we can + # proceed with adding routes. The check is due to LP: #2024481. + grep_cmd = (f'grep "Added BGP Speaker for local_as={local_as}"' + f' /var/log/neutron/neutron-bgp-dragent.log') + # Usually we only have one unit in test bundles but let's be generic. + for unit in zaza.model.get_units("neutron-dynamic-routing"): + juju_utils.remote_run(unit, fatal=True, + remote_cmd=grep_cmd) + + def setup_bgp_speaker(peer_application_name, keystone_session=None): """Perform BGP Speaker setup. @@ -66,6 +83,10 @@ def setup_bgp_speaker(peer_application_name, keystone_session=None): bgp_speaker = openstack_utils.create_bgp_speaker( neutron_client, local_as=dr_asn) + # Due to LP: #2024481 make sure the BGP speaker is actually scheduled + # on this unit before adding any networks to it. + _assert_speaker_added(local_as=bgp_speaker["local_as"]) + # Add networks to bgp speaker logging.info("Advertising BGP routes") openstack_utils.add_network_to_bgp_speaker(