From: Steve Baker Date: Thu, 27 Jun 2013 01:39:30 +0000 (+1200) Subject: Ports depend on the subnets in the same network. X-Git-Tag: 2014.1~399^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=f2ecb7fb6ec05e2040e36f9b015ae5684f06c14f;p=openstack-build%2Fheat-build.git Ports depend on the subnets in the same network. 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 --- diff --git a/heat/engine/resources/quantum/port.py b/heat/engine/resources/quantum/port.py index de72238d..5ddc96f4 100644 --- a/heat/engine/resources/quantum/port.py +++ b/heat/engine/resources/quantum/port.py @@ -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, diff --git a/heat/tests/test_quantum.py b/heat/tests/test_quantum.py index 0c44c8b8..441235bc 100644 --- a/heat/tests/test_quantum.py +++ b/heat/tests/test_quantum.py @@ -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, {}, {}, {})