diff options
author | Taseer Ahmed <taseer94@gmail.com> | 2017-10-13 12:34:00 +0500 |
---|---|---|
committer | Taseer Ahmed <taseer94@gmail.com> | 2017-10-19 20:07:54 +0500 |
commit | bc8f8f580bf356dace5fa0a0968f9d179d5e515a (patch) | |
tree | c6be68211d750e81910a75f3cc747fe9b27f4efc | |
parent | 530153597deb5030c296358431d9549d13b7288b (diff) |
Add reason for stack creation failure
JIRA: SNAPS-190
Change-Id: I59b7d416ef16cd1f301ccbdcdd8a7529527b3dd6
Signed-off-by: Taseer Ahmed <taseer94@gmail.com>
-rw-r--r-- | snaps/openstack/create_stack.py | 12 | ||||
-rw-r--r-- | snaps/openstack/tests/create_stack_tests.py | 20 | ||||
-rw-r--r-- | snaps/openstack/utils/heat_utils.py | 10 |
3 files changed, 36 insertions, 6 deletions
diff --git a/snaps/openstack/create_stack.py b/snaps/openstack/create_stack.py index ce87e89..c161973 100644 --- a/snaps/openstack/create_stack.py +++ b/snaps/openstack/create_stack.py @@ -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) diff --git a/snaps/openstack/tests/create_stack_tests.py b/snaps/openstack/tests/create_stack_tests.py index d2b138e..f4eb1eb 100644 --- a/snaps/openstack/tests/create_stack_tests.py +++ b/snaps/openstack/tests/create_stack_tests.py @@ -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. diff --git a/snaps/openstack/utils/heat_utils.py b/snaps/openstack/utils/heat_utils.py index 6910bfe..8b9395b 100644 --- a/snaps/openstack/utils/heat_utils.py +++ b/snaps/openstack/utils/heat_utils.py @@ -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 |