]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
NSX: ensure dhcp port is setup on metadata network
authorarmando-migliaccio <armamig@gmail.com>
Tue, 8 Apr 2014 15:43:00 +0000 (08:43 -0700)
committerThomas Goirand <thomas@goirand.fr>
Mon, 9 Jun 2014 15:06:53 +0000 (23:06 +0800)
Change in scheduling behavior caused a regression
where the dhcp port is no longer provisioned on
the (admin) metadata network created when a subnet
is uplinked to a router.

This change recovers the past behavior and extend UT
coverage to avoid further regression.

Closes-bug: #1304127

Change-Id: I8420203f68a43368f3784adb0c4cbbe55f048662
(cherry picked from commit 4cb3eb2a98246f28f8016cfe32946d365203fbae)

neutron/plugins/vmware/dhcp_meta/rpc.py
neutron/tests/unit/vmware/test_nsx_plugin.py

index 3b8ef0fec70ea0111d6e399aafb86d3a34ed0e0f..b3b960c7de8b22e7ca0133ca81d79765e7c8ac88 100644 (file)
@@ -164,6 +164,8 @@ def _create_metadata_access_network(plugin, context, router_id):
     meta_net = plugin.create_network(context,
                                      {'network': net_data})
     greenthread.sleep(0)  # yield
+    plugin.schedule_network(context, meta_net)
+    greenthread.sleep(0)  # yield
     # From this point on there will be resources to garbage-collect
     # in case of failures
     meta_sub = None
@@ -187,6 +189,8 @@ def _create_metadata_access_network(plugin, context, router_id):
         plugin.add_router_interface(context, router_id,
                                     {'subnet_id': meta_sub['id']})
         greenthread.sleep(0)  # yield
+        # Tell to start the metadata agent proxy, only if we had success
+        _notify_rpc_agent(context, {'subnet': meta_sub}, 'subnet.create.end')
     except (ntn_exc.NeutronException,
             nsx_exc.NsxPluginException,
             api_exc.NsxApiException):
@@ -194,9 +198,6 @@ def _create_metadata_access_network(plugin, context, router_id):
         # as it will be removed with the network
         plugin.delete_network(context, meta_net['id'])
 
-    # Tell to start the metadata agent proxy
-    _notify_rpc_agent(context, {'network': meta_net}, 'network.create.end')
-
 
 def _destroy_metadata_access_network(plugin, context, router_id, ports):
     if not ports:
index 412034590212f100e892c944aae0835170c003cb..380c75ef21940b3e78cad310d6b218c71fa397f0 100644 (file)
@@ -767,25 +767,39 @@ class TestL3NatTestCase(L3NatTest,
 
     def test_metadatata_network_created_with_router_interface_add(self):
         self._metadata_setup()
-        with self.router() as r:
-            with self.subnet() as s:
-                self._router_interface_action('add',
-                                              r['router']['id'],
-                                              s['subnet']['id'],
-                                              None)
-                r_ports = self._list('ports')['ports']
-                self.assertEqual(len(r_ports), 2)
-                ips = []
-                for port in r_ports:
-                    ips.extend([netaddr.IPAddress(fixed_ip['ip_address'])
-                                for fixed_ip in port['fixed_ips']])
-                meta_cidr = netaddr.IPNetwork('169.254.0.0/16')
-                self.assertTrue(any([ip in meta_cidr for ip in ips]))
-                # Needed to avoid 409
-                self._router_interface_action('remove',
-                                              r['router']['id'],
-                                              s['subnet']['id'],
-                                              None)
+        with mock.patch.object(self._plugin_class, 'schedule_network') as f:
+            with self.router() as r:
+                with self.subnet() as s:
+                    self._router_interface_action('add',
+                                                  r['router']['id'],
+                                                  s['subnet']['id'],
+                                                  None)
+                    r_ports = self._list('ports')['ports']
+                    self.assertEqual(len(r_ports), 2)
+                    ips = []
+                    for port in r_ports:
+                        ips.extend([netaddr.IPAddress(fixed_ip['ip_address'])
+                                    for fixed_ip in port['fixed_ips']])
+                    meta_cidr = netaddr.IPNetwork('169.254.0.0/16')
+                    self.assertTrue(any([ip in meta_cidr for ip in ips]))
+                    # Needed to avoid 409
+                    self._router_interface_action('remove',
+                                                  r['router']['id'],
+                                                  s['subnet']['id'],
+                                                  None)
+            # Verify that the metadata network gets scheduled first, so that
+            # an active dhcp agent can pick it up
+            expected_meta_net = {
+                'status': 'ACTIVE',
+                'subnets': [],
+                'name': 'meta-%s' % r['router']['id'],
+                'admin_state_up': True,
+                'tenant_id': '',
+                'port_security_enabled': False,
+                'shared': False,
+                'id': mock.ANY
+            }
+            f.assert_called_once_with(mock.ANY, expected_meta_net)
         self._metadata_teardown()
 
     def test_metadata_network_create_rollback_on_create_subnet_failure(self):