]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Allow ports to be created on networks that do not exist in NVP
authorAaron Rosen <arosen@nicira.com>
Mon, 13 May 2013 00:25:04 +0000 (17:25 -0700)
committerAaron Rosen <arosen@nicira.com>
Mon, 13 May 2013 17:08:36 +0000 (10:08 -0700)
If a network exists in the quantum database but not in NVP we should allow
someone to create a port on this network and set the status to ERROR. The
reason for this is if one deletes a network from NVP and when the dhcp agent
goes to create it's dhcp port on this network an error will be raised to the
agent and it will enter a constant state of resyncing.

This patch also adds a unit test for update_port() for the same situation.

Fixes bug 1179327

Change-Id: Ie77fc48d11644b820c0cc3b3fa341856e36f8511

quantum/plugins/nicira/QuantumPlugin.py
quantum/tests/unit/nicira/test_nicira_plugin.py

index aa8ad0e2fe55fc8412967080f1b5829190cd7be4..8787e1d65c1e9b6584b2d0291df6a99fd779ab1a 100644 (file)
@@ -1188,6 +1188,10 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
                     self._port_drivers['create']['default'])
 
                 port_create_func(context, port_data)
+            except q_exc.NotFound:
+                LOG.warning(_("Network %s was not found in NVP."),
+                            port_data['network_id'])
+                port_data['status'] = constants.PORT_STATUS_ERROR
             except Exception as e:
                 # FIXME (arosen) or the plugin_interface call failed in which
                 # case we need to garbage collect the left over port in nvp.
index b2baee8605242f82f29557d719ef576a77adf3f7..16dc01e62a3f8e7b4958bc831be1dc1d7fa47e23 100644 (file)
@@ -838,6 +838,26 @@ class NiciraQuantumNVPOutOfSync(test_l3_plugin.L3NatTestCaseBase,
         self.assertEqual(net['port']['status'],
                          constants.PORT_STATUS_ERROR)
 
+    def test_create_port_on_network_not_in_nvp(self):
+        res = self._create_network('json', 'net1', True)
+        net1 = self.deserialize('json', res)
+        self.fc._fake_lswitch_dict.clear()
+        res = self._create_port('json', net1['network']['id'])
+        port = self.deserialize('json', res)
+        self.assertEqual(port['port']['status'], constants.PORT_STATUS_ERROR)
+
+    def test_update_port_not_in_nvp(self):
+        res = self._create_network('json', 'net1', True)
+        net1 = self.deserialize('json', res)
+        res = self._create_port('json', net1['network']['id'])
+        port = self.deserialize('json', res)
+        self.fc._fake_lswitch_lport_dict.clear()
+        data = {'port': {'name': 'error_port'}}
+        req = self.new_update_request('ports', data, port['port']['id'])
+        port = self.deserialize('json', req.get_response(self.api))
+        self.assertEqual(port['port']['status'], constants.PORT_STATUS_ERROR)
+        self.assertEqual(port['port']['name'], 'error_port')
+
     def test_delete_port_and_network_not_in_nvp(self):
         res = self._create_network('json', 'net1', True)
         net1 = self.deserialize('json', res)