diff options
author | 2017-06-07 14:56:00 -0600 | |
---|---|---|
committer | 2017-06-07 14:56:00 -0600 | |
commit | 95d35a166fc66944fb0fc6091f4b84568aef0e7d (patch) | |
tree | 5ad804fe917c7c7a2bcf99ad285159ea0f29d015 /snaps/openstack/tests | |
parent | c8212122569c2dbf6290b43a0fbde0171c2ffdc5 (diff) |
Removed current working directory logic retrieving test file resources.
Some of the SNAPS tests leverage file resources contained within the
project. These resources were being accessed via relative paths which
required the test clients to ensure that the CWD was the <repo>/snaps
directory. Replaced that logic to leverage the import pkg_resources
making the tests much more flexible and robust.
JIRA: SNAPS-89
Change-Id: Ic9c429ee53e4dd785641e11e1ed4de5aeeab54d1
Signed-off-by: spisarski <s.pisarski@cablelabs.com>
Diffstat (limited to 'snaps/openstack/tests')
-rw-r--r-- | snaps/openstack/tests/conf/__init__.py | 15 | ||||
-rw-r--r-- | snaps/openstack/tests/create_stack_tests.py | 19 | ||||
-rw-r--r-- | snaps/openstack/tests/os_source_file_test.py | 4 |
3 files changed, 31 insertions, 7 deletions
diff --git a/snaps/openstack/tests/conf/__init__.py b/snaps/openstack/tests/conf/__init__.py new file mode 100644 index 0000000..271c742 --- /dev/null +++ b/snaps/openstack/tests/conf/__init__.py @@ -0,0 +1,15 @@ +# 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. +__author__ = 'spisarski' diff --git a/snaps/openstack/tests/create_stack_tests.py b/snaps/openstack/tests/create_stack_tests.py index fa75475..bee1340 100644 --- a/snaps/openstack/tests/create_stack_tests.py +++ b/snaps/openstack/tests/create_stack_tests.py @@ -12,6 +12,7 @@ # 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 pkg_resources import time from heatclient.exc import HTTPBadRequest @@ -145,12 +146,17 @@ class CreateStackSuccessTests(OSIntegrationTestCase): self.env_values = {'image_name': self.image_creator.image_settings.name, 'flavor_name': self.flavor_creator.flavor_settings.name} + self.heat_tmplt_path = pkg_resources.resource_filename('examples.heat', 'test_heat_template.yaml') + def tearDown(self): """ Cleans the stack and downloaded stack file """ if self.stack_creator: - self.stack_creator.clean() + try: + self.stack_creator.clean() + except: + pass if self.image_creator: try: @@ -173,7 +179,7 @@ class CreateStackSuccessTests(OSIntegrationTestCase): # 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='../examples/heat/test_heat_template.yaml', + template_path=self.heat_tmplt_path, env_values=self.env_values) self.stack_creator = create_stack.OpenStackHeatStack(self.os_creds, stack_settings) created_stack = self.stack_creator.create() @@ -193,7 +199,7 @@ class CreateStackSuccessTests(OSIntegrationTestCase): # Create Stack # Set the default stack settings, then set any custom parameters sent from the app template_dict = heat_utils.parse_heat_template_str( - file_utils.read_file('../examples/heat/test_heat_template.yaml')) + file_utils.read_file(self.heat_tmplt_path)) stack_settings = StackSettings(name=self.__class__.__name__ + '-' + str(self.guid) + '-stack', template=template_dict, env_values=self.env_values) @@ -214,7 +220,7 @@ class CreateStackSuccessTests(OSIntegrationTestCase): """ # Create Stack template_dict = heat_utils.parse_heat_template_str( - file_utils.read_file('../examples/heat/test_heat_template.yaml')) + file_utils.read_file(self.heat_tmplt_path)) stack_settings = StackSettings(name=self.__class__.__name__ + '-' + str(self.guid) + '-stack', template=template_dict, env_values=self.env_values) @@ -253,7 +259,7 @@ class CreateStackSuccessTests(OSIntegrationTestCase): """ # Create Stack template_dict = heat_utils.parse_heat_template_str( - file_utils.read_file('../examples/heat/test_heat_template.yaml')) + file_utils.read_file(self.heat_tmplt_path)) stack_settings = StackSettings(name=self.__class__.__name__ + '-' + str(self.guid) + '-stack', template=template_dict, env_values=self.env_values) @@ -283,6 +289,7 @@ class CreateStackNegativeTests(OSIntegrationTestCase): self.stack_name = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.stack_creator = None + self.heat_tmplt_path = pkg_resources.resource_filename('examples.heat', 'test_heat_template.yaml') def tearDown(self): if self.stack_creator: @@ -293,7 +300,7 @@ class CreateStackNegativeTests(OSIntegrationTestCase): """ Expect an StackCreationError when the stack file does not exist """ - stack_settings = StackSettings(name=self.stack_name, template_path='../examples/heat/test_heat_template.yaml') + stack_settings = StackSettings(name=self.stack_name, template_path=self.heat_tmplt_path) self.stack_creator = create_stack.OpenStackHeatStack(self.os_creds, stack_settings) with self.assertRaises(HTTPBadRequest): self.stack_creator.create() diff --git a/snaps/openstack/tests/os_source_file_test.py b/snaps/openstack/tests/os_source_file_test.py index 3a632e5..4b421e8 100644 --- a/snaps/openstack/tests/os_source_file_test.py +++ b/snaps/openstack/tests/os_source_file_test.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import logging +import pkg_resources import uuid import unittest @@ -22,7 +23,8 @@ from snaps.openstack.create_user import UserSettings from snaps.openstack.tests import openstack_tests from snaps.openstack.utils import deploy_utils, keystone_utils -dev_os_env_file = 'openstack/tests/conf/os_env.yaml' + +dev_os_env_file = pkg_resources.resource_filename('snaps.openstack.tests.conf', 'os_env.yaml') # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # To run these tests from an IDE, the CWD must be set to the snaps directory of this project |