diff options
author | spisarski <s.pisarski@cablelabs.com> | 2017-11-17 11:52:01 -0700 |
---|---|---|
committer | spisarski <s.pisarski@cablelabs.com> | 2017-11-20 08:54:21 -0700 |
commit | 0812d4eca28734872a5565afe9288e002721794b (patch) | |
tree | ccaf3a0e2e8a389ab95025b7a4a19e9f4bd8980d | |
parent | 3482f6e28e26025043f61efb90892d886f5909cc (diff) |
Refactoring of StackSettings to extend StackConfig
StackSettings and heat_utils have a runtime cyclical
dependency. This patch reduces this dependency and
deprecates the StackSettings class.
JIRA: SNAPS-225
Change-Id: I8dc7a4d80efce93452908563730babf14c17e615
Signed-off-by: spisarski <s.pisarski@cablelabs.com>
-rw-r--r-- | docs/how-to-use/LibraryUsage.rst | 7 | ||||
-rw-r--r-- | docs/how-to-use/UnitTests.rst | 8 | ||||
-rw-r--r-- | snaps/config/stack.py | 68 | ||||
-rw-r--r-- | snaps/config/tests/stack_tests.py | 98 | ||||
-rw-r--r-- | snaps/openstack/create_stack.py | 81 | ||||
-rw-r--r-- | snaps/openstack/tests/create_stack_tests.py | 120 | ||||
-rw-r--r-- | snaps/openstack/tests/openstack_tests.py | 2 | ||||
-rw-r--r-- | snaps/openstack/utils/tests/heat_utils_tests.py | 39 | ||||
-rw-r--r-- | snaps/test_suite_builder.py | 3 |
9 files changed, 288 insertions, 138 deletions
diff --git a/docs/how-to-use/LibraryUsage.rst b/docs/how-to-use/LibraryUsage.rst index b7ac644..7c82387 100644 --- a/docs/how-to-use/LibraryUsage.rst +++ b/docs/how-to-use/LibraryUsage.rst @@ -508,7 +508,7 @@ Create Heat Stack - Heat StackĀ - snaps.openstack.create\_stack.OpenStackHeatStack - - snaps.openstack.create\_stack.StackSettings + - snaps.config.stack.StackConfig - name - the stack's name (required) - template - the heat template in dict() format (required when @@ -520,9 +520,10 @@ Create Heat Stack .. code:: python - from snaps.openstack.create_stack import StackSettings, OpenStackHeatStack + from snaps.config.stack import StackConfig + from snaps.openstack.create_stack import OpenStackHeatStack - stack_settings = StackSettings(name='stack-name', template_path='/tmp/template.yaml') + stack_settings = StackConfig(name='stack-name', template_path='/tmp/template.yaml') stack_creator = OpenStackHeatStack(os_creds, stack_settings) stack_creator.create() diff --git a/docs/how-to-use/UnitTests.rst b/docs/how-to-use/UnitTests.rst index 8ba65fe..f46d9ee 100644 --- a/docs/how-to-use/UnitTests.rst +++ b/docs/how-to-use/UnitTests.rst @@ -234,11 +234,17 @@ InterfaceRouterDomainObjectTests Ensures that all required members are included when constructing a InterfaceRouter domain object +StackConfigUnitTests +-------------------- + +Ensures that all required members are included when constructing a +StackConfig object + StackSettingsUnitTests ---------------------- Ensures that all required members are included when constructing a -StackSettings object +deprecated StackSettings object StackDomainObjectTests ---------------------- diff --git a/snaps/config/stack.py b/snaps/config/stack.py new file mode 100644 index 0000000..0655961 --- /dev/null +++ b/snaps/config/stack.py @@ -0,0 +1,68 @@ +# Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs") +# and others. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +STACK_DELETE_TIMEOUT = 1200 +STACK_COMPLETE_TIMEOUT = 1200 +POLL_INTERVAL = 3 +STATUS_CREATE_FAILED = 'CREATE_FAILED' +STATUS_CREATE_COMPLETE = 'CREATE_COMPLETE' +STATUS_DELETE_COMPLETE = 'DELETE_COMPLETE' +STATUS_DELETE_FAILED = 'DELETE_FAILED' + + +class StackConfig(object): + """ + Configuration for Heat stack + """ + + def __init__(self, **kwargs): + """ + Constructor + :param name: the stack's name (required) + :param template: the heat template in dict() format (required if + template_path attribute is None) + :param template_path: the location of the heat template file (required + if template attribute is None) + :param env_values: dict() of strings for substitution of template + default values (optional) + """ + + self.name = kwargs.get('name') + self.template = kwargs.get('template') + self.template_path = kwargs.get('template_path') + self.env_values = kwargs.get('env_values') + if 'stack_create_timeout' in kwargs: + self.stack_create_timeout = kwargs['stack_create_timeout'] + else: + self.stack_create_timeout = STACK_COMPLETE_TIMEOUT + + if not self.name: + raise StackConfigError('name is required') + + if not self.template and not self.template_path: + raise StackConfigError('A Heat template is required') + + def __eq__(self, other): + return (self.name == other.name and + self.template == other.template and + self.template_path == other.template_path and + self.env_values == other.env_values and + self.stack_create_timeout == other.stack_create_timeout) + + +class StackConfigError(Exception): + """ + Exception to be thrown when an stack configuration are incorrect + """ diff --git a/snaps/config/tests/stack_tests.py b/snaps/config/tests/stack_tests.py new file mode 100644 index 0000000..cf6e7d8 --- /dev/null +++ b/snaps/config/tests/stack_tests.py @@ -0,0 +1,98 @@ +# Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs") +# and others. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import unittest + +import snaps +from snaps.config.stack import StackConfigError, StackConfig + + +class StackConfigUnitTests(unittest.TestCase): + """ + Tests the construction of the StackConfig class + """ + + def test_no_params(self): + with self.assertRaises(StackConfigError): + StackConfig() + + def test_empty_config(self): + with self.assertRaises(StackConfigError): + StackConfig(**dict()) + + def test_name_only(self): + with self.assertRaises(StackConfigError): + StackConfig(name='foo') + + def test_config_with_name_only(self): + with self.assertRaises(StackConfigError): + StackConfig(**{'name': 'foo'}) + + def test_config_minimum_template(self): + settings = StackConfig(**{'name': 'stack', 'template': 'foo'}) + self.assertEqual('stack', settings.name) + self.assertEqual('foo', settings.template) + self.assertIsNone(settings.template_path) + self.assertIsNone(settings.env_values) + self.assertEqual(snaps.config.stack.STACK_COMPLETE_TIMEOUT, + settings.stack_create_timeout) + + def test_config_minimum_template_path(self): + settings = StackConfig(**{'name': 'stack', 'template_path': 'foo'}) + self.assertEqual('stack', settings.name) + self.assertIsNone(settings.template) + self.assertEqual('foo', settings.template_path) + self.assertIsNone(settings.env_values) + self.assertEqual(snaps.config.stack.STACK_COMPLETE_TIMEOUT, + settings.stack_create_timeout) + + def test_minimum_template(self): + settings = StackConfig(name='stack', template='foo') + self.assertEqual('stack', settings.name) + self.assertEqual('foo', settings.template) + self.assertIsNone(settings.template_path) + self.assertIsNone(settings.env_values) + self.assertEqual(snaps.config.stack.STACK_COMPLETE_TIMEOUT, + settings.stack_create_timeout) + + def test_minimum_template_path(self): + settings = StackConfig(name='stack', template_path='foo') + self.assertEqual('stack', settings.name) + self.assertEqual('foo', settings.template_path) + self.assertIsNone(settings.template) + self.assertIsNone(settings.env_values) + self.assertEqual(snaps.config.stack.STACK_COMPLETE_TIMEOUT, + settings.stack_create_timeout) + + def test_all(self): + env_values = {'foo': 'bar'} + settings = StackConfig( + name='stack', template='bar', template_path='foo', + env_values=env_values, stack_create_timeout=999) + self.assertEqual('stack', settings.name) + self.assertEqual('bar', settings.template) + self.assertEqual('foo', settings.template_path) + self.assertEqual(env_values, settings.env_values) + self.assertEqual(999, settings.stack_create_timeout) + + def test_config_all(self): + env_values = {'foo': 'bar'} + settings = StackConfig( + **{'name': 'stack', 'template': 'bar', 'template_path': 'foo', + 'env_values': env_values, 'stack_create_timeout': 999}) + self.assertEqual('stack', settings.name) + self.assertEqual('bar', settings.template) + self.assertEqual('foo', settings.template_path) + self.assertEqual(env_values, settings.env_values) + self.assertEqual(999, settings.stack_create_timeout) diff --git a/snaps/openstack/create_stack.py b/snaps/openstack/create_stack.py index 4ed293d..33e0106 100644 --- a/snaps/openstack/create_stack.py +++ b/snaps/openstack/create_stack.py @@ -18,6 +18,8 @@ import time from heatclient.exc import HTTPNotFound +import snaps +from snaps.config.stack import StackConfig from snaps.openstack.create_flavor import OpenStackFlavor from snaps.openstack.create_instance import OpenStackVmInstance from snaps.openstack.create_keypairs import OpenStackKeypair @@ -36,14 +38,6 @@ __author__ = 'spisarski' logger = logging.getLogger('create_stack') -STACK_DELETE_TIMEOUT = 1200 -STACK_COMPLETE_TIMEOUT = 1200 -POLL_INTERVAL = 3 -STATUS_CREATE_FAILED = 'CREATE_FAILED' -STATUS_CREATE_COMPLETE = 'CREATE_COMPLETE' -STATUS_DELETE_COMPLETE = 'DELETE_COMPLETE' -STATUS_DELETE_FAILED = 'DELETE_FAILED' - class OpenStackHeatStack(OpenStackCloudObject, object): """ @@ -183,7 +177,7 @@ class OpenStackHeatStack(OpenStackCloudObject, object): return heat_utils.get_stack_status(self.__heat_cli, self.__stack.id) def stack_complete(self, block=False, timeout=None, - poll_interval=POLL_INTERVAL): + poll_interval=snaps.config.stack.POLL_INTERVAL): """ Returns true when the stack status returns the value of expected_status_code @@ -195,11 +189,13 @@ class OpenStackHeatStack(OpenStackCloudObject, object): """ if not timeout: timeout = self.stack_settings.stack_create_timeout - return self._stack_status_check(STATUS_CREATE_COMPLETE, block, timeout, - poll_interval, STATUS_CREATE_FAILED) + return self._stack_status_check( + snaps.config.stack.STATUS_CREATE_COMPLETE, block, timeout, + poll_interval, snaps.config.stack.STATUS_CREATE_FAILED) - def stack_deleted(self, block=False, timeout=STACK_DELETE_TIMEOUT, - poll_interval=POLL_INTERVAL): + def stack_deleted(self, block=False, + timeout=snaps.config.stack.STACK_DELETE_TIMEOUT, + poll_interval=snaps.config.stack.POLL_INTERVAL): """ Returns true when the stack status returns the value of expected_status_code @@ -209,8 +205,9 @@ class OpenStackHeatStack(OpenStackCloudObject, object): :param poll_interval: The polling interval in seconds :return: T/F """ - return self._stack_status_check(STATUS_DELETE_COMPLETE, block, timeout, - poll_interval, STATUS_DELETE_FAILED) + return self._stack_status_check( + snaps.config.stack.STATUS_DELETE_COMPLETE, block, timeout, + poll_interval, snaps.config.stack.STATUS_DELETE_FAILED) def get_network_creators(self): """ @@ -455,7 +452,8 @@ class OpenStackHeatStack(OpenStackCloudObject, object): 'Timeout checking for stack status for ' + expected_status_code) return False - def _status(self, expected_status_code, fail_status=STATUS_CREATE_FAILED): + def _status(self, expected_status_code, + fail_status=snaps.config.stack.STATUS_CREATE_FAILED): """ Returns True when active else False :param expected_status_code: stack status evaluated with this string @@ -472,7 +470,8 @@ class OpenStackHeatStack(OpenStackCloudObject, object): resources = heat_utils.get_resources(self.__heat_cli, self.__stack) logger.error('Stack %s failed', self.__stack.name) for resource in resources: - if resource.status != STATUS_CREATE_COMPLETE: + if (resource.status != + snaps.config.stack.STATUS_CREATE_COMPLETE): logger.error( 'Resource: [%s] status: [%s] reason: [%s]', resource.name, resource.status, resource.status_reason) @@ -486,47 +485,19 @@ class OpenStackHeatStack(OpenStackCloudObject, object): return status == expected_status_code -class StackSettings: - def __init__(self, **kwargs): - """ - Constructor - :param name: the stack's name (required) - :param template: the heat template in dict() format (required if - template_path attribute is None) - :param template_path: the location of the heat template file (required - if template attribute is None) - :param env_values: dict() of strings for substitution of template - default values (optional) - """ - - self.name = kwargs.get('name') - self.template = kwargs.get('template') - self.template_path = kwargs.get('template_path') - self.env_values = kwargs.get('env_values') - if 'stack_create_timeout' in kwargs: - self.stack_create_timeout = kwargs['stack_create_timeout'] - else: - self.stack_create_timeout = STACK_COMPLETE_TIMEOUT - - if not self.name: - raise StackSettingsError('name is required') - - if not self.template and not self.template_path: - raise StackSettingsError('A Heat template is required') - - def __eq__(self, other): - return (self.name == other.name and - self.template == other.template and - self.template_path == other.template_path and - self.env_values == other.env_values and - self.stack_create_timeout == other.stack_create_timeout) - - -class StackSettingsError(Exception): +class StackSettings(StackConfig): """ - Exception to be thrown when an stack settings are incorrect + Class to hold the configuration settings required for creating OpenStack + stack objects + deprecated """ + def __init__(self, **kwargs): + from warnings import warn + warn('Use snaps.config.stack.StackConfig instead', + DeprecationWarning) + super(self.__class__, self).__init__(**kwargs) + class StackCreationError(Exception): """ diff --git a/snaps/openstack/tests/create_stack_tests.py b/snaps/openstack/tests/create_stack_tests.py index bc9cb2c..1df22fa 100644 --- a/snaps/openstack/tests/create_stack_tests.py +++ b/snaps/openstack/tests/create_stack_tests.py @@ -17,9 +17,12 @@ import time import pkg_resources from heatclient.exc import HTTPBadRequest + +import snaps from snaps import file_utils from snaps.config.flavor import FlavorConfig from snaps.config.image import ImageConfig +from snaps.config.stack import StackConfigError, StackConfig from snaps.openstack.create_flavor import OpenStackFlavor from snaps.openstack.create_image import OpenStackImage @@ -32,9 +35,8 @@ import logging import unittest import uuid -from snaps.openstack import create_stack from snaps.openstack.create_stack import ( - StackSettings, StackSettingsError, StackCreationError, StackError) + StackSettings, StackCreationError, StackError, OpenStackHeatStack) 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 @@ -50,19 +52,19 @@ class StackSettingsUnitTests(unittest.TestCase): """ def test_no_params(self): - with self.assertRaises(StackSettingsError): + with self.assertRaises(StackConfigError): StackSettings() def test_empty_config(self): - with self.assertRaises(StackSettingsError): + with self.assertRaises(StackConfigError): StackSettings(**dict()) def test_name_only(self): - with self.assertRaises(StackSettingsError): + with self.assertRaises(StackConfigError): StackSettings(name='foo') def test_config_with_name_only(self): - with self.assertRaises(StackSettingsError): + with self.assertRaises(StackConfigError): StackSettings(**{'name': 'foo'}) def test_config_minimum_template(self): @@ -71,7 +73,7 @@ class StackSettingsUnitTests(unittest.TestCase): self.assertEqual('foo', settings.template) self.assertIsNone(settings.template_path) self.assertIsNone(settings.env_values) - self.assertEqual(create_stack.STACK_COMPLETE_TIMEOUT, + self.assertEqual(snaps.config.stack.STACK_COMPLETE_TIMEOUT, settings.stack_create_timeout) def test_config_minimum_template_path(self): @@ -80,7 +82,7 @@ class StackSettingsUnitTests(unittest.TestCase): self.assertIsNone(settings.template) self.assertEqual('foo', settings.template_path) self.assertIsNone(settings.env_values) - self.assertEqual(create_stack.STACK_COMPLETE_TIMEOUT, + self.assertEqual(snaps.config.stack.STACK_COMPLETE_TIMEOUT, settings.stack_create_timeout) def test_minimum_template(self): @@ -89,7 +91,7 @@ class StackSettingsUnitTests(unittest.TestCase): self.assertEqual('foo', settings.template) self.assertIsNone(settings.template_path) self.assertIsNone(settings.env_values) - self.assertEqual(create_stack.STACK_COMPLETE_TIMEOUT, + self.assertEqual(snaps.config.stack.STACK_COMPLETE_TIMEOUT, settings.stack_create_timeout) def test_minimum_template_path(self): @@ -98,7 +100,7 @@ class StackSettingsUnitTests(unittest.TestCase): self.assertEqual('foo', settings.template_path) self.assertIsNone(settings.template) self.assertIsNone(settings.env_values) - self.assertEqual(create_stack.STACK_COMPLETE_TIMEOUT, + self.assertEqual(snaps.config.stack.STACK_COMPLETE_TIMEOUT, settings.stack_create_timeout) def test_all(self): @@ -199,12 +201,12 @@ class CreateStackSuccessTests(OSIntegrationTestCase): # Create Stack # Set the default stack settings, then set any custom parameters sent # from the app - stack_settings = StackSettings( + stack_settings = StackConfig( name=self.__class__.__name__ + '-' + str(self.guid) + '-stack', template_path=self.heat_tmplt_path, env_values=self.env_values) - self.stack_creator = create_stack.OpenStackHeatStack(self.heat_creds, - stack_settings) + self.stack_creator = OpenStackHeatStack( + self.heat_creds, stack_settings) created_stack = self.stack_creator.create() self.assertIsNotNone(created_stack) @@ -222,13 +224,13 @@ class CreateStackSuccessTests(OSIntegrationTestCase): # Create Stack # Set the default stack settings, then set any custom parameters sent # from the app - stack_settings = StackSettings( + stack_settings = StackConfig( 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) + self.stack_creator = OpenStackHeatStack( + self.heat_creds, stack_settings) with self.assertRaises(StackCreationError): self.stack_creator.create() @@ -241,12 +243,12 @@ class CreateStackSuccessTests(OSIntegrationTestCase): # from the app template_dict = heat_utils.parse_heat_template_str( file_utils.read_file(self.heat_tmplt_path)) - stack_settings = StackSettings( + stack_settings = StackConfig( name=self.__class__.__name__ + '-' + str(self.guid) + '-stack', template=template_dict, env_values=self.env_values) - self.stack_creator = create_stack.OpenStackHeatStack(self.heat_creds, - stack_settings) + self.stack_creator = OpenStackHeatStack( + self.heat_creds, stack_settings) created_stack = self.stack_creator.create() self.assertIsNotNone(created_stack) @@ -265,12 +267,12 @@ class CreateStackSuccessTests(OSIntegrationTestCase): # Create Stack template_dict = heat_utils.parse_heat_template_str( file_utils.read_file(self.heat_tmplt_path)) - stack_settings = StackSettings( + stack_settings = StackConfig( name=self.__class__.__name__ + '-' + str(self.guid) + '-stack', template=template_dict, env_values=self.env_values) - self.stack_creator = create_stack.OpenStackHeatStack(self.heat_creds, - stack_settings) + self.stack_creator = OpenStackHeatStack( + self.heat_creds, stack_settings) created_stack = self.stack_creator.create() self.assertIsNotNone(created_stack) @@ -280,7 +282,7 @@ class CreateStackSuccessTests(OSIntegrationTestCase): self.assertEqual(created_stack.name, retrieved_stack.name) self.assertEqual(created_stack.id, retrieved_stack.id) self.assertEqual(0, len(self.stack_creator.get_outputs())) - self.assertEqual(create_stack.STATUS_CREATE_COMPLETE, + self.assertEqual(snaps.config.stack.STATUS_CREATE_COMPLETE, self.stack_creator.get_status()) # Delete Stack manually @@ -291,7 +293,7 @@ class CreateStackSuccessTests(OSIntegrationTestCase): while time.time() < end_time: status = heat_utils.get_stack_status(self.heat_cli, retrieved_stack.id) - if status == create_stack.STATUS_DELETE_COMPLETE: + if status == snaps.config.stack.STATUS_DELETE_COMPLETE: deleted = True break @@ -309,12 +311,12 @@ class CreateStackSuccessTests(OSIntegrationTestCase): # Create Stack template_dict = heat_utils.parse_heat_template_str( file_utils.read_file(self.heat_tmplt_path)) - stack_settings = StackSettings( + stack_settings = StackConfig( name=self.__class__.__name__ + '-' + str(self.guid) + '-stack', template=template_dict, env_values=self.env_values) - self.stack_creator = create_stack.OpenStackHeatStack(self.heat_creds, - stack_settings) + self.stack_creator = OpenStackHeatStack( + self.heat_creds, stack_settings) created_stack1 = self.stack_creator.create() retrieved_stack = heat_utils.get_stack_by_id(self.heat_cli, @@ -325,8 +327,7 @@ class CreateStackSuccessTests(OSIntegrationTestCase): self.assertEqual(0, len(self.stack_creator.get_outputs())) # Should be retrieving the instance data - stack_creator2 = create_stack.OpenStackHeatStack(self.heat_creds, - stack_settings) + stack_creator2 = OpenStackHeatStack(self.heat_creds, stack_settings) stack2 = stack_creator2.create() self.assertEqual(created_stack1.id, stack2.id) @@ -335,12 +336,12 @@ class CreateStackSuccessTests(OSIntegrationTestCase): Tests the creation of an OpenStack stack from Heat template file and the retrieval of the network creator. """ - stack_settings = StackSettings( + stack_settings = StackConfig( name=self.__class__.__name__ + '-' + str(self.guid) + '-stack', template_path=self.heat_tmplt_path, env_values=self.env_values) - self.stack_creator = create_stack.OpenStackHeatStack(self.heat_creds, - stack_settings) + self.stack_creator = OpenStackHeatStack( + self.heat_creds, stack_settings) created_stack = self.stack_creator.create() self.assertIsNotNone(created_stack) @@ -371,12 +372,12 @@ class CreateStackSuccessTests(OSIntegrationTestCase): Tests the creation of an OpenStack stack from Heat template file and the retrieval of the network creator. """ - stack_settings = StackSettings( + stack_settings = StackConfig( name=self.__class__.__name__ + '-' + str(self.guid) + '-stack', template_path=self.heat_tmplt_path, env_values=self.env_values) - self.stack_creator = create_stack.OpenStackHeatStack(self.heat_creds, - stack_settings) + self.stack_creator = OpenStackHeatStack( + self.heat_creds, stack_settings) created_stack = self.stack_creator.create() self.assertIsNotNone(created_stack) @@ -480,11 +481,11 @@ class CreateStackFloatingIpTests(OSIntegrationTestCase): the retrieval of two VM instance creators and attempt to connect via SSH to the first one with a floating IP. """ - stack_settings = StackSettings( + stack_settings = StackConfig( name=self.__class__.__name__ + '-' + str(self.guid) + '-stack', template_path=self.heat_tmplt_path, env_values=self.env_values) - self.stack_creator = create_stack.OpenStackHeatStack( + self.stack_creator = OpenStackHeatStack( self.heat_creds, stack_settings, [self.image_creator.image_settings]) created_stack = self.stack_creator.create() @@ -539,11 +540,11 @@ class CreateStackRouterTests(OSIntegrationTestCase): self.heat_tmplt_path = pkg_resources.resource_filename( 'snaps.openstack.tests.heat', 'router_heat_template.yaml') - stack_settings = StackSettings( + stack_settings = StackConfig( name=self.__class__.__name__ + '-' + str(self.guid) + '-stack', template_path=self.heat_tmplt_path, env_values=self.env_values) - self.stack_creator = create_stack.OpenStackHeatStack( + self.stack_creator = OpenStackHeatStack( self.heat_creds, stack_settings) self.created_stack = self.stack_creator.create() self.assertIsNotNone(self.created_stack) @@ -606,11 +607,11 @@ class CreateStackVolumeTests(OSIntegrationTestCase): self.heat_tmplt_path = pkg_resources.resource_filename( 'snaps.openstack.tests.heat', 'volume_heat_template.yaml') - stack_settings = StackSettings( + stack_settings = StackConfig( name=self.__class__.__name__ + '-' + str(self.guid) + '-stack', template_path=self.heat_tmplt_path, env_values=self.env_values) - self.stack_creator = create_stack.OpenStackHeatStack( + self.stack_creator = OpenStackHeatStack( self.heat_creds, stack_settings) self.created_stack = self.stack_creator.create() self.assertIsNotNone(self.created_stack) @@ -693,10 +694,10 @@ class CreateStackFlavorTests(OSIntegrationTestCase): self.heat_tmplt_path = pkg_resources.resource_filename( 'snaps.openstack.tests.heat', 'flavor_heat_template.yaml') - stack_settings = StackSettings( + stack_settings = StackConfig( name=self.guid + '-stack', template_path=self.heat_tmplt_path) - self.stack_creator = create_stack.OpenStackHeatStack( + self.stack_creator = OpenStackHeatStack( self.heat_creds, stack_settings) self.created_stack = self.stack_creator.create() self.assertIsNotNone(self.created_stack) @@ -759,11 +760,11 @@ class CreateStackKeypairTests(OSIntegrationTestCase): self.heat_tmplt_path = pkg_resources.resource_filename( 'snaps.openstack.tests.heat', 'keypair_heat_template.yaml') - stack_settings = StackSettings( + stack_settings = StackConfig( name=self.__class__.__name__ + '-' + str(self.guid) + '-stack', template_path=self.heat_tmplt_path, env_values=self.env_values) - self.stack_creator = create_stack.OpenStackHeatStack( + self.stack_creator = OpenStackHeatStack( self.heat_creds, stack_settings) self.created_stack = self.stack_creator.create() self.assertIsNotNone(self.created_stack) @@ -844,11 +845,11 @@ class CreateStackSecurityGroupTests(OSIntegrationTestCase): self.heat_tmplt_path = pkg_resources.resource_filename( 'snaps.openstack.tests.heat', 'security_group_heat_template.yaml') - stack_settings = StackSettings( + stack_settings = StackConfig( name=self.__class__.__name__ + '-' + str(self.guid) + '-stack', template_path=self.heat_tmplt_path, env_values=self.env_values) - self.stack_creator = create_stack.OpenStackHeatStack( + self.stack_creator = OpenStackHeatStack( self.heat_creds, stack_settings) self.created_stack = self.stack_creator.create() self.assertIsNotNone(self.created_stack) @@ -935,10 +936,10 @@ class CreateStackNegativeTests(OSIntegrationTestCase): """ Expect an StackCreationError when the stack file does not exist """ - stack_settings = StackSettings(name=self.stack_name, - template_path=self.heat_tmplt_path) - self.stack_creator = create_stack.OpenStackHeatStack(self.heat_creds, - stack_settings) + stack_settings = StackConfig(name=self.stack_name, + template_path=self.heat_tmplt_path) + self.stack_creator = OpenStackHeatStack( + self.heat_creds, stack_settings) with self.assertRaises(HTTPBadRequest): self.stack_creator.create() @@ -946,10 +947,10 @@ class CreateStackNegativeTests(OSIntegrationTestCase): """ Expect an StackCreationError when the stack file does not exist """ - stack_settings = StackSettings(name=self.stack_name, - template_path='foo') - self.stack_creator = create_stack.OpenStackHeatStack(self.heat_creds, - stack_settings) + stack_settings = StackConfig( + name=self.stack_name, template_path='foo') + self.stack_creator = OpenStackHeatStack( + self.heat_creds, stack_settings) with self.assertRaises(IOError): self.stack_creator.create() @@ -1041,12 +1042,12 @@ class CreateStackFailureTests(OSIntegrationTestCase): # Create Stack # Set the default stack settings, then set any custom parameters sent # from the app - stack_settings = StackSettings( + stack_settings = StackConfig( name=self.__class__.__name__ + '-' + str(self.guid) + '-stack', template_path=self.heat_tmplt_path, env_values=self.env_values) - self.stack_creator = create_stack.OpenStackHeatStack(self.heat_creds, - stack_settings) + self.stack_creator = OpenStackHeatStack( + self.heat_creds, stack_settings) with self.assertRaises(StackError): try: @@ -1057,7 +1058,8 @@ class CreateStackFailureTests(OSIntegrationTestCase): found = False for resource in resources: - if resource.status == create_stack.STATUS_CREATE_COMPLETE: + if (resource.status == + snaps.config.stack.STATUS_CREATE_COMPLETE): found = True self.assertTrue(found) raise diff --git a/snaps/openstack/tests/openstack_tests.py b/snaps/openstack/tests/openstack_tests.py index 8430a96..ff64af5 100644 --- a/snaps/openstack/tests/openstack_tests.py +++ b/snaps/openstack/tests/openstack_tests.py @@ -81,7 +81,7 @@ def get_credentials(os_env_file=None, proxy_settings_str=None, elif config.get('OS_INSECURE'): https_cacert = False - interface = 'admin' + interface = 'public' if config.get('OS_INTERFACE'): interface = config.get('OS_INTERFACE') diff --git a/snaps/openstack/utils/tests/heat_utils_tests.py b/snaps/openstack/utils/tests/heat_utils_tests.py index a5b684f..d90fed4 100644 --- a/snaps/openstack/utils/tests/heat_utils_tests.py +++ b/snaps/openstack/utils/tests/heat_utils_tests.py @@ -20,13 +20,13 @@ import uuid import time +import snaps.config.stack as stack_config from snaps.config.flavor import FlavorConfig -from snaps.openstack import create_stack from snaps.openstack.create_flavor import OpenStackFlavor from snaps.openstack.create_image import OpenStackImage from snaps.openstack.create_instance import OpenStackVmInstance -from snaps.openstack.create_stack import StackSettings +from snaps.openstack.create_stack import StackConfig from snaps.openstack.tests import openstack_tests from snaps.openstack.tests.os_source_file_test import OSComponentTestCase from snaps.openstack.utils import ( @@ -107,10 +107,10 @@ class HeatUtilsCreateSimpleStackTests(OSComponentTestCase): 'inst_name': self.vm_inst_name} heat_tmplt_path = pkg_resources.resource_filename( 'snaps.openstack.tests.heat', 'test_heat_template.yaml') - self.stack_settings1 = StackSettings( + self.stack_settings1 = StackConfig( name=stack_name1, template_path=heat_tmplt_path, env_values=env_values) - self.stack_settings2 = StackSettings( + self.stack_settings2 = StackConfig( name=stack_name2, template_path=heat_tmplt_path, env_values=env_values) self.stack1 = None @@ -272,7 +272,7 @@ class HeatUtilsCreateComplexStackTests(OSComponentTestCase): 'external_net_name': self.ext_net_name} heat_tmplt_path = pkg_resources.resource_filename( 'snaps.openstack.tests.heat', 'floating_ip_heat_template.yaml') - stack_settings = StackSettings( + stack_settings = StackConfig( name=stack_name, template_path=heat_tmplt_path, env_values=env_values) self.heat_client = heat_utils.heat_client(self.os_creds) @@ -291,15 +291,16 @@ class HeatUtilsCreateComplexStackTests(OSComponentTestCase): try: heat_utils.delete_stack(self.heat_client, self.stack) # Wait until stack deployment has completed - end_time = time.time() + create_stack.STACK_COMPLETE_TIMEOUT + end_time = (time.time() + + stack_config.STACK_COMPLETE_TIMEOUT) is_deleted = False while time.time() < end_time: status = heat_utils.get_stack_status(self.heat_client, self.stack.id) - if status == create_stack.STATUS_DELETE_COMPLETE: + if status == stack_config.STATUS_DELETE_COMPLETE: is_deleted = True break - elif status == create_stack.STATUS_DELETE_FAILED: + elif status == stack_config.STATUS_DELETE_FAILED: is_deleted = False break @@ -447,7 +448,7 @@ class HeatUtilsRouterTests(OSComponentTestCase): heat_tmplt_path = pkg_resources.resource_filename( 'snaps.openstack.tests.heat', 'router_heat_template.yaml') - self.stack_settings = StackSettings( + self.stack_settings = StackConfig( name=stack_name, template_path=heat_tmplt_path, env_values=env_values) self.stack = None @@ -473,15 +474,15 @@ class HeatUtilsRouterTests(OSComponentTestCase): self.heat_client, self.stack_settings) # Wait until stack deployment has completed - end_time = time.time() + create_stack.STACK_COMPLETE_TIMEOUT + end_time = time.time() + stack_config.STACK_COMPLETE_TIMEOUT is_active = False while time.time() < end_time: status = heat_utils.get_stack_status(self.heat_client, self.stack.id) - if status == create_stack.STATUS_CREATE_COMPLETE: + if status == stack_config.STATUS_CREATE_COMPLETE: is_active = True break - elif status == create_stack.STATUS_CREATE_FAILED: + elif status == stack_config.STATUS_CREATE_FAILED: is_active = False break @@ -522,7 +523,7 @@ class HeatUtilsVolumeTests(OSComponentTestCase): heat_tmplt_path = pkg_resources.resource_filename( 'snaps.openstack.tests.heat', 'volume_heat_template.yaml') - self.stack_settings = StackSettings( + self.stack_settings = StackConfig( name=stack_name, template_path=heat_tmplt_path, env_values=env_values) self.stack = None @@ -602,7 +603,7 @@ class HeatUtilsFlavorTests(OSComponentTestCase): heat_tmplt_path = pkg_resources.resource_filename( 'snaps.openstack.tests.heat', 'flavor_heat_template.yaml') - self.stack_settings = StackSettings( + self.stack_settings = StackConfig( name=stack_name, template_path=heat_tmplt_path) self.stack = None self.heat_client = heat_utils.heat_client(self.os_creds) @@ -660,7 +661,7 @@ class HeatUtilsKeypairTests(OSComponentTestCase): heat_tmplt_path = pkg_resources.resource_filename( 'snaps.openstack.tests.heat', 'keypair_heat_template.yaml') - self.stack_settings = StackSettings( + self.stack_settings = StackConfig( name=stack_name, template_path=heat_tmplt_path, env_values=env_values) self.stack = None @@ -723,7 +724,7 @@ class HeatUtilsSecurityGroupTests(OSComponentTestCase): heat_tmplt_path = pkg_resources.resource_filename( 'snaps.openstack.tests.heat', 'security_group_heat_template.yaml') - self.stack_settings = StackSettings( + self.stack_settings = StackConfig( name=stack_name, template_path=heat_tmplt_path, env_values=env_values) self.stack = None @@ -790,14 +791,14 @@ def stack_active(heat_cli, stack): :return: T/F """ # Wait until stack deployment has completed - end_time = time.time() + create_stack.STACK_COMPLETE_TIMEOUT + end_time = time.time() + stack_config.STACK_COMPLETE_TIMEOUT is_active = False while time.time() < end_time: status = heat_utils.get_stack_status(heat_cli, stack.id) - if status == create_stack.STATUS_CREATE_COMPLETE: + if status == stack_config.STATUS_CREATE_COMPLETE: is_active = True break - elif status == create_stack.STATUS_CREATE_FAILED: + elif status == stack_config.STATUS_CREATE_FAILED: is_active = False break diff --git a/snaps/test_suite_builder.py b/snaps/test_suite_builder.py index abfd2b6..ffb27a8 100644 --- a/snaps/test_suite_builder.py +++ b/snaps/test_suite_builder.py @@ -16,6 +16,7 @@ import logging import unittest +from snaps.config.tests.stack_tests import StackConfigUnitTests from snaps.config.tests.router_tests import RouterConfigUnitTests from snaps.config.tests.user_tests import UserConfigUnitTests from snaps.config.tests.project_tests import ProjectConfigUnitTests @@ -205,6 +206,8 @@ def add_unit_tests(suite): suite.addTest(unittest.TestLoader().loadTestsFromTestCase( ResourceDomainObjectTests)) suite.addTest(unittest.TestLoader().loadTestsFromTestCase( + StackConfigUnitTests)) + suite.addTest(unittest.TestLoader().loadTestsFromTestCase( StackSettingsUnitTests)) suite.addTest(unittest.TestLoader().loadTestsFromTestCase( VolumeTypeDomainObjectTests)) |