From 01efa1e4229157b46d352bce202ed4192992dd3f Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Fri, 26 Jan 2018 09:49:49 +0100 Subject: Fix last Pylint error in Functest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It also fixes all pylint warnings in router and the related unit tests. tox.ini is updated to ensure that no error is introduced. Change-Id: Iddd74b0dac7b6581d72b04369140006c9e19f998 Signed-off-by: Cédric Ollivier --- .../opnfv_tests/vnf/router/cloudify_vrouter.py | 25 +++++----------- .../router/test_controller/function_test_exec.py | 2 ++ functest/opnfv_tests/vnf/router/utilvnf.py | 35 ++++++++++++---------- .../vnf/router/vnf_controller/checker.py | 8 +++-- .../vnf/router/vnf_controller/command_generator.py | 10 +++++-- .../vnf/router/vnf_controller/ssh_client.py | 28 +++++++++-------- .../vnf/router/vnf_controller/vm_controller.py | 2 ++ .../vnf/router/vnf_controller/vnf_controller.py | 11 +++++-- functest/opnfv_tests/vnf/router/vrouter_base.py | 9 ++++-- 9 files changed, 75 insertions(+), 55 deletions(-) (limited to 'functest/opnfv_tests/vnf') diff --git a/functest/opnfv_tests/vnf/router/cloudify_vrouter.py b/functest/opnfv_tests/vnf/router/cloudify_vrouter.py index f2cd63fb..1596860d 100644 --- a/functest/opnfv_tests/vnf/router/cloudify_vrouter.py +++ b/functest/opnfv_tests/vnf/router/cloudify_vrouter.py @@ -7,6 +7,8 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 +# pylint: disable=missing-docstring + """vrouter testcase implementation.""" import logging @@ -50,6 +52,7 @@ __author__ = "Shuya Nakama " class CloudifyVrouter(vrouter_base.VrouterOnBoardingBase): + # pylint: disable=too-many-instance-attributes """vrouter testcase deployed with Cloudify Orchestrator.""" __logger = logging.getLogger(__name__) @@ -129,6 +132,7 @@ class CloudifyVrouter(vrouter_base.VrouterOnBoardingBase): self.created_object.append(image_creator) def deploy_orchestrator(self): + # pylint: disable=too-many-locals,too-many-statements """ Deploy Cloudify Manager. network, security group, fip, VM creation @@ -408,7 +412,7 @@ class CloudifyVrouter(vrouter_base.VrouterOnBoardingBase): try: cfy_client.executions.cancel(execution['id'], force=True) - except: # pylint: disable=broad-except + except Exception: # pylint: disable=broad-except self.__logger.warn("Can't cancel the current exec") execution = cfy_client.executions.start( @@ -419,27 +423,14 @@ class CloudifyVrouter(vrouter_base.VrouterOnBoardingBase): wait_for_execution(cfy_client, execution, self.__logger) cfy_client.deployments.delete(self.vnf['descriptor'].get('name')) cfy_client.blueprints.delete(self.vnf['descriptor'].get('name')) - except: # pylint: disable=broad-except + except Exception: # pylint: disable=broad-except self.__logger.warn("Some issue during the undeployment ..") self.__logger.warn("Tenant clean continue ..") - - self.__logger.info('Remove the cloudify manager OS object ..') - for creator in reversed(self.created_object): - try: - creator.clean() - except Exception as exc: - self.logger.error('Unexpected error cleaning - %s', exc) - super(CloudifyVrouter, self).clean() - def run(self, **kwargs): - """Execute CloudifyVrouter test case.""" - return super(CloudifyVrouter, self).run(**kwargs) - def get_vnf_info_list(self, target_vnf_name): - return self.util.get_vnf_info_list(self.cfy_manager_ip, - self.deployment_name, - target_vnf_name) + return self.util.get_vnf_info_list( + self.cfy_manager_ip, self.deployment_name, target_vnf_name) # ---------------------------------------------------------- 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 d023d479..be7bee88 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 @@ -7,6 +7,8 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 +# pylint: disable=missing-docstring + """vrouter function test execution module""" import logging diff --git a/functest/opnfv_tests/vnf/router/utilvnf.py b/functest/opnfv_tests/vnf/router/utilvnf.py index 9d196836..421cfe83 100644 --- a/functest/opnfv_tests/vnf/router/utilvnf.py +++ b/functest/opnfv_tests/vnf/router/utilvnf.py @@ -7,6 +7,8 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 +# pylint: disable=missing-docstring + """ Utility module of vrouter testcase """ import json @@ -46,7 +48,7 @@ NUMBER_OF_DIGITS_FOR_AVG_JITTER = 3 NUMBER_OF_DIGITS_FOR_AVG_PKT_LOSS = 1 -class Utilvnf(object): +class Utilvnf(object): # pylint: disable=too-many-instance-attributes """ Utility class of vrouter testcase """ logger = logging.getLogger(__name__) @@ -107,7 +109,7 @@ class Utilvnf(object): self.test_result_json_file = "test_result.json" if os.path.isfile(self.test_result_json_file): os.remove(self.test_result_json_file) - self.logger.debug("removed %s" % self.test_result_json_file) + self.logger.debug("removed %s", self.test_result_json_file) def get_nova_client(self): nova_client = nova_utils.nova_client(self.snaps_creds) @@ -127,7 +129,7 @@ class Utilvnf(object): break address = server.addresses[ - network_name][NOVA_CILENT_NETWORK_INFO_INDEX]["addr"] + network_name][NOVA_CILENT_NETWORK_INFO_INDEX]["addr"] return address @@ -141,8 +143,7 @@ class Utilvnf(object): break mac_address = server.addresses[network_name][ - NOVA_CILENT_NETWORK_INFO_INDEX][ - "OS-EXT-IPS-MAC:mac_addr"] + NOVA_CILENT_NETWORK_INFO_INDEX]["OS-EXT-IPS-MAC:mac_addr"] return mac_address @@ -226,10 +227,7 @@ class Utilvnf(object): vnf["user"] = self.image["user"] vnf["pass"] = self.image["pass"] - if vnf_name == target_vnf_name: - vnf["target_vnf_flag"] = True - else: - vnf["target_vnf_flag"] = False + vnf["target_vnf_flag"] = bool(vnf_name == target_vnf_name) self.logger.debug("vnf name : " + vnf_name) self.logger.debug(vnf_name + " floating ip address : " + @@ -251,14 +249,16 @@ class Utilvnf(object): return vnf_info_list - def get_target_vnf(self, vnf_info_list): + @staticmethod + def get_target_vnf(vnf_info_list): for vnf in vnf_info_list: if vnf["target_vnf_flag"]: return vnf return None - def get_reference_vnf_list(self, vnf_info_list): + @staticmethod + def get_reference_vnf_list(vnf_info_list): reference_vnf_list = [] for vnf in vnf_info_list: if not vnf["target_vnf_flag"]: @@ -266,14 +266,16 @@ class Utilvnf(object): return reference_vnf_list - def get_vnf_info(self, vnf_info_list, vnf_name): + @staticmethod + def get_vnf_info(vnf_info_list, vnf_name): for vnf in vnf_info_list: if vnf["vnf_name"] == vnf_name: return vnf return None - def convert_functional_test_result(self, result_data_list): + @staticmethod + def convert_functional_test_result(result_data_list): result = {} for result_data in result_data_list: test_kind = result_data["test_kind"] @@ -311,11 +313,12 @@ class Utilvnf(object): output_json_data = json.dumps(test_result, sort_keys=True, indent=4) - self.logger.debug("test_result %s" % output_json_data) + self.logger.debug("test_result %s", output_json_data) else: - self.logger.debug("Not found %s" % self.test_result_json_file) + self.logger.debug("Not found %s", self.test_result_json_file) - def get_test_scenario(self, file_path): + @staticmethod + def get_test_scenario(file_path): test_scenario_file = open(file_path, 'r') test_scenario_yaml = yaml.safe_load(test_scenario_file) diff --git a/functest/opnfv_tests/vnf/router/vnf_controller/checker.py b/functest/opnfv_tests/vnf/router/vnf_controller/checker.py index 198a5ffc..a7a70f6d 100644 --- a/functest/opnfv_tests/vnf/router/vnf_controller/checker.py +++ b/functest/opnfv_tests/vnf/router/vnf_controller/checker.py @@ -7,6 +7,8 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 +# pylint: disable=missing-docstring + """vrouter test result check module""" import json @@ -24,7 +26,8 @@ class Checker(object): def __init__(self): self.logger.debug("init checker") - def load_check_rule(self, rule_file_dir, rule_file_name, parameter): + @staticmethod + def load_check_rule(rule_file_dir, rule_file_name, parameter): loader = FileSystemLoader(rule_file_dir, encoding='utf8') env = Environment(loader=loader) @@ -33,7 +36,8 @@ class Checker(object): check_rule_data = json.loads(check_rule) return check_rule_data - def regexp_information(self, response, rules): + @staticmethod + def regexp_information(response, rules): status = False result_data = {} 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 98cb14cc..7d9116bc 100644 --- a/functest/opnfv_tests/vnf/router/vnf_controller/command_generator.py +++ b/functest/opnfv_tests/vnf/router/vnf_controller/command_generator.py @@ -7,6 +7,8 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 +# pylint: disable=missing-docstring + """command generator module for vrouter testing""" import logging @@ -21,12 +23,16 @@ class CommandGenerator(object): def __init__(self): self.logger.debug("init command generator") - def load_template(self, template_dir, template): + @staticmethod + def load_template(template_dir, template): + # pylint disable=missing-docstring loader = FileSystemLoader(template_dir, encoding='utf8') env = Environment(loader=loader) return env.get_template(template) - def command_create(self, template, parameter): + @staticmethod + def command_create(template, parameter): + # pylint disable=missing-docstring commands = template.render(parameter) return commands.split('\n') 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 c85a5735..628afd30 100644 --- a/functest/opnfv_tests/vnf/router/vnf_controller/ssh_client.py +++ b/functest/opnfv_tests/vnf/router/vnf_controller/ssh_client.py @@ -10,10 +10,11 @@ """ssh client module for vrouter testing""" import logging -import paramiko import time import yaml +import paramiko + from functest.opnfv_tests.vnf.router.utilvnf import Utilvnf RECEIVE_ROOP_WAIT = 1 @@ -23,7 +24,7 @@ DEFAULT_CONNECT_RETRY_COUNT = 10 DEFAULT_SEND_TIMEOUT = 10 -class SshClient(object): +class SshClient(object): # pylint: disable=too-many-instance-attributes """ssh client class for vrouter testing""" logger = logging.getLogger(__name__) @@ -51,6 +52,7 @@ class SshClient(object): def connect(self, time_out=DEFAULT_CONNECT_TIMEOUT, retrycount=DEFAULT_CONNECT_RETRY_COUNT): + # pylint: disable=missing-docstring while retrycount > 0: try: self.logger.info("SSH connect to %s.", self.ip_address) @@ -72,7 +74,7 @@ class SshClient(object): self.shell.recv(self.ssh_revieve_buff) break - except: # pylint: disable=broad-except + except Exception: # pylint: disable=broad-except self.logger.info("SSH timeout for %s...", self.ip_address) time.sleep(time_out) retrycount -= 1 @@ -88,13 +90,14 @@ class SshClient(object): return self.connected def send(self, cmd, prompt, timeout=DEFAULT_SEND_TIMEOUT): + # pylint: disable=missing-docstring if self.connected is True: self.shell.settimeout(timeout) self.logger.debug("Commandset : '%s'", cmd) try: self.shell.send(cmd + '\n') - except: # pylint: disable=broad-except + except Exception: # pylint: disable=broad-except self.logger.error("ssh send timeout : Command : '%s'", cmd) return None @@ -103,7 +106,7 @@ class SshClient(object): time.sleep(RECEIVE_ROOP_WAIT) try: res = self.shell.recv(self.ssh_revieve_buff) - except: # pylint: disable=broad-except + except Exception: # pylint: disable=broad-except self.logger.error("ssh receive timeout : Command : '%s'", cmd) break @@ -112,18 +115,19 @@ class SshClient(object): self.logger.debug("Response : '%s'", res_buff) return res_buff - else: - self.logger.error("Cannot connected to IP '%s'.", self.ip_address) - return None + self.logger.error("Cannot connected to IP '%s'.", self.ip_address) + return None def close(self): + # pylint: disable=missing-docstring if self.connected is True: self.ssh.close() - def error_check(response, err_strs=["error", - "warn", - "unknown command", - "already exist"]): + @staticmethod + def error_check(response, err_strs=None): + # pylint: disable=missing-docstring + if err_strs is None: + err_strs = ["error", "warn", "unknown command", "already exist"] for err in err_strs: if err in response: return False 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 d1c2e324..10e48645 100644 --- a/functest/opnfv_tests/vnf/router/vnf_controller/vm_controller.py +++ b/functest/opnfv_tests/vnf/router/vnf_controller/vm_controller.py @@ -7,6 +7,8 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 +# pylint: disable=missing-docstring + """vm controll module""" import logging 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 814e9e33..a5b1ad85 100644 --- a/functest/opnfv_tests/vnf/router/vnf_controller/vnf_controller.py +++ b/functest/opnfv_tests/vnf/router/vnf_controller/vnf_controller.py @@ -7,14 +7,17 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 +# pylint: disable=missing-docstring + """vrouter controll module""" import logging import os -import prettytable import time import yaml +import prettytable + from functest.opnfv_tests.vnf.router.utilvnf import Utilvnf from functest.opnfv_tests.vnf.router.vnf_controller.checker import Checker from functest.opnfv_tests.vnf.router.vnf_controller.ssh_client import ( @@ -45,6 +48,7 @@ class VnfController(object): def config_vnf(self, source_vnf, destination_vnf, test_cmd_file_path, parameter_file_path, prompt_file_path): + # pylint: disable=too-many-arguments parameter_file = open(parameter_file_path, 'r') cmd_input_param = yaml.safe_load(parameter_file) @@ -63,6 +67,7 @@ class VnfController(object): def result_check(self, target_vnf, reference_vnf, check_rule_file_path_list, parameter_file_path, prompt_file_path): + # pylint: disable=too-many-arguments,too-many-locals res_dict_data_list = [] @@ -93,8 +98,8 @@ class VnfController(object): checker = Checker() res_table = prettytable.PrettyTable( - header_style='upper', padding_width=5, - field_names=['test item', 'result']) + header_style='upper', padding_width=5, + field_names=['test item', 'result']) status = True res_data_list = [] diff --git a/functest/opnfv_tests/vnf/router/vrouter_base.py b/functest/opnfv_tests/vnf/router/vrouter_base.py index a534f1f2..0678313e 100644 --- a/functest/opnfv_tests/vnf/router/vrouter_base.py +++ b/functest/opnfv_tests/vnf/router/vrouter_base.py @@ -7,15 +7,18 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 +# pylint: disable=missing-docstring + """vrouter testing base class module""" import datetime import json import logging import os -import pkg_resources import time +import pkg_resources + import functest.core.vnf as vnf from functest.utils.constants import CONST from functest.opnfv_tests.vnf.router.test_controller import function_test_exec @@ -66,8 +69,7 @@ class VrouterOnBoardingBase(vnf.VnfOnBoarding): test_info["test_kind"] + " test.") (result, result_data) = self.function_test_vrouter( - target_vnf_name, - test_info) + target_vnf_name, test_info) test_result_data_list.append(result_data) if not result: break @@ -115,5 +117,6 @@ class VrouterOnBoardingBase(vnf.VnfOnBoarding): return result, test_result_data def get_vnf_info_list(self, target_vnf_name): + # pylint: disable=unused-argument,no-self-use vnf_info_list = [] return vnf_info_list -- cgit 1.2.3-korg