]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Add dependency between RouterGateway and RouterInterface
authorSteve Baker <sbaker@redhat.com>
Tue, 21 May 2013 01:21:11 +0000 (13:21 +1200)
committerSteve Baker <sbaker@redhat.com>
Wed, 26 Jun 2013 23:55:37 +0000 (11:55 +1200)
When a template has a RouterGateway and a RouterInterface with the
same router_id, there is an implicit dependency on delete where
the gateway must be deleted before the interface.

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

Fixed bug: #1182266

Change-Id: I90ebe987c1d6e81f8936ceb81b81376c7e0d497a

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

index 898a7a848900ddc045949e20179a29b2f9e58597..7a62898542934b3fdb8e66327ef0edda0c226a4e 100644 (file)
@@ -95,6 +95,16 @@ class RouterGateway(quantum.QuantumResource):
                          'network_id': {'Type': 'String',
                                         'Required': True}}
 
+    def add_dependencies(self, deps):
+        super(RouterGateway, self).add_dependencies(deps)
+        # depend on any RouterInterface in this template with the same
+        # router_id as this router_id
+        for resource in self.stack.resources.itervalues():
+            if (resource.type() == 'OS::Quantum::RouterInterface' and
+                resource.properties.get('router_id') ==
+                    self.properties.get('router_id')):
+                        deps += (self, resource)
+
     def handle_create(self):
         router_id = self.properties.get('router_id')
         network_id = self.properties.get('network_id')
index 0c44c8b8a26ba0bf47fadba94fcb9aaf3a4b5f9f..41e39c0e00186ebe3705cb21b317b25bf3b1bf2f 100644 (file)
@@ -281,6 +281,10 @@ class QuantumNetTest(HeatTestCase):
         stack = parse_stack(t)
         rsrc = self.create_net(t, stack, 'network')
 
+        # assert the implicit dependency between the gateway and the interface
+        deps = stack.dependencies[stack['router_interface']]
+        self.assertIn(stack['gateway'], deps)
+
         rsrc.validate()
 
         ref_id = rsrc.FnGetRefId()