diff options
author | Cedric Ollivier <cedric.ollivier@orange.com> | 2018-03-12 14:38:42 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2018-03-12 14:38:42 +0000 |
commit | aedd8d57351150bb97dc4d23bc5d0b3e5eb76db9 (patch) | |
tree | a37e9468ab27ab46e0c7b2247233a0cf4a874109 | |
parent | f1d75ce5003044a7d85d8fd09643f89e74776c20 (diff) | |
parent | a1a2fa10cd8cffbe7dc4cffec3446aafe73d87ba (diff) |
Merge changes from topic 'refactor_tempest'
* changes:
Refactor configure_tempest_patrole()
Improve tempest files management
-rw-r--r-- | functest/opnfv_tests/openstack/patrole/patrole.py | 32 | ||||
-rw-r--r-- | functest/opnfv_tests/openstack/tempest/tempest.py | 5 | ||||
-rw-r--r-- | functest/tests/unit/openstack/tempest/test_tempest.py | 20 |
3 files changed, 31 insertions, 26 deletions
diff --git a/functest/opnfv_tests/openstack/patrole/patrole.py b/functest/opnfv_tests/openstack/patrole/patrole.py index 1f1674564..1c17af03b 100644 --- a/functest/opnfv_tests/openstack/patrole/patrole.py +++ b/functest/opnfv_tests/openstack/patrole/patrole.py @@ -31,8 +31,8 @@ class Patrole(tempest.TempestCommon): super(Patrole, self).__init__(**kwargs) self.res_dir = os.path.join( getattr(config.CONF, 'dir_results'), 'patrole') - 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.list = os.path.join(self.res_dir, 'tempest-list.txt') + self.conf_file = None def run(self, **kwargs): self.start_time = time.time() @@ -46,15 +46,15 @@ class Patrole(tempest.TempestCommon): resources = self.resources.create() compute_cnt = snaps_utils.get_active_compute_cnt( self.resources.os_creds) - self.configure_tempest_patrole( - self.deployment_dir, + 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, - role=kwargs.get('role', 'admin')) + compute_cnt=compute_cnt) + self.configure_tempest_patrole(kwargs.get('role', 'admin')) self.generate_test_list(self.verifier_repo_dir) - self.apply_tempest_blacklist() self.run_verifier_tests() self.parse_verifier_result() self.generate_report() @@ -67,24 +67,12 @@ class Patrole(tempest.TempestCommon): self.stop_time = time.time() return res - def configure_tempest_patrole( - self, deployment_dir, network_name=None, image_id=None, - flavor_id=None, compute_cnt=None, role='admin'): - # pylint: disable=too-many-arguments - """ - Add/update needed parameters into tempest.conf file - """ - self.__logger.debug( - "Updating selected tempest.conf parameters for Patrole") - conf_file = conf_utils.configure_verifier(deployment_dir) - conf_utils.configure_tempest_update_params( - conf_file, self.res_dir, network_name, image_id, flavor_id, - compute_cnt) + def configure_tempest_patrole(self, role='admin'): rconfig = conf_utils.ConfigParser.RawConfigParser() - rconfig.read(conf_file) + rconfig.read(self.conf_file) rconfig.set('identity-feature-enabled', 'api_v2', False) rconfig.add_section('rbac') rconfig.set('rbac', 'enable_rbac', True) rconfig.set('rbac', 'rbac_test_role', role) - with open(conf_file, 'wb') as config_file: + with open(self.conf_file, 'wb') as config_file: rconfig.write(config_file) diff --git a/functest/opnfv_tests/openstack/tempest/tempest.py b/functest/opnfv_tests/openstack/tempest/tempest.py index a0c09ac06..d7b33ecb6 100644 --- a/functest/opnfv_tests/openstack/tempest/tempest.py +++ b/functest/opnfv_tests/openstack/tempest/tempest.py @@ -119,12 +119,15 @@ class TempestCommon(testcase.TestCase): "testr list-tests {1} > {2};" "cd -;".format(verifier_repo_dir, testr_mode, - self.raw_list)) + self.list)) functest_utils.execute_command(cmd) def apply_tempest_blacklist(self): """Exclude blacklisted test cases.""" LOGGER.debug("Applying tempest blacklist...") + if os.path.exists(self.raw_list): + os.remove(self.raw_list) + os.rename(self.list, self.raw_list) cases_file = self.read_file(self.raw_list) result_file = open(self.list, 'w') black_tests = [] diff --git a/functest/tests/unit/openstack/tempest/test_tempest.py b/functest/tests/unit/openstack/tempest/test_tempest.py index 2b9dcff44..7a2394918 100644 --- a/functest/tests/unit/openstack/tempest/test_tempest.py +++ b/functest/tests/unit/openstack/tempest/test_tempest.py @@ -84,7 +84,7 @@ class OSTempestTesting(unittest.TestCase): cmd = ("cd {0};" "testr list-tests {1} > {2};" "cd -;".format(verifier_repo_dir, testr_mode, - self.tempestcommon.raw_list)) + self.tempestcommon.list)) self.tempestcommon.generate_test_list('test_verifier_repo_dir') mock_exec.assert_called_once_with(cmd) @@ -99,7 +99,10 @@ class OSTempestTesting(unittest.TestCase): with self.assertRaises(Exception): self.tempestcommon.parse_verifier_result() - def test_apply_missing_blacklist(self): + @mock.patch("os.rename") + @mock.patch("os.remove") + @mock.patch("os.path.exists", return_value=True) + def test_apply_missing_blacklist(self, *args): with mock.patch('__builtin__.open', mock.mock_open()) as mock_open, \ mock.patch.object(self.tempestcommon, 'read_file', return_value=['test1', 'test2']): @@ -110,8 +113,15 @@ class OSTempestTesting(unittest.TestCase): obj = mock_open() obj.write.assert_any_call('test1\n') obj.write.assert_any_call('test2\n') + args[0].assert_called_once_with(self.tempestcommon.raw_list) + args[1].assert_called_once_with(self.tempestcommon.raw_list) + args[2].assert_called_once_with( + self.tempestcommon.list, self.tempestcommon.raw_list) - def test_apply_blacklist_default(self): + @mock.patch("os.rename") + @mock.patch("os.remove") + @mock.patch("os.path.exists", return_value=True) + def test_apply_blacklist_default(self, *args): item_dict = {'scenarios': ['deploy_scenario'], 'installers': ['installer_type'], 'tests': ['test2']} @@ -126,6 +136,10 @@ class OSTempestTesting(unittest.TestCase): obj = mock_open() obj.write.assert_any_call('test1\n') self.assertFalse(obj.write.assert_any_call('test2\n')) + args[0].assert_called_once_with(self.tempestcommon.raw_list) + args[1].assert_called_once_with(self.tempestcommon.raw_list) + args[2].assert_called_once_with( + self.tempestcommon.list, self.tempestcommon.raw_list) @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.LOGGER.info') def test_run_verifier_tests_default(self, mock_logger_info): |