diff options
author | Cedric Ollivier <cedric.ollivier@orange.com> | 2018-03-12 14:42:23 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2018-03-12 14:42:23 +0000 |
commit | 42867b6f9bd8053b4d91ee0fc1fd127ae2919f15 (patch) | |
tree | 2f25590f0f9ca8719b3853ef873589c35760a8c3 | |
parent | aedd8d57351150bb97dc4d23bc5d0b3e5eb76db9 (diff) | |
parent | 1bdf68f6ed2d55d72d47c0ee4c7a7bc286c4ca3d (diff) |
Merge changes from topic 'refactor_tempest'
* changes:
Rewrite refstack testcase
Fix many pylint warnings
21 files changed, 108 insertions, 452 deletions
diff --git a/docker/restapi/Dockerfile b/docker/restapi/Dockerfile index d4074bec3..32a8b3964 100644 --- a/docker/restapi/Dockerfile +++ b/docker/restapi/Dockerfile @@ -5,7 +5,6 @@ ARG OPENSTACK_TAG=stable/pike ARG ODL_TAG=85448c9d97b89989488e675b29b38ac42d8674e4 ARG RALLY_TAG=stable/0.10 ARG OS_FAULTS_TAG=0.1.16 -ARG REFSTACK_TAG=a59189eaacda24b787ecb65e6634257beba361ec ARG REFSTACK_TARGET=2017.09 ARG FDS_TAG=master ARG VIMS_TAG=stable @@ -29,9 +28,6 @@ RUN apk --no-cache add --update python3 sshpass \ update-requirements -s --source /src/openstack-requirements /src/os-faults/ && \ git clone --depth 1 https://github.com/openstack/rally.git -b $RALLY_TAG /src/rally && \ update-requirements -s --source /src/openstack-requirements /src/rally/ && \ - git clone https://github.com/openstack/refstack-client.git /src/refstack-client && \ - (cd /src/refstack-client && git checkout $REFSTACK_TAG) && \ - update-requirements -s --source /src/openstack-requirements /src/refstack-client/ && \ git clone https://github.com/openstack/patrole.git /src/patrole && \ (cd /src/patrole && git checkout $PATROLE_TAG) && \ update-requirements -s --source /src/openstack-requirements /src/patrole/ && \ @@ -40,7 +36,7 @@ RUN apk --no-cache add --update python3 sshpass \ tempest /src/os-faults && \ pip install --no-cache-dir --src /src -cupper-constraints.txt \ -chttps://git.opnfv.org/functest/plain/upper-constraints.txt?h=$BRANCH \ - -e/src/refstack-client oslotest /src/patrole /src/rally -rthirdparty-requirements.txt && \ + oslotest /src/patrole /src/rally -rthirdparty-requirements.txt && \ python3 -m pip install --no-cache-dir --src /src -cupper-constraints.txt \ -chttps://git.opnfv.org/functest/plain/upper-constraints.txt?h=$BRANCH \ doctor-tests && \ @@ -48,7 +44,6 @@ RUN apk --no-cache add --update python3 sshpass \ (cd /src/odl_test && git checkout $ODL_TAG) && \ git clone --depth 1 -b $FDS_TAG https://gerrit.opnfv.org/gerrit/fds /src/fds && \ git clone --depth 1 -b $VIMS_TAG https://github.com/boucherv-orange/clearwater-live-test /src/vims-test && \ - ln -s /src/tempest /src/refstack-client/.tempest && \ virtualenv --system-site-packages /src/tempest/.venv --python=python2.7 && \ git clone https://github.com/RebacaInc/abot_charm.git /src/epc-requirements/abot_charm && \ python3 -m pip install --no-cache-dir --src /src -cupper-constraints.txt \ @@ -66,7 +61,7 @@ RUN apk --no-cache add --update python3 sshpass \ wget -q -O /etc/neutron/policy.json https://raw.githubusercontent.com/openstack/neutron/$OPENSTACK_TAG/etc/policy.json && \ wget -q -O /etc/glance/policy.json https://raw.githubusercontent.com/openstack/glance/$OPENSTACK_TAG/etc/policy.json && \ cp /usr/lib/python2.7/site-packages/functest/ci/testcases.yaml /usr/lib/python2.7/site-packages/xtesting/ci && \ - rm -r upper-constraints.txt thirdparty-requirements.txt /src/refstack-client/.git /src/odl_test/.git \ + rm -r upper-constraints.txt thirdparty-requirements.txt /src/odl_test/.git \ /src/os-faults /src/rally /src/fds/.git /src/vims-test/.git /src/epc-requirements/abot_charm/.git && \ apk del .build-deps EXPOSE 5000 diff --git a/docker/smoke/Dockerfile b/docker/smoke/Dockerfile index 91885f165..85d942a1e 100644 --- a/docker/smoke/Dockerfile +++ b/docker/smoke/Dockerfile @@ -5,7 +5,6 @@ ARG OPENSTACK_TAG=stable/pike ARG ODL_TAG=85448c9d97b89989488e675b29b38ac42d8674e4 ARG RALLY_TAG=stable/0.10 ARG OS_FAULTS_TAG=0.1.16 -ARG REFSTACK_TAG=a59189eaacda24b787ecb65e6634257beba361ec ARG REFSTACK_TARGET=2017.09 COPY thirdparty-requirements.txt thirdparty-requirements.txt @@ -22,20 +21,16 @@ RUN apk --no-cache add --virtual .build-deps --update \ update-requirements -s --source /src/openstack-requirements /src/os-faults/ && \ git clone --depth 1 https://github.com/openstack/rally.git -b $RALLY_TAG /src/rally && \ update-requirements -s --source /src/openstack-requirements /src/rally/ && \ - git clone https://github.com/openstack/refstack-client.git /src/refstack-client && \ - (cd /src/refstack-client && git checkout $REFSTACK_TAG) && \ - update-requirements -s --source /src/openstack-requirements /src/refstack-client/ && \ pip install --no-cache-dir --src /src -cupper-constraints.txt \ -chttps://git.opnfv.org/functest/plain/upper-constraints.txt?h=$BRANCH \ tempest /src/os-faults && \ pip install --no-cache-dir --src /src -cupper-constraints.txt \ -chttps://git.opnfv.org/functest/plain/upper-constraints.txt?h=$BRANCH \ - -e/src/refstack-client /src/rally -rthirdparty-requirements.txt && \ + /src/rally -rthirdparty-requirements.txt && \ git clone https://git.opendaylight.org/gerrit/p/integration/test.git /src/odl_test && \ (cd /src/odl_test && git checkout $ODL_TAG) && \ - ln -s /src/tempest /src/refstack-client/.tempest && \ virtualenv --system-site-packages /src/tempest/.venv && \ - rm -r upper-constraints.txt thirdparty-requirements.txt /src/refstack-client/.git /src/odl_test/.git \ + rm -r upper-constraints.txt thirdparty-requirements.txt /src/odl_test/.git \ /src/os-faults /src/rally && \ mkdir -p /etc/rally && \ printf "[database]\nconnection = 'sqlite:////var/lib/rally/database/rally.sqlite'" > /etc/rally/rally.conf && \ diff --git a/docker/smoke/testcases.yaml b/docker/smoke/testcases.yaml index 5b1f56a9d..62ac80a59 100644 --- a/docker/smoke/testcases.yaml +++ b/docker/smoke/testcases.yaml @@ -78,14 +78,14 @@ tiers: blocking: false description: >- This test case runs a sub group of tests of the OpenStack - Defcore testcases by using refstack client. + Defcore testcases. dependencies: installer: '' scenario: '' run: module: - 'functest.opnfv_tests.openstack.refstack_client.refstack_client' - class: 'RefstackClient' + 'functest.opnfv_tests.openstack.refstack.refstack' + class: 'Refstack' - case_name: odl diff --git a/functest/api/base.py b/functest/api/base.py index 75f059b74..b10482931 100644 --- a/functest/api/base.py +++ b/functest/api/base.py @@ -26,9 +26,6 @@ LOGGER = logging.getLogger(__name__) class ApiResource(Resource): """ API Resource class""" - def __init__(self): - super(ApiResource, self).__init__() - def _post_args(self): # pylint: disable=no-self-use # pylint: disable=maybe-no-member """ Return action and args after parsing request """ diff --git a/functest/api/resources/v1/envs.py b/functest/api/resources/v1/envs.py index 3e6f05ac9..d808ae3c9 100644 --- a/functest/api/resources/v1/envs.py +++ b/functest/api/resources/v1/envs.py @@ -10,12 +10,12 @@ Resources to handle environment related requests """ -import pkg_resources import socket import IPy from flask import jsonify from flasgger.utils import swag_from +import pkg_resources from functest.api.base import ApiResource from functest.api.common import api_utils diff --git a/functest/api/resources/v1/tiers.py b/functest/api/resources/v1/tiers.py index 523df130e..58540425b 100644 --- a/functest/api/resources/v1/tiers.py +++ b/functest/api/resources/v1/tiers.py @@ -11,11 +11,11 @@ Resources to handle tier related requests """ -import pkg_resources import re from flask import jsonify from flasgger.utils import swag_from +import pkg_resources from functest.api.base import ApiResource from functest.api.common import api_utils diff --git a/functest/api/server.py b/functest/api/server.py index 3200c1a2f..2a6b228ff 100644 --- a/functest/api/server.py +++ b/functest/api/server.py @@ -89,7 +89,7 @@ def init_db(): except TypeError: pass return False - # pylint: disable=bad-builtin + # pylint: disable=bad-option-value,bad-builtin, subclses = filter(func, inspect.getmembers(models, inspect.isclass)) LOGGER.debug('Import models: %s', [subcls[1] for subcls in subclses]) BASE.metadata.create_all(bind=ENGINE) diff --git a/functest/ci/testcases.yaml b/functest/ci/testcases.yaml index ce1823adc..0b7ae4f49 100644 --- a/functest/ci/testcases.yaml +++ b/functest/ci/testcases.yaml @@ -140,14 +140,14 @@ tiers: blocking: false description: >- This test case runs a sub group of tests of the OpenStack - Defcore testcases by using refstack client. + Defcore testcases. dependencies: installer: '' scenario: '' run: module: - 'functest.opnfv_tests.openstack.refstack_client.refstack_client' - class: 'RefstackClient' + 'functest.opnfv_tests.openstack.refstack.refstack' + class: 'Refstack' - case_name: patrole diff --git a/functest/opnfv_tests/openstack/rally/rally.py b/functest/opnfv_tests/openstack/rally/rally.py index f9fb7b8a4..1502d5825 100644 --- a/functest/opnfv_tests/openstack/rally/rally.py +++ b/functest/opnfv_tests/openstack/rally/rally.py @@ -189,7 +189,7 @@ class RallyBase(testcase.TestCase): return False for result in report.get('result'): - if result is None or len(result.get('error')) > 0: + if result is None or result.get('error'): return False return True diff --git a/functest/opnfv_tests/openstack/refstack_client/__init__.py b/functest/opnfv_tests/openstack/refstack/__init__.py index e69de29bb..e69de29bb 100644 --- a/functest/opnfv_tests/openstack/refstack_client/__init__.py +++ b/functest/opnfv_tests/openstack/refstack/__init__.py diff --git a/functest/opnfv_tests/openstack/refstack/refstack.py b/functest/opnfv_tests/openstack/refstack/refstack.py new file mode 100644 index 000000000..b5766a020 --- /dev/null +++ b/functest/opnfv_tests/openstack/refstack/refstack.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python + +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 + +"""Refstack testcase implementation.""" + +import logging +import os +import shutil +import time + +from refstack_client import list_parser +from xtesting.core import testcase +from xtesting.energy import energy + +from functest.opnfv_tests.openstack.snaps import snaps_utils +from functest.opnfv_tests.openstack.tempest import conf_utils +from functest.opnfv_tests.openstack.tempest import tempest +from functest.utils import config + + +class Refstack(tempest.TempestCommon): + """Refstack testcase implementation class.""" + + __logger = logging.getLogger(__name__) + + defcorelist = os.path.join( + getattr(config.CONF, 'dir_refstack_data'), 'defcore.txt') + + def __init__(self, **kwargs): + if "case_name" not in kwargs: + kwargs["case_name"] = 'refstack' + super(Refstack, self).__init__(**kwargs) + self.res_dir = os.path.join( + getattr(config.CONF, 'dir_results'), 'refstack') + self.list = os.path.join(self.res_dir, 'tempest-list.txt') + + @energy.enable_recording + def run(self, **kwargs): + """Start Refstack testcase.""" + self.start_time = time.time() + try: + if not os.path.exists(self.res_dir): + os.makedirs(self.res_dir) + resources = self.resources.create() + compute_cnt = snaps_utils.get_active_compute_cnt( + self.resources.os_creds) + conf_file = conf_utils.configure_verifier(self.deployment_dir) + conf_utils.configure_tempest_update_params( + conf_file, self.res_dir, + network_name=resources.get("network_name"), + image_id=resources.get("image_id"), + flavor_id=resources.get("flavor_id"), + compute_cnt=compute_cnt) + parser = list_parser.TestListParser('/src/tempest') + nfile = parser.get_normalized_test_list(Refstack.defcorelist) + shutil.copyfile(nfile, self.list) + self.run_verifier_tests() + self.parse_verifier_result() + self.generate_report() + res = testcase.TestCase.EX_OK + except Exception as err: # pylint: disable=broad-except + self.__logger.error('Error with run: %s', err) + res = testcase.TestCase.EX_RUN_ERROR + finally: + self.resources.cleanup() + self.stop_time = time.time() + return res diff --git a/functest/opnfv_tests/openstack/refstack_client/refstack_client.py b/functest/opnfv_tests/openstack/refstack_client/refstack_client.py deleted file mode 100644 index bcd42c30e..000000000 --- a/functest/opnfv_tests/openstack/refstack_client/refstack_client.py +++ /dev/null @@ -1,261 +0,0 @@ -#!/usr/bin/env python - -# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 - -"""Refstack client testcase implemenation.""" - -from __future__ import division - -import argparse -import ConfigParser -import logging -import os -import re -import sys -import subprocess -import time - -from xtesting.core import testcase -from xtesting.energy import energy - -from functest.opnfv_tests.openstack.tempest import conf_utils -from functest.opnfv_tests.openstack.tempest import tempest -from functest.utils import config -from functest.utils import functest_utils - - -__author__ = ("Matthew Li <matthew.lijun@huawei.com>," - "Linda Wang <wangwulin@huawei.com>") - -# logging configuration """ -LOGGER = logging.getLogger(__name__) - - -class RefstackClient(testcase.TestCase): - """RefstackClient testcase implementation class.""" - # pylint: disable=too-many-instance-attributes - - defcorelist = os.path.join( - getattr(config.CONF, 'dir_refstack_data'), 'defcore.txt') - - def __init__(self, **kwargs): - """Initialize RefstackClient testcase object.""" - if "case_name" not in kwargs: - kwargs["case_name"] = "refstack_defcore" - super(RefstackClient, self).__init__(**kwargs) - self.res_dir = os.path.join( - getattr(config.CONF, 'dir_results'), 'refstack') - self.conf_path = os.path.join(self.res_dir, 'refstack_tempest.conf') - - @staticmethod - def run_defcore(conf, testlist): - """Run defcore sys command.""" - insecure = '' - if ('https' in os.environ['OS_AUTH_URL'] and - os.getenv('OS_INSECURE', '').lower() == 'true'): - insecure = '-k' - cmd = ("refstack-client test {0} -c {1} -v --test-list {2}" - .format(insecure, conf, testlist)) - LOGGER.info("Starting Refstack_defcore test case: '%s'.", cmd) - functest_utils.execute_command(cmd) - - def run_defcore_default(self): - """Run default defcore sys command.""" - insecure = '' - if ('https' in os.environ['OS_AUTH_URL'] and - os.getenv('OS_INSECURE', '').lower() == 'true'): - insecure = '-k' - options = ["-v"] if not insecure else ["-v", insecure] - cmd = (["refstack-client", "test", "-c", self.conf_path] + - options + ["--test-list", self.defcorelist]) - LOGGER.info("Starting Refstack_defcore test case: '%s'.", cmd) - with open(os.path.join(self.res_dir, "refstack.log"), 'w+') as fstdout: - subprocess.call(cmd, shell=False, stdout=fstdout, - stderr=subprocess.STDOUT) - - def parse_refstack_result(self): - """Parse Refstack results.""" - try: - with open(os.path.join(self.res_dir, - "refstack.log"), 'r') as logfile: - for line in logfile.readlines(): - if 'Tests' in line: - break - if re.search(r"\} tempest\.", line): - LOGGER.info(line.replace('\n', '')) - - with open(os.path.join(self.res_dir, - "refstack.log"), 'r') as logfile: - output = logfile.read() - - for match in re.findall(r"Ran: (\d+) tests in (\d+\.\d{4}) sec.", - output): - num_tests = match[0] - LOGGER.info("Ran: %s tests in %s sec.", num_tests, match[1]) - for match in re.findall(r"(- Passed: )(\d+)", output): - num_success = match[1] - LOGGER.info("".join(match)) - for match in re.findall(r"(- Skipped: )(\d+)", output): - num_skipped = match[1] - LOGGER.info("".join(match)) - for match in re.findall(r"(- Failed: )(\d+)", output): - num_failures = match[1] - LOGGER.info("".join(match)) - success_testcases = [] - for match in re.findall(r"\{0\} (.*?) \.{3} ok", output): - success_testcases.append(match) - failed_testcases = [] - for match in re.findall(r"\{0\} (.*?) \.{3} FAILED", output): - failed_testcases.append(match) - skipped_testcases = [] - for match in re.findall(r"\{0\} (.*?) \.{3} SKIPPED:", output): - skipped_testcases.append(match) - - num_executed = int(num_tests) - int(num_skipped) - - try: - self.result = 100 * int(num_success) / int(num_executed) - except ZeroDivisionError: - LOGGER.error("No test has been executed") - - self.details = {"tests": int(num_tests), - "failures": int(num_failures), - "success": success_testcases, - "errors": failed_testcases, - "skipped": skipped_testcases} - except Exception: # pylint: disable=broad-except - self.result = 0 - LOGGER.info("Testcase %s success_rate is %s%%", - self.case_name, self.result) - - def configure_tempest_defcore(self): - # pylint: disable=too-many-arguments - """ - Add/update needed parameters into tempest.conf file - """ - resources = tempest.TempestResourcesManager().create( - create_project=True, use_custom_images=True, - use_custom_flavors=True) - verifier_id = conf_utils.get_verifier_id() - deployment_id = conf_utils.get_verifier_deployment_id() - deployment_dir = conf_utils.get_verifier_deployment_dir( - verifier_id, deployment_id) - conf_file = conf_utils.configure_verifier(deployment_dir) - conf_utils.configure_tempest_update_params( - conf_file, self.res_dir, resources.get("network_name"), - resources.get("image_id"), resources.get("flavor_id")) - LOGGER.debug( - "Updating selected tempest.conf parameters for defcore...") - rconfig = ConfigParser.RawConfigParser() - rconfig.read(conf_file) - rconfig.set( - 'DEFAULT', 'log_file', '{}/tempest.log'.format(deployment_dir)) - rconfig.set('oslo_concurrency', 'lock_path', - '{}/lock_files'.format(deployment_dir)) - conf_utils.generate_test_accounts_file( - tenant_id=resources.get("project_id")) - rconfig.set('auth', 'test_accounts_file', - conf_utils.TEST_ACCOUNTS_FILE) - rconfig.set('scenario', 'img_dir', '{}'.format(deployment_dir)) - rconfig.set('scenario', 'img_file', 'tempest-image') - rconfig.set('compute', 'image_ref', resources.get("image_id")) - rconfig.set('compute', 'image_ref_alt', resources.get("image_id_alt")) - rconfig.set('compute', 'flavor_ref', resources.get("flavor_id")) - rconfig.set('compute', 'flavor_ref_alt', - resources.get("flavor_id_alt")) - if not os.path.exists(self.res_dir): - os.makedirs(self.res_dir) - with open(self.conf_path, 'w') as config_fd: - rconfig.write(config_fd) - - @energy.enable_recording - def run(self, **kwargs): - """ - Start RefstackClient testcase. - - used for functest command line, - functest testcase run refstack_defcore - """ - self.start_time = time.time() - try: - # Make sure that Tempest is configured - self.configure_tempest_defcore() - self.run_defcore_default() - self.parse_refstack_result() - res = testcase.TestCase.EX_OK - except Exception: # pylint: disable=broad-except - LOGGER.exception("Error with run") - res = testcase.TestCase.EX_RUN_ERROR - self.stop_time = time.time() - return res - - @staticmethod - def main(**kwargs): - """ - Execute RefstackClient testcase manually. - - used for manually running, - python refstack_client.py -c <tempest_conf_path> - --testlist <testlist_path> - can generate a reference refstack_tempest.conf by - python tempest_conf.py - """ - try: - conf_path = kwargs['config'] - if not os.path.isfile(conf_path): - LOGGER.error("Conf file not valid: %s", conf_path) - return testcase.TestCase.EX_RUN_ERROR - testlist = kwargs['testlist'] - if not os.path.isfile(testlist): - LOGGER.error("testlist file not valid: %s", testlist) - return testcase.TestCase.EX_RUN_ERROR - except KeyError as exc: - LOGGER.error("Cannot run refstack client. Please check " - "%s", exc) - return testcase.TestCase.EX_RUN_ERROR - try: - RefstackClient.run_defcore(conf_path, testlist) - except Exception as exc: # pylint: disable=broad-except - LOGGER.error('Error with run: %s', exc) - return testcase.TestCase.EX_RUN_ERROR - return testcase.TestCase.EX_OK - - -class RefstackClientParser(object): # pylint: disable=too-few-public-methods - """Command line argument parser helper.""" - - def __init__(self): - """Initialize helper object.""" - self.parser = argparse.ArgumentParser() - self.parser.add_argument( - '-c', '--config', - help='the file path of refstack_tempest.conf') - self.parser.add_argument( - '-t', '--testlist', - help='Specify the file path or URL of a test list text file. ' - 'This test list will contain specific test cases that ' - 'should be tested.', - default=RefstackClient.defcorelist) - - def parse_args(self, argv=None): - """Parse command line arguments.""" - return vars(self.parser.parse_args(argv)) - - -def main(): - """Run RefstackClient testcase with CLI.""" - logging.basicConfig() - refstackclient = RefstackClient() - parser = RefstackClientParser() - args = parser.parse_args(sys.argv[1:]) - try: - result = refstackclient.main(**args) - if result != testcase.TestCase.EX_OK: - return result - except Exception: # pylint: disable=broad-except - return testcase.TestCase.EX_RUN_ERROR diff --git a/functest/opnfv_tests/vnf/ims/ixia/utils/IxLoadUtils.py b/functest/opnfv_tests/vnf/ims/ixia/utils/IxLoadUtils.py index 50dfbc661..bc71a38cf 100644 --- a/functest/opnfv_tests/vnf/ims/ixia/utils/IxLoadUtils.py +++ b/functest/opnfv_tests/vnf/ims/ixia/utils/IxLoadUtils.py @@ -7,11 +7,12 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 -import requests import sys import time import logging +import requests + from functest.opnfv_tests.vnf.ims.ixia.utils import IxRestUtils diff --git a/functest/opnfv_tests/vnf/router/utilvnf.py b/functest/opnfv_tests/vnf/router/utilvnf.py index 6861b3865..2865175b3 100644 --- a/functest/opnfv_tests/vnf/router/utilvnf.py +++ b/functest/opnfv_tests/vnf/router/utilvnf.py @@ -20,7 +20,6 @@ import yaml from functest.utils import config from git import Repo -from requests.auth import HTTPBasicAuth from snaps.openstack.utils import nova_utils @@ -175,7 +174,7 @@ class Utilvnf(object): # pylint: disable=too-many-instance-attributes response = requests.get( url, - auth=HTTPBasicAuth('admin', 'admin'), + auth=requests.auth.HTTPBasicAuth('admin', 'admin'), headers={'Tenant': 'default_tenant'}) resp_data = response.json() diff --git a/functest/tests/unit/openstack/refstack_client/__init__.py b/functest/tests/unit/openstack/refstack_client/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/functest/tests/unit/openstack/refstack_client/__init__.py +++ /dev/null diff --git a/functest/tests/unit/openstack/refstack_client/test_refstack_client.py b/functest/tests/unit/openstack/refstack_client/test_refstack_client.py deleted file mode 100644 index c26857e4d..000000000 --- a/functest/tests/unit/openstack/refstack_client/test_refstack_client.py +++ /dev/null @@ -1,148 +0,0 @@ -#!/usr/bin/env python - -# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 - -# pylint: disable=missing-docstring - -import logging -import os -import unittest - -import mock -import pkg_resources -from snaps.openstack.os_credentials import OSCreds -from xtesting.core import testcase - -from functest.opnfv_tests.openstack.refstack_client.refstack_client import \ - RefstackClient, RefstackClientParser - -__author__ = ("Matthew Li <matthew.lijun@huawei.com>," - "Linda Wang <wangwulin@huawei.com>") - - -class OSRefstackClientTesting(unittest.TestCase): - """The class testing RefstackClient """ - # pylint: disable=missing-docstring, too-many-public-methods - - _config = pkg_resources.resource_filename( - 'functest', - 'opnfv_tests/openstack/refstack_client/refstack_tempest.conf') - - def setUp(self): - self.default_args = {'config': None, - 'testlist': RefstackClient.defcorelist} - os.environ['OS_AUTH_URL'] = 'https://ip:5000/v3' - os.environ['OS_INSECURE'] = 'true' - self.case_name = 'refstack_defcore' - self.result = 0 - self.os_creds = OSCreds( - username='user', password='pass', - auth_url='http://foo.com:5000/v3', project_name='bar') - self.details = {"tests": 3, - "failures": 1, - "success": ['tempest.api.compute [18.464988s]'], - "errors": ['tempest.api.volume [0.230334s]'], - "skipped": ['tempest.api.network [1.265828s]']} - - def _create_client(self): - with mock.patch('snaps.openstack.tests.openstack_tests.' - 'get_credentials', return_value=self.os_creds): - return RefstackClient() - - @mock.patch('functest.utils.functest_utils.execute_command') - def test_run_defcore_insecure(self, m_cmd): - insecure = '-k' - config = 'tempest.conf' - testlist = 'testlist' - client = self._create_client() - cmd = ("refstack-client test {0} -c {1} -v --test-list {2}".format( - insecure, config, testlist)) - client.run_defcore(config, testlist) - m_cmd.assert_any_call(cmd) - - @mock.patch('functest.utils.functest_utils.execute_command') - def test_run_defcore(self, m_cmd): - os.environ['OS_AUTH_URL'] = 'http://ip:5000/v3' - insecure = '' - config = 'tempest.conf' - testlist = 'testlist' - client = self._create_client() - cmd = ("refstack-client test {0} -c {1} -v --test-list {2}".format( - insecure, config, testlist)) - client.run_defcore(config, testlist) - m_cmd.assert_any_call(cmd) - - @mock.patch('functest.opnfv_tests.openstack.refstack_client.' - 'refstack_client.LOGGER.info') - @mock.patch('__builtin__.open', side_effect=Exception) - def test_parse_refstack_result_fail(self, *args): - self._create_client().parse_refstack_result() - args[1].assert_called_once_with( - "Testcase %s success_rate is %s%%", - self.case_name, self.result) - - def test_parse_refstack_result_ok(self): - log_file = (''' - {0} tempest.api.compute [18.464988s] ... ok - {0} tempest.api.volume [0.230334s] ... FAILED - {0} tempest.api.network [1.265828s] ... SKIPPED: - Ran: 3 tests in 1259.0000 sec. - - Passed: 1 - - Skipped: 1 - - Failed: 1 - ''') - client = self._create_client() - with mock.patch('__builtin__.open', - mock.mock_open(read_data=log_file)): - client.parse_refstack_result() - self.assertEqual(client.details, self.details) - - def _get_main_kwargs(self, key=None): - kwargs = {'config': self._config, - 'testlist': RefstackClient.defcorelist} - if key: - del kwargs[key] - return kwargs - - def _test_main_missing_keyword(self, key): - kwargs = self._get_main_kwargs(key) - client = self._create_client() - self.assertEqual(client.main(**kwargs), - testcase.TestCase.EX_RUN_ERROR) - - def test_main_missing_conf(self): - self._test_main_missing_keyword('config') - - def test_main_missing_testlist(self): - self._test_main_missing_keyword('testlist') - - def _test_argparser(self, arg, value): - self.default_args[arg] = value - parser = RefstackClientParser() - self.assertEqual(parser.parse_args(["--{}={}".format(arg, value)]), - self.default_args) - - def test_argparser_conf(self): - self._test_argparser('config', self._config) - - def test_argparser_testlist(self): - self._test_argparser('testlist', RefstackClient.defcorelist) - - def test_argparser_multiple_args(self): - self.default_args['config'] = self._config - self.default_args['testlist'] = RefstackClient.defcorelist - parser = RefstackClientParser() - self.assertEqual(parser.parse_args( - ["--config={}".format(self._config), - "--testlist={}".format(RefstackClient.defcorelist)]), - self.default_args) - - -if __name__ == "__main__": - logging.disable(logging.CRITICAL) - unittest.main(verbosity=2) diff --git a/functest/tests/unit/utils/test_functest_utils.py b/functest/tests/unit/utils/test_functest_utils.py index 77328fda8..d35ed8ced 100644 --- a/functest/tests/unit/utils/test_functest_utils.py +++ b/functest/tests/unit/utils/test_functest_utils.py @@ -20,6 +20,7 @@ from functest.utils import functest_utils class FunctestUtilsTesting(unittest.TestCase): + # pylint: disable=too-many-instance-attributes readline = 0 test_ip = ['10.1.23.4', '10.1.14.15', '10.1.16.15'] @@ -90,8 +91,8 @@ class FunctestUtilsTesting(unittest.TestCase): @mock.patch('functest.utils.functest_utils.LOGGER.error') @mock.patch('functest.utils.functest_utils.LOGGER.info') - def test_execute_command_args_present_with_error(self, mock_logger_info, - mock_logger_error): + def test_exec_cmd_args_present_ko(self, mock_logger_info, + mock_logger_error): with mock.patch('functest.utils.functest_utils.subprocess.Popen') \ as mock_subproc_open, \ mock.patch('six.moves.builtins.open', @@ -120,8 +121,7 @@ class FunctestUtilsTesting(unittest.TestCase): mock_logger_error.assert_called_once_with(self.error_msg) @mock.patch('functest.utils.functest_utils.LOGGER.info') - def test_execute_command_args_present_with_success(self, mock_logger_info, - ): + def test_exec_cmd_args_present_ok(self, mock_logger_info): with mock.patch('functest.utils.functest_utils.subprocess.Popen') \ as mock_subproc_open, \ mock.patch('six.moves.builtins.open', @@ -149,7 +149,8 @@ class FunctestUtilsTesting(unittest.TestCase): mopen.assert_called_once_with(self.output_file, "w") @mock.patch('sys.stdout') - def test_execute_command_args_missing_with_success(self, stdout=None): + def test_exec_cmd_args_missing_ok(self, stdout=None): + # pylint: disable=unused-argument with mock.patch('functest.utils.functest_utils.subprocess.Popen') \ as mock_subproc_open: @@ -172,7 +173,8 @@ class FunctestUtilsTesting(unittest.TestCase): self.assertEqual(resp, 0) @mock.patch('sys.stdout') - def test_execute_command_args_missing_with_error(self, stdout=None): + def test_exec_cmd_args_missing_ko(self, stdout=None): + # pylint: disable=unused-argument with mock.patch('functest.utils.functest_utils.subprocess.Popen') \ as mock_subproc_open: @@ -193,7 +195,7 @@ class FunctestUtilsTesting(unittest.TestCase): output_file=None) self.assertEqual(resp, 1) - def test_get_parameter_from_yaml_failed(self): + def test_get_param_from_yaml_failed(self): self.file_yaml['general'] = None with mock.patch('six.moves.builtins.open', mock.mock_open()), \ mock.patch('functest.utils.functest_utils.yaml.safe_load') \ @@ -206,7 +208,7 @@ class FunctestUtilsTesting(unittest.TestCase): " defined in config_functest.yaml" % self.parameter) in excep.exception) - def test_get_parameter_from_yaml_default(self): + def test_get_param_from_yaml_def(self): with mock.patch('six.moves.builtins.open', mock.mock_open()), \ mock.patch('functest.utils.functest_utils.yaml.safe_load') \ as mock_yaml: diff --git a/requirements.txt b/requirements.txt index 304bb8746..3196f52a8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -27,3 +27,4 @@ httplib2>=0.7.5 # MIT oslo.serialization!=2.19.1,>=1.10.0 # Apache-2.0 oslo.utils>=3.20.0 # Apache-2.0 xtesting +refstack-client @@ -12,7 +12,6 @@ scripts = console_scripts = functest = functest.cli.cli_base:cli functest_odl = functest.opnfv_tests.sdn.odl.odl:main - functest_refstack_client = functest.opnfv_tests.openstack.refstack_client.refstack_client:main check_deployment = functest.ci.check_deployment:main functest_restapi = functest.api.server:main @@ -33,7 +33,7 @@ modules = functest.ci functest.cli functest.opnfv_tests.openstack.rally - functest.opnfv_tests.openstack.refstack_client + functest.opnfv_tests.openstack.refstack functest.opnfv_tests.openstack.snaps functest.opnfv_tests.openstack.tempest functest.opnfv_tests.openstack.vping @@ -43,21 +43,23 @@ modules = functest.tests.unit.cli functest.tests.unit.odl functest.tests.unit.openstack.rally - functest.tests.unit.openstack.refstack_client functest.tests.unit.openstack.snaps functest.tests.unit.openstack.tempest functest.tests.unit.openstack.vping functest.tests.unit.vnf.router + functest.tests.unit.utils functest.utils.config functest.utils.constants functest.utils.env functest.utils.functest_utils commands = bash -c "\ - pylint -f parseable --disable=locally-disabled functest | \ + pylint -f parseable --ignore-imports=y --disable=locally-disabled functest | \ tee pylint.out | sed -ne '/Raw metrics/,//p'" pylint --reports=n --errors-only functest - pylint --disable=locally-disabled --ignore-imports=y --reports=n {[testenv:pylint]modules} + pylint --disable=locally-disabled \ + --disable=duplicate-code \ + --ignore-imports=y --reports=n {[testenv:pylint]modules} [testenv:yamllint] basepython = python2.7 diff --git a/upper-constraints.txt b/upper-constraints.txt index df37ad954..ea6809dd0 100644 --- a/upper-constraints.txt +++ b/upper-constraints.txt @@ -9,6 +9,7 @@ git+https://gerrit.opnfv.org/gerrit/domino#egg=domino git+https://gerrit.opnfv.org/gerrit/parser#egg=nfv-heattranslator&subdirectory=tosca2heat/heat-translator git+https://gerrit.opnfv.org/gerrit/parser#egg=nfv-toscaparser&subdirectory=tosca2heat/tosca-parser -e git+https://gerrit.opnfv.org/gerrit/parser#egg=nfv-parser +git+https://github.com/openstack/refstack-client@a59189eaacda24b787ecb65e6634257beba361ec#egg=refstack-client cloudify-rest-client===4.0 openbaton-cli===2.2.1b7 robotframework===3.0.2 |