Add reason for stack creation failure 79/44979/7
authorTaseer Ahmed <taseer94@gmail.com>
Fri, 13 Oct 2017 07:34:00 +0000 (12:34 +0500)
committerTaseer Ahmed <taseer94@gmail.com>
Thu, 19 Oct 2017 15:07:54 +0000 (20:07 +0500)
JIRA: SNAPS-190

Change-Id: I59b7d416ef16cd1f301ccbdcdd8a7529527b3dd6
Signed-off-by: Taseer Ahmed <taseer94@gmail.com>
snaps/openstack/create_stack.py
snaps/openstack/tests/create_stack_tests.py
snaps/openstack/utils/heat_utils.py

index ce87e89..c161973 100644 (file)
@@ -29,6 +29,7 @@ __author__ = 'spisarski'
 
 logger = logging.getLogger('create_stack')
 
+STACK_DELETE_TIMEOUT = 1200
 STACK_COMPLETE_TIMEOUT = 1200
 POLL_INTERVAL = 3
 STATUS_CREATE_FAILED = 'CREATE_FAILED'
@@ -107,9 +108,12 @@ class OpenStackHeatStack(OpenStackCloudObject, object):
                     self.stack_settings.name)
                 return self.__stack
             else:
+                status = heat_utils.get_stack_status_reason(self.__heat_cli,
+                                                            self.__stack.id)
+                logger.error(
+                    'ERROR: STACK CREATION FAILED: ' + status)
                 raise StackCreationError(
-                    'Stack was not created or activated in the alloted amount '
-                    'of time')
+                    'Failure while creating stack')
 
     def clean(self):
         """
@@ -192,7 +196,7 @@ class OpenStackHeatStack(OpenStackCloudObject, object):
         return self._stack_status_check(STATUS_CREATE_COMPLETE, block, timeout,
                                         poll_interval, STATUS_CREATE_FAILED)
 
-    def stack_deleted(self, block=False, timeout=None,
+    def stack_deleted(self, block=False, timeout=STACK_DELETE_TIMEOUT,
                       poll_interval=POLL_INTERVAL):
         """
         Returns true when the stack status returns the value of
@@ -203,8 +207,6 @@ class OpenStackHeatStack(OpenStackCloudObject, object):
         :param poll_interval: The polling interval in seconds
         :return: T/F
         """
-        if not timeout:
-            timeout = self.stack_settings.stack_create_timeout
         return self._stack_status_check(STATUS_DELETE_COMPLETE, block, timeout,
                                         poll_interval, STATUS_DELETE_FAILED)
 
index d2b138e..f4eb1eb 100644 (file)
@@ -30,7 +30,8 @@ import unittest
 import uuid
 
 from snaps.openstack import create_stack
-from snaps.openstack.create_stack import StackSettings, StackSettingsError
+from snaps.openstack.create_stack import (
+    StackSettings, StackSettingsError, StackCreationError)
 from snaps.openstack.tests import openstack_tests, create_instance_tests
 from snaps.openstack.tests.os_source_file_test import OSIntegrationTestCase
 from snaps.openstack.utils import heat_utils, neutron_utils, nova_utils
@@ -214,6 +215,23 @@ class CreateStackSuccessTests(OSIntegrationTestCase):
         self.assertEqual(created_stack.id, retrieved_stack.id)
         self.assertEqual(0, len(self.stack_creator.get_outputs()))
 
+    def test_create_stack_short_timeout(self):
+        """
+        Tests the creation of an OpenStack stack from Heat template file.
+        """
+        # Create Stack
+        # Set the default stack settings, then set any custom parameters sent
+        # from the app
+        stack_settings = StackSettings(
+            name=self.__class__.__name__ + '-' + str(self.guid) + '-stack',
+            template_path=self.heat_tmplt_path,
+            env_values=self.env_values, stack_create_timeout=0)
+
+        self.stack_creator = create_stack.OpenStackHeatStack(self.heat_creds,
+                                                             stack_settings)
+        with self.assertRaises(StackCreationError):
+            self.stack_creator.create()
+
     def test_create_stack_template_dict(self):
         """
         Tests the creation of an OpenStack stack from a heat dict() object.
index 6910bfe..8b9395b 100644 (file)
@@ -87,6 +87,16 @@ def get_stack_status(heat_cli, stack_id):
     return heat_cli.stacks.get(stack_id).stack_status
 
 
+def get_stack_status_reason(heat_cli, stack_id):
+    """
+    Returns the current status of the Heat stack
+    :param heat_cli: the OpenStack heat client
+    :param stack_id: the ID of the heat stack to retrieve
+    :return: reason for stack creation failure
+    """
+    return heat_cli.stacks.get(stack_id).stack_status_reason
+
+
 def create_stack(heat_cli, stack_settings):
     """
     Executes an Ansible playbook to the given host