]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix NVP plugin not notifying metadata access network to DHCP agent
authorSalvatore Orlando <salv.orlando@gmail.com>
Tue, 26 Feb 2013 16:57:55 +0000 (17:57 +0100)
committerSalvatore Orlando <salv.orlando@gmail.com>
Tue, 26 Feb 2013 17:01:00 +0000 (18:01 +0100)
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

quantum/plugins/nicira/nicira_nvp_plugin/common/metadata_access.py
quantum/tests/unit/nicira/test_nicira_plugin.py
quantum/tests/unit/test_l3_plugin.py

index 8ec2c1eadbc6862feac4b62808366b91223e9946..f3a07aea73653c1da7315cbd0096701d88199271 100644 (file)
 # @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:
index 87c09abe195d1d684c87a426aa67a9fd16739f96..f4c8d97860ca18e6d59f727b064998dbe9ef51f7 100644 (file)
@@ -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):
index c4920f15d7afd495ec262756dca00133ed8d3efc..557353e04d9a6d37346a3a62f98ab7f8d05fcefa 100644 (file)
@@ -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',