From aae87c9b776f995d00725230fd3dbb8346a92225 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Mon, 19 Jan 2015 22:15:48 +1000 Subject: [PATCH] Move ResourceGroup update sequence test to functional This was largely done by I3d8b173f6ee7f77c7c1687769cb6fc19c1c61f89 This just cleans up the functional test to reuse the existing template. Part of blueprint decouple-nested Change-Id: Ic777e7f381968e2c93e4c737dfec0cf26229602f --- heat/tests/test_resource_group.py | 37 ------------- .../functional/test_resource_group.py | 54 +++++++++---------- 2 files changed, 26 insertions(+), 65 deletions(-) diff --git a/heat/tests/test_resource_group.py b/heat/tests/test_resource_group.py index 93de84d62a..8e76a8326d 100644 --- a/heat/tests/test_resource_group.py +++ b/heat/tests/test_resource_group.py @@ -381,43 +381,6 @@ class ResourceGroupTest(common.HeatTestCase): self.assertEqual((resg.CREATE, resg.COMPLETE), resg.state) return resg - def test_zero_resources(self): - noresources = copy.deepcopy(template) - noresources['resources']['group1']['properties']['count'] = 0 - resg = self._create_dummy_stack(noresources, expect_count=0) - self.assertEqual((resg.CREATE, resg.COMPLETE), resg.state) - - def test_delete(self): - """Test basic delete.""" - resg = self._create_dummy_stack() - self.assertIsNotNone(resg.nested()) - scheduler.TaskRunner(resg.delete)() - self.assertEqual((resg.DELETE, resg.COMPLETE), resg.nested().state) - self.assertEqual((resg.DELETE, resg.COMPLETE), resg.state) - - def test_update(self): - """Test basic update.""" - resg = self._create_dummy_stack() - self.assertEqual(2, len(resg.nested())) - resource_names = [r.name for r in resg.nested().iter_resources()] - self.assertEqual(['0', '1'], sorted(resource_names)) - old_snip = copy.deepcopy(resg.t) - new_snip = copy.deepcopy(resg.t) - new_snip['Properties']['count'] = 3 - scheduler.TaskRunner(resg.update, new_snip)() - self.stack = resg.nested() - self.assertEqual((resg.UPDATE, resg.COMPLETE), resg.state) - self.assertEqual((resg.UPDATE, resg.COMPLETE), resg.nested().state) - self.assertEqual(3, len(resg.nested())) - resource_names = [r.name for r in resg.nested().iter_resources()] - self.assertEqual(['0', '1', '2'], sorted(resource_names)) - scheduler.TaskRunner(resg.update, old_snip)() - self.assertEqual((resg.UPDATE, resg.COMPLETE), resg.state) - self.assertEqual((resg.UPDATE, resg.COMPLETE), resg.nested().state) - self.assertEqual(2, len(resg.nested())) - resource_names = [r.name for r in resg.nested().iter_resources()] - self.assertEqual(['0', '1'], sorted(resource_names)) - def test_props_update(self): """Test update of resource_def properties.""" resg = self._create_dummy_stack() diff --git a/heat_integrationtests/functional/test_resource_group.py b/heat_integrationtests/functional/test_resource_group.py index dba6f5c7b6..497838c96f 100644 --- a/heat_integrationtests/functional/test_resource_group.py +++ b/heat_integrationtests/functional/test_resource_group.py @@ -19,15 +19,16 @@ import yaml from heat_integrationtests.common import test -template = ''' +class ResourceGroupTest(test.HeatIntegrationTest): + template = ''' heat_template_version: 2013-05-23 resources: random_group: type: OS::Heat::ResourceGroup properties: - count: 2 + count: 0 resource_def: - type: OS::Heat::RandomString + type: My::RandomString properties: length: 30 outputs: @@ -39,9 +40,6 @@ outputs: value: {get_attr: [random_group, value]} ''' - -class ResourceGroupTest(test.HeatIntegrationTest): - def setUp(self): super(ResourceGroupTest, self).setUp() self.client = self.orchestration_client @@ -66,29 +64,22 @@ class ResourceGroupTest(test.HeatIntegrationTest): # e.g images etc in the nested schema. nested_template_fail = ''' heat_template_version: 2013-05-23 +parameters: + length: + type: string + default: 50 resources: random: type: OS::Heat::RandomString properties: - length: BAD -''' - - template_zero_nested = ''' -heat_template_version: 2013-05-23 -resources: - random_group: - type: OS::Heat::ResourceGroup - properties: - count: 0 - resource_def: - type: My::RandomString + length: BAD ''' files = {'provider.yaml': nested_template_fail} env = {'resource_registry': {'My::RandomString': 'provider.yaml'}} stack_identifier = self.stack_create( - template=template_zero_nested, + template=self.template, files=files, environment=env ) @@ -101,8 +92,7 @@ resources: self.assertEqual({}, self.list_resources(nested_identifier)) # Prove validation works for non-zero create/update - template_two_nested = template_zero_nested.replace("count: 0", - "count: 2") + template_two_nested = self.template.replace("count: 0", "count: 2") expected_err = "length Value 'BAD' is not an integer" ex = self.assertRaises(exc.HTTPBadRequest, self.update_stack, stack_identifier, template_two_nested, @@ -119,7 +109,7 @@ resources: resources = self.list_resources(nested_identifier) self.assertEqual(expected_count, len(resources)) expected_resources = dict( - (str(idx), 'OS::Heat::RandomString') + (str(idx), 'My::RandomString') for idx in range(expected_count)) self.assertEqual(expected_resources, resources) @@ -131,7 +121,11 @@ resources: return output_value # verify that the resources in resource group are identically # configured, resource names and outputs are appropriate. - stack_identifier = self.stack_create(template=template) + env = {'resource_registry': + {'My::RandomString': 'OS::Heat::RandomString'}} + create_template = self.template.replace("count: 0", "count: 2") + stack_identifier = self.stack_create(template=create_template, + environment=env) self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'}, self.list_resources(stack_identifier)) @@ -147,21 +141,25 @@ resources: def test_update_increase_decrease_count(self): # create stack with resource group count 2 - stack_identifier = self.stack_create(template=template) + env = {'resource_registry': + {'My::RandomString': 'OS::Heat::RandomString'}} + create_template = self.template.replace("count: 0", "count: 2") + stack_identifier = self.stack_create(template=create_template, + environment=env) self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'}, self.list_resources(stack_identifier)) # verify that the resource group has 2 resources self._validate_resources(stack_identifier, 2) # increase the resource group count to 5 - update_template = template.replace("count: 2", "count: 5") - self.update_stack(stack_identifier, update_template) + update_template = self.template.replace("count: 0", "count: 5") + self.update_stack(stack_identifier, update_template, environment=env) # verify that the resource group has 5 resources self._validate_resources(stack_identifier, 5) # decrease the resource group count to 3 - update_template = template.replace("count: 2", "count: 3") - self.update_stack(stack_identifier, update_template) + update_template = self.template.replace("count: 0", "count: 3") + self.update_stack(stack_identifier, update_template, environment=env) # verify that the resource group has 3 resources self._validate_resources(stack_identifier, 3)