Merge "Create common stack_create functional test helper"
diff --git a/common/test.py b/common/test.py
index 1721697..43336a9 100644
--- a/common/test.py
+++ b/common/test.py
@@ -327,3 +327,25 @@
def list_resources(self, stack_identifier):
resources = self.client.resources.list(stack_identifier)
return dict((r.resource_name, r.resource_type) for r in resources)
+
+ def stack_create(self, stack_name=None, template=None, files=None,
+ parameters=None, environment=None):
+ name = stack_name or self._stack_rand_name()
+ templ = template or self.template
+ templ_files = files or {}
+ params = parameters or {}
+ env = environment or {}
+ self.client.stacks.create(
+ stack_name=name,
+ template=templ,
+ files=templ_files,
+ disable_rollback=True,
+ parameters=params,
+ environment=env
+ )
+ self.addCleanup(self.client.stacks.delete, name)
+
+ stack = self.client.stacks.get(name)
+ stack_identifier = '%s/%s' % (name, stack.id)
+ self._wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')
+ return stack_identifier
diff --git a/functional/test_update.py b/functional/test_update.py
index dcba97d..610fe10 100644
--- a/functional/test_update.py
+++ b/functional/test_update.py
@@ -58,21 +58,7 @@
self.client = self.orchestration_client
def test_stack_update_nochange(self):
- stack_name = self._stack_rand_name()
- self.client.stacks.create(
- stack_name=stack_name,
- template=self.template,
- files={},
- disable_rollback=True,
- parameters={},
- environment={}
- )
- 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')
+ stack_identifier = self.stack_create()
expected_resources = {'random1': 'OS::Heat::RandomString'}
self.assertEqual(expected_resources,
self.list_resources(stack_identifier))
@@ -83,29 +69,13 @@
self.list_resources(stack_identifier))
def test_stack_update_add_remove(self):
- stack_name = self._stack_rand_name()
-
- self.client.stacks.create(
- stack_name=stack_name,
- template=self.template,
- files={},
- disable_rollback=True,
- parameters={},
- environment={}
- )
- 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')
+ stack_identifier = self.stack_create()
initial_resources = {'random1': 'OS::Heat::RandomString'}
self.assertEqual(initial_resources,
self.list_resources(stack_identifier))
# Add one resource via a stack update
self.update_stack(stack_identifier, self.update_template)
- stack = self.client.stacks.get(stack_identifier)
updated_resources = {'random1': 'OS::Heat::RandomString',
'random2': 'OS::Heat::RandomString'}
self.assertEqual(updated_resources,
@@ -117,25 +87,15 @@
self.list_resources(stack_identifier))
def test_stack_update_provider(self):
- 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,
+ stack_identifier = self.stack_create(
template=self.provider_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 = {'random1': 'My::RandomString'}
self.assertEqual(initial_resources,
self.list_resources(stack_identifier))
@@ -158,7 +118,6 @@
files['provider.yaml'] = self.update_template
self.update_stack(stack_identifier, self.provider_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
@@ -179,25 +138,16 @@
# 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,
+ stack_identifier = self.stack_create(
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))
@@ -209,7 +159,8 @@
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)
+ parent_id = stack_identifier.split("/")[-1]
+ self.assertEqual(parent_id, nested_stack.parent)
# Then check the expected resources are in the nested stack
nested_resources = {'0': 'My::RandomString',
@@ -230,7 +181,6 @@
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