Remove redundant checks of stack status

The main methods create/update/delete in HeatIntegrationTest class
already contains _wait_for_stack_status, so we can remove duplicate
checks in tests.
Also was added paramter enable_cleanup for stack_create method, which
allows to disable CleanUp method in tests, where we delete stack
manually.

Change-Id: I41b546d648656676ec9bc3b38940eac68f9a848d
diff --git a/common/test.py b/common/test.py
index 2868d0f..a7aa039 100644
--- a/common/test.py
+++ b/common/test.py
@@ -352,7 +352,8 @@
 
     def stack_create(self, stack_name=None, template=None, files=None,
                      parameters=None, environment=None,
-                     expected_status='CREATE_COMPLETE', disable_rollback=True):
+                     expected_status='CREATE_COMPLETE', disable_rollback=True,
+                     enable_cleanup=True):
         name = stack_name or self._stack_rand_name()
         templ = template or self.template
         templ_files = files or {}
@@ -366,7 +367,7 @@
             parameters=params,
             environment=env
         )
-        if expected_status not in ['ROLLBACK_COMPLETE']:
+        if expected_status not in ['ROLLBACK_COMPLETE'] and enable_cleanup:
             self.addCleanup(self.client.stacks.delete, name)
 
         stack = self.client.stacks.get(name)
diff --git a/functional/test_autoscaling.py b/functional/test_autoscaling.py
index 489ae63..301981f 100644
--- a/functional/test_autoscaling.py
+++ b/functional/test_autoscaling.py
@@ -183,7 +183,6 @@
                                'flavor': self.conf.instance_type}}
         self.update_stack(stack_identifier, self.template,
                           environment=env2, files=files)
-        self._wait_for_stack_status(stack_identifier, 'UPDATE_COMPLETE')
         stack = self.client.stacks.get(stack_identifier)
         self.assert_instance_count(stack, 5)
 
@@ -374,7 +373,6 @@
         # test stack update
         self.update_stack(stack_identifier, updt_template,
                           environment=env, files=files)
-        self._wait_for_stack_status(stack_identifier, 'UPDATE_COMPLETE')
         updt_stack = self.client.stacks.get(stack_identifier)
 
         # test that the launch configuration is replaced
diff --git a/functional/test_default_parameters.py b/functional/test_default_parameters.py
index 138a13e..00000fd 100644
--- a/functional/test_default_parameters.py
+++ b/functional/test_default_parameters.py
@@ -68,8 +68,6 @@
         self.client = self.orchestration_client
 
     def test_defaults(self):
-        stack_name = self._stack_rand_name()
-
         env = {'parameters': {}, 'parameter_defaults': {}}
         if self.param:
             env['parameters'] = {'length': self.param}
@@ -84,22 +82,13 @@
         else:
             nested_template = self.nested_template
 
-        self.client.stacks.create(
-            stack_name=stack_name,
+        stack_identifier = self.stack_create(
             template=self.template,
             files={'nested_random.yaml': nested_template},
-            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')
-
-        stack = self.client.stacks.get(stack_name)
+        stack = self.client.stacks.get(stack_identifier)
         for out in stack.outputs:
             if out['output_key'] == 'random1':
                 self.assertEqual(self.expect1, len(out['output_value']))
diff --git a/functional/test_heat_autoscaling.py b/functional/test_heat_autoscaling.py
index 0e6e0cb..dbe3e8f 100644
--- a/functional/test_heat_autoscaling.py
+++ b/functional/test_heat_autoscaling.py
@@ -132,4 +132,3 @@
             'scaling_adjustment: 2')
 
         self.update_stack(stack_identifier, template=new_template)
-        self._wait_for_stack_status(stack_identifier, 'UPDATE_COMPLETE')
diff --git a/functional/test_instance_group.py b/functional/test_instance_group.py
index 5c88bed..1455d0b 100644
--- a/functional/test_instance_group.py
+++ b/functional/test_instance_group.py
@@ -174,7 +174,6 @@
                                'flavor': self.conf.instance_type}}
         self.update_stack(stack_identifier, self.template,
                           environment=env2, files=files)
-        self._wait_for_stack_status(stack_identifier, 'UPDATE_COMPLETE')
         stack = self.client.stacks.get(stack_identifier)
         self.assert_instance_count(stack, 5)
 
@@ -345,7 +344,6 @@
         # test stack update
         self.update_stack(stack_identifier, updt_template,
                           environment=env, files=files)
-        self._wait_for_stack_status(stack_identifier, 'UPDATE_COMPLETE')
         updt_stack = self.client.stacks.get(stack_identifier)
 
         # test that the launch configuration is replaced
diff --git a/functional/test_notifications.py b/functional/test_notifications.py
index a9b6cf1..a4c419c 100644
--- a/functional/test_notifications.py
+++ b/functional/test_notifications.py
@@ -141,17 +141,9 @@
         return len(handler.notifications) == count
 
     def test_basic_notifications(self):
