From dbee58e7bb2ed1df6bb513247ec7ac07387ff5d1 Mon Sep 17 00:00:00 2001 From: Aaron Rosen Date: Sun, 12 May 2013 17:25:04 -0700 Subject: [PATCH] Allow ports to be created on networks that do not exist in NVP 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 | 4 ++++ .../tests/unit/nicira/test_nicira_plugin.py | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/quantum/plugins/nicira/QuantumPlugin.py b/quantum/plugins/nicira/QuantumPlugin.py index aa8ad0e2f..8787e1d65 100644 --- a/quantum/plugins/nicira/QuantumPlugin.py +++ b/quantum/plugins/nicira/QuantumPlugin.py @@ -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. diff --git a/quantum/tests/unit/nicira/test_nicira_plugin.py b/quantum/tests/unit/nicira/test_nicira_plugin.py index b2baee860..16dc01e62 100644 --- a/quantum/tests/unit/nicira/test_nicira_plugin.py +++ b/quantum/tests/unit/nicira/test_nicira_plugin.py @@ -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) -- 2.45.2