From a0048cb6268c46a1b2f8a30cc851be5bed56a7e8 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Tue, 8 Apr 2014 17:44:42 -0400 Subject: [PATCH] Add load_test mechanism for InputScenarioUtils Similar to what was done for the negative test framework this commit adds a method to handle using CONF values with testscenarios. Previously the attr's were set in the test class definition which would force a getattr at import time. This will cause issues if the config file is not present. By adding a method which won't be executed at import but rather when the tests are run we can avoid this. Change-Id: Ib635f8b895f6642f78a3af644170700f72259d46 --- tempest/scenario/test_server_basic_ops.py | 11 +---------- tempest/scenario/utils.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/tempest/scenario/test_server_basic_ops.py b/tempest/scenario/test_server_basic_ops.py index aa398446b0..eefc624e83 100644 --- a/tempest/scenario/test_server_basic_ops.py +++ b/tempest/scenario/test_server_basic_ops.py @@ -20,13 +20,11 @@ from tempest.scenario import manager from tempest.scenario import utils as test_utils from tempest import test -import testscenarios - CONF = config.CONF LOG = logging.getLogger(__name__) -load_tests = testscenarios.load_tests_apply_scenarios +load_tests = test_utils.load_tests_input_scenario_utils class TestServerBasicOps(manager.OfficialClientTest): @@ -43,13 +41,6 @@ class TestServerBasicOps(manager.OfficialClientTest): * Terminate the instance """ - scenario_utils = test_utils.InputScenarioUtils() - scenario_flavor = scenario_utils.scenario_flavors - scenario_image = scenario_utils.scenario_images - - scenarios = testscenarios.multiply_scenarios(scenario_image, - scenario_flavor) - def setUp(self): super(TestServerBasicOps, self).setUp() # Setup image and flavor the test instance diff --git a/tempest/scenario/utils.py b/tempest/scenario/utils.py index 4702c7216d..7b1a679fae 100644 --- a/tempest/scenario/utils.py +++ b/tempest/scenario/utils.py @@ -12,6 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. +import testscenarios +import testtools + from tempest import clients from tempest.common.utils import misc from tempest import config @@ -134,3 +137,22 @@ class InputScenarioUtils(object): for f in flavors if re.search(self.flavor_pattern, str(f.name)) ] return self._scenario_flavors + + +def load_tests_input_scenario_utils(*args): + """ + Wrapper for testscenarios to set the scenarios to avoid running a getattr + on the CONF object at import. + """ + if getattr(args[0], 'suiteClass', None) is not None: + loader, standard_tests, pattern = args + else: + standard_tests, module, loader = args + scenario_utils = InputScenarioUtils() + scenario_flavor = scenario_utils.scenario_flavors + scenario_image = scenario_utils.scenario_images + for test in testtools.iterate_tests(standard_tests): + setattr(test, 'scenarios', testscenarios.multiply_scenarios( + scenario_image, + scenario_flavor)) + return testscenarios.load_tests_apply_scenarios(*args)