From c1b25e9a487436c75d2f0fd625b95c6c59563e64 Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Thu, 12 Sep 2019 10:22:49 +0200 Subject: Select python 3.6 as default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It switches to Python3 as default due to new OPNFV iruya release date (December) which is very closed to Python2 EOL. Functest Iruya (first release published in April) has supported both Python2 and Python3. Change-Id: I4c1294a5361e591fc7a8a88b3d067fc3b39e00c4 Signed-off-by: Cédric Ollivier --- functest/core/cloudify.py | 7 +++---- functest/core/singlevm.py | 9 ++++----- functest/core/tenantnetwork.py | 2 +- functest/opnfv_tests/openstack/rally/rally.py | 22 +++++++--------------- .../opnfv_tests/openstack/vping/vping_userdata.py | 2 +- functest/opnfv_tests/sdn/odl/odl.py | 2 +- functest/opnfv_tests/vnf/epc/juju_epc.py | 4 ++-- functest/opnfv_tests/vnf/ims/clearwater.py | 19 ++++++++----------- functest/opnfv_tests/vnf/ims/cloudify_ims.py | 4 ++-- functest/opnfv_tests/vnf/ims/heat_ims.py | 2 +- .../opnfv_tests/vnf/router/cloudify_vrouter.py | 2 +- .../router/test_controller/function_test_exec.py | 2 +- functest/opnfv_tests/vnf/router/utilvnf.py | 2 +- .../vnf/router/vnf_controller/checker.py | 2 +- .../vnf/router/vnf_controller/command_generator.py | 2 +- .../vnf/router/vnf_controller/ssh_client.py | 4 ++-- .../vnf/router/vnf_controller/vm_controller.py | 2 +- .../vnf/router/vnf_controller/vnf_controller.py | 2 +- functest/opnfv_tests/vnf/router/vrouter_base.py | 2 +- functest/tests/unit/utils/test_functest_utils.py | 4 ++-- functest/utils/config.py | 2 +- 21 files changed, 43 insertions(+), 56 deletions(-) (limited to 'functest') diff --git a/functest/core/cloudify.py b/functest/core/cloudify.py index 21bfc937e..b5bd1b3c2 100644 --- a/functest/core/cloudify.py +++ b/functest/core/cloudify.py @@ -147,7 +147,7 @@ class Cloudify(singlevm.SingleVm2): self.cfy_client.executions.cancel( execution['id'], force=True) except Exception: # pylint: disable=broad-except - self.__logger.warn("Can't cancel the current exec") + self.__logger.warning("Can't cancel the current exec") execution = self.cfy_client.executions.start( dep_name, 'uninstall', parameters=dict(ignore_failure=True)) wait_for_execution(self.cfy_client, execution, self.__logger) @@ -191,9 +191,8 @@ def wait_for_execution(client, execution, logger, timeout=3600, ): 'execution of operation {0} for deployment {1} ' 'timed out'.format(execution.workflow_id, execution.deployment_id)) - else: - # update the remaining timeout - timeout = deadline - time.time() + # update the remaining timeout + timeout = deadline - time.time() if not execution_ended: execution = client.executions.get(execution.id) diff --git a/functest/core/singlevm.py b/functest/core/singlevm.py index 1da30de34..0473a21da 100644 --- a/functest/core/singlevm.py +++ b/functest/core/singlevm.py @@ -230,11 +230,10 @@ class VmReady1(tenantnetwork.TenantNetwork1): self.__logger.debug( "regex found: '%s' in console\n%s", regex, console) return True - else: - self.__logger.debug( - "try %s: cannot find regex '%s' in console\n%s", - iloop + 1, regex, console) - time.sleep(10) + self.__logger.debug( + "try %s: cannot find regex '%s' in console\n%s", + iloop + 1, regex, console) + time.sleep(10) self.__logger.error("cannot find regex '%s' in console", regex) return False diff --git a/functest/core/tenantnetwork.py b/functest/core/tenantnetwork.py index ae739ac36..604e49ae5 100644 --- a/functest/core/tenantnetwork.py +++ b/functest/core/tenantnetwork.py @@ -33,7 +33,7 @@ from functest.utils import config from functest.utils import env -class NewProject(object): +class NewProject(): """Ease creating new projects/users""" # pylint: disable=too-many-instance-attributes diff --git a/functest/opnfv_tests/openstack/rally/rally.py b/functest/opnfv_tests/openstack/rally/rally.py index 8100edaff..9a04f3873 100644 --- a/functest/opnfv_tests/openstack/rally/rally.py +++ b/functest/opnfv_tests/openstack/rally/rally.py @@ -22,7 +22,6 @@ import shutil import subprocess import time -from threading import Timer import pkg_resources import prettytable from ruamel.yaml import YAML @@ -101,7 +100,6 @@ class RallyBase(singlevm.VmReady2): self.run_cmd = '' self.network_extensions = [] self.services = [] - self.task_aborted = False def build_task_args(self, test_name): """Build arguments for the Rally task.""" @@ -425,25 +423,19 @@ class RallyBase(singlevm.VmReady2): else: LOGGER.info('Test scenario: "%s" Failed.', test_name) - def kill_task(self, proc): - """ Kill a task.""" - proc.kill() - self.task_aborted = True - def run_task(self, test_name): """Run a task.""" LOGGER.info('Starting test scenario "%s" ...', test_name) LOGGER.debug('running command: %s', self.run_cmd) proc = subprocess.Popen(self.run_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - self.task_aborted = False - timer = Timer(self.task_timeout, self.kill_task, [proc]) - timer.start() - output = proc.communicate()[0] - if self.task_aborted: - LOGGER.error("Failed to complete task") - raise Exception("Failed to complete task") - timer.cancel() + try: + output = proc.communicate(timeout=self.task_timeout)[0] + except subprocess.TimeoutExpired: + proc.kill() + proc.communicate() + LOGGER.error("Failed to complete run task") + raise Exception("Failed to complete run task") task_id = self.get_task_id(output) LOGGER.debug('task_id : %s', task_id) if task_id is None: diff --git a/functest/opnfv_tests/openstack/vping/vping_userdata.py b/functest/opnfv_tests/openstack/vping/vping_userdata.py index a58184c59..225c167d5 100644 --- a/functest/opnfv_tests/openstack/vping/vping_userdata.py +++ b/functest/opnfv_tests/openstack/vping/vping_userdata.py @@ -88,7 +88,7 @@ class VPingUserdata(singlevm.VmReady2): elif sec % 10 == 0: if "request failed" in p_console: self.logger.debug( - "It seems userdata is not supported in nova boot. " + + "It seems userdata is not supported in nova boot. " "Waiting a bit...") tries += 1 else: diff --git a/functest/opnfv_tests/sdn/odl/odl.py b/functest/opnfv_tests/sdn/odl/odl.py index 17600a316..b54f0f54b 100644 --- a/functest/opnfv_tests/sdn/odl/odl.py +++ b/functest/opnfv_tests/sdn/odl/odl.py @@ -189,7 +189,7 @@ class ODLTests(robotframework.RobotFramework): return self.run_suites(suites, **kwargs) -class ODLParser(object): # pylint: disable=too-few-public-methods +class ODLParser(): # pylint: disable=too-few-public-methods """Parser to run ODL test suites.""" def __init__(self): diff --git a/functest/opnfv_tests/vnf/epc/juju_epc.py b/functest/opnfv_tests/vnf/epc/juju_epc.py index 7c8a925bb..5a0a86b0c 100644 --- a/functest/opnfv_tests/vnf/epc/juju_epc.py +++ b/functest/opnfv_tests/vnf/epc/juju_epc.py @@ -148,13 +148,13 @@ class JujuEpc(singlevm.VmReady2): def check_requirements(self): if not os.path.exists("/src/epc-requirements/go/bin/juju"): - self.__logger.warn( + self.__logger.warning( "Juju cannot be cross-compiled (arm and arm64) from the time " "being") self.is_skipped = True self.project.clean() if env.get('NEW_USER_ROLE').lower() == "admin": - self.__logger.warn( + self.__logger.warning( "Defining NEW_USER_ROLE=admin will easily break the testcase " "because Juju doesn't manage tenancy (e.g. subnet " "overlapping)") diff --git a/functest/opnfv_tests/vnf/ims/clearwater.py b/functest/opnfv_tests/vnf/ims/clearwater.py index 64f0428b3..67128b11c 100644 --- a/functest/opnfv_tests/vnf/ims/clearwater.py +++ b/functest/opnfv_tests/vnf/ims/clearwater.py @@ -24,7 +24,7 @@ __author__ = ("Valentin Boucher , " "Helen Yao ") -class ClearwaterTesting(object): +class ClearwaterTesting(): """vIMS clearwater base usable by several orchestrators""" def __init__(self, case_name, bono_ip, ellis_ip): @@ -91,8 +91,7 @@ class ClearwaterTesting(object): 'Account %s is created on Ellis\n%s', params.get('full_name'), account_res) return account_res - else: - raise Exception("Cannot create ellis account") + raise Exception("Cannot create ellis account") except Exception: # pylint: disable=broad-except self.logger.info( "try %s: cannot create ellis account", iloop + 1) @@ -110,8 +109,7 @@ class ClearwaterTesting(object): cookies = req.cookies self.logger.debug('cookies: %s', cookies) return cookies - else: - raise Exception('Failed to get cookies for Ellis') + raise Exception('Failed to get cookies for Ellis') except Exception: # pylint: disable=broad-except self.logger.info( "try %s: cannot get cookies for Ellis", iloop + 1) @@ -128,13 +126,12 @@ class ClearwaterTesting(object): self.logger.info( 'Calling number is created: %s', number_res) return number_res + if req and req.json(): + reason = req.json()['reason'] else: - if req and req.json(): - reason = req.json()['reason'] - else: - reason = req - self.logger.info("cannot create a number: %s", reason) - raise Exception('Failed to create a number') + reason = req + self.logger.info("cannot create a number: %s", reason) + raise Exception('Failed to create a number') except Exception: # pylint: disable=broad-except self.logger.info( "try %s: cannot create a number", iloop + 1) diff --git a/functest/opnfv_tests/vnf/ims/cloudify_ims.py b/functest/opnfv_tests/vnf/ims/cloudify_ims.py index 0f6adf96a..d937cc052 100644 --- a/functest/opnfv_tests/vnf/ims/cloudify_ims.py +++ b/functest/opnfv_tests/vnf/ims/cloudify_ims.py @@ -103,7 +103,7 @@ class CloudifyIms(cloudify.Cloudify): def check_requirements(self): if env.get('NEW_USER_ROLE').lower() == "admin": - self.__logger.warn( + self.__logger.warning( "Defining NEW_USER_ROLE=admin will easily break the testcase " "because Cloudify doesn't manage tenancy (e.g. subnet " "overlapping)") @@ -250,7 +250,7 @@ class CloudifyIms(cloudify.Cloudify): self.result += vnf_test_rate / 3 * 100 if vnf_test_rate == 0: self.details['test_vnf'].update(status='FAIL') - return True if vnf_test_rate > 0 else False + return bool(vnf_test_rate > 0) def clean(self): """Clean created objects/functions.""" diff --git a/functest/opnfv_tests/vnf/ims/heat_ims.py b/functest/opnfv_tests/vnf/ims/heat_ims.py index 9ea9c5627..4a57a7445 100644 --- a/functest/opnfv_tests/vnf/ims/heat_ims.py +++ b/functest/opnfv_tests/vnf/ims/heat_ims.py @@ -234,7 +234,7 @@ class HeatIms(singlevm.VmReady2): if vnf_test_rate == 0: self.details['test_vnf'].update(status='FAIL') self._monit() - return True if vnf_test_rate > 0 else False + return bool(vnf_test_rate > 0) def clean(self): """Clean created objects/functions.""" diff --git a/functest/opnfv_tests/vnf/router/cloudify_vrouter.py b/functest/opnfv_tests/vnf/router/cloudify_vrouter.py index b449d2d81..c793953d3 100644 --- a/functest/opnfv_tests/vnf/router/cloudify_vrouter.py +++ b/functest/opnfv_tests/vnf/router/cloudify_vrouter.py @@ -113,7 +113,7 @@ class CloudifyVrouter(cloudify.Cloudify): def check_requirements(self): if env.get('NEW_USER_ROLE').lower() == "admin": - self.__logger.warn( + self.__logger.warning( "Defining NEW_USER_ROLE=admin will easily break the testcase " "because Cloudify doesn't manage tenancy (e.g. subnet " "overlapping)") diff --git a/functest/opnfv_tests/vnf/router/test_controller/function_test_exec.py b/functest/opnfv_tests/vnf/router/test_controller/function_test_exec.py index 0b8a69b73..0a56913b7 100644 --- a/functest/opnfv_tests/vnf/router/test_controller/function_test_exec.py +++ b/functest/opnfv_tests/vnf/router/test_controller/function_test_exec.py @@ -21,7 +21,7 @@ from functest.opnfv_tests.vnf.router.vnf_controller.vnf_controller import ( VnfController) -class FunctionTestExec(object): +class FunctionTestExec(): """vrouter function test execution class""" logger = logging.getLogger(__name__) diff --git a/functest/opnfv_tests/vnf/router/utilvnf.py b/functest/opnfv_tests/vnf/router/utilvnf.py index a54f6cb0b..2db3b38e5 100644 --- a/functest/opnfv_tests/vnf/router/utilvnf.py +++ b/functest/opnfv_tests/vnf/router/utilvnf.py @@ -43,7 +43,7 @@ NUMBER_OF_DIGITS_FOR_AVG_JITTER = 3 NUMBER_OF_DIGITS_FOR_AVG_PKT_LOSS = 1 -class Utilvnf(object): # pylint: disable=too-many-instance-attributes +class Utilvnf(): # pylint: disable=too-many-instance-attributes """ Utility class of vrouter testcase """ logger = logging.getLogger(__name__) diff --git a/functest/opnfv_tests/vnf/router/vnf_controller/checker.py b/functest/opnfv_tests/vnf/router/vnf_controller/checker.py index a7a70f6d7..d3a216ed0 100644 --- a/functest/opnfv_tests/vnf/router/vnf_controller/checker.py +++ b/functest/opnfv_tests/vnf/router/vnf_controller/checker.py @@ -18,7 +18,7 @@ import re from jinja2 import Environment, FileSystemLoader -class Checker(object): +class Checker(): """vrouter test result check class""" logger = logging.getLogger(__name__) diff --git a/functest/opnfv_tests/vnf/router/vnf_controller/command_generator.py b/functest/opnfv_tests/vnf/router/vnf_controller/command_generator.py index 7d9116bcc..a86a16485 100644 --- a/functest/opnfv_tests/vnf/router/vnf_controller/command_generator.py +++ b/functest/opnfv_tests/vnf/router/vnf_controller/command_generator.py @@ -15,7 +15,7 @@ import logging from jinja2 import Environment, FileSystemLoader -class CommandGenerator(object): +class CommandGenerator(): """command generator class for vrouter testing""" logger = logging.getLogger(__name__) diff --git a/functest/opnfv_tests/vnf/router/vnf_controller/ssh_client.py b/functest/opnfv_tests/vnf/router/vnf_controller/ssh_client.py index 6f4a9cf7f..0969eab3b 100644 --- a/functest/opnfv_tests/vnf/router/vnf_controller/ssh_client.py +++ b/functest/opnfv_tests/vnf/router/vnf_controller/ssh_client.py @@ -24,7 +24,7 @@ DEFAULT_CONNECT_RETRY_COUNT = 10 DEFAULT_SEND_TIMEOUT = 10 -class SshClient(object): # pylint: disable=too-many-instance-attributes +class SshClient(): # pylint: disable=too-many-instance-attributes """ssh client class for vrouter testing""" logger = logging.getLogger(__name__) @@ -80,7 +80,7 @@ class SshClient(object): # pylint: disable=too-many-instance-attributes retrycount -= 1 if retrycount == 0: - self.logger.warn( + self.logger.warning( "Cannot establish connection to IP '%s'", self.ip_address) self.connected = False return self.connected diff --git a/functest/opnfv_tests/vnf/router/vnf_controller/vm_controller.py b/functest/opnfv_tests/vnf/router/vnf_controller/vm_controller.py index a73855421..b159ddda4 100644 --- a/functest/opnfv_tests/vnf/router/vnf_controller/vm_controller.py +++ b/functest/opnfv_tests/vnf/router/vnf_controller/vm_controller.py @@ -23,7 +23,7 @@ from functest.opnfv_tests.vnf.router.vnf_controller.ssh_client import ( SshClient) -class VmController(object): +class VmController(): """vm controll class""" logger = logging.getLogger(__name__) diff --git a/functest/opnfv_tests/vnf/router/vnf_controller/vnf_controller.py b/functest/opnfv_tests/vnf/router/vnf_controller/vnf_controller.py index a5b1ad856..7ed287c6e 100644 --- a/functest/opnfv_tests/vnf/router/vnf_controller/vnf_controller.py +++ b/functest/opnfv_tests/vnf/router/vnf_controller/vnf_controller.py @@ -26,7 +26,7 @@ from functest.opnfv_tests.vnf.router.vnf_controller.vm_controller import ( VmController) -class VnfController(object): +class VnfController(): """vrouter controll class""" logger = logging.getLogger(__name__) diff --git a/functest/opnfv_tests/vnf/router/vrouter_base.py b/functest/opnfv_tests/vnf/router/vrouter_base.py index 8cfab341e..932770b9c 100644 --- a/functest/opnfv_tests/vnf/router/vrouter_base.py +++ b/functest/opnfv_tests/vnf/router/vrouter_base.py @@ -24,7 +24,7 @@ from functest.opnfv_tests.vnf.router.test_controller import function_test_exec __author__ = "Shuya Nakama " -class VrouterOnBoardingBase(object): +class VrouterOnBoardingBase(): """vrouter testing base class""" def __init__(self, util, util_info): diff --git a/functest/tests/unit/utils/test_functest_utils.py b/functest/tests/unit/utils/test_functest_utils.py index 4ec205894..f6a80e264 100644 --- a/functest/tests/unit/utils/test_functest_utils.py +++ b/functest/tests/unit/utils/test_functest_utils.py @@ -82,7 +82,7 @@ class FunctestUtilsTesting(unittest.TestCase): def _get_environ(self, var, *args): # pylint: disable=unused-argument if var == 'INSTALLER_TYPE': return self.installer - elif var == 'DEPLOY_SCENARIO': + if var == 'DEPLOY_SCENARIO': return self.scenario return var @@ -322,7 +322,7 @@ class FunctestUtilsTesting(unittest.TestCase): self.assertEqual( functest_utils.convert_dict_to_ini({"a": "b"}), "a:b") value = functest_utils.convert_dict_to_ini({"a": "b", "c": "d"}) - self.assertTrue(value == "a:b,c:d" or value == "c:d,a:b") + self.assertTrue(value in ('a:b,c:d', 'c:d,a:b')) with self.assertRaises(AssertionError): functest_utils.convert_list_to_ini("") diff --git a/functest/utils/config.py b/functest/utils/config.py index 61d8401c5..c2897d361 100644 --- a/functest/utils/config.py +++ b/functest/utils/config.py @@ -10,7 +10,7 @@ import six from functest.utils import env -class Config(object): +class Config(): def __init__(self): try: # pylint: disable=bad-continuation -- cgit 1.2.3-korg