]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Ensure to remove auto delete ports from OFC in NEC plugin
authorAkihiro MOTOKI <motoki@da.jp.nec.com>
Wed, 12 Jun 2013 08:18:55 +0000 (17:18 +0900)
committerAkihiro MOTOKI <motoki@da.jp.nec.com>
Wed, 12 Jun 2013 08:40:34 +0000 (17:40 +0900)
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

quantum/plugins/nec/nec_plugin.py
quantum/tests/unit/nec/test_nec_plugin.py

index 022eff36de0c810026997e51068c0fa892249e18..9a5e9b261f0ffd167f72d8aaee527d04f8953793 100644 (file)
@@ -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])
index 6aacfe3cfb5c3ef6a49083094ff46e9f724fa91e..c3ea46b9eb2f5cf3d5b39c035a95b001fd8348a8 100644 (file)
@@ -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')