]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Prevent floating-ip and ex-gateway ports should prevent net deletion
authorDan Wendlandt <dan@nicira.com>
Sun, 9 Sep 2012 14:53:37 +0000 (07:53 -0700)
committerDan Wendlandt <dan@nicira.com>
Sun, 9 Sep 2012 14:53:37 +0000 (07:53 -0700)
bug 1044331

Old behavior meant that any port with device owner starting with
"network:" would be auto-deleted when a network was deleted.  We don't
want that behavior for floating IPs or external network gateways.
This provides a model where we explicitly list the set of owners that
should be auto-deleted.

- Also clean up NetworkInUse message to no longer mention 'attachment',
since that is API v1 terminology.

Change-Id: Icb727ae86d490456ec1ebc55cec1bf98ae6490c9

quantum/common/exceptions.py
quantum/db/db_base_plugin_v2.py

index 0a117c3a2907ada05ff433bff9cd589723559394..eeb0b6d7bbc738fef6e6ebf052b4ba4cd5318c08 100644 (file)
@@ -85,7 +85,7 @@ class InUse(QuantumException):
 
 class NetworkInUse(InUse):
     message = _("Unable to complete operation on network %(net_id)s. "
-                "There is one or more attachments plugged into its ports.")
+                "There is one or more ports still in use on the network.")
 
 
 class SubnetInUse(InUse):
index 9782b5bd2ce63ff7715fa91a40bc4119dc16925d..ab9ba928e6d5ea12f35bfa3d9f9e67a16a845571 100644 (file)
@@ -36,6 +36,15 @@ LOG = logging.getLogger(__name__)
 
 AGENT_OWNER_PREFIX = 'network:'
 
+# Ports with the following 'device_owner' values will not prevent
+# network deletion.  If delete_network() finds that all ports on a
+# network have these owners, it will explicitly delete each port
+# and allow network deletion to continue.  Similarly, if delete_subnet()
+# finds out that all existing IP Allocations are associated with ports
+# with these owners, it will allow subnet deletion to proceed with the
+# IP allocations being cleaned up by cascade.
+AUTO_DELETE_PORT_OWNERS = ['network:dhcp', 'network:router_interface']
+
 
 class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
     """ A class that implements the v2 Quantum plugin interface
@@ -888,10 +897,10 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
             ports = self.get_ports(context, filters=filter)
 
             # check if there are any tenant owned ports in-use
-            only_svc = all(p['device_owner'].startswith(AGENT_OWNER_PREFIX)
-                           for p in ports)
+            only_auto_del = all(p['device_owner'] in AUTO_DELETE_PORT_OWNERS
+                                for p in ports)
 
-            if not only_svc:
+            if not only_auto_del:
                 raise q_exc.NetworkInUse(net_id=id)
 
             # clean up network owned ports
@@ -1082,10 +1091,10 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
             allocated_qry = allocated_qry.options(orm.joinedload('ports'))
             allocated = allocated_qry.filter_by(subnet_id=id).all()
 
-            only_svc = all(not a.port_id or
-                           a.ports.device_owner.startswith(AGENT_OWNER_PREFIX)
-                           for a in allocated)
-            if not only_svc:
+            only_auto_del = all(not a.port_id or
+                                a.ports.device_owner in AUTO_DELETE_PORT_OWNERS
+                                for a in allocated)
+            if not only_auto_del:
                 raise q_exc.NetworkInUse(subnet_id=id)
 
             # remove network owned ports