Add functional test for update of group of provider resources
A new test which tests the (previously buggy) behavior when updating
a nested stack of more than one level of nesting, specifically updating
a ResourceGroup which contains provider resources.
Change-Id: I8abfd99f1ecc2cc84410fb552f18f93e47144c17
Related-Bug: #1389499
diff --git a/functional/test_update.py b/functional/test_update.py
index 84c872c..da2b5e3 100644
--- a/functional/test_update.py
+++ b/functional/test_update.py
@@ -42,6 +42,17 @@
type: My::RandomString
'''
+ provider_group_template = '''
+heat_template_version: 2013-05-23
+resources:
+ random_group:
+ type: OS::Heat::ResourceGroup
+ properties:
+ count: 2
+ resource_def:
+ type: My::RandomString
+'''
+
def setUp(self):
super(UpdateStackTest, self).setUp()
self.client = self.orchestration_client
@@ -181,3 +192,83 @@
'random2': 'OS::Heat::RandomString'}
self.assertEqual(nested_resources,
self.list_resources(nested_identifier))
+
+ def test_stack_update_provider_group(self):
+ '''Test two-level nested update.'''
+ # Create a ResourceGroup (which creates a nested stack),
+ # containing provider resources (which create a nested
+ # stack), thus excercising an update which traverses
+ # two levels of nesting.
+ stack_name = self._stack_rand_name()
+ files = {'provider.yaml': self.template}
+ env = {'resource_registry':
+ {'My::RandomString': 'provider.yaml'}}
+
+ self.client.stacks.create(
+ stack_name=stack_name,
+ template=self.provider_group_template,
+ files=files,
+ disable_rollback=True,
+ parameters={},
+ environment=env
+ )
+ self.addCleanup(self.client.stacks.delete, stack_name)
+
+ stack = self.client.stacks.get(stack_name)
+ stack_identifier = '%s/%s' % (stack_name, stack.id)
+
+ self._wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')
+ initial_resources = {'random_group': 'OS::Heat::ResourceGroup'}
+ self.assertEqual(initial_resources,
+ self.list_resources(stack_identifier))
+
+ # Prove the resource is backed by a nested stack, save the ID
+ rsrc = self.client.resources.get(stack_identifier, 'random_group')
+ physical_resource_id = rsrc.physical_resource_id
+
+ nested_stack = self.client.stacks.get(physical_resource_id)
+ nested_identifier = '%s/%s' % (nested_stack.stack_name,
+ nested_stack.id)
+ self.assertEqual(stack.id, nested_stack.parent)
+
+ # Then check the expected resources are in the nested stack
+ nested_resources = {'0': 'My::RandomString',
+ '1': 'My::RandomString'}
+ self.assertEqual(nested_resources,
+ self.list_resources(nested_identifier))
+
+ for n_rsrc in nested_resources:
+ rsrc = self.client.resources.get(nested_identifier, n_rsrc)
+ provider_stack = self.client.stacks.get(rsrc.physical_resource_id)
+ provider_identifier = '%s/%s' % (provider_stack.stack_name,
+ provider_stack.id)
+ provider_resources = {u'random1': u'OS::Heat::RandomString'}
+ self.assertEqual(provider_resources,
+ self.list_resources(provider_identifier))
+
+ # Add one resource via a stack update by changing the nested stack
+ files['provider.yaml'] = self.update_template
+ self.update_stack(stack_identifier, self.provider_group_template,
+ environment=env, files=files)
+ stack = self.client.stacks.get(stack_identifier)
+
+ # Parent resources should be unchanged and the nested stack
+ # should have been updated in-place without replacement
+ self.assertEqual(initial_resources,
+ self.list_resources(stack_identifier))
+
+ # Resource group stack should also be unchanged (but updated)
+ nested_stack = self.client.stacks.get(nested_identifier)
+ self.assertEqual('UPDATE_COMPLETE', nested_stack.stack_status)
+ self.assertEqual(nested_resources,
+ self.list_resources(nested_identifier))
+
+ for n_rsrc in nested_resources:
+ rsrc = self.client.resources.get(nested_identifier, n_rsrc)
+ provider_stack = self.client.stacks.get(rsrc.physical_resource_id)
+ provider_identifier = '%s/%s' % (provider_stack.stack_name,
+ provider_stack.id)
+ provider_resources = {'random1': 'OS::Heat::RandomString',
+ 'random2': 'OS::Heat::RandomString'}
+ self.assertEqual(provider_resources,
+ self.list_resources(provider_identifier))