From a861327795a10f51d3c80cce65d45812321a893f Mon Sep 17 00:00:00 2001 From: Tobias Urdin Date: Fri, 11 Jan 2019 13:57:36 +0100 Subject: [PATCH] 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 --- .../api/rpc/agentnotifiers/bgp_dr_rpc_agent_api.py | 8 ++++++++ .../api/rpc/agentnotifiers/test_bgp_dr_rpc_agent_api.py | 7 +++++++ .../tests/unit/services/bgp/agent/test_bgp_dragent.py | 9 +++++++++ 3 files changed, 24 insertions(+) diff --git a/neutron_dynamic_routing/api/rpc/agentnotifiers/bgp_dr_rpc_agent_api.py b/neutron_dynamic_routing/api/rpc/agentnotifiers/bgp_dr_rpc_agent_api.py index 450888bf..33da5f56 100644 --- a/neutron_dynamic_routing/api/rpc/agentnotifiers/bgp_dr_rpc_agent_api.py +++ b/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. diff --git a/neutron_dynamic_routing/tests/unit/api/rpc/agentnotifiers/test_bgp_dr_rpc_agent_api.py b/neutron_dynamic_routing/tests/unit/api/rpc/agentnotifiers/test_bgp_dr_rpc_agent_api.py index 367e10b7..702271c2 100644 --- a/neutron_dynamic_routing/tests/unit/api/rpc/agentnotifiers/test_bgp_dr_rpc_agent_api.py +++ b/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'}] diff --git a/neutron_dynamic_routing/tests/unit/services/bgp/agent/test_bgp_dragent.py b/neutron_dynamic_routing/tests/unit/services/bgp/agent/test_bgp_dragent.py index 8b04248f..6084359c 100644 --- a/neutron_dynamic_routing/tests/unit/services/bgp/agent/test_bgp_dragent.py +++ b/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,