summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--functest/cli/commands/cli_env.py4
-rw-r--r--functest/cli/commands/cli_os.py13
-rw-r--r--functest/energy/energy.py6
-rw-r--r--functest/tests/unit/cli/commands/test_cli_os.py5
-rw-r--r--functest/tests/unit/energy/test_functest_energy.py2
-rw-r--r--functest/tests/unit/test_utils.py14
-rw-r--r--functest/tests/unit/utils/test_openstack_clean.py37
-rw-r--r--functest/tests/unit/utils/test_openstack_snapshot.py2
-rw-r--r--functest/tests/unit/utils/test_openstack_utils.py5
-rw-r--r--functest/utils/functest_vacation.py6
-rw-r--r--tox.ini6
11 files changed, 65 insertions, 35 deletions
diff --git a/functest/cli/commands/cli_env.py b/functest/cli/commands/cli_env.py
index 0e0afe529..c41f8f340 100644
--- a/functest/cli/commands/cli_env.py
+++ b/functest/cli/commands/cli_env.py
@@ -12,6 +12,8 @@ import prettytable
from functest.utils.constants import CONST
+import six
+
class Env(object):
@@ -52,7 +54,7 @@ class CliEnv(Env):
msg = prettytable.PrettyTable(
header_style='upper', padding_width=5,
field_names=['Functest Environment', 'value'])
- for key, value in env_info.iteritems():
+ for key, value in six.iteritems(env_info):
if key is not None:
msg.add_row([key, value])
click.echo(msg.get_string())
diff --git a/functest/cli/commands/cli_os.py b/functest/cli/commands/cli_os.py
index 71cd78c58..1ec705a5d 100644
--- a/functest/cli/commands/cli_os.py
+++ b/functest/cli/commands/cli_os.py
@@ -9,9 +9,10 @@
import os
-from urlparse import urlparse
import click
+import six
+from six.moves.urllib.parse import urlparse
from functest.ci import check_deployment
from functest.utils.constants import CONST
@@ -58,16 +59,18 @@ class OpenStack(object):
def snapshot_create(self):
self.ping_endpoint()
if os.path.isfile(self.snapshot_file):
- answer = raw_input("It seems there is already an OpenStack "
- "snapshot. Do you want to overwrite it with "
- "the current OpenStack status? [y|n]\n")
+ answer = six.moves.input(
+ "It seems there is already an OpenStack "
+ "snapshot. Do you want to overwrite it with "
+ "the current OpenStack status? [y|n]\n")
while True:
if answer.lower() in ["y", "yes"]:
break
elif answer.lower() in ["n", "no"]:
return
else:
- answer = raw_input("Invalid answer. Please type [y|n]\n")
+ answer = six.moves.input(
+ "Invalid answer. Please type [y|n]\n")
click.echo("Generating Openstack snapshot...")
os_snapshot.main()
diff --git a/functest/energy/energy.py b/functest/energy/energy.py
index 119942bbf..2835e05c1 100644
--- a/functest/energy/energy.py
+++ b/functest/energy/energy.py
@@ -12,10 +12,10 @@
import json
import logging
-import urllib
from functools import wraps
import requests
+from six.moves import urllib
from functest.utils.constants import CONST
import functest.utils.functest_utils as ft_utils
@@ -103,7 +103,7 @@ class EnergyRecorder(object):
assert environment
uri_comp = "/recorders/environment/"
- uri_comp += urllib.quote_plus(environment)
+ uri_comp += urllib.parse.quote_plus(environment)
# Creds
creds_usr = ft_utils.get_functest_config(
@@ -130,7 +130,7 @@ class EnergyRecorder(object):
except Exception as exc: # pylint: disable=broad-except
EnergyRecorder.logger.info(
"Energy recorder API is not available, cause=%s",
- exc.message)
+ str(exc))
api_available = False
# Final config
EnergyRecorder.energy_recorder_api = {
diff --git a/functest/tests/unit/cli/commands/test_cli_os.py b/functest/tests/unit/cli/commands/test_cli_os.py
index 806bc9312..434370a5c 100644
--- a/functest/tests/unit/cli/commands/test_cli_os.py
+++ b/functest/tests/unit/cli/commands/test_cli_os.py
@@ -82,7 +82,7 @@ class CliOpenStackTesting(unittest.TestCase):
return_value=True)
@mock.patch('functest.cli.commands.cli_os.click.echo')
def test_snapshot_create_overwrite(self, mock_click_echo, mock_os_path):
- with mock.patch('__builtin__.raw_input', return_value="y") \
+ with mock.patch('six.moves.input', return_value="y") \
as mock_raw_input, \
mock.patch.object(self.cli_os, 'ping_endpoint'), \
mock.patch('functest.cli.commands.cli_os.os_snapshot.main') \
@@ -111,7 +111,8 @@ class CliOpenStackTesting(unittest.TestCase):
return_value=True)
@mock.patch('functest.cli.commands.cli_os.click.echo')
def test_snapshot_show_default(self, mock_click_echo, mock_os_path):
- with mock.patch('__builtin__.open', mock.mock_open(read_data='0')) \
+ with mock.patch('six.moves.builtins.open',
+ mock.mock_open(read_data='0')) \
as m:
self.cli_os.snapshot_file = self.snapshot_file
self.cli_os.snapshot_show()
diff --git a/functest/tests/unit/energy/test_functest_energy.py b/functest/tests/unit/energy/test_functest_energy.py
index 99110802e..9e19a33df 100644
--- a/functest/tests/unit/energy/test_functest_energy.py
+++ b/functest/tests/unit/energy/test_functest_energy.py
@@ -266,7 +266,7 @@ class EnergyRecorderTest(unittest.TestCase):
with self.assertRaises(Exception) as context:
self.__decorated_method_with_ex()
self.assertTrue(
- self.exception_message_to_preserve in context.exception
+ self.exception_message_to_preserve in str(context.exception)
)
self.assertTrue(finish_mock.called)
diff --git a/functest/tests/unit/test_utils.py b/functest/tests/unit/test_utils.py
index e171db022..159047649 100644
--- a/functest/tests/unit/test_utils.py
+++ b/functest/tests/unit/test_utils.py
@@ -8,16 +8,22 @@
import re
-class RegexMatch(str):
+class RegexMatch(object):
+ def __init__(self, msg):
+ self.msg = msg
+
def __eq__(self, other):
- match = re.search(self, other)
+ match = re.search(self.msg, other)
if match:
return True
return False
-class SubstrMatch(str):
+class SubstrMatch(object):
+ def __init__(self, msg):
+ self.msg = msg
+
def __eq__(self, other):
- if self in other:
+ if self.msg in other:
return True
return False
diff --git a/functest/tests/unit/utils/test_openstack_clean.py b/functest/tests/unit/utils/test_openstack_clean.py
index 6ae7faa4a..afd9120a8 100644
--- a/functest/tests/unit/utils/test_openstack_clean.py
+++ b/functest/tests/unit/utils/test_openstack_clean.py
@@ -73,8 +73,9 @@ class OSCleanTesting(unittest.TestCase):
"-----------------"
"---------")
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.logger.debug')
- def test_remove_instances(self, mock_logger_debug):
+ def test_remove_instances(self, mock_logger_debug, *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_instances', return_value=self.test_list):
openstack_clean.remove_instances(self.client, self.update_list)
@@ -83,16 +84,19 @@ class OSCleanTesting(unittest.TestCase):
"instance and will "
"NOT be deleted.")
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.logger.debug')
- def test_remove_instances_missing_instances(self, mock_logger_debug):
+ def test_remove_instances_missing_instances(self, mock_logger_debug,
+ *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_instances', return_value=[]):
openstack_clean.remove_instances(self.client, self.update_list)
mock_logger_debug.assert_any_call("Removing Nova instances...")
mock_logger_debug.assert_any_call("No instances found.")
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.logger.debug')
- def test_remove_instances_delete_success(self, mock_logger_debug):
+ def test_remove_instances_delete_success(self, mock_logger_debug, *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_instances', return_value=self.test_list), \
mock.patch('functest.utils.openstack_clean.os_utils'
@@ -105,8 +109,10 @@ class OSCleanTesting(unittest.TestCase):
" '\s*\S+'"
" ..."))
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.logger.debug')
- def test_remove_instances_pending_delete_success(self, mock_logger_debug):
+ def test_remove_instances_pending_delete_success(self, mock_logger_debug,
+ *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_instances', return_value=self.deleted_list), \
mock.patch('functest.utils.openstack_clean.os_utils'
@@ -118,8 +124,10 @@ class OSCleanTesting(unittest.TestCase):
" '\s*\S+'"
" ...").assert_not_called()
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.logger.debug')
- def test_remove_instances_other_delete_success(self, mock_logger_debug):
+ def test_remove_instances_other_delete_success(self, mock_logger_debug,
+ *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_instances', return_value=self.other_list), \
mock.patch('functest.utils.openstack_clean.os_utils'
@@ -132,10 +140,11 @@ class OSCleanTesting(unittest.TestCase):
" '\s*\S+'"
" ..."))
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.logger.error')
@mock.patch('functest.utils.openstack_clean.logger.debug')
def test_remove_instances_delete_failed(self, mock_logger_debug,
- mock_logger_error):
+ mock_logger_error, *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_instances', return_value=self.test_list), \
mock.patch('functest.utils.openstack_clean.os_utils'
@@ -276,7 +285,7 @@ class OSCleanTesting(unittest.TestCase):
def test_remove_floatingips_delete_success(self, mock_logger_debug):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_floating_ips',
- return_value=self.floatingips_list), \
+ side_effect=[self.floatingips_list, None]), \
mock.patch('functest.utils.openstack_clean.os_utils'
'.delete_floating_ip', return_value=True):
openstack_clean.remove_floatingips(self.client, self.remove_list)
@@ -306,12 +315,13 @@ class OSCleanTesting(unittest.TestCase):
RegexMatch("Removing floating "
"IP \s*\S+ ..."))
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.remove_routers')
@mock.patch('functest.utils.openstack_clean.remove_ports')
@mock.patch('functest.utils.openstack_clean.logger.debug')
def test_remove_networks(self, mock_logger_debug,
mock_remove_ports,
- mock_remove_routers):
+ mock_remove_routers, *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_network_list',
return_value=self.test_dict_list), \
@@ -331,12 +341,13 @@ class OSCleanTesting(unittest.TestCase):
self.routers,
self.update_list)
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.remove_routers')
@mock.patch('functest.utils.openstack_clean.remove_ports')
@mock.patch('functest.utils.openstack_clean.logger.debug')
def test_remove_networks_missing_networks(self, mock_logger_debug,
mock_remove_ports,
- mock_remove_routers):
+ mock_remove_routers, *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_network_list', return_value=None), \
mock.patch('functest.utils.openstack_clean.os_utils'
@@ -354,12 +365,13 @@ class OSCleanTesting(unittest.TestCase):
self.routers,
self.update_list)
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.remove_routers')
@mock.patch('functest.utils.openstack_clean.remove_ports')
@mock.patch('functest.utils.openstack_clean.logger.debug')
def test_remove_networks_delete_success(self, mock_logger_debug,
mock_remove_ports,
- mock_remove_routers):
+ mock_remove_routers, *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_network_list',
@@ -385,6 +397,7 @@ class OSCleanTesting(unittest.TestCase):
self.routers,
self.remove_list)
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.remove_routers')
@mock.patch('functest.utils.openstack_clean.remove_ports')
@mock.patch('functest.utils.openstack_clean.logger.error')
@@ -392,7 +405,7 @@ class OSCleanTesting(unittest.TestCase):
def test_remove_networks_delete_failed(self, mock_logger_debug,
mock_logger_error,
mock_remove_ports,
- mock_remove_routers):
+ mock_remove_routers, *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_network_list',
return_value=self.test_dict_list), \
@@ -711,7 +724,7 @@ class OSCleanTesting(unittest.TestCase):
as mock_remove_tenants, \
mock.patch('functest.utils.openstack_clean.yaml.safe_load',
return_value=mock.Mock()), \
- mock.patch('__builtin__.open', mock.mock_open()) as m:
+ mock.patch('six.moves.builtins.open', mock.mock_open()) as m:
openstack_clean.main()
self.assertTrue(mock_remove_instances)
self.assertTrue(mock_remove_images)
diff --git a/functest/tests/unit/utils/test_openstack_snapshot.py b/functest/tests/unit/utils/test_openstack_snapshot.py
index 33e74609b..919b28c6b 100644
--- a/functest/tests/unit/utils/test_openstack_snapshot.py
+++ b/functest/tests/unit/utils/test_openstack_snapshot.py
@@ -222,7 +222,7 @@ class OSSnapshotTesting(unittest.TestCase):
return_value=self.update_list), \
mock.patch('functest.utils.openstack_snapshot.get_tenants',
return_value=self.update_list), \
- mock.patch('__builtin__.open', mock.mock_open()) as m:
+ mock.patch('six.moves.builtins.open', mock.mock_open()) as m:
openstack_snapshot.main()
mock_logger_info.assert_called_once_with("Generating OpenStack "
"snapshot...")
diff --git a/functest/tests/unit/utils/test_openstack_utils.py b/functest/tests/unit/utils/test_openstack_utils.py
index 307cbe37d..01085bb7d 100644
--- a/functest/tests/unit/utils/test_openstack_utils.py
+++ b/functest/tests/unit/utils/test_openstack_utils.py
@@ -365,7 +365,8 @@ class OSUtilsTesting(unittest.TestCase):
except:
pass
f = 'rc_file'
- with mock.patch('__builtin__.open', mock.mock_open(read_data=msg),
+ with mock.patch('six.moves.builtins.open',
+ mock.mock_open(read_data=msg),
create=True) as m:
m.return_value.__iter__ = lambda self: iter(self.readline, '')
openstack_utils.source_credentials(f)
@@ -1460,7 +1461,7 @@ class OSUtilsTesting(unittest.TestCase):
return_value=True), \
mock.patch('functest.utils.openstack_utils.get_image_id',
return_value=''), \
- mock.patch('__builtin__.open',
+ mock.patch('six.moves.builtins.open',
mock.mock_open(read_data='1')) as m:
self.assertEqual(openstack_utils.
create_glance_image(self.glance_client,
diff --git a/functest/utils/functest_vacation.py b/functest/utils/functest_vacation.py
index c2e40b072..71861ba7c 100644
--- a/functest/utils/functest_vacation.py
+++ b/functest/utils/functest_vacation.py
@@ -46,8 +46,8 @@ def main():
finally:
endwin()
- print '\nSnake.PY-26lines by Kris Cieslak (defaultset.blogspot.com).'
- print 'OPNFV adaptation by Functest dream team.'
+ print('\nSnake.PY-26ines by Kris Cieslak (defaultset.blogspot.com).')
+ print('OPNFV adaptation by Functest dream team.')
score = str(len(snake) - len(body) - 1)
print ('Thanks for playing, your score: %s.' % score)
- print 'Find and fix more bugs in your real OPNFV setup!\n'
+ print('Find and fix more bugs in your real OPNFV setup!\n')
diff --git a/tox.ini b/tox.ini
index 1e5487b12..62bed4f7b 100644
--- a/tox.ini
+++ b/tox.ini
@@ -31,8 +31,10 @@ whitelist_externals = bash
modules =
functest.api
functest.core
+ functest.energy
functest.opnfv_tests.sdn.odl
functest.tests.unit.core
+ functest.tests.unit.energy
functest.tests.unit.odl
functest.tests.unit.utils.test_decorators
functest.utils.decorators
@@ -55,9 +57,11 @@ commands =
[testenv:py35]
dirs =
functest/tests/unit/ci
+ functest/tests/unit/cli
functest/tests/unit/core
+ functest/tests/unit/energy
functest/tests/unit/odl
- functest/tests/unit/utils/test_decorators.py
+ functest/tests/unit/utils
commands = nosetests {[testenv:py35]dirs}
[testenv:cover]