Add py3 support in tempest and rally 81/60281/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>
Fri, 27 Jul 2018 12:31:36 +0000 (14:31 +0200)
Change-Id: I009d38a0db409ab4ec641cba9173ab2386d0ce2a
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
(cherry picked from commit 09d6e6feef33fa47bca440a096894b851b1ebca5)

functest/opnfv_tests/openstack/patrole/patrole.py
functest/opnfv_tests/openstack/tempest/conf_utils.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 e2ea351..efc513c 100644 (file)
@@ -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)
index 327333e..88ad3b2 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 58881f7..cbcf46f 100644 (file)
@@ -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.'
index 7c361b4..1585cac 100644 (file)
@@ -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'] = ''
index 8db21ff..1493c2a 100644 (file)
@@ -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'
diff --git a/tox.ini b/tox.ini
index af347d5..dc1c180 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -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}