DVR: Fix neutron metering agent to notify hosts hosting DVR
DVR router updates are notified based on where they are hosted.
But in the case of metering rpc notifier the notification to a
specific host was not implemented and also when a call is being
made to routers_updated_on_host, it is being ignored since it only
implements the routers_updated function call.
Change-Id: I39b0d43b14294a8eecf6cba230d948c2c45a0b7a
Closes-Bug: #1682345
(cherry picked from commit 72338d9fad
)
This commit is contained in:
parent
fa1c3b4438
commit
ba075c6581
|
@ -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(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)
|
||||
|
|
|
@ -16,6 +16,7 @@ import mock
|
|||
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 import context
|
||||
from neutron.db import api as db_api
|
||||
|
@ -132,6 +133,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',
|
||||
|
|
Loading…
Reference in New Issue