From ccba71e38adff7a57ba2e471378cadd0421793f3 Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Tue, 21 May 2013 13:21:22 +1200 Subject: [PATCH] Add dependency between FloatingIP and RouterGateway 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 | 12 ++++++++++++ heat/tests/test_quantum.py | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/heat/engine/resources/quantum/floatingip.py b/heat/engine/resources/quantum/floatingip.py index 389ad58a91..b5083c32a6 100644 --- a/heat/engine/resources/quantum/floatingip.py +++ b/heat/engine/resources/quantum/floatingip.py @@ -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: diff --git a/heat/tests/test_quantum.py b/heat/tests/test_quantum.py index fd8412014b..ec1f913e64 100644 --- a/heat/tests/test_quantum.py +++ b/heat/tests/test_quantum.py @@ -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)