diff options
6 files changed, 39 insertions, 79 deletions
diff --git a/functest/opnfv_tests/openstack/patrole/patrole.py b/functest/opnfv_tests/openstack/patrole/patrole.py index ebc3d1448..211abb931 100644 --- a/functest/opnfv_tests/openstack/patrole/patrole.py +++ b/functest/opnfv_tests/openstack/patrole/patrole.py @@ -15,7 +15,6 @@ import time from xtesting.core import testcase -from functest.opnfv_tests.openstack.snaps import snaps_utils from functest.opnfv_tests.openstack.tempest import conf_utils from functest.opnfv_tests.openstack.tempest import tempest from functest.utils import config @@ -32,7 +31,6 @@ class Patrole(tempest.TempestCommon): self.res_dir = os.path.join( getattr(config.CONF, 'dir_results'), 'patrole') self.list = os.path.join(self.res_dir, 'tempest-list.txt') - self.conf_file = None def run(self, **kwargs): self.start_time = time.time() @@ -41,26 +39,15 @@ class Patrole(tempest.TempestCommon): self.mode = "'{}(?=patrole_tempest_plugin.tests.api.({}))'".format( self.mode, '|'.join(kwargs.get('services', []))) try: - if not os.path.exists(self.res_dir): - os.makedirs(self.res_dir) - resources = self.resources.create() - compute_cnt = snaps_utils.get_active_compute_cnt( - self.resources.os_creds) - self.conf_file = conf_utils.configure_verifier(self.deployment_dir) - conf_utils.configure_tempest_update_params( - self.conf_file, self.res_dir, - network_name=resources.get("network_name"), - image_id=resources.get("image_id"), - flavor_id=resources.get("flavor_id"), - compute_cnt=compute_cnt) + self.configure() self.configure_tempest_patrole(kwargs.get('role', 'admin')) - self.generate_test_list(self.verifier_repo_dir) + self.generate_test_list() self.run_verifier_tests() self.parse_verifier_result() self.generate_report() res = testcase.TestCase.EX_OK - except Exception as err: # pylint: disable=broad-except - self.__logger.error('Error with run: %s', err) + except Exception: # pylint: disable=broad-except + self.__logger.error('Error with run') res = testcase.TestCase.EX_RUN_ERROR finally: self.resources.cleanup() diff --git a/functest/opnfv_tests/openstack/refstack/refstack.py b/functest/opnfv_tests/openstack/refstack/refstack.py index b5766a020..a55b147f1 100644 --- a/functest/opnfv_tests/openstack/refstack/refstack.py +++ b/functest/opnfv_tests/openstack/refstack/refstack.py @@ -18,8 +18,6 @@ from refstack_client import list_parser from xtesting.core import testcase from xtesting.energy import energy -from functest.opnfv_tests.openstack.snaps import snaps_utils -from functest.opnfv_tests.openstack.tempest import conf_utils from functest.opnfv_tests.openstack.tempest import tempest from functest.utils import config @@ -45,27 +43,17 @@ class Refstack(tempest.TempestCommon): """Start Refstack testcase.""" self.start_time = time.time() try: - if not os.path.exists(self.res_dir): - os.makedirs(self.res_dir) - resources = self.resources.create() - compute_cnt = snaps_utils.get_active_compute_cnt( - self.resources.os_creds) - conf_file = conf_utils.configure_verifier(self.deployment_dir) - conf_utils.configure_tempest_update_params( - conf_file, self.res_dir, - network_name=resources.get("network_name"), - image_id=resources.get("image_id"), - flavor_id=resources.get("flavor_id"), - compute_cnt=compute_cnt) - parser = list_parser.TestListParser('/src/tempest') + self.configure() + parser = list_parser.TestListParser( + getattr(config.CONF, 'dir_repo_tempest')) nfile = parser.get_normalized_test_list(Refstack.defcorelist) shutil.copyfile(nfile, self.list) self.run_verifier_tests() self.parse_verifier_result() self.generate_report() res = testcase.TestCase.EX_OK - except Exception as err: # pylint: disable=broad-except - self.__logger.error('Error with run: %s', err) + except Exception: # pylint: disable=broad-except + self.__logger.exception('Error with run') res = testcase.TestCase.EX_RUN_ERROR finally: self.resources.cleanup() diff --git a/functest/opnfv_tests/openstack/tempest/conf_utils.py b/functest/opnfv_tests/openstack/tempest/conf_utils.py index 95777ea90..8832a48bf 100644 --- a/functest/opnfv_tests/openstack/tempest/conf_utils.py +++ b/functest/opnfv_tests/openstack/tempest/conf_utils.py @@ -173,18 +173,6 @@ def backup_tempest_config(conf_file, res_dir): os.path.join(res_dir, 'tempest.conf')) -def configure_tempest(deployment_dir, res_dir, network_name=None, - image_id=None, flavor_id=None, compute_cnt=None): - # pylint: disable=too-many-arguments - """ - Calls rally verify and updates the generated tempest.conf with - given parameters - """ - conf_file = configure_verifier(deployment_dir) - configure_tempest_update_params(conf_file, res_dir, network_name, image_id, - flavor_id, compute_cnt) - - def generate_test_accounts_file(tenant_id): """ Add needed tenant and user params into test_accounts.yaml diff --git a/functest/opnfv_tests/openstack/tempest/tempest.py b/functest/opnfv_tests/openstack/tempest/tempest.py index 059def384..acab29d85 100644 --- a/functest/opnfv_tests/openstack/tempest/tempest.py +++ b/functest/opnfv_tests/openstack/tempest/tempest.py @@ -62,6 +62,7 @@ class TempestCommon(testcase.TestCase): self.res_dir = TempestCommon.TEMPEST_RESULTS_DIR self.raw_list = os.path.join(self.res_dir, 'test_raw_list.txt') self.list = os.path.join(self.res_dir, 'test_list.txt') + self.conf_file = None @staticmethod def read_file(filename): @@ -98,7 +99,7 @@ class TempestCommon(testcase.TestCase): result['num_failures'] = int(new_line[2]) return result - def generate_test_list(self, verifier_repo_dir): + def generate_test_list(self): """Generate test list based on the test mode.""" LOGGER.debug("Generating test case list...") if self.mode == 'custom': @@ -117,7 +118,7 @@ class TempestCommon(testcase.TestCase): testr_mode = self.mode cmd = ("cd {0};" "testr list-tests {1} > {2};" - "cd -;".format(verifier_repo_dir, + "cd -;".format(self.verifier_repo_dir, testr_mode, self.list)) functest_utils.execute_command(cmd) @@ -248,33 +249,39 @@ class TempestCommon(testcase.TestCase): subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - def run(self, **kwargs): + def configure(self): + """ + Create all openstack resources for tempest-based testcases and write + tempest.conf. + """ + if not os.path.exists(self.res_dir): + os.makedirs(self.res_dir) + resources = self.resources.create() + compute_cnt = snaps_utils.get_active_compute_cnt( + self.resources.os_creds) + self.conf_file = conf_utils.configure_verifier(self.deployment_dir) + conf_utils.configure_tempest_update_params( + self.conf_file, self.res_dir, + network_name=resources.get("network_name"), + image_id=resources.get("image_id"), + flavor_id=resources.get("flavor_id"), + compute_cnt=compute_cnt) + def run(self, **kwargs): self.start_time = time.time() try: - if not os.path.exists(self.res_dir): - os.makedirs(self.res_dir) - resources = self.resources.create() - compute_cnt = snaps_utils.get_active_compute_cnt( - self.resources.os_creds) - conf_utils.configure_tempest( - self.deployment_dir, self.res_dir, - network_name=resources.get("network_name"), - image_id=resources.get("image_id"), - flavor_id=resources.get("flavor_id"), - compute_cnt=compute_cnt) - self.generate_test_list(self.verifier_repo_dir) + self.configure() + self.generate_test_list() self.apply_tempest_blacklist() self.run_verifier_tests() self.parse_verifier_result() self.generate_report() res = testcase.TestCase.EX_OK - except Exception as err: # pylint: disable=broad-except - LOGGER.error('Error with run: %s', err) + except Exception: # pylint: disable=broad-except + LOGGER.exception('Error with run') res = testcase.TestCase.EX_RUN_ERROR finally: self.resources.cleanup() - self.stop_time = time.time() return res diff --git a/functest/tests/unit/openstack/tempest/test_conf_utils.py b/functest/tests/unit/openstack/tempest/test_conf_utils.py index 1c9a8aeee..fa53b57b1 100644 --- a/functest/tests/unit/openstack/tempest/test_conf_utils.py +++ b/functest/tests/unit/openstack/tempest/test_conf_utils.py @@ -233,16 +233,6 @@ class OSTempestConfUtilsTesting(unittest.TestCase): 'test_conf_file', res_dir='test_dir') self.assertTrue(mock_copyfile.called) - def test_conf_tempest_def(self): - with mock.patch('functest.opnfv_tests.openstack.tempest.' - 'conf_utils.configure_verifier', - return_value='test_conf_file'), \ - mock.patch('functest.opnfv_tests.openstack.tempest.' - 'conf_utils.configure_tempest_update_params')\ - as mock_upd: - conf_utils.configure_tempest('test_dep_dir', 'test_dir') - self.assertTrue(mock_upd.called) - def test_gen_test_accounts_file_def(self): with mock.patch("__builtin__.open", mock.mock_open()), \ mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' diff --git a/functest/tests/unit/openstack/tempest/test_tempest.py b/functest/tests/unit/openstack/tempest/test_tempest.py index 52d98465d..436821143 100644 --- a/functest/tests/unit/openstack/tempest/test_tempest.py +++ b/functest/tests/unit/openstack/tempest/test_tempest.py @@ -59,7 +59,7 @@ class OSTempestTesting(unittest.TestCase): 'os.path.isfile', return_value=False), \ self.assertRaises(Exception) as context: msg = "Tempest test list file %s NOT found." - self.tempestcommon.generate_test_list('test_verifier_repo_dir') + self.tempestcommon.generate_test_list() self.assertTrue( (msg % conf_utils.TEMPEST_CUSTOM) in context.exception) @@ -69,7 +69,7 @@ class OSTempestTesting(unittest.TestCase): 'shutil.copyfile') as mock_copyfile, \ mock.patch('functest.opnfv_tests.openstack.tempest.tempest.' 'os.path.isfile', return_value=True): - self.tempestcommon.generate_test_list('test_verifier_repo_dir') + self.tempestcommon.generate_test_list() self.assertTrue(mock_copyfile.called) @mock.patch('functest.utils.functest_utils.execute_command') @@ -86,7 +86,7 @@ class OSTempestTesting(unittest.TestCase): "testr list-tests {1} > {2};" "cd -;".format(verifier_repo_dir, testr_mode, self.tempestcommon.list)) - self.tempestcommon.generate_test_list('test_verifier_repo_dir') + self.tempestcommon.generate_test_list() mock_exec.assert_called_once_with(cmd) def test_gen_tl_smoke_mode(self): @@ -210,7 +210,7 @@ class OSTempestTesting(unittest.TestCase): @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.' 'get_active_compute_cnt', return_value=2) @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.' - 'conf_utils.configure_tempest', side_effect=Exception) + 'TempestCommon.configure', side_effect=Exception) def test_run_configure_tempest_ko(self, *args): # pylint: disable=unused-argument self.assertEqual(self.tempestcommon.run(), @@ -224,7 +224,7 @@ class OSTempestTesting(unittest.TestCase): @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.' 'get_active_compute_cnt', return_value=2) @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.' - 'conf_utils.configure_tempest') + 'TempestCommon.configure') def _test_run(self, status, *args): # pylint: disable=unused-argument self.assertEqual(self.tempestcommon.run(), status) |