Add py3 support in tempest and rally 57/58557/1
authorCédric Ollivier <cedric.ollivier@orange.com>
Thu, 14 Jun 2018 18:51:41 +0000 (20:51 +0200)
committerCédric Ollivier <cedric.ollivier@orange.com>
Thu, 14 Jun 2018 18:51:41 +0000 (20:51 +0200)
Change-Id: I009d38a0db409ab4ec641cba9173ab2386d0ce2a
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
functest/opnfv_tests/openstack/patrole/patrole.py
functest/opnfv_tests/openstack/tempest/conf_utils.py
functest/opnfv_tests/openstack/tempest/tempest.py
functest/tests/unit/openstack/rally/test_rally.py
functest/tests/unit/openstack/tempest/test_conf_utils.py
functest/tests/unit/openstack/tempest/test_tempest.py
tox.ini

index 0c5eedf..c4ed808 100644 (file)
@@ -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)
index 062d75e..d62f3da 100644 (file)
 
 """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'))
index 7f1baeb..7fb24f2 100644 (file)
@@ -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:
index 3ef90c4..f7523b4 100644 (file)
@@ -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}]
index bc3c983..6f44337 100644 (file)
@@ -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'] = ''
index 25737d1..9116100 100644 (file)
@@ -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 62785a1..291ea3b 100644 (file)
--- 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}