diff options
author | Cédric Ollivier <cedric.ollivier@orange.com> | 2018-06-14 20:51:41 +0200 |
---|---|---|
committer | Cédric Ollivier <cedric.ollivier@orange.com> | 2018-07-27 14:31:36 +0200 |
commit | a321d59c36f368a3a1aeefaa09c9e66b1e8c13c0 (patch) | |
tree | b186e9a1d417d4c73ee135aa4a5688a4689f73d2 | |
parent | cbf303ec56a1e59d87cf15ba98c6626fa6a03c03 (diff) |
Add py3 support in tempest and rally
Change-Id: I009d38a0db409ab4ec641cba9173ab2386d0ce2a
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
(cherry picked from commit 09d6e6feef33fa47bca440a096894b851b1ebca5)
-rw-r--r-- | functest/opnfv_tests/openstack/patrole/patrole.py | 5 | ||||
-rw-r--r-- | functest/opnfv_tests/openstack/tempest/conf_utils.py | 10 | ||||
-rw-r--r-- | functest/tests/unit/openstack/rally/test_rally.py | 12 | ||||
-rw-r--r-- | functest/tests/unit/openstack/tempest/test_conf_utils.py | 11 | ||||
-rw-r--r-- | functest/tests/unit/openstack/tempest/test_tempest.py | 11 | ||||
-rw-r--r-- | tox.ini | 2 |
6 files changed, 28 insertions, 23 deletions
diff --git a/functest/opnfv_tests/openstack/patrole/patrole.py b/functest/opnfv_tests/openstack/patrole/patrole.py index e2ea3514d..efc513cdb 100644 --- a/functest/opnfv_tests/openstack/patrole/patrole.py +++ b/functest/opnfv_tests/openstack/patrole/patrole.py @@ -11,7 +11,8 @@ import logging -from functest.opnfv_tests.openstack.tempest import conf_utils +from six.moves import configparser + from functest.opnfv_tests.openstack.tempest import tempest @@ -21,7 +22,7 @@ class Patrole(tempest.TempestCommon): def configure(self, **kwargs): super(Patrole, self).configure(**kwargs) - rconfig = conf_utils.ConfigParser.RawConfigParser() + rconfig = configparser.RawConfigParser() rconfig.read(self.conf_file) rconfig.add_section('rbac') rconfig.set('rbac', 'enable_rbac', True) diff --git a/functest/opnfv_tests/openstack/tempest/conf_utils.py b/functest/opnfv_tests/openstack/tempest/conf_utils.py index 327333e0d..88ad3b2d9 100644 --- a/functest/opnfv_tests/openstack/tempest/conf_utils.py +++ b/functest/opnfv_tests/openstack/tempest/conf_utils.py @@ -10,13 +10,15 @@ """Tempest configuration utilities.""" -import ConfigParser +from __future__ import print_function + import logging import fileinput import os import subprocess import pkg_resources +from six.moves import configparser import yaml from functest.utils import config @@ -54,9 +56,9 @@ def create_rally_deployment(): rally_patch_conf = pfile.read() for line in fileinput.input(RALLY_CONF_PATH, inplace=1): - print line, + print(line, end=' ') if "cirros|testvm" in line: - print rally_patch_conf + print(rally_patch_conf) LOGGER.info("Creating Rally environment...") @@ -189,7 +191,7 @@ def configure_tempest_update_params( Add/update needed parameters into tempest.conf file """ LOGGER.debug("Updating selected tempest.conf parameters...") - rconfig = ConfigParser.RawConfigParser() + rconfig = configparser.RawConfigParser() rconfig.read(tempest_conf_file) rconfig.set('compute', 'fixed_network_name', network_name) rconfig.set('compute', 'volume_device_name', env.get('VOLUME_DEVICE_NAME')) diff --git a/functest/tests/unit/openstack/rally/test_rally.py b/functest/tests/unit/openstack/rally/test_rally.py index 58881f7a4..cbcf46fce 100644 --- a/functest/tests/unit/openstack/rally/test_rally.py +++ b/functest/tests/unit/openstack/rally/test_rally.py @@ -108,7 +108,7 @@ class OSRallyTesting(unittest.TestCase): self.assertEqual(self.rally_base.get_cmd_output(proc), 'line1line2') - @mock.patch('__builtin__.open', mock.mock_open()) + @mock.patch('six.moves.builtins.open', mock.mock_open()) @mock.patch('functest.opnfv_tests.openstack.rally.rally.yaml.safe_load', return_value={'scenario': [ {'scenarios': ['test_scenario'], @@ -123,7 +123,7 @@ class OSRallyTesting(unittest.TestCase): self.assertEqual(self.rally_base.excl_scenario(), ['test']) mock_func.assert_called() - @mock.patch('__builtin__.open', mock.mock_open()) + @mock.patch('six.moves.builtins.open', mock.mock_open()) @mock.patch('functest.opnfv_tests.openstack.rally.rally.yaml.safe_load', return_value={'scenario': [ {'scenarios': ['^os-[^-]+-featT-modeT$'], @@ -151,12 +151,12 @@ class OSRallyTesting(unittest.TestCase): ['test1', 'test2', 'test3', 'test4']) mock_func.assert_called() - @mock.patch('__builtin__.open', side_effect=Exception) + @mock.patch('six.moves.builtins.open', side_effect=Exception) def test_excl_scenario_exception(self, mock_open): self.assertEqual(self.rally_base.excl_scenario(), []) mock_open.assert_called() - @mock.patch('__builtin__.open', mock.mock_open()) + @mock.patch('six.moves.builtins.open', mock.mock_open()) @mock.patch('functest.opnfv_tests.openstack.rally.rally.yaml.safe_load', return_value={'functionality': [ {'functions': ['no_migration'], 'tests': ['test']}]}) @@ -169,7 +169,7 @@ class OSRallyTesting(unittest.TestCase): mock_func.assert_called() mock_yaml_load.assert_called() - @mock.patch('__builtin__.open', side_effect=Exception) + @mock.patch('six.moves.builtins.open', side_effect=Exception) def test_excl_func_exception(self, mock_open): self.assertEqual(self.rally_base.excl_func(), []) mock_open.assert_called() @@ -234,7 +234,7 @@ class OSRallyTesting(unittest.TestCase): text = 'Failed to retrieve task_id, validating task...' mock_logger_error.assert_any_call(text) - @mock.patch('__builtin__.open', mock.mock_open()) + @mock.patch('six.moves.builtins.open', mock.mock_open()) @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.' '_prepare_test_list', return_value='test_file_name') @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.' diff --git a/functest/tests/unit/openstack/tempest/test_conf_utils.py b/functest/tests/unit/openstack/tempest/test_conf_utils.py index 7c361b4d8..1585cac09 100644 --- a/functest/tests/unit/openstack/tempest/test_conf_utils.py +++ b/functest/tests/unit/openstack/tempest/test_conf_utils.py @@ -127,16 +127,13 @@ class OSTempestConfUtilsTesting(unittest.TestCase): self.assertTrue(mock_get_did.called) def _test_missing_param(self, params, image_id, flavor_id, alt=False): - with mock.patch('functest.opnfv_tests.openstack.tempest.' - 'conf_utils.ConfigParser.RawConfigParser.' + with mock.patch('six.moves.configparser.RawConfigParser.' 'set') as mset, \ - mock.patch('functest.opnfv_tests.openstack.tempest.' - 'conf_utils.ConfigParser.RawConfigParser.' + mock.patch('six.moves.configparser.RawConfigParser.' 'read') as mread, \ - mock.patch('functest.opnfv_tests.openstack.tempest.' - 'conf_utils.ConfigParser.RawConfigParser.' + mock.patch('six.moves.configparser.RawConfigParser.' 'write') as mwrite, \ - mock.patch('__builtin__.open', mock.mock_open()), \ + mock.patch('six.moves.builtins.open', mock.mock_open()), \ mock.patch('functest.utils.functest_utils.yaml.safe_load', return_value={'validation': {'ssh_timeout': 300}}): os.environ['OS_INTERFACE'] = '' diff --git a/functest/tests/unit/openstack/tempest/test_tempest.py b/functest/tests/unit/openstack/tempest/test_tempest.py index 8db21ff3f..1493c2a35 100644 --- a/functest/tests/unit/openstack/tempest/test_tempest.py +++ b/functest/tests/unit/openstack/tempest/test_tempest.py @@ -112,7 +112,8 @@ class OSTempestTesting(unittest.TestCase): @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, \ + with mock.patch('six.moves.builtins.open', + mock.mock_open()) as mock_open, \ mock.patch.object(self.tempestcommon, 'read_file', return_value=['test1', 'test2']): conf_utils.TEMPEST_BLACKLIST = Exception @@ -134,7 +135,8 @@ class OSTempestTesting(unittest.TestCase): item_dict = {'scenarios': ['deploy_scenario'], 'installers': ['installer_type'], 'tests': ['test2']} - with mock.patch('__builtin__.open', mock.mock_open()) as mock_open, \ + with mock.patch('six.moves.builtins.open', + mock.mock_open()) as mock_open, \ mock.patch.object(self.tempestcommon, 'read_file', return_value=['test1', 'test2']), \ mock.patch('functest.opnfv_tests.openstack.tempest.tempest.' @@ -152,8 +154,9 @@ class OSTempestTesting(unittest.TestCase): @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.LOGGER.info') def test_run_verifier_tests_default(self, mock_logger_info): - with mock.patch('__builtin__.open', mock.mock_open()), \ - mock.patch('__builtin__.iter', return_value=[r'\} tempest\.']), \ + with mock.patch('six.moves.builtins.open', mock.mock_open()), \ + mock.patch('six.moves.builtins.iter', + return_value=[r'\} tempest\.']), \ mock.patch('functest.opnfv_tests.openstack.tempest.tempest.' 'subprocess.Popen'): conf_utils.TEMPEST_LIST = 'test_tempest_list' @@ -100,6 +100,8 @@ dirs = functest/tests/unit/ci functest/tests/unit/cli functest/tests/unit/odl + functest/tests/unit/openstack/rally + functest/tests/unit/openstack/tempest functest/tests/unit/utils commands = nosetests {[testenv:py35]dirs} |