]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
NSX: fix error when creating VM ports on subnets without dhcp
authorarmando-migliaccio <armamig@gmail.com>
Tue, 6 May 2014 01:39:55 +0000 (18:39 -0700)
committerThomas Goirand <thomas@goirand.fr>
Mon, 9 Jun 2014 15:06:54 +0000 (23:06 +0800)
The error was caused by a missing LSN port (which is created when
the subnet is setup with dhcp enabled). Therefore, check the port
is in place before proceeding with the setup.

Change-Id: I658ead0c324a24ad3f061844ecac13cd3359d341
Closes-bug: 1316365
(cherry picked from commit 7458427a0018437f4c7cac127bcd03c93cccfe70)

neutron/plugins/vmware/dhcp_meta/lsnmanager.py
neutron/tests/unit/vmware/test_dhcpmeta.py

index d5ba9db2dbeddb6bda799d3edeac12c8a4391bb3..1e8f9cb552c084761411861118c554a87be373eb 100644 (file)
@@ -296,12 +296,11 @@ class LsnManager(object):
             self.lsn_port_dispose(context, network_id, const.METADATA_MAC)
 
     def _lsn_port_host_conf(self, context, network_id, subnet_id, data, hdlr):
-        lsn_id = None
-        lsn_port_id = None
+        lsn_id, lsn_port_id = self.lsn_port_get(
+            context, network_id, subnet_id, raise_on_err=False)
         try:
-            lsn_id, lsn_port_id = self.lsn_port_get(
-                context, network_id, subnet_id)
-            hdlr(self.cluster, lsn_id, lsn_port_id, data)
+            if lsn_id and lsn_port_id:
+                hdlr(self.cluster, lsn_id, lsn_port_id, data)
         except (n_exc.NotFound, api_exc.NsxApiException):
             LOG.error(_('Error while configuring LSN '
                         'port %s'), lsn_port_id)
index a44da91647112ce9b8e7d1181da4670559b8b94b..088cb2ddfec452e7a8e9b597e62331160757355d 100644 (file)
@@ -666,14 +666,10 @@ class LsnManagerTestCase(base.BaseTestCase):
 
     def test_lsn_port_host_conf_lsn_port_not_found(self):
         with mock.patch.object(
-            self.manager,
-            'lsn_port_get',
-            side_effect=p_exc.LsnPortNotFound(lsn_id=self.lsn_id,
-                                              entity='subnet',
-                                              entity_id=self.sub_id)):
-            self.assertRaises(p_exc.PortConfigurationError,
-                              self.manager._lsn_port_host_conf, mock.ANY,
-                              self.net_id, self.sub_id, mock.ANY, mock.Mock())
+            self.manager, 'lsn_port_get', return_value=(None, None)) as f:
+            self.manager._lsn_port_host_conf(
+                mock.ANY, self.net_id, self.sub_id, mock.ANY, mock.Mock())
+            self.assertEqual(1, f.call_count)
 
     def _test_lsn_port_update(self, dhcp=None, meta=None):
         self.manager.lsn_port_update(