]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Ports depend on the subnets in the same network.
authorSteve Baker <sbaker@redhat.com>
Thu, 27 Jun 2013 01:39:30 +0000 (13:39 +1200)
committerSteve Baker <sbaker@redhat.com>
Thu, 27 Jun 2013 02:29:11 +0000 (14:29 +1200)
Without establishing this implicit dependency, the following
sometimes occurs:
- Ports get assigned to instances without any IP address
- Stack delete fails as ports still exist in subnets.

Fixes bug: #1192371

Change-Id: Ifd892cef4c2eebaea5568afbd320c8865c845d70

heat/engine/resources/quantum/port.py
heat/tests/test_quantum.py

index de72238d5c08e69949534187d18772fb8d4f214d..5ddc96f4d1ab70eff477824fbb92665e32bb5018 100644 (file)
@@ -56,6 +56,19 @@ class Port(quantum.QuantumResource):
         "tenant_id": "tenant owning the port"
     }
 
+    def add_dependencies(self, deps):
+        super(Port, self).add_dependencies(deps)
+        # Depend on any Subnet in this template with the same
+        # network_id as this network_id.
+        # It is not known which subnet a port might be assigned
+        # to so all subnets in a network should be created before
+        # the ports in that network.
+        for resource in self.stack.resources.itervalues():
+            if (resource.type() == 'OS::Quantum::Subnet' and
+                resource.properties.get('network_id') ==
+                    self.properties.get('network_id')):
+                        deps += (self, resource)
+
     def handle_create(self):
         props = self.prepare_properties(
             self.properties,
index 0c44c8b8a26ba0bf47fadba94fcb9aaf3a4b5f9f..441235bcec2558804b7c16e9b834586750754b6b 100644 (file)
@@ -77,6 +77,13 @@ quantum_template = '''
         }]
       }
     },
+    "port2": {
+      "Type": "OS::Quantum::Port",
+      "Properties": {
+        "name": "port2",
+        "network_id": { "Ref" : "network" }
+      }
+    },
     "router": {
       "Type": "OS::Quantum::Router"
     },
@@ -394,6 +401,11 @@ class QuantumSubnetTest(HeatTestCase):
         self.assertEqual('91e47a57-7508-46fe-afc9-fc454e8580e1',
                          rsrc.FnGetAtt('id'))
 
+        # assert the dependency (implicit or explicit) between the ports
+        # and the subnet
+        self.assertIn(stack['port'], stack.dependencies[stack['subnet']])
+        self.assertIn(stack['port2'], stack.dependencies[stack['subnet']])
+
         self.assertRaises(resource.UpdateReplace,
                           rsrc.handle_update, {}, {}, {})