Create and update func tests for resource group

Added create and update functional tests for resource group.

Change-Id: I3d8b173f6ee7f77c7c1687769cb6fc19c1c61f89
diff --git a/functional/test_resource_group.py b/functional/test_resource_group.py
index afd9f55..8ccddd8 100644
--- a/functional/test_resource_group.py
+++ b/functional/test_resource_group.py
@@ -17,6 +17,27 @@
 from heat_integrationtests.common import test
 
 
+template = '''
+heat_template_version: 2013-05-23
+resources:
+  random_group:
+    type: OS::Heat::ResourceGroup
+    properties:
+      count: 2
+      resource_def:
+        type: OS::Heat::RandomString
+        properties:
+          length: 30
+outputs:
+  random1:
+    value: {get_attr: [random_group, resource.0.value]}
+  random2:
+    value: {get_attr: [random_group, resource.1.value]}
+  all_values:
+    value: {get_attr: [random_group, value]}
+'''
+
+
 class ResourceGroupTest(test.HeatIntegrationTest):
 
     def setUp(self):
@@ -90,3 +111,54 @@
                                template=template_two_nested,
                                environment=env, files=files)
         self.assertIn(expected_err, six.text_type(ex))
+
+    def _validate_resources(self, stack_identifier, expected_count):
+        nested_identifier = self._group_nested_identifier(stack_identifier)
+        resources = self.list_resources(nested_identifier)
+        self.assertEqual(expected_count, len(resources))
+        expected_resources = dict(
+            (str(idx), 'OS::Heat::RandomString')
+            for idx in range(expected_count))
+
+        self.assertEqual(expected_resources, resources)
+
+    def test_create(self):
+        def validate_output(stack, output_key, length):
+            output_value = self._stack_output(stack, output_key)
+            self.assertEqual(length, len(output_value))
+            return output_value
+        # verify that the resources in resource group are identically
+        # configured, resource names and outputs are appropriate.
+        stack_identifier = self.stack_create('create_stack', template=template)
+        self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'},
+                         self.list_resources(stack_identifier))
+
+        # validate count, type and name of resources in a resource group.
+        self._validate_resources(stack_identifier, 2)
+
+        # validate outputs
+        stack = self.client.stacks.get(stack_identifier)
+        outputs = []
+        outputs.append(validate_output(stack, 'random1', 30))
+        outputs.append(validate_output(stack, 'random2', 30))
+        self.assertEqual(outputs, self._stack_output(stack, 'all_values'))
+
+    def test_update_increase_decrease_count(self):
+        # create stack with resource group count 2
+        stack_identifier = self.stack_create('update_stack', template=template)
+        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)
+        # 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)
+        # verify that the resource group has 3 resources
+        self._validate_resources(stack_identifier, 3)