diff --git a/neutron/api/rpc/agentnotifiers/metering_rpc_agent_api.py b/neutron/api/rpc/agentnotifiers/metering_rpc_agent_api.py index fdbb2f28103..65c1977630d 100644 --- a/neutron/api/rpc/agentnotifiers/metering_rpc_agent_api.py +++ b/neutron/api/rpc/agentnotifiers/metering_rpc_agent_api.py @@ -70,6 +70,14 @@ class MeteringAgentNotifyAPI(object): cctxt = self.client.prepare(fanout=True) cctxt.cast(context, method, router_id=router_id) + def _notification_host(self, context, method, host, **kwargs): + """Notify the agent that is hosting the router.""" + LOG.debug('Notify agent at %(host)s the message ' + '%(method)s', {'host': host, + 'method': method}) + cctxt = self.client.prepare(server=host) + cctxt.cast(context, method, **kwargs) + def _notification(self, context, method, routers): """Notify all the agents that are hosting the routers.""" plugin = directory.get_plugin(plugin_constants.L3) @@ -101,3 +109,8 @@ class MeteringAgentNotifyAPI(object): def remove_metering_label(self, context, routers): self._notification(context, 'remove_metering_label', routers) + + def routers_updated_on_host(self, context, router_ids, host): + """Notify router updates to specific hosts hosting DVR routers.""" + self._notification_host(context, 'routers_updated', host, + routers=router_ids) diff --git a/neutron/tests/unit/services/metering/test_metering_plugin.py b/neutron/tests/unit/services/metering/test_metering_plugin.py index 53715296640..bab4bcf7d20 100644 --- a/neutron/tests/unit/services/metering/test_metering_plugin.py +++ b/neutron/tests/unit/services/metering/test_metering_plugin.py @@ -17,6 +17,7 @@ from neutron_lib import context from neutron_lib.plugins import directory from oslo_utils import uuidutils +from neutron.api.rpc.agentnotifiers import metering_rpc_agent_api from neutron.api.v2 import attributes as attr from neutron.common import utils from neutron.db import api as db_api @@ -133,6 +134,23 @@ class TestMeteringPlugin(test_db_base_plugin_v2.NeutronDbPluginV2TestCase, self.remove_rule_patch = mock.patch(remove_rule) self.mock_remove_rule = self.remove_rule_patch.start() + def test_routers_updated_on_host_rpc_call(self): + router_test = { + 'id': 'xyz', + 'name': 'testrouter'} + notify_host = ('neutron.api.rpc.agentnotifiers.' + + 'metering_rpc_agent_api.MeteringAgentNotifyAPI' + + '._notification_host') + self.notify_patch = mock.patch(notify_host) + self.mock_notify_host = self.notify_patch.start() + metering_rpc_handle = metering_rpc_agent_api.MeteringAgentNotifyAPI() + metering_rpc_handle.routers_updated_on_host( + self.ctx, + [router_test['id']], + 'test_host') + self.mock_notify_host.assert_called_with(self.ctx, 'routers_updated', + 'test_host', routers=['xyz']) + def test_add_metering_label_rpc_call(self): second_uuid = 'e27fe2df-376e-4ac7-ae13-92f050a21f84' expected = [{'status': 'ACTIVE',