]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Add dependency between FloatingIP and RouterGateway
authorSteve Baker <sbaker@redhat.com>
Tue, 21 May 2013 01:21:22 +0000 (13:21 +1200)
committerSteve Baker <sbaker@redhat.com>
Mon, 17 Jun 2013 23:26:59 +0000 (11:26 +1200)
When a template has a FloatingIP and a RouterGateway on the same
external network, there is an implicit dependency on create where
the gateway must be created before the floating ip.

This is implemented by overiding add_dependencies in FloatingIP
and looking in the stack for RouterGateway resource to depend on.

Fixed bug: #1182266

Change-Id: I40f281e5bf2a27280d328fe11d32e6404f412a79

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

index 389ad58a9181c30d3731ae87895a27183c12663b..b5083c32a6c8f1d262ac5aa84c737ceba6097da3 100644 (file)
@@ -31,6 +31,16 @@ class FloatingIP(quantum.QuantumResource):
                          'port_id': {'Type': 'String'},
                          'fixed_ip_address': {'Type': 'String'}}
 
+    def add_dependencies(self, deps):
+        super(FloatingIP, self).add_dependencies(deps)
+        # depend on any RouterGateway in this template with the same
+        # network_id as this floating_network_id
+        for resource in self.stack.resources.itervalues():
+            if (resource.type() == 'OS::Quantum::RouterGateway' and
+                resource.properties.get('network_id') ==
+                    self.properties.get('floating_network_id')):
+                        deps += (self, resource)
+
     def handle_create(self):
         props = self.prepare_properties(
             self.properties,
@@ -74,6 +84,8 @@ class FloatingIPAssociation(quantum.QuantumResource):
         self.resource_id_set('%s:%s' % (floatingip_id, props['port_id']))
 
     def handle_delete(self):
+        if not self.resource_id:
+            return
         client = self.quantum()
         (floatingip_id, port_id) = self.resource_id.split(':')
         try:
index fd8412014b7198b4b2efd33008476f5e023d1c8a..ec1f913e643998d030a0eeffce4b1893125ea20f 100644 (file)
@@ -128,6 +128,16 @@ quantum_floating_template = '''
         "floatingip_id": { "Ref" : "floating_ip" },
         "port_id": { "Ref" : "port_floating" }
       }
+    },
+    "router": {
+      "Type": "OS::Quantum::Router"
+    },
+    "gateway": {
+      "Type": "OS::Quantum::RouterGateway",
+      "Properties": {
+        "router_id": { "Ref" : "router" },
+        "network_id": "abcd1234"
+      }
     }
   }
 }
@@ -624,6 +634,11 @@ class QuantumFloatingIPTest(HeatTestCase):
         t = template_format.parse(quantum_floating_template)
         stack = parse_stack(t)
 
+        # assert the implicit dependency between the floating_ip
+        # and the gateway
+        deps = stack.dependencies[stack['gateway']]
+        self.assertIn(stack['floating_ip'], deps)
+
         fip = stack['floating_ip']
         scheduler.TaskRunner(fip.create)()
         self.assertEqual(floatingip.FloatingIP.CREATE_COMPLETE, fip.state)