From 2acc26f922cd243c53f0ca9b8fe9976b87dc5211 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Tue, 26 Feb 2013 17:57:55 +0100 Subject: [PATCH] Fix NVP plugin not notifying metadata access network to DHCP agent Bug 1133395 Due to recent changes in notification logic between Quantum and the DHCP agent, the notifier the NVP plugin previously used for metadata access network was not working anymore and needed to be replaced Change-Id: Ifa0ea55116cf5ef6d546d28ca52e643987b3e5a0 --- .../common/metadata_access.py | 34 +++++++++---------- .../tests/unit/nicira/test_nicira_plugin.py | 14 +------- quantum/tests/unit/test_l3_plugin.py | 19 +++++------ 3 files changed, 26 insertions(+), 41 deletions(-) diff --git a/quantum/plugins/nicira/nicira_nvp_plugin/common/metadata_access.py b/quantum/plugins/nicira/nicira_nvp_plugin/common/metadata_access.py index 8ec2c1eadb..f3a07aea73 100644 --- a/quantum/plugins/nicira/nicira_nvp_plugin/common/metadata_access.py +++ b/quantum/plugins/nicira/nicira_nvp_plugin/common/metadata_access.py @@ -18,12 +18,13 @@ # @author: Salvatore Orlando, VMware import netaddr +from oslo.config import cfg +from quantum.api.rpc.agentnotifiers import dhcp_rpc_agent_api from quantum.api.v2 import attributes from quantum.common import constants from quantum.common import exceptions as q_exc from quantum.db import l3_db -from quantum.openstack.common import cfg from quantum.openstack.common import log as logging from quantum.openstack.common.notifier import api as notifier_api from quantum.plugins.nicira.nicira_nvp_plugin.common import (exceptions @@ -81,14 +82,13 @@ class NvpMetadataAccess(object): {'subnet': subnet_data}) self.add_router_interface(ctx_elevated, router_id, {'subnet_id': meta_sub['id']}) - # We need to send a notification to the dhcp agent in order - # to start the metadata agent proxy - # Note: the publisher id is the same used in the api module - notifier_api.notify(context, - notifier_api.publisher_id('network'), - 'network.create.end', - notifier_api.CONF.default_notification_level, - {'network': meta_net}) + if cfg.CONF.dhcp_agent_notification: + # We need to send a notification to the dhcp agent in + # order to start the metadata agent proxy + dhcp_notifier = dhcp_rpc_agent_api.DhcpAgentNotifyAPI() + dhcp_notifier.notify(ctx_elevated, + {'network': meta_net}, + 'network.create.end') def _destroy_metadata_access_network(self, context, router_id, ports): @@ -105,15 +105,13 @@ class NvpMetadataAccess(object): ctx_elevated, router_id, {'port_id': meta_port['id']}) # Remove network (this will remove the subnet too) self.delete_network(ctx_elevated, meta_net_id) - # We need to send a notification to the dhcp agent in order - # to stop the metadata agent proxy - # Note: the publisher id is the same used in the api module - notifier_api.notify( - context, - notifier_api.publisher_id('network'), - 'network.delete.end', - notifier_api.CONF.default_notification_level, - {'network_id': meta_net_id}) + if cfg.CONF.dhcp_agent_notification: + # We need to send a notification to the dhcp agent in + # order to stop the metadata agent proxy + dhcp_notifier = dhcp_rpc_agent_api.DhcpAgentNotifyAPI() + dhcp_notifier.notify(ctx_elevated, + {'network': {'id': meta_net_id}}, + 'network.delete.end') def _handle_metadata_access_network(self, context, router_id): if not cfg.CONF.NVP.enable_metadata_access_network: diff --git a/quantum/tests/unit/nicira/test_nicira_plugin.py b/quantum/tests/unit/nicira/test_nicira_plugin.py index 87c09abe19..f4c8d97860 100644 --- a/quantum/tests/unit/nicira/test_nicira_plugin.py +++ b/quantum/tests/unit/nicira/test_nicira_plugin.py @@ -274,19 +274,7 @@ class TestNiciraL3NatTestCase(test_l3_plugin.L3NatDBTestCase, def test_router_add_interface_subnet_with_metadata_access(self): self._nvp_metadata_setup() - notifications = ['router.create.start', - 'router.create.end', - 'network.create.start', - 'network.create.end', - 'subnet.create.start', - 'subnet.create.end', - 'router.interface.create', - 'network.create.end', - 'router.interface.create', - 'router.interface.delete', - 'router.interface.delete', - 'network.delete.end'] - self.test_router_add_interface_subnet(exp_notifications=notifications) + self.test_router_add_interface_subnet() self._nvp_metadata_teardown() def test_router_add_interface_port_with_metadata_access(self): diff --git a/quantum/tests/unit/test_l3_plugin.py b/quantum/tests/unit/test_l3_plugin.py index c4920f15d7..557353e04d 100644 --- a/quantum/tests/unit/test_l3_plugin.py +++ b/quantum/tests/unit/test_l3_plugin.py @@ -633,16 +633,15 @@ class L3NatDBTestCase(L3NatTestCaseBase): fip['floatingip']['router_id'], None, expected_code=exc.HTTPConflict.code) - def test_router_add_interface_subnet(self, exp_notifications=None): - if not exp_notifications: - exp_notifications = ['router.create.start', - 'router.create.end', - 'network.create.start', - 'network.create.end', - 'subnet.create.start', - 'subnet.create.end', - 'router.interface.create', - 'router.interface.delete'] + def test_router_add_interface_subnet(self): + exp_notifications = ['router.create.start', + 'router.create.end', + 'network.create.start', + 'network.create.end', + 'subnet.create.start', + 'subnet.create.end', + 'router.interface.create', + 'router.interface.delete'] with self.router() as r: with self.subnet() as s: body = self._router_interface_action('add',