aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2018-06-14 20:51:41 +0200
committerCédric Ollivier <cedric.ollivier@orange.com>2018-06-14 20:51:41 +0200
commit09d6e6feef33fa47bca440a096894b851b1ebca5 (patch)
treee3a528dc0c5509cd1ca4071b165399ca3f344817
parent1ef7fd44523182a8b8ddcc97433fff55ba17fce8 (diff)
Add py3 support in tempest and rally
Change-Id: I009d38a0db409ab4ec641cba9173ab2386d0ce2a Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
-rw-r--r--functest/opnfv_tests/openstack/patrole/patrole.py5
-rw-r--r--functest/opnfv_tests/openstack/tempest/conf_utils.py10
-rw-r--r--functest/opnfv_tests/openstack/tempest/tempest.py3
-rw-r--r--functest/tests/unit/openstack/rally/test_rally.py18
-rw-r--r--functest/tests/unit/openstack/tempest/test_conf_utils.py11
-rw-r--r--functest/tests/unit/openstack/tempest/test_tempest.py11
-rw-r--r--tox.ini2
7 files changed, 33 insertions, 27 deletions
diff --git a/functest/opnfv_tests/openstack/patrole/patrole.py b/functest/opnfv_tests/openstack/patrole/patrole.py
index 0c5eedf48..c4ed80837 100644
--- a/functest/opnfv_tests/openstack/patrole/patrole.py
+++ b/functest/opnfv_tests/openstack/patrole/patrole.py
@@ -12,7 +12,8 @@
import logging
import os
-from functest.opnfv_tests.openstack.tempest import conf_utils
+from six.moves import configparser
+
from functest.opnfv_tests.openstack.tempest import tempest
from functest.utils import config
@@ -34,7 +35,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 062d75ef1..d62f3daa0 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/opnfv_tests/openstack/tempest/tempest.py b/functest/opnfv_tests/openstack/tempest/tempest.py
index 7f1baeb79..7fb24f239 100644
--- a/functest/opnfv_tests/openstack/tempest/tempest.py
+++ b/functest/opnfv_tests/openstack/tempest/tempest.py
@@ -21,6 +21,7 @@ import time
import uuid
import os_client_config
+from six.moves import configparser
from xtesting.core import testcase
import yaml
@@ -313,7 +314,7 @@ class TempestNeutronTrunk(TempestCommon):
def configure(self, **kwargs):
super(TempestNeutronTrunk, self).configure(**kwargs)
- rconfig = conf_utils.ConfigParser.RawConfigParser()
+ rconfig = configparser.RawConfigParser()
rconfig.read(self.conf_file)
rconfig.set('network-feature-enabled', 'api_extensions', 'all')
with open(self.conf_file, 'wb') as config_file:
diff --git a/functest/tests/unit/openstack/rally/test_rally.py b/functest/tests/unit/openstack/rally/test_rally.py
index 3ef90c44e..f7523b4a0 100644
--- a/functest/tests/unit/openstack/rally/test_rally.py
+++ b/functest/tests/unit/openstack/rally/test_rally.py
@@ -104,7 +104,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'],
@@ -119,7 +119,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$'],
@@ -147,12 +147,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']}]})
@@ -165,7 +165,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()
@@ -229,7 +229,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.'
@@ -255,7 +255,7 @@ class OSRallyTesting(unittest.TestCase):
self.rally_base._run_task('test_name')
mock_save_res.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.RallyBase.'
'task_succeed', return_value=True)
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
@@ -498,7 +498,7 @@ class OSRallyTesting(unittest.TestCase):
self.assertEqual(self.rally_base.summary[0]['nb_success'], 1)
def test_is_successful_false(self):
- with mock.patch('__builtin__.super') as mock_super:
+ with mock.patch('six.moves.builtins.super') as mock_super:
self.rally_base.summary = [{"task_status": True},
{"task_status": False}]
self.assertEqual(self.rally_base.is_successful(),
@@ -506,7 +506,7 @@ class OSRallyTesting(unittest.TestCase):
mock_super(rally.RallyBase, self).is_successful.assert_not_called()
def test_is_successful_true(self):
- with mock.patch('__builtin__.super') as mock_super:
+ with mock.patch('six.moves.builtins.super') as mock_super:
mock_super(rally.RallyBase, self).is_successful.return_value = 424
self.rally_base.summary = [{"task_status": True},
{"task_status": True}]
diff --git a/functest/tests/unit/openstack/tempest/test_conf_utils.py b/functest/tests/unit/openstack/tempest/test_conf_utils.py
index bc3c983b6..6f44337c9 100644
--- a/functest/tests/unit/openstack/tempest/test_conf_utils.py
+++ b/functest/tests/unit/openstack/tempest/test_conf_utils.py
@@ -156,16 +156,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 25737d123..9116100cd 100644
--- a/functest/tests/unit/openstack/tempest/test_tempest.py
+++ b/functest/tests/unit/openstack/tempest/test_tempest.py
@@ -114,7 +114,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
@@ -136,7 +137,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.'
@@ -154,8 +156,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'
diff --git a/tox.ini b/tox.ini
index 62785a1db..291ea3b61 100644
--- a/tox.ini
+++ b/tox.ini
@@ -101,6 +101,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}