-        stack_identifier = self._stack_rand_name()
-        # do this manually so we can call _stack_delete() directly.
-        self.client.stacks.create(
-            stack_name=stack_identifier,
-            template=self.basic_template,
-            files={},
-            disable_rollback=True,
-            parameters={},
-            environment={}
-        )
-        self._wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')
+        # disable cleanup so we can call _stack_delete() directly.
+        stack_identifier = self.stack_create(template=self.basic_template,
+                                             enable_cleanup=False)
         self.update_stack(stack_identifier,
                           template=self.update_basic_template)
         self.stack_suspend(stack_identifier)
diff --git a/functional/test_template_resource.py b/functional/test_template_resource.py
index 392bddd..356fc2a 100644
--- a/functional/test_template_resource.py
+++ b/functional/test_template_resource.py
@@ -102,17 +102,12 @@
         This tests that if you manually delete a nested
         stack, the parent stack is still deletable.
         """
-        name = self._stack_rand_name()
-        # do this manually so we can call _stack_delete() directly.
-        self.client.stacks.create(
-            stack_name=name,
+        # disable cleanup so we can call _stack_delete() directly.
+        stack_identifier = self.stack_create(
             template=self.template,
             files={'nested.yaml': self.nested_templ},
             environment=self.env_templ,
-            disable_rollback=True)
-        stack = self.client.stacks.get(name)
-        stack_identifier = '%s/%s' % (name, stack.id)
-        self._wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')
+            enable_cleanup=False)
 
         nested_ident = self.assert_resource_is_a_stack(stack_identifier,
                                                        'secret1')
@@ -445,16 +440,11 @@
         return yaml.load(yaml_templ)
 
     def test_abandon(self):
-        stack_name = self._stack_rand_name()
-        self.client.stacks.create(
-            stack_name=stack_name,
+        stack_identifier = self.stack_create(
             template=self.main_template,
             files={'the.yaml': self.nested_templ},
-            disable_rollback=True,
+            enable_cleanup=False
         )
-        stack = self.client.stacks.get(stack_name)
-        stack_identifier = '%s/%s' % (stack_name, stack.id)
-        self._wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')
 
         info = self.stack_abandon(stack_id=stack_identifier)
         self.assertEqual(self._yaml_to_json(self.main_template),
@@ -527,16 +517,10 @@
         self.client = self.orchestration_client
 
     def test_check(self):
-        stack_name = self._stack_rand_name()
-        self.client.stacks.create(
-            stack_name=stack_name,
+        stack_identifier = self.stack_create(
             template=self.main_template,
-            files={'the.yaml': self.nested_templ},
-            disable_rollback=True,
+            files={'the.yaml': self.nested_templ}
         )
-        stack = self.client.stacks.get(stack_name)
-        stack_identifier = '%s/%s' % (stack_name, stack.id)
-        self._wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')
 
         self.client.actions.check(stack_id=stack_identifier)
         self._wait_for_stack_status(stack_identifier, 'CHECK_COMPLETE')
diff --git a/scenario/test_server_cfn_init.py b/scenario/test_server_cfn_init.py
index a49606c..8134713 100644
--- a/scenario/test_server_cfn_init.py
+++ b/scenario/test_server_cfn_init.py
@@ -47,9 +47,6 @@
             # logs to be compared
             self._log_console_output(servers=[server])
 
-        # Check stack status
-        self._wait_for_stack_status(sid, 'CREATE_COMPLETE')
-
         stack = self.client.stacks.get(sid)
 
         # This is an assert of great significance, as it means the following
diff --git a/scenario/test_server_software_config.py b/scenario/test_server_software_config.py
index 8b614c1..19fd1a8 100644
--- a/scenario/test_server_software_config.py
+++ b/scenario/test_server_software_config.py
@@ -84,9 +84,6 @@
             # logs to be compared
             self._log_console_output(servers=[server])
 
-        # Check that stack was fully created
-        self._wait_for_stack_status(sid, 'CREATE_COMPLETE')
-
         complete_server_metadata = self.client.resources.metadata(
             sid, 'server')
 
diff --git a/scenario/test_volumes.py b/scenario/test_volumes.py
index 79d4931..7562304 100644
--- a/scenario/test_volumes.py
+++ b/scenario/test_volumes.py
@@ -61,8 +61,7 @@
 
         # Delete the stack and ensure a backup is created for volume_id
         # but the volume itself is gone
-        self.client.stacks.delete(stack_id)
-        self._wait_for_stack_status(stack_id, 'DELETE_COMPLETE')
+        self._stack_delete(stack_id)
         self.assertRaises(cinder_exceptions.NotFound,
                           self.volume_client.volumes.get,
                           volume_id)
@@ -97,8 +96,7 @@
                          testfile_data)
 
         # Delete the stack and ensure the volume is gone
-        self.client.stacks.delete(stack_identifier2)
-        self._wait_for_stack_status(stack_identifier2, 'DELETE_COMPLETE')
+        self._stack_delete(stack_identifier2)
         self.assertRaises(cinder_exceptions.NotFound,
                           self.volume_client.volumes.get,
                           volume_id2)