From: Akihiro MOTOKI Date: Wed, 12 Jun 2013 08:18:55 +0000 (+0900) Subject: Ensure to remove auto delete ports from OFC in NEC plugin X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=da6816c6c703be68f5a0ce537364bc096ec2bd9d;p=openstack-build%2Fneutron-build.git Ensure to remove auto delete ports from OFC in NEC plugin When deleting a network, dhcp ports are removed automatically in db_plugin. This causes a failure network deletion since the corresponding port exists on OFC and the network on OFC cannot be deleted unless a subnet on the network is deleted explicitly. This commit gets auto-delete ports and delete the corresponding ports on the controller before deleting the network. Fixes bug #1190163 Change-Id: Ifffaa1a28b5fac0b0a98036a926550255cc25c9d --- diff --git a/quantum/plugins/nec/nec_plugin.py b/quantum/plugins/nec/nec_plugin.py index 022eff36d..9a5e9b261 100644 --- a/quantum/plugins/nec/nec_plugin.py +++ b/quantum/plugins/nec/nec_plugin.py @@ -24,6 +24,7 @@ from quantum.common import rpc as q_rpc from quantum.common import topics from quantum.db import agents_db from quantum.db import agentschedulers_db +from quantum.db import db_base_plugin_v2 from quantum.db import dhcp_rpc_base from quantum.db import extraroute_db from quantum.db import l3_gwmode_db @@ -317,6 +318,15 @@ class NECPluginV2(nec_plugin_base.NECPluginV2Base, net = super(NECPluginV2, self).get_network(context, id) tenant_id = net['tenant_id'] + # Make sure auto-delete ports on OFC are deleted. + filter = {'network_id': [id], + 'device_owner': db_base_plugin_v2.AUTO_DELETE_PORT_OWNERS} + auto_delete_ports = self.get_ports(context, filters=filter) + for port in auto_delete_ports: + LOG.debug(_('delete_network(): deleting auto-delete port' + ' from OFC: %s'), port) + self.deactivate_port(context, port) + # get packet_filters associated with the network if self.packet_filter_enabled: filters = dict(network_id=[id]) diff --git a/quantum/tests/unit/nec/test_nec_plugin.py b/quantum/tests/unit/nec/test_nec_plugin.py index 6aacfe3cf..c3ea46b9e 100644 --- a/quantum/tests/unit/nec/test_nec_plugin.py +++ b/quantum/tests/unit/nec/test_nec_plugin.py @@ -288,6 +288,13 @@ class TestNecPluginOfcManager(NecPluginV2TestCase): super(TestNecPluginOfcManager, self).setUp() self.ofc = self.plugin.ofc + def _create_resource(self, resource, data): + collection = resource + 's' + data = {resource: data} + req = self.new_create_request(collection, data) + res = self.deserialize(self.fmt, req.get_response(self.api)) + return res[resource] + def _update_resource(self, resource, id, data): collection = resource + 's' data = {resource: data} @@ -496,6 +503,39 @@ class TestNecPluginOfcManager(NecPluginV2TestCase): ] self.ofc.assert_has_calls(expected) + def test_delete_network_with_dhcp_port(self): + self.ofc.exists_ofc_tenant.return_value = False + self.ofc.exists_ofc_port.side_effect = [False, True] + + ctx = mock.ANY + with self.network() as network: + with self.subnet(network=network): + net = network['network'] + p = self._create_resource('port', + {'network_id': net['id'], + 'tenant_id': net['tenant_id'], + 'device_owner': 'network:dhcp', + 'device_id': 'dhcp-port1'}) + # Make sure that the port is created on OFC. + portinfo = {'id': p['id'], 'port_no': 123} + self._rpcapi_update_ports(added=[portinfo]) + # In a case of dhcp port, the port is deleted automatically + # when delete_network. + + expected = [ + mock.call.exists_ofc_tenant(ctx, self._tenant_id), + mock.call.create_ofc_tenant(ctx, self._tenant_id), + mock.call.create_ofc_network(ctx, self._tenant_id, + net['id'], net['name']), + mock.call.exists_ofc_port(ctx, p['id']), + mock.call.create_ofc_port(ctx, p['id'], mock.ANY), + mock.call.exists_ofc_port(ctx, p['id']), + mock.call.delete_ofc_port(ctx, p['id'], mock.ANY), + mock.call.delete_ofc_network(ctx, net['id'], mock.ANY), + mock.call.delete_ofc_tenant(ctx, self._tenant_id) + ] + self.ofc.assert_has_calls(expected) + def test_update_port(self): self._test_update_port_with_admin_state(resource='port')