Browse Source

Add agent_updated to BgpDrAgentNotifyApi notifier

When a bgp-dragent is deployed with enable_new_services
set to False so that the agent is disabled upon creation
the first attempt to enable it again throws an error but
the second time works, see the bug report.

Change-Id: If77e2035d0c12d0391ab9c38054bf2e0d24dac4a
Closes-Bug: 1799455
changes/10/630210/3
Tobias Urdin 3 years ago
parent
commit
a861327795
  1. 8
      neutron_dynamic_routing/api/rpc/agentnotifiers/bgp_dr_rpc_agent_api.py
  2. 7
      neutron_dynamic_routing/tests/unit/api/rpc/agentnotifiers/test_bgp_dr_rpc_agent_api.py
  3. 9
      neutron_dynamic_routing/tests/unit/services/bgp/agent/test_bgp_dragent.py

8
neutron_dynamic_routing/api/rpc/agentnotifiers/bgp_dr_rpc_agent_api.py

@ -33,6 +33,14 @@ class BgpDrAgentNotifyApi(object):
self.client = n_rpc.get_client(target)
self.topic = topic
def agent_updated(self, context, admin_state_up, host):
"""Tell BgpDrAgent that agent was updated.
This effectively tells the bgp_dragent to resync.
"""
self._notification_host_cast(context, 'agent_updated',
{'admin_state_up': admin_state_up}, host)
def bgp_routes_advertisement(self, context, bgp_speaker_id,
routes, host):
"""Tell BgpDrAgent to begin advertising the given route.

7
neutron_dynamic_routing/tests/unit/api/rpc/agentnotifiers/test_bgp_dr_rpc_agent_api.py

@ -37,6 +37,13 @@ class TestBgpDrAgentNotifyApi(base.BaseTestCase):
self.context = context.get_admin_context()
self.host = 'host-1'
def test_agent_updated(self):
admin_state_up = True
host = 'my-hostname'
self.notifier.agent_updated(self.context, admin_state_up, host)
self.assertEqual(1, self.mock_cast.call_count)
self.assertEqual(0, self.mock_call.call_count)
def test_notify_dragent_bgp_routes_advertisement(self):
bgp_speaker_id = 'bgp-speaker-1'
routes = [{'destination': '1.1.1.1', 'next_hop': '2.2.2.2'}]

9
neutron_dynamic_routing/tests/unit/services/bgp/agent/test_bgp_dragent.py

@ -66,6 +66,7 @@ class TestBgpDrAgent(base.BaseTestCase):
super(TestBgpDrAgent, self).setUp()
cfg.CONF.register_opts(bgp_config.BGP_DRIVER_OPTS, 'BGP')
cfg.CONF.register_opts(bgp_config.BGP_PROTO_CONFIG_OPTS, 'BGP')
cfg.CONF.register_opts(config.AGENT_STATE_OPTS, 'AGENT')
mock_log_p = mock.patch.object(bgp_dragent, 'LOG')
self.mock_log = mock_log_p.start()
self.driver_cls_p = mock.patch(
@ -111,6 +112,14 @@ class TestBgpDrAgent(base.BaseTestCase):
bgp_dr.after_start()
self.assertIsNotNone(len(sync_state.mock_calls))
def test_agent_updated(self):
bgp_dr = bgp_dragent.BgpDrAgentWithStateReport(HOSTNAME)
payload = {'admin_state_up': True}
with mock.patch.object(bgp_dr, 'agent_updated') as agent_updated:
bgp_dr.agent_updated(self.context, payload)
self.assertIsNotNone(len(agent_updated.mock_calls))
self.assertEqual(1, bgp_dr.agent_updated.call_count)
def _test_sync_state_helper(self, bgp_speaker_list=None,
cached_info=None,
safe_configure_call_count=0,

Loading…
Cancel
Save