diff options
Diffstat (limited to 'functest')
12 files changed, 123 insertions, 99 deletions
diff --git a/functest/core/vnf.py b/functest/core/vnf.py index 856e62b5..5339e42e 100644 --- a/functest/core/vnf.py +++ b/functest/core/vnf.py @@ -198,8 +198,7 @@ class VnfOnBoarding(base.TestCase): * the user, * the tenant """ - self.__logger.info("test cleaning") - self.__logger.info('Remove the cloudify manager OS object ..') + self.__logger.info('Removing the VNF resources ..') for creator in reversed(self.created_object): try: creator.clean() 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 <shuya.nakama@okinawaopenlabs.org>" 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 diff --git a/functest/tests/unit/vnf/router/test_cloudify_vrouter.py b/functest/tests/unit/vnf/router/test_cloudify_vrouter.py index 2e24e7e9..9711da72 100644 --- a/functest/tests/unit/vnf/router/test_cloudify_vrouter.py +++ b/functest/tests/unit/vnf/router/test_cloudify_vrouter.py @@ -20,11 +20,7 @@ from functest.opnfv_tests.vnf.router import cloudify_vrouter class CloudifyVrouterTesting(unittest.TestCase): - @mock.patch('functest.opnfv_tests.vnf.router.cloudify_vrouter.Utilvnf') - @mock.patch('functest.opnfv_tests.vnf.router.cloudify_vrouter.vrouter_base' - '.Utilvnf') - @mock.patch('os.makedirs') - def setUp(self, *args): + def setUp(self): self.tenant = 'cloudify_vrouter' self.creds = {'username': 'user', @@ -46,13 +42,20 @@ class CloudifyVrouterTesting(unittest.TestCase): {'name': 'm1.medium', 'ram_min': 2048}}}} - with mock.patch('functest.opnfv_tests.vnf.router.cloudify_vrouter.' - 'get_config', return_value={ - 'tenant_images': 'foo', - 'orchestrator': self.orchestrator, - 'vnf': self.vnf, - 'vnf_test_suite': '', - 'version': 'whatever'}): + # pylint: disable=bad-continuation + with mock.patch( + 'functest.opnfv_tests.vnf.router.cloudify_vrouter.Utilvnf'), \ + mock.patch('functest.opnfv_tests.vnf.router.' + 'cloudify_vrouter.vrouter_base.Utilvnf'), \ + mock.patch('os.makedirs'), \ + mock.patch( + 'functest.opnfv_tests.vnf.router.cloudify_vrouter.' + 'get_config', + return_value={ + 'tenant_images': 'foo', + 'orchestrator': self.orchestrator, + 'vnf': self.vnf, 'vnf_test_suite': '', + 'version': 'whatever'}): self.router_vnf = cloudify_vrouter.CloudifyVrouter() diff --git a/functest/utils/env.py b/functest/utils/env.py index f0952500..f6e6e100 100644 --- a/functest/utils/env.py +++ b/functest/utils/env.py @@ -1,52 +1,54 @@ #!/usr/bin/env python -import pkg_resources +# pylint: disable=missing-docstring + import os import re +import pkg_resources import six -default_envs = { - 'NODE_NAME': 'unknown_pod', - 'CI_DEBUG': 'false', - 'DEPLOY_SCENARIO': 'os-nosdn-nofeature-noha', - 'DEPLOY_TYPE': 'virt', - 'INSTALLER_TYPE': None, - 'INSTALLER_IP': None, - 'BUILD_TAG': None, - 'OS_ENDPOINT_TYPE': None, - 'OS_AUTH_URL': None, - 'CONFIG_FUNCTEST_YAML': pkg_resources.resource_filename( - 'functest', 'ci/config_functest.yaml'), - 'OS_INSECURE': '', - 'OS_REGION_NAME': 'RegionOne' -} - - -class Environment(object): +class Environment(object): # pylint: disable=too-few-public-methods + + default_envs = { + 'NODE_NAME': 'unknown_pod', + 'CI_DEBUG': 'false', + 'DEPLOY_SCENARIO': 'os-nosdn-nofeature-noha', + 'DEPLOY_TYPE': 'virt', + 'INSTALLER_TYPE': None, + 'INSTALLER_IP': None, + 'BUILD_TAG': None, + 'OS_ENDPOINT_TYPE': None, + 'OS_AUTH_URL': None, + 'CONFIG_FUNCTEST_YAML': pkg_resources.resource_filename( + 'functest', 'ci/config_functest.yaml'), + 'OS_INSECURE': '', + 'OS_REGION_NAME': 'RegionOne' + } def __init__(self): - for k, v in six.iteritems(os.environ): - self.__setattr__(k, v) - for k, v in six.iteritems(default_envs): - if k not in os.environ: - self.__setattr__(k, v) + for key, value in six.iteritems(os.environ): + setattr(self, key, value) + for key, value in six.iteritems(self.default_envs): + if key not in os.environ: + setattr(self, key, value) self._set_ci_run() if 'CI_LOOP' not in os.environ: self._set_ci_loop() def _set_ci_run(self): - if self.BUILD_TAG: - self.IS_CI_RUN = True + if getattr(self, "BUILD_TAG"): + setattr(self, "IS_CI_RUN", True) else: - self.IS_CI_RUN = False + setattr(self, "IS_CI_RUN", False) def _set_ci_loop(self): - if self.BUILD_TAG and re.search("daily", self.BUILD_TAG): - self.CI_LOOP = "daily" + if (getattr(self, "BUILD_TAG") and + re.search("daily", getattr(self, "BUILD_TAG"))): + setattr(self, "CI_LOOP", "daily") else: - self.CI_LOOP = "weekly" + setattr(self, "CI_LOOP", "weekly") ENV = Environment() |