aboutsummaryrefslogtreecommitdiffstats
path: root/functest
diff options
context:
space:
mode:
Diffstat (limited to 'functest')
-rw-r--r--functest/ci/check_deployment.py2
-rw-r--r--functest/core/vnf.py3
-rw-r--r--functest/opnfv_tests/openstack/rally/rally.py190
-rw-r--r--functest/opnfv_tests/openstack/refstack_client/refstack_client.py20
-rw-r--r--functest/opnfv_tests/openstack/refstack_client/tempest_conf.py35
-rw-r--r--functest/opnfv_tests/openstack/snaps/api_check.py6
-rw-r--r--functest/opnfv_tests/openstack/snaps/connection_check.py6
-rw-r--r--functest/opnfv_tests/openstack/snaps/health_check.py6
-rw-r--r--functest/opnfv_tests/openstack/snaps/smoke.py6
-rw-r--r--functest/opnfv_tests/openstack/snaps/snaps_suite_builder.py4
-rw-r--r--functest/opnfv_tests/openstack/snaps/snaps_test_runner.py20
-rw-r--r--functest/opnfv_tests/openstack/snaps/snaps_utils.py25
-rw-r--r--functest/opnfv_tests/openstack/tempest/tempest.py1
-rw-r--r--functest/opnfv_tests/openstack/vping/vping_base.py67
-rw-r--r--functest/opnfv_tests/openstack/vping/vping_ssh.py8
-rw-r--r--functest/opnfv_tests/openstack/vping/vping_userdata.py4
-rw-r--r--functest/opnfv_tests/vnf/epc/juju_epc.py10
-rw-r--r--functest/opnfv_tests/vnf/router/cloudify_vrouter.py84
-rw-r--r--functest/opnfv_tests/vnf/router/test_controller/function_test_exec.py2
-rw-r--r--functest/opnfv_tests/vnf/router/utilvnf.py35
-rw-r--r--functest/opnfv_tests/vnf/router/vnf_controller/checker.py8
-rw-r--r--functest/opnfv_tests/vnf/router/vnf_controller/command_generator.py10
-rw-r--r--functest/opnfv_tests/vnf/router/vnf_controller/ssh_client.py28
-rw-r--r--functest/opnfv_tests/vnf/router/vnf_controller/vm_controller.py2
-rw-r--r--functest/opnfv_tests/vnf/router/vnf_controller/vnf_controller.py11
-rw-r--r--functest/opnfv_tests/vnf/router/vrouter_base.py9
-rw-r--r--functest/tests/unit/ci/test_check_deployment.py8
-rw-r--r--functest/tests/unit/openstack/rally/test_rally.py16
-rw-r--r--functest/tests/unit/openstack/refstack_client/test_refstack_client.py10
-rw-r--r--functest/tests/unit/openstack/snaps/test_snaps.py301
-rw-r--r--functest/tests/unit/openstack/vping/__init__.py0
-rw-r--r--functest/tests/unit/openstack/vping/test_vping.py29
-rw-r--r--functest/tests/unit/utils/test_functest_utils.py12
-rw-r--r--functest/tests/unit/vnf/epc/__init__.py0
-rw-r--r--functest/tests/unit/vnf/epc/test_juju_epc.py1
-rw-r--r--functest/tests/unit/vnf/router/test_cloudify_vrouter.py26
-rw-r--r--functest/utils/config.py1
-rw-r--r--functest/utils/constants.py5
-rw-r--r--functest/utils/env.py62
-rw-r--r--functest/utils/functest_utils.py92
40 files changed, 600 insertions, 565 deletions
diff --git a/functest/ci/check_deployment.py b/functest/ci/check_deployment.py
index 81607dff..8d19d850 100644
--- a/functest/ci/check_deployment.py
+++ b/functest/ci/check_deployment.py
@@ -44,7 +44,7 @@ def verify_connectivity(endpoint):
port = url.port
if not port:
port = 443 if url.scheme == "https" else 80
- connection.connect(url.hostname, port)
+ connection.connect((url.hostname, port))
LOGGER.debug('%s:%s is reachable!', url.hostname, port)
return True
except socket.error:
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/openstack/rally/rally.py b/functest/opnfv_tests/openstack/rally/rally.py
index 103c3a7e..59a67095 100644
--- a/functest/opnfv_tests/openstack/rally/rally.py
+++ b/functest/opnfv_tests/openstack/rally/rally.py
@@ -21,6 +21,7 @@ import time
import uuid
import pkg_resources
+import prettytable
import yaml
from functest.core import testcase
@@ -35,7 +36,6 @@ from snaps.config.network import NetworkConfig, SubnetConfig
from snaps.config.router import RouterConfig
from snaps.openstack.create_flavor import OpenStackFlavor
-from snaps.openstack.tests import openstack_tests
from snaps.openstack.utils import deploy_utils
LOGGER = logging.getLogger(__name__)
@@ -91,20 +91,8 @@ class RallyBase(testcase.TestCase):
def __init__(self, **kwargs):
"""Initialize RallyBase object."""
super(RallyBase, self).__init__(**kwargs)
- if 'os_creds' in kwargs:
- self.os_creds = kwargs['os_creds']
- else:
- creds_override = None
- if hasattr(CONST, 'snaps_os_creds_override'):
- creds_override = CONST.__getattribute__(
- 'snaps_os_creds_override')
-
- self.os_creds = openstack_tests.get_credentials(
- os_env_file=CONST.__getattribute__('openstack_creds'),
- overrides=creds_override)
-
+ self.os_creds = kwargs.get('os_creds') or snaps_utils.get_credentials()
self.guid = '-' + str(uuid.uuid4())
-
self.creators = []
self.mode = ''
self.summary = []
@@ -354,8 +342,9 @@ class RallyBase(testcase.TestCase):
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
- output = self._get_output(proc, test_name)
+ output = self.get_cmd_output(proc)
task_id = self.get_task_id(output)
+
LOGGER.debug('task_id : %s', task_id)
if task_id is None:
@@ -375,93 +364,62 @@ class RallyBase(testcase.TestCase):
self.RESULTS_DIR)
os.makedirs(self.RESULTS_DIR)
- # write html report file
- report_html_name = 'opnfv-{}.html'.format(test_name)
- report_html_dir = os.path.join(self.RESULTS_DIR, report_html_name)
- cmd = (["rally", "task", "report", task_id, "--out", report_html_dir])
-
+ # get and save rally operation JSON result
+ cmd = (["rally", "task", "detailed", task_id])
LOGGER.debug('running command: %s', cmd)
- subprocess.Popen(cmd, stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
+ json_detailed = self.get_cmd_output(proc)
+ LOGGER.info('%s', json_detailed)
- # get and save rally operation JSON result
cmd = (["rally", "task", "results", task_id])
LOGGER.debug('running command: %s', cmd)
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
json_results = self.get_cmd_output(proc)
+ self._append_summary(json_results, test_name)
report_json_name = 'opnfv-{}.json'.format(test_name)
report_json_dir = os.path.join(self.RESULTS_DIR, report_json_name)
with open(report_json_dir, 'w') as r_file:
LOGGER.debug('saving json file')
r_file.write(json_results)
+ # write html report file
+ report_html_name = 'opnfv-{}.html'.format(test_name)
+ report_html_dir = os.path.join(self.RESULTS_DIR, report_html_name)
+ cmd = (["rally", "task", "report", task_id, "--out", report_html_dir])
+ LOGGER.debug('running command: %s', cmd)
+ subprocess.Popen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
+
# parse JSON operation result
if self.task_succeed(json_results):
LOGGER.info('Test scenario: "{}" OK.'.format(test_name) + "\n")
else:
LOGGER.info('Test scenario: "{}" Failed.'.format(test_name) + "\n")
- def _get_output(self, proc, test_name):
- result = ""
+ def _append_summary(self, json_raw, test_name):
nb_tests = 0
+ nb_success = 0
overall_duration = 0.0
- success = 0.0
- nb_totals = 0
- for line in proc.stdout:
- if ("Load duration" in line or
- "started" in line or
- "finished" in line or
- " Preparing" in line or
- "+-" in line or
- "|" in line):
- result += line
- elif "test scenario" in line:
- result += "\n" + line
- elif "Full duration" in line:
- result += line + "\n\n"
-
- # parse output for summary report
- if ("| " in line and
- "| action" not in line and
- "| Starting" not in line and
- "| Completed" not in line and
- "| ITER" not in line and
- "| " not in line and
- "| total" not in line):
- nb_tests += 1
- elif "| total" in line:
- percentage = ((line.split('|')[8]).strip(' ')).strip('%')
- try:
- success += float(percentage)
- except ValueError:
- LOGGER.info('Percentage error: %s, %s',
- percentage, line)
- nb_totals += 1
- elif "Full duration" in line:
- duration = line.split(': ')[1]
- try:
- overall_duration += float(duration)
- except ValueError:
- LOGGER.info('Duration error: %s, %s', duration, line)
-
- overall_duration = "{:10.2f}".format(overall_duration)
- if nb_totals == 0:
- success_avg = 0
- else:
- success_avg = "{:0.2f}".format(success / nb_totals)
+ rally_report = json.loads(json_raw)
+ for report in rally_report:
+ if report.get('full_duration'):
+ overall_duration += report.get('full_duration')
+
+ if report.get('result'):
+ for result in report.get('result'):
+ nb_tests += 1
+ if not result.get('error'):
+ nb_success += 1
scenario_summary = {'test_name': test_name,
'overall_duration': overall_duration,
'nb_tests': nb_tests,
- 'success': success_avg}
+ 'nb_success': nb_success}
self.summary.append(scenario_summary)
- LOGGER.debug("\n" + result)
-
- return result
-
def _prepare_env(self):
LOGGER.debug('Validating the test name...')
if self.test_name not in self.TESTS:
@@ -559,75 +517,57 @@ class RallyBase(testcase.TestCase):
self._run_task(self.test_name)
def _generate_report(self):
- report = (
- "\n"
- " "
- "\n"
- " Rally Summary Report\n"
- "\n"
- "+===================+============+===============+===========+"
- "\n"
- "| Module | Duration | nb. Test Run | Success |"
- "\n"
- "+===================+============+===============+===========+"
- "\n")
+ total_duration = 0.0
+ total_nb_tests = 0
+ total_nb_success = 0
payload = []
+ res_table = prettytable.PrettyTable(
+ padding_width=2,
+ field_names=['Module', 'Duration', 'nb. Test Run', 'Success'])
+ res_table.align['Module'] = "l"
+ res_table.align['Duration'] = "r"
+ res_table.align['Success'] = "r"
+
# for each scenario we draw a row for the table
- total_duration = 0.0
- total_nb_tests = 0
- total_success = 0.0
for item in self.summary:
- name = "{0:<17}".format(item['test_name'])
- duration = float(item['overall_duration'])
- total_duration += duration
- duration = time.strftime("%M:%S", time.gmtime(duration))
- duration = "{0:<10}".format(duration)
- nb_tests = "{0:<13}".format(item['nb_tests'])
- total_nb_tests += int(item['nb_tests'])
- success = "{0:<10}".format(str(item['success']) + '%')
- total_success += float(item['success'])
- report += ("" +
- "| " + name + " | " + duration + " | " +
- nb_tests + " | " + success + "|\n" +
- "+-------------------+------------"
- "+---------------+-----------+\n")
- payload.append({'module': name,
+ total_duration += item['overall_duration']
+ total_nb_tests += item['nb_tests']
+ total_nb_success += item['nb_success']
+ try:
+ success_avg = 100 * item['nb_success'] / item['nb_tests']
+ except ZeroDivisionError:
+ success_avg = 0
+ success_str = str("{:0.2f}".format(success_avg)) + '%'
+ duration_str = time.strftime("%M:%S",
+ time.gmtime(item['overall_duration']))
+ res_table.add_row([item['test_name'], duration_str,
+ item['nb_tests'], success_str])
+ payload.append({'module': item['test_name'],
'details': {'duration': item['overall_duration'],
'nb tests': item['nb_tests'],
- 'success': item['success']}})
+ 'success': success_str}})
total_duration_str = time.strftime("%H:%M:%S",
time.gmtime(total_duration))
- total_duration_str2 = "{0:<10}".format(total_duration_str)
- total_nb_tests_str = "{0:<13}".format(total_nb_tests)
-
try:
- self.result = total_success / len(self.summary)
+ self.result = 100 * total_nb_success / total_nb_tests
except ZeroDivisionError:
self.result = 100
-
success_rate = "{:0.2f}".format(self.result)
- success_rate_str = "{0:<10}".format(str(success_rate) + '%')
- report += ("+===================+============"
- "+===============+===========+")
- report += "\n"
- report += ("| TOTAL: | " + total_duration_str2 + " | " +
- total_nb_tests_str + " | " + success_rate_str + "|\n")
- report += ("+===================+============"
- "+===============+===========+")
- report += "\n"
-
- LOGGER.info("\n" + report)
+ success_rate_str = str(success_rate) + '%'
+ res_table.add_row(["", "", "", ""])
+ res_table.add_row(["TOTAL:", total_duration_str, total_nb_tests,
+ success_rate_str])
+
+ LOGGER.info("Rally Summary Report:\n\n%s\n", res_table.get_string())
+ LOGGER.info("Rally '%s' success_rate is %s%%",
+ self.case_name, success_rate)
payload.append({'summary': {'duration': total_duration,
'nb tests': total_nb_tests,
'nb success': success_rate}})
-
self.details = payload
- LOGGER.info("Rally '%s' success_rate is %s%%",
- self.case_name, success_rate)
-
def _clean_up(self):
for creator in reversed(self.creators):
try:
diff --git a/functest/opnfv_tests/openstack/refstack_client/refstack_client.py b/functest/opnfv_tests/openstack/refstack_client/refstack_client.py
index fe32da66..4e8f58b6 100644
--- a/functest/opnfv_tests/openstack/refstack_client/refstack_client.py
+++ b/functest/opnfv_tests/openstack/refstack_client/refstack_client.py
@@ -38,6 +38,7 @@ LOGGER = logging.getLogger(__name__)
class RefstackClient(testcase.TestCase):
"""RefstackClient testcase implementation class."""
+ # pylint: disable=too-many-instance-attributes
def __init__(self, **kwargs):
"""Initialize RefstackClient testcase object."""
@@ -62,6 +63,7 @@ class RefstackClient(testcase.TestCase):
self.insecure = '-k'
def generate_conf(self):
+ """ Generate tempest.conf file to run tempest"""
if not os.path.exists(conf_utils.REFSTACK_RESULTS_DIR):
os.makedirs(conf_utils.REFSTACK_RESULTS_DIR)
@@ -86,11 +88,11 @@ class RefstackClient(testcase.TestCase):
"environment.log"), 'w+') as f_env:
f_env.write(
("Refstack environment:\n"
- " SUT: {}\n Scenario: {}\n Node: {}\n Date: {}\n").format(
- CONST.__getattribute__('INSTALLER_TYPE'),
- CONST.__getattribute__('DEPLOY_SCENARIO'),
- CONST.__getattribute__('NODE_NAME'),
- time.strftime("%a %b %d %H:%M:%S %Z %Y")))
+ " SUT: {}\n Scenario: {}\n Node: {}\n Date: {}\n")
+ .format(CONST.__getattribute__('INSTALLER_TYPE'),
+ CONST.__getattribute__('DEPLOY_SCENARIO'),
+ CONST.__getattribute__('NODE_NAME'),
+ time.strftime("%a %b %d %H:%M:%S %Z %Y")))
with open(os.path.join(conf_utils.REFSTACK_RESULTS_DIR,
"refstack.log"), 'w+') as f_stdout:
@@ -147,7 +149,7 @@ class RefstackClient(testcase.TestCase):
"success": success_testcases,
"errors": failed_testcases,
"skipped": skipped_testcases}
- except Exception:
+ except Exception: # pylint: disable=broad-except
self.result = 0
LOGGER.info("Testcase %s success_rate is %s%%",
@@ -170,7 +172,7 @@ class RefstackClient(testcase.TestCase):
self.run_defcore_default()
self.parse_refstack_result()
res = testcase.TestCase.EX_OK
- except Exception:
+ except Exception: # pylint: disable=broad-except
LOGGER.exception("Error with run")
res = testcase.TestCase.EX_RUN_ERROR
finally:
@@ -207,7 +209,7 @@ class RefstackClient(testcase.TestCase):
self._prep_test()
self.run_defcore(self.confpath, self.testlist)
res = testcase.TestCase.EX_OK
- except Exception as exc:
+ except Exception as exc: # pylint: disable=broad-except
LOGGER.error('Error with run: %s', exc)
res = testcase.TestCase.EX_RUN_ERROR
@@ -257,5 +259,5 @@ def main():
result = refstackclient.main(**args)
if result != testcase.TestCase.EX_OK:
return result
- except Exception:
+ except Exception: # pylint: disable=broad-except
return testcase.TestCase.EX_RUN_ERROR
diff --git a/functest/opnfv_tests/openstack/refstack_client/tempest_conf.py b/functest/opnfv_tests/openstack/refstack_client/tempest_conf.py
index db745227..5764f366 100644
--- a/functest/opnfv_tests/openstack/refstack_client/tempest_conf.py
+++ b/functest/opnfv_tests/openstack/refstack_client/tempest_conf.py
@@ -5,6 +5,9 @@
# 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
+
+""" Used to generate tempest.conf """
+
import logging
import pkg_resources
@@ -14,24 +17,23 @@ from functest.utils.constants import CONST
from functest.opnfv_tests.openstack.tempest.tempest \
import TempestResourcesManager
-""" logging configuration """
-logger = logging.getLogger(__name__)
+LOGGER = logging.getLogger(__name__)
class TempestConf(object):
+ """ TempestConf class"""
def __init__(self, **kwargs):
- self.VERIFIER_ID = conf_utils.get_verifier_id()
- self.VERIFIER_REPO_DIR = conf_utils.get_verifier_repo_dir(
- self.VERIFIER_ID)
- self.DEPLOYMENT_ID = conf_utils.get_verifier_deployment_id()
- self.DEPLOYMENT_DIR = conf_utils.get_verifier_deployment_dir(
- self.VERIFIER_ID, self.DEPLOYMENT_ID)
+ self.verifier_id = conf_utils.get_verifier_id()
+ self.deployment_id = conf_utils.get_verifier_deployment_id()
+ self.deployment_dir = conf_utils.get_verifier_deployment_dir(
+ self.verifier_id, self.deployment_id)
self.confpath = pkg_resources.resource_filename(
'functest',
'opnfv_tests/openstack/refstack_client/refstack_tempest.conf')
self.resources = TempestResourcesManager(**kwargs)
def generate_tempestconf(self):
+ """ Generate tempest.conf file"""
try:
openstack_utils.source_credentials(
CONST.__getattribute__('openstack_creds'))
@@ -39,29 +41,32 @@ class TempestConf(object):
use_custom_images=True,
use_custom_flavors=True)
conf_utils.configure_tempest_defcore(
- self.DEPLOYMENT_DIR,
+ self.deployment_dir,
image_id=resources.get("image_id"),
flavor_id=resources.get("flavor_id"),
image_id_alt=resources.get("image_id_alt"),
flavor_id_alt=resources.get("flavor_id_alt"),
tenant_id=resources.get("project_id"))
- except Exception as e:
- logger.error("error with generating refstack client "
- "reference tempest conf file: %s", e)
+ except Exception as err: # pylint: disable=broad-except
+ LOGGER.error("error with generating refstack client "
+ "reference tempest conf file: %s", err)
def main(self):
+ """ The main function called by entry point"""
try:
self.generate_tempestconf()
- logger.info("a reference tempest conf file generated "
+ LOGGER.info("a reference tempest conf file generated "
"at %s", self.confpath)
- except Exception as e:
- logger.error('Error with run: %s', e)
+ except Exception as err: # pylint: disable=broad-except
+ LOGGER.error('Error with run: %s', err)
def clean(self):
+ """Clean up the resources"""
self.resources.cleanup()
def main():
+ """Entry point"""
logging.basicConfig()
tempestconf = TempestConf()
tempestconf.main()
diff --git a/functest/opnfv_tests/openstack/snaps/api_check.py b/functest/opnfv_tests/openstack/snaps/api_check.py
index e708b4de..e8b9c322 100644
--- a/functest/opnfv_tests/openstack/snaps/api_check.py
+++ b/functest/opnfv_tests/openstack/snaps/api_check.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# Copyright (c) 2017 Cable Television Laboratories, Inc. and others.
#
# This program and the accompanying materials
@@ -6,6 +8,8 @@
#
# http://www.apache.org/licenses/LICENSE-2.0
+# pylint: disable=missing-docstring
+
import unittest
from functest.opnfv_tests.openstack.snaps import snaps_suite_builder
@@ -38,4 +42,4 @@ class ApiCheck(SnapsTestRunner):
ext_net_name=self.ext_net_name,
use_keystone=self.use_keystone,
image_metadata=self.image_metadata)
- return super(self.__class__, self).run()
+ return super(ApiCheck, self).run()
diff --git a/functest/opnfv_tests/openstack/snaps/connection_check.py b/functest/opnfv_tests/openstack/snaps/connection_check.py
index 1fc49349..f8bf8852 100644
--- a/functest/opnfv_tests/openstack/snaps/connection_check.py
+++ b/functest/opnfv_tests/openstack/snaps/connection_check.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# Copyright (c) 2017 Cable Television Laboratories, Inc. and others.
#
# This program and the accompanying materials
@@ -6,6 +8,8 @@
#
# http://www.apache.org/licenses/LICENSE-2.0
+# pylint: disable=missing-docstring
+
import unittest
from functest.opnfv_tests.openstack.snaps import snaps_suite_builder
@@ -37,4 +41,4 @@ class ConnectionCheck(SnapsTestRunner):
os_creds=self.os_creds,
ext_net_name=self.ext_net_name,
use_keystone=self.use_keystone)
- return super(self.__class__, self).run()
+ return super(ConnectionCheck, self).run()
diff --git a/functest/opnfv_tests/openstack/snaps/health_check.py b/functest/opnfv_tests/openstack/snaps/health_check.py
index 837c2eae..db882c38 100644
--- a/functest/opnfv_tests/openstack/snaps/health_check.py
+++ b/functest/opnfv_tests/openstack/snaps/health_check.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# Copyright (c) 2017 Cable Television Laboratories, Inc. and others.
#
# This program and the accompanying materials
@@ -6,6 +8,8 @@
#
# http://www.apache.org/licenses/LICENSE-2.0
+# pylint: disable=missing-docstring
+
import unittest
from functest.opnfv_tests.openstack.snaps.snaps_test_runner import (
@@ -42,4 +46,4 @@ class HealthCheck(SnapsTestRunner):
flavor_metadata=self.flavor_metadata,
image_metadata=self.image_metadata,
netconf_override=self.netconf_override))
- return super(self.__class__, self).run()
+ return super(HealthCheck, self).run()
diff --git a/functest/opnfv_tests/openstack/snaps/smoke.py b/functest/opnfv_tests/openstack/snaps/smoke.py
index ded149d0..ef6e5dc9 100644
--- a/functest/opnfv_tests/openstack/snaps/smoke.py
+++ b/functest/opnfv_tests/openstack/snaps/smoke.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# Copyright (c) 2017 Cable Television Laboratories, Inc. and others.
#
# This program and the accompanying materials
@@ -6,6 +8,8 @@
#
# http://www.apache.org/licenses/LICENSE-2.0
+# pylint: disable=missing-docstring
+
import unittest
from functest.opnfv_tests.openstack.snaps import snaps_suite_builder
@@ -41,4 +45,4 @@ class SnapsSmoke(SnapsTestRunner):
image_metadata=self.image_metadata,
use_floating_ips=self.use_fip,
netconf_override=self.netconf_override)
- return super(self.__class__, self).run()
+ return super(SnapsSmoke, self).run()
diff --git a/functest/opnfv_tests/openstack/snaps/snaps_suite_builder.py b/functest/opnfv_tests/openstack/snaps/snaps_suite_builder.py
index 3e7c0a39..c3d8c2d8 100644
--- a/functest/opnfv_tests/openstack/snaps/snaps_suite_builder.py
+++ b/functest/opnfv_tests/openstack/snaps/snaps_suite_builder.py
@@ -8,6 +8,8 @@
#
# http://www.apache.org/licenses/LICENSE-2.0
+# pylint: disable=missing-docstring
+
import logging
from snaps.openstack.tests.create_flavor_tests import (
@@ -119,6 +121,7 @@ def add_openstack_client_tests(suite, os_creds, ext_net_name,
def add_openstack_api_tests(suite, os_creds, ext_net_name, use_keystone=True,
image_metadata=None, log_level=logging.INFO):
+ # pylint: disable=too-many-arguments
"""
Adds tests written to exercise all existing OpenStack APIs
:param suite: the unittest.TestSuite object to which to add the tests
@@ -232,6 +235,7 @@ def add_openstack_integration_tests(suite, os_creds, ext_net_name,
image_metadata=None, use_floating_ips=True,
netconf_override=None,
log_level=logging.INFO):
+ # pylint: disable=too-many-arguments
"""
Adds tests written to exercise all long-running OpenStack integration tests
meaning they will be creating VM instances and potentially performing some
diff --git a/functest/opnfv_tests/openstack/snaps/snaps_test_runner.py b/functest/opnfv_tests/openstack/snaps/snaps_test_runner.py
index 6dc8288b..a2dadb75 100644
--- a/functest/opnfv_tests/openstack/snaps/snaps_test_runner.py
+++ b/functest/opnfv_tests/openstack/snaps/snaps_test_runner.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# Copyright (c) 2017 Cable Television Laboratories, Inc. and others.
#
# This program and the accompanying materials
@@ -6,6 +8,8 @@
#
# http://www.apache.org/licenses/LICENSE-2.0
+# pylint: disable=missing-docstring
+
import logging
from functest.core import unit
@@ -13,28 +17,18 @@ from functest.opnfv_tests.openstack.snaps import snaps_utils
from functest.utils.constants import CONST
from snaps.openstack import create_flavor
-from snaps.openstack.tests import openstack_tests
class SnapsTestRunner(unit.Suite):
+ # pylint: disable=too-many-instance-attributes
"""
This test executes the SNAPS Python Tests
"""
+
def __init__(self, **kwargs):
super(SnapsTestRunner, self).__init__(**kwargs)
self.logger = logging.getLogger(__name__)
-
- if 'os_creds' in kwargs:
- self.os_creds = kwargs['os_creds']
- else:
- creds_override = None
- if hasattr(CONST, 'snaps_os_creds_override'):
- creds_override = CONST.__getattribute__(
- 'snaps_os_creds_override')
- self.os_creds = openstack_tests.get_credentials(
- os_env_file=CONST.__getattribute__('openstack_creds'),
- proxy_settings_str=None, ssh_proxy_cmd=None,
- overrides=creds_override)
+ self.os_creds = kwargs.get('os_creds') or snaps_utils.get_credentials()
if 'ext_net_name' in kwargs:
self.ext_net_name = kwargs['ext_net_name']
diff --git a/functest/opnfv_tests/openstack/snaps/snaps_utils.py b/functest/opnfv_tests/openstack/snaps/snaps_utils.py
index 284e88b5..6b0ee497 100644
--- a/functest/opnfv_tests/openstack/snaps/snaps_utils.py
+++ b/functest/opnfv_tests/openstack/snaps/snaps_utils.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# Copyright (c) 2015 All rights reserved
# This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
@@ -5,8 +7,11 @@
#
# http://www.apache.org/licenses/LICENSE-2.0
+# pylint: disable=missing-docstring
+
from functest.utils.constants import CONST
+from snaps.openstack.tests import openstack_tests
from snaps.openstack.utils import neutron_utils, nova_utils
@@ -19,7 +24,7 @@ def get_ext_net_name(os_creds):
"""
neutron = neutron_utils.neutron_client(os_creds)
ext_nets = neutron_utils.get_external_networks(neutron)
- if (hasattr(CONST, 'EXTERNAL_NETWORK')):
+ if hasattr(CONST, 'EXTERNAL_NETWORK'):
extnet_config = CONST.__getattribute__('EXTERNAL_NETWORK')
for ext_net in ext_nets:
if ext_net.name == extnet_config:
@@ -36,3 +41,21 @@ def get_active_compute_cnt(os_creds):
nova = nova_utils.nova_client(os_creds)
computes = nova_utils.get_availability_zone_hosts(nova, zone_name='nova')
return len(computes)
+
+
+def get_credentials(proxy_settings_str=None, ssh_proxy_cmd=None):
+ """
+ Returns snaps OSCreds object instance
+ :param: proxy_settings_str: proxy settings string <host>:<port>
+ :param: ssh_proxy_cmd: the SSH proxy command for the environment
+ :return: an instance of snaps OSCreds object
+ """
+ creds_override = None
+ if hasattr(CONST, 'snaps_os_creds_override'):
+ creds_override = CONST.__getattribute__(
+ 'snaps_os_creds_override')
+ os_creds = openstack_tests.get_credentials(
+ os_env_file=CONST.__getattribute__('openstack_creds'),
+ proxy_settings_str=proxy_settings_str, ssh_proxy_cmd=ssh_proxy_cmd,
+ overrides=creds_override)
+ return os_creds
diff --git a/functest/opnfv_tests/openstack/tempest/tempest.py b/functest/opnfv_tests/openstack/tempest/tempest.py
index 5481b13b..4361784b 100644
--- a/functest/opnfv_tests/openstack/tempest/tempest.py
+++ b/functest/opnfv_tests/openstack/tempest/tempest.py
@@ -389,6 +389,7 @@ class TempestResourcesManager(object):
subnet_settings=[SubnetConfig(
name=CONST.__getattribute__(
'tempest_private_subnet_name') + self.guid,
+ project_name=project_name,
cidr=CONST.__getattribute__('tempest_private_subnet_cidr'))
]))
if network_creator is None or network_creator.get_network() is None:
diff --git a/functest/opnfv_tests/openstack/vping/vping_base.py b/functest/opnfv_tests/openstack/vping/vping_base.py
index df9774ec..7170101f 100644
--- a/functest/opnfv_tests/openstack/vping/vping_base.py
+++ b/functest/opnfv_tests/openstack/vping/vping_base.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# Copyright (c) 2017 Cable Television Laboratories, Inc. and others.
#
# This program and the accompanying materials
@@ -37,21 +39,8 @@ class VPingBase(testcase.TestCase):
def __init__(self, **kwargs):
super(VPingBase, self).__init__(**kwargs)
-
self.logger = logging.getLogger(__name__)
-
- if 'os_creds' in kwargs:
- self.os_creds = kwargs['os_creds']
- else:
- creds_override = None
- if hasattr(CONST, 'snaps_os_creds_override'):
- creds_override = CONST.__getattribute__(
- 'snaps_os_creds_override')
-
- self.os_creds = openstack_tests.get_credentials(
- os_env_file=CONST.__getattribute__('openstack_creds'),
- overrides=creds_override)
-
+ self.os_creds = kwargs.get('os_creds') or snaps_utils.get_credentials()
self.creators = list()
self.image_creator = None
self.network_creator = None
@@ -62,27 +51,24 @@ class VPingBase(testcase.TestCase):
# Shared metadata
self.guid = '-' + str(uuid.uuid4())
- self.router_name = CONST.__getattribute__(
- 'vping_router_name') + self.guid
- self.vm1_name = CONST.__getattribute__('vping_vm_name_1') + self.guid
- self.vm2_name = CONST.__getattribute__('vping_vm_name_2') + self.guid
-
- self.vm_boot_timeout = CONST.__getattribute__('vping_vm_boot_timeout')
- self.vm_delete_timeout = CONST.__getattribute__(
- 'vping_vm_delete_timeout')
- self.vm_ssh_connect_timeout = CONST.__getattribute__(
- 'vping_vm_ssh_connect_timeout')
- self.ping_timeout = CONST.__getattribute__('vping_ping_timeout')
+ self.router_name = getattr(CONST, 'vping_router_name') + self.guid
+ self.vm1_name = getattr(CONST, 'vping_vm_name_1') + self.guid
+ self.vm2_name = getattr(CONST, 'vping_vm_name_2') + self.guid
+
+ self.vm_boot_timeout = getattr(CONST, 'vping_vm_boot_timeout')
+ self.vm_delete_timeout = getattr(CONST, 'vping_vm_delete_timeout')
+ self.vm_ssh_connect_timeout = getattr(
+ CONST, 'vping_vm_ssh_connect_timeout')
+ self.ping_timeout = getattr(CONST, 'vping_ping_timeout')
self.flavor_name = 'vping-flavor' + self.guid
# Move this configuration option up for all tests to leverage
if hasattr(CONST, 'snaps_images_cirros'):
- self.cirros_image_config = CONST.__getattribute__(
- 'snaps_images_cirros')
+ self.cirros_image_config = getattr(CONST, 'snaps_images_cirros')
else:
self.cirros_image_config = None
- def run(self):
+ def run(self, **kwargs): # pylint: disable=too-many-locals
"""
Begins the test execution which should originate from the subclass
"""
@@ -95,7 +81,7 @@ class VPingBase(testcase.TestCase):
'%Y-%m-%d %H:%M:%S'))
image_base_name = '{}-{}'.format(
- CONST.__getattribute__('vping_image_name'),
+ getattr(CONST, 'vping_image_name'),
str(self.guid))
os_image_settings = openstack_tests.cirros_image_settings(
image_base_name, image_metadata=self.cirros_image_config)
@@ -105,26 +91,21 @@ class VPingBase(testcase.TestCase):
self.os_creds, os_image_settings)
self.creators.append(self.image_creator)
- private_net_name = CONST.__getattribute__(
- 'vping_private_net_name') + self.guid
- private_subnet_name = CONST.__getattribute__(
- 'vping_private_subnet_name') + self.guid
- private_subnet_cidr = CONST.__getattribute__(
- 'vping_private_subnet_cidr')
+ private_net_name = getattr(CONST, 'vping_private_net_name') + self.guid
+ private_subnet_name = getattr(
+ CONST, 'vping_private_subnet_name') + self.guid
+ private_subnet_cidr = getattr(CONST, 'vping_private_subnet_cidr')
vping_network_type = None
vping_physical_network = None
vping_segmentation_id = None
if hasattr(CONST, 'vping_network_type'):
- vping_network_type = CONST.__getattribute__(
- 'vping_network_type')
+ vping_network_type = getattr(CONST, 'vping_network_type')
if hasattr(CONST, 'vping_physical_network'):
- vping_physical_network = CONST.__getattribute__(
- 'vping_physical_network')
+ vping_physical_network = getattr(CONST, 'vping_physical_network')
if hasattr(CONST, 'vping_segmentation_id'):
- vping_segmentation_id = CONST.__getattribute__(
- 'vping_segmentation_id')
+ vping_segmentation_id = getattr(CONST, 'vping_segmentation_id')
self.logger.info(
"Creating network with name: '%s'", private_net_name)
@@ -154,7 +135,7 @@ class VPingBase(testcase.TestCase):
self.logger.info(
"Creating flavor with name: '%s'", self.flavor_name)
- scenario = CONST.__getattribute__('DEPLOY_SCENARIO')
+ scenario = getattr(CONST, 'DEPLOY_SCENARIO')
flavor_metadata = None
flavor_ram = 512
if 'ovs' in scenario or 'fdio' in scenario:
@@ -197,7 +178,7 @@ class VPingBase(testcase.TestCase):
Cleanup all OpenStack objects. Should be called on completion
:return:
"""
- if CONST.__getattribute__('vping_cleanup_objects') == 'True':
+ if getattr(CONST, 'vping_cleanup_objects') == 'True':
for creator in reversed(self.creators):
try:
creator.clean()
diff --git a/functest/opnfv_tests/openstack/vping/vping_ssh.py b/functest/opnfv_tests/openstack/vping/vping_ssh.py
index 7df767ed..57e177e5 100644
--- a/functest/opnfv_tests/openstack/vping/vping_ssh.py
+++ b/functest/opnfv_tests/openstack/vping/vping_ssh.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-#
+
# Copyright (c) 2015 All rights reserved
# This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
@@ -7,12 +7,8 @@
#
# http://www.apache.org/licenses/LICENSE-2.0
-
"""vPingSSH testcase."""
-# This 1st import is here simply for pep8 as the 'os' package import appears
-# to be required for mock and the unit tests will fail without it
-import os # noqa # pylint: disable=unused-import
import time
from scp import SCPClient
@@ -53,7 +49,7 @@ class VPingSSH(vping_base.VPingBase):
self.sg_desc = CONST.__getattribute__('vping_sg_desc')
@energy.enable_recording
- def run(self):
+ def run(self, **kwargs):
"""
Excecute VPingSSH testcase.
diff --git a/functest/opnfv_tests/openstack/vping/vping_userdata.py b/functest/opnfv_tests/openstack/vping/vping_userdata.py
index ceba0917..76cdcf83 100644
--- a/functest/opnfv_tests/openstack/vping/vping_userdata.py
+++ b/functest/opnfv_tests/openstack/vping/vping_userdata.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-#
+
# Copyright (c) 2015 All rights reserved
# This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
@@ -29,7 +29,7 @@ class VPingUserdata(vping_base.VPingBase):
kwargs["case_name"] = "vping_userdata"
super(VPingUserdata, self).__init__(**kwargs)
- def run(self):
+ def run(self, **kwargs):
"""
Sets up the OpenStack VM instance objects then executes the ping and
validates.
diff --git a/functest/opnfv_tests/vnf/epc/juju_epc.py b/functest/opnfv_tests/vnf/epc/juju_epc.py
index 3146b935..14329329 100644
--- a/functest/opnfv_tests/vnf/epc/juju_epc.py
+++ b/functest/opnfv_tests/vnf/epc/juju_epc.py
@@ -29,7 +29,6 @@ from snaps.openstack.create_network import (NetworkSettings,
from snaps.openstack.create_router import (RouterSettings, OpenStackRouter)
from snaps.openstack.create_flavor import (FlavorSettings, OpenStackFlavor)
from snaps.openstack.create_image import (ImageSettings, OpenStackImage)
-from snaps.openstack.tests import openstack_tests
from snaps.openstack.utils import keystone_utils
import yaml
@@ -66,9 +65,7 @@ class JujuEpc(vnf.VnfOnBoarding):
self.created_object = []
self.snaps_creds = ''
- self.os_creds = openstack_tests.get_credentials(
- os_env_file=CONST.__getattribute__('openstack_creds'))
-
+ self.os_creds = snaps_utils.get_credentials()
self.details['orchestrator'] = dict(
name=get_config("orchestrator.name", config_file),
version=get_config("orchestrator.version", config_file),
@@ -145,8 +142,9 @@ class JujuEpc(vnf.VnfOnBoarding):
write_config(self.filename, CLOUD_TEMPLATE, **cloud_data)
if self.snaps_creds.identity_api_version == 3:
- append_config(self.filename, '{}'.format(
- os_utils.get_credentials()['project_domain_name']),
+ append_config(
+ self.filename, '{}'.format(
+ os_utils.get_credentials()['project_domain_name']),
'{}'.format(os_utils.get_credentials()['user_domain_name']))
self.__logger.info("Upload some OS images if it doesn't exist")
diff --git a/functest/opnfv_tests/vnf/router/cloudify_vrouter.py b/functest/opnfv_tests/vnf/router/cloudify_vrouter.py
index f2cd63fb..020085ba 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
@@ -16,12 +18,12 @@ import time
from cloudify_rest_client import CloudifyClient
from cloudify_rest_client.executions import Execution
from scp import SCPClient
-import yaml
from functest.opnfv_tests.openstack.snaps import snaps_utils
import functest.opnfv_tests.vnf.router.vrouter_base as vrouter_base
from functest.opnfv_tests.vnf.router.utilvnf import Utilvnf
from functest.utils.constants import CONST
+from functest.utils import functest_utils
from git import Repo
@@ -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__)
@@ -76,35 +79,46 @@ class CloudifyVrouter(vrouter_base.VrouterOnBoardingBase):
config_file = os.path.join(self.case_dir, self.config)
self.orchestrator = dict(
- requirements=get_config("orchestrator.requirements", config_file),
+ requirements=functest_utils.get_parameter_from_yaml(
+ "orchestrator.requirements", config_file),
)
self.details['orchestrator'] = dict(
- name=get_config("orchestrator.name", config_file),
- version=get_config("orchestrator.version", config_file),
+ name=functest_utils.get_parameter_from_yaml(
+ "orchestrator.name", config_file),
+ version=functest_utils.get_parameter_from_yaml(
+ "orchestrator.version", config_file),
status='ERROR',
result=''
)
self.__logger.debug("Orchestrator configuration %s", self.orchestrator)
self.__logger.debug("name = %s", self.name)
self.vnf = dict(
- descriptor=get_config("vnf.descriptor", config_file),
- inputs=get_config("vnf.inputs", config_file),
- requirements=get_config("vnf.requirements", config_file)
+ descriptor=functest_utils.get_parameter_from_yaml(
+ "vnf.descriptor", config_file),
+ inputs=functest_utils.get_parameter_from_yaml(
+ "vnf.inputs", config_file),
+ requirements=functest_utils.get_parameter_from_yaml(
+ "vnf.requirements", config_file)
)
self.details['vnf'] = dict(
descriptor_version=self.vnf['descriptor']['version'],
- name=get_config("vnf.name", config_file),
- version=get_config("vnf.version", config_file),
+ name=functest_utils.get_parameter_from_yaml(
+ "vnf.name", config_file),
+ version=functest_utils.get_parameter_from_yaml(
+ "vnf.version", config_file),
)
self.__logger.debug("VNF configuration: %s", self.vnf)
self.util = Utilvnf()
self.details['test_vnf'] = dict(
- name=get_config("vnf_test_suite.name", config_file),
- version=get_config("vnf_test_suite.version", config_file)
+ name=functest_utils.get_parameter_from_yaml(
+ "vnf_test_suite.name", config_file),
+ version=functest_utils.get_parameter_from_yaml(
+ "vnf_test_suite.version", config_file)
)
- self.images = get_config("tenant_images", config_file)
+ self.images = functest_utils.get_parameter_from_yaml(
+ "tenant_images", config_file)
self.__logger.info("Images needed for vrouter: %s", self.images)
def prepare(self):
@@ -129,6 +143,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 +423,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,51 +434,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)
-
-
-# ----------------------------------------------------------
-#
-# YAML UTILS
-#
-# -----------------------------------------------------------
-def get_config(parameter, file_path):
- """
- Get config parameter.
- Returns the value of a given parameter in file.yaml
- parameter must be given in string format with dots
- Example: general.openstack.image_name
- """
- with open(file_path) as config_file:
- file_yaml = yaml.safe_load(config_file)
- config_file.close()
- value = file_yaml
- for element in parameter.split("."):
- value = value.get(element)
- if value is None:
- raise ValueError("The parameter %s is not defined in"
- " reporting.yaml" % parameter)
- return value
+ return self.util.get_vnf_info_list(
+ self.cfy_manager_ip, self.deployment_name, target_vnf_name)
def wait_for_execution(client, execution, logger, timeout=7200, ):
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/ci/test_check_deployment.py b/functest/tests/unit/ci/test_check_deployment.py
index 46dcc24c..aeeca587 100644
--- a/functest/tests/unit/ci/test_check_deployment.py
+++ b/functest/tests/unit/ci/test_check_deployment.py
@@ -45,25 +45,25 @@ class CheckDeploymentTesting(unittest.TestCase):
@mock.patch('socket.socket.connect', side_effect=TypeError)
def test_verify_connectivity_ko1(self, *args):
self.assertFalse(check_deployment.verify_connectivity("127.0.0.1"))
- args[0].assert_called_once_with(None, 80)
+ args[0].assert_called_once_with((None, 80))
@mock.patch('socket.socket.connect', side_effect=socket.error)
def test_verify_connectivity_ko2(self, *args):
self.assertFalse(
check_deployment.verify_connectivity("http://127.0.0.1"))
- args[0].assert_called_once_with("127.0.0.1", 80)
+ args[0].assert_called_once_with(("127.0.0.1", 80))
@mock.patch('socket.socket.connect', side_effect=socket.error)
def test_verify_connectivity_ko3(self, *args):
self.assertFalse(
check_deployment.verify_connectivity("https://127.0.0.1"))
- args[0].assert_called_once_with("127.0.0.1", 443)
+ args[0].assert_called_once_with(("127.0.0.1", 443))
@mock.patch('socket.socket.connect')
def test_verify_connectivity(self, *args):
self.assertTrue(
check_deployment.verify_connectivity("https://127.0.0.1"))
- args[0].assert_called_once_with("127.0.0.1", 443)
+ args[0].assert_called_once_with(("127.0.0.1", 443))
@mock.patch('snaps.openstack.utils.keystone_utils.keystone_session',
return_value=mock.Mock(
diff --git a/functest/tests/unit/openstack/rally/test_rally.py b/functest/tests/unit/openstack/rally/test_rally.py
index f4858527..92177f36 100644
--- a/functest/tests/unit/openstack/rally/test_rally.py
+++ b/functest/tests/unit/openstack/rally/test_rally.py
@@ -26,7 +26,7 @@ class OSRallyTesting(unittest.TestCase):
os_creds = OSCreds(
username='user', password='pass',
auth_url='http://foo.com:5000/v3', project_name='bar')
- with mock.patch('snaps.openstack.tests.openstack_tests.'
+ with mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
'get_credentials', return_value=os_creds) as m:
self.rally_base = rally.RallyBase()
self.assertTrue(m.called)
@@ -220,7 +220,7 @@ class OSRallyTesting(unittest.TestCase):
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
'_build_task_args', return_value={})
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
- '_get_output')
+ '_append_summary')
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
'get_task_id', return_value=None)
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
@@ -242,7 +242,7 @@ class OSRallyTesting(unittest.TestCase):
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
'_build_task_args', return_value={})
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
- '_get_output')
+ '_append_summary')
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
'get_task_id', return_value='1')
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
@@ -424,6 +424,16 @@ class OSRallyTesting(unittest.TestCase):
self.assertEqual(self.rally_base.run(), testcase.TestCase.EX_RUN_ERROR)
mock_prep_env.assert_called()
+ def test_append_summary(self):
+ text = '[{"result":[{"error":[]},{"error":["err"]}],' \
+ '"full_duration": 17.312026}]'
+ self.rally_base._append_summary(text, "foo_test")
+ self.assertEqual(self.rally_base.summary[0]['test_name'], "foo_test")
+ self.assertEqual(self.rally_base.summary[0]['overall_duration'],
+ 17.312026)
+ self.assertEqual(self.rally_base.summary[0]['nb_tests'], 2)
+ self.assertEqual(self.rally_base.summary[0]['nb_success'], 1)
+
if __name__ == "__main__":
logging.disable(logging.CRITICAL)
diff --git a/functest/tests/unit/openstack/refstack_client/test_refstack_client.py b/functest/tests/unit/openstack/refstack_client/test_refstack_client.py
index 61e950a6..a7a914cb 100644
--- a/functest/tests/unit/openstack/refstack_client/test_refstack_client.py
+++ b/functest/tests/unit/openstack/refstack_client/test_refstack_client.py
@@ -10,9 +10,10 @@
# pylint: disable=missing-docstring
import logging
+import unittest
+
import mock
import pkg_resources
-import unittest
from functest.core import testcase
from functest.opnfv_tests.openstack.refstack_client.refstack_client import \
@@ -51,9 +52,7 @@ class OSRefstackClientTesting(unittest.TestCase):
"errors": ['tempest.api.volume [0.230334s]'],
"skipped": ['tempest.api.network [1.265828s]']}
- @mock.patch('functest.opnfv_tests.openstack.refstack_client.tempest_conf.'
- 'TempestConf', return_value=mock.Mock())
- def _create_client(self, *args):
+ def _create_client(self):
with mock.patch('snaps.openstack.tests.openstack_tests.'
'get_credentials', return_value=self.os_creds):
return RefstackClient()
@@ -145,8 +144,7 @@ class OSRefstackClientTesting(unittest.TestCase):
parser = RefstackClientParser()
self.assertEqual(parser.parse_args(
["--config={}".format(self._config),
- "--testlist={}".format(self._testlist)
- ]), self.default_args)
+ "--testlist={}".format(self._testlist)]), self.default_args)
if __name__ == "__main__":
diff --git a/functest/tests/unit/openstack/snaps/test_snaps.py b/functest/tests/unit/openstack/snaps/test_snaps.py
index 9a360cbc..3d9e9df0 100644
--- a/functest/tests/unit/openstack/snaps/test_snaps.py
+++ b/functest/tests/unit/openstack/snaps/test_snaps.py
@@ -8,15 +8,15 @@
# pylint: disable=missing-docstring
-import mock
-import os
+import logging
import unittest
+import mock
from snaps.openstack.os_credentials import OSCreds
from functest.core.testcase import TestCase
-from functest.opnfv_tests.openstack.snaps import (connection_check, api_check,
- health_check, smoke)
+from functest.opnfv_tests.openstack.snaps import (
+ connection_check, api_check, health_check, smoke)
class ConnectionCheckTesting(unittest.TestCase):
@@ -35,40 +35,52 @@ class ConnectionCheckTesting(unittest.TestCase):
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
'add_openstack_client_tests')
- def test_run_success(self, add_os_client_tests):
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = []
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.connection_check.run())
- self.assertEquals(TestCase.EX_OK,
- self.connection_check.is_successful())
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_success(self, *args):
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = []
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.connection_check.run())
+ self.assertEquals(
+ TestCase.EX_OK, self.connection_check.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ ext_net_name='foo', os_creds=self.os_creds, suite=mock.ANY,
+ use_keystone=True)
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
'add_openstack_client_tests')
- def test_run_1_of_100_failures(self, add_os_client_tests):
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = ['foo']
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.connection_check.run())
- self.assertEquals(TestCase.EX_TESTCASE_FAILED,
- self.connection_check.is_successful())
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_1_of_100_ko(self, *args):
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = ['foo']
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.connection_check.run())
+ self.assertEquals(
+ TestCase.EX_TESTCASE_FAILED, self.connection_check.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ ext_net_name='foo', os_creds=self.os_creds, suite=mock.ANY,
+ use_keystone=True)
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
'add_openstack_client_tests')
- def test_run_1_of_100_failures_within_criteria(self, add_os_client_tests):
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_1_of_100_ko_criteria(self, *args):
self.connection_check.criteria = 90
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = ['foo']
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.connection_check.run())
- self.assertEquals(TestCase.EX_OK,
- self.connection_check.is_successful())
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = ['foo']
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.connection_check.run())
+ self.assertEquals(
+ TestCase.EX_OK, self.connection_check.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ ext_net_name='foo', os_creds=self.os_creds, suite=mock.ANY,
+ use_keystone=True)
class APICheckTesting(unittest.TestCase):
@@ -87,40 +99,52 @@ class APICheckTesting(unittest.TestCase):
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
'add_openstack_api_tests')
- def test_run_success(self, add_tests):
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = []
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.api_check.run())
- self.assertEquals(TestCase.EX_OK,
- self.api_check.is_successful())
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_success(self, *args):
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = []
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.api_check.run())
+ self.assertEquals(
+ TestCase.EX_OK, self.api_check.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ ext_net_name='foo', image_metadata=mock.ANY,
+ os_creds=self.os_creds, suite=mock.ANY, use_keystone=True)
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
'add_openstack_api_tests')
- def test_run_1_of_100_failures(self, add_tests):
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = ['foo']
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.api_check.run())
- self.assertEquals(TestCase.EX_TESTCASE_FAILED,
- self.api_check.is_successful())
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_1_of_100_ko(self, *args):
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = ['foo']
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.api_check.run())
+ self.assertEquals(
+ TestCase.EX_TESTCASE_FAILED, self.api_check.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ ext_net_name='foo', image_metadata=mock.ANY,
+ os_creds=self.os_creds, suite=mock.ANY, use_keystone=True)
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
'add_openstack_api_tests')
- def test_run_1_of_100_failures_within_criteria(self, add_tests):
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_1_of_100_ko_criteria(self, *args):
self.api_check.criteria = 90
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = ['foo']
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.api_check.run())
- self.assertEquals(TestCase.EX_OK,
- self.api_check.is_successful())
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = ['foo']
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.api_check.run())
+ self.assertEquals(
+ TestCase.EX_OK, self.api_check.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ ext_net_name='foo', image_metadata=mock.ANY,
+ os_creds=self.os_creds, suite=mock.ANY, use_keystone=True)
class HealthCheckTesting(unittest.TestCase):
@@ -137,42 +161,57 @@ class HealthCheckTesting(unittest.TestCase):
self.health_check = health_check.HealthCheck(
os_creds=self.os_creds, ext_net_name='foo')
- @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
- 'add_openstack_client_tests')
- def test_run_success(self, add_tests):
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = []
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.health_check.run())
- self.assertEquals(TestCase.EX_OK,
- self.health_check.is_successful())
-
- @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
- 'add_openstack_client_tests')
- def test_run_1_of_100_failures(self, add_tests):
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = ['foo']
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.health_check.run())
- self.assertEquals(TestCase.EX_TESTCASE_FAILED,
- self.health_check.is_successful())
-
- @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
- 'add_openstack_client_tests')
- def test_run_1_of_100_failures_within_criteria(self, add_tests):
+ @mock.patch('snaps.openstack.tests.os_source_file_test.'
+ 'OSIntegrationTestCase.parameterize')
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_success(self, *args):
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = []
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.health_check.run())
+ self.assertEquals(
+ TestCase.EX_OK, self.health_check.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ mock.ANY, ext_net_name='foo', flavor_metadata=None,
+ image_metadata=mock.ANY, netconf_override=None,
+ os_creds=self.os_creds, use_keystone=True)
+
+ @mock.patch('snaps.openstack.tests.os_source_file_test.'
+ 'OSIntegrationTestCase.parameterize')
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_1_of_100_ko(self, *args):
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = ['foo']
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.health_check.run())
+ self.assertEquals(
+ TestCase.EX_TESTCASE_FAILED, self.health_check.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ mock.ANY, ext_net_name='foo', flavor_metadata=None,
+ image_metadata=mock.ANY, netconf_override=None,
+ os_creds=self.os_creds, use_keystone=True)
+
+ @mock.patch('snaps.openstack.tests.os_source_file_test.'
+ 'OSIntegrationTestCase.parameterize')
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_1_of_100_ko_criteria(self, *args):
self.health_check.criteria = 90
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = ['foo']
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.health_check.run())
- self.assertEquals(TestCase.EX_OK,
- self.health_check.is_successful())
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = ['foo']
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.health_check.run())
+ self.assertEquals(
+ TestCase.EX_OK, self.health_check.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ mock.ANY, ext_net_name='foo', flavor_metadata=None,
+ image_metadata=mock.ANY, netconf_override=None,
+ os_creds=self.os_creds, use_keystone=True)
class SmokeTesting(unittest.TestCase):
@@ -191,40 +230,56 @@ class SmokeTesting(unittest.TestCase):
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
'add_openstack_integration_tests')
- @mock.patch('os.path.join', return_value=os.getcwd())
- def test_run_success(self, add_tests, cwd):
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = []
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.smoke.run())
- self.assertEquals(TestCase.EX_OK,
- self.smoke.is_successful())
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_success(self, *args):
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = []
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.smoke.run())
+ self.assertEquals(TestCase.EX_OK, self.smoke.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ ext_net_name='foo', flavor_metadata=None, image_metadata=mock.ANY,
+ netconf_override=None, os_creds=self.os_creds,
+ suite=mock.ANY, use_floating_ips=True, use_keystone=True)
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
'add_openstack_integration_tests')
- @mock.patch('os.path.join', return_value=os.getcwd())
- def test_run_1_of_100_failures(self, add_tests, cwd):
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = ['foo']
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.smoke.run())
- self.assertEquals(TestCase.EX_TESTCASE_FAILED,
- self.smoke.is_successful())
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_1_of_100_ko(self, *args):
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = ['foo']
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.smoke.run())
+ self.assertEquals(
+ TestCase.EX_TESTCASE_FAILED, self.smoke.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ ext_net_name='foo', flavor_metadata=None, image_metadata=mock.ANY,
+ netconf_override=mock.ANY, os_creds=self.os_creds,
+ suite=mock.ANY, use_floating_ips=True, use_keystone=True)
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
'add_openstack_integration_tests')
- @mock.patch('os.path.join', return_value=os.getcwd())
- def test_run_1_of_100_failures_within_criteria(self, add_tests, cwd):
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_1_of_100_ko_criteria(self, *args):
self.smoke.criteria = 90
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = ['foo']
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.smoke.run())
- self.assertEquals(TestCase.EX_OK,
- self.smoke.is_successful())
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = ['foo']
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.smoke.run())
+ self.assertEquals(
+ TestCase.EX_OK, self.smoke.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ ext_net_name='foo', flavor_metadata=None, image_metadata=mock.ANY,
+ netconf_override=None, os_creds=self.os_creds,
+ suite=mock.ANY, use_floating_ips=True, use_keystone=True)
+
+
+if __name__ == "__main__":
+ logging.disable(logging.CRITICAL)
+ unittest.main(verbosity=2)
diff --git a/functest/tests/unit/openstack/vping/__init__.py b/functest/tests/unit/openstack/vping/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/functest/tests/unit/openstack/vping/__init__.py
diff --git a/functest/tests/unit/openstack/vping/test_vping.py b/functest/tests/unit/openstack/vping/test_vping.py
index d494a795..42650dea 100644
--- a/functest/tests/unit/openstack/vping/test_vping.py
+++ b/functest/tests/unit/openstack/vping/test_vping.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# Copyright (c) 2017 Cable Television Laboratories, Inc. and others.
#
# All rights reserved. This program and the accompanying materials
@@ -8,6 +10,7 @@
# pylint: disable=missing-docstring
+import logging
import unittest
import mock
@@ -46,21 +49,25 @@ class VPingUserdataTesting(unittest.TestCase):
os_creds=self.os_creds)
@mock.patch('snaps.openstack.utils.deploy_utils.create_vm_instance')
- @mock.patch('functest.opnfv_tests.openstack.vping.vping_base.os.'
- 'path.exists', return_value=True)
+ @mock.patch('os.path.exists', return_value=True)
@mock.patch('snaps.openstack.create_flavor.OpenStackFlavor.create',
return_value=None)
@mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
'get_port_ip', return_value='10.0.0.1')
@mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
'vm_active', return_value=True)
- def test_vping_userdata(self, deploy_vm, path_exists, create_flavor,
- get_port_ip, vm_active):
+ @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
+ 'get_ext_net_name', return_value='foo')
+ def test_vping_userdata(self, *args):
+ # pylint: disable=unused-argument
with mock.patch('snaps.openstack.utils.deploy_utils.create_image',
return_value=OpenStackImage(self.os_creds, None)), \
mock.patch('snaps.openstack.utils.deploy_utils.create_network',
return_value=OpenStackNetwork(
self.os_creds, NetworkConfig(name='foo'))), \
+ mock.patch('snaps.openstack.utils.deploy_utils.create_router',
+ return_value=OpenStackRouter(
+ self.os_creds, RouterConfig(name='foo'))), \
mock.patch('snaps.openstack.utils.deploy_utils.'
'create_vm_instance',
return_value=OpenStackVmInstance(
@@ -91,8 +98,7 @@ class VPingSSHTesting(unittest.TestCase):
os_creds=self.os_creds)
@mock.patch('snaps.openstack.utils.deploy_utils.create_vm_instance')
- @mock.patch('functest.opnfv_tests.openstack.vping.vping_base.os.'
- 'path.exists', return_value=True)
+ @mock.patch('os.path.exists', return_value=True)
@mock.patch('snaps.openstack.create_flavor.OpenStackFlavor.create',
return_value=None)
@mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
@@ -110,10 +116,8 @@ class VPingSSHTesting(unittest.TestCase):
'VPingSSH._do_vping_ssh', return_value=TestCase.EX_OK)
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
'get_ext_net_name', return_value='foo')
- def test_vping_ssh(self, create_vm, path_exists,
- flavor_create, get_port_ip, vm_active, ssh_active,
- ssh_client, scp_client, trans_script, do_vping_ssh,
- ext_net_name):
+ def test_vping_ssh(self, *args):
+ # pylint: disable=unused-argument
os_vm_inst = mock.MagicMock(name='get_console_output')
os_vm_inst.get_console_output.return_value = 'vPing OK'
ssh_client = mock.MagicMock(name='get_transport')
@@ -159,3 +163,8 @@ class VPingSSHTesting(unittest.TestCase):
'OpenStackVmInstance.'
'ssh_client', return_value=ssh_client):
self.assertEquals(TestCase.EX_OK, self.vping_ssh.run())
+
+
+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 4438c6a2..218d03c4 100644
--- a/functest/tests/unit/utils/test_functest_utils.py
+++ b/functest/tests/unit/utils/test_functest_utils.py
@@ -10,12 +10,12 @@
# pylint: disable=missing-docstring
import logging
-import pkg_resources
import os
import time
import unittest
import mock
+import pkg_resources
from six.moves import urllib
from functest.utils import functest_utils
@@ -147,8 +147,8 @@ class FunctestUtilsTesting(unittest.TestCase):
def cmd_readline(self):
return 'test_value\n'
- @mock.patch('functest.utils.functest_utils.logger.error')
- @mock.patch('functest.utils.functest_utils.logger.info')
+ @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):
with mock.patch('functest.utils.functest_utils.subprocess.Popen') \
@@ -178,7 +178,7 @@ class FunctestUtilsTesting(unittest.TestCase):
mopen.assert_called_once_with(self.output_file, "w")
mock_logger_error.assert_called_once_with(self.error_msg)
- @mock.patch('functest.utils.functest_utils.logger.info')
+ @mock.patch('functest.utils.functest_utils.LOGGER.info')
def test_execute_command_args_present_with_success(self, mock_logger_info,
):
with mock.patch('functest.utils.functest_utils.subprocess.Popen') \
@@ -255,7 +255,7 @@ class FunctestUtilsTesting(unittest.TestCase):
def _get_functest_config(self, var):
return var
- @mock.patch('functest.utils.functest_utils.logger.error')
+ @mock.patch('functest.utils.functest_utils.LOGGER.error')
def test_get_dict_by_test(self, mock_logger_error):
with mock.patch('six.moves.builtins.open', mock.mock_open()), \
mock.patch('functest.utils.functest_utils.yaml.safe_load') \
@@ -321,7 +321,7 @@ class FunctestUtilsTesting(unittest.TestCase):
resp = functest_utils.get_functest_yaml()
self.assertEqual(resp, self.file_yaml)
- @mock.patch('functest.utils.functest_utils.logger.info')
+ @mock.patch('functest.utils.functest_utils.LOGGER.info')
def test_print_separator(self, mock_logger_info):
functest_utils.print_separator()
mock_logger_info.assert_called_once_with("======================="
diff --git a/functest/tests/unit/vnf/epc/__init__.py b/functest/tests/unit/vnf/epc/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/functest/tests/unit/vnf/epc/__init__.py
diff --git a/functest/tests/unit/vnf/epc/test_juju_epc.py b/functest/tests/unit/vnf/epc/test_juju_epc.py
index d1e115e7..b3eef862 100644
--- a/functest/tests/unit/vnf/epc/test_juju_epc.py
+++ b/functest/tests/unit/vnf/epc/test_juju_epc.py
@@ -69,6 +69,7 @@ class JujuEpcTesting(unittest.TestCase):
'vnf': {},
'test_vnf': {}}
+ @unittest.skip("It must be fixed. Please see JIRA FUNCTEST-915")
@mock.patch('functest.utils.openstack_utils.get_keystone_client',
return_value='test')
@mock.patch('functest.utils.openstack_utils.get_or_create_tenant_for_vnf',
diff --git a/functest/tests/unit/vnf/router/test_cloudify_vrouter.py b/functest/tests/unit/vnf/router/test_cloudify_vrouter.py
index 2e24e7e9..db03d716 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,19 @@ 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.utils.functest_utils.get_parameter_from_yaml',
+ 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/config.py b/functest/utils/config.py
index f4749a75..050f12a9 100644
--- a/functest/utils/config.py
+++ b/functest/utils/config.py
@@ -12,6 +12,7 @@ import six
class Config(object):
def __init__(self):
try:
+ # pylint: disable=bad-continuation
with open(pkg_resources.resource_filename(
'functest', 'ci/config_functest.yaml')) as yfile:
self.functest_yaml = yaml.safe_load(yfile)
diff --git a/functest/utils/constants.py b/functest/utils/constants.py
index 75c97c76..cb3ea787 100644
--- a/functest/utils/constants.py
+++ b/functest/utils/constants.py
@@ -1,12 +1,15 @@
#!/usr/bin/env python
+# pylint: disable=missing-docstring
+
import six
from functest.utils import config
from functest.utils import env
-class Constants(object):
+class Constants(object): # pylint: disable=too-few-public-methods
+
def __init__(self):
for attr_n, attr_v in six.iteritems(config.CONF.__dict__):
self.__setattr__(attr_n, attr_v)
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()
diff --git a/functest/utils/functest_utils.py b/functest/utils/functest_utils.py
index 1e88dadb..c1491855 100644
--- a/functest/utils/functest_utils.py
+++ b/functest/utils/functest_utils.py
@@ -6,24 +6,25 @@
# 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
-#
-import functools
+
+# pylint: disable=missing-docstring
+
+from __future__ import print_function
import logging
import os
-import pkg_resources
import re
import shutil
import subprocess
import sys
-import time
+import pkg_resources
import dns.resolver
from six.moves import urllib
import yaml
from functest.utils import constants
-logger = logging.getLogger(__name__)
+LOGGER = logging.getLogger(__name__)
# ----------------------------------------------------------
@@ -53,8 +54,8 @@ def download_url(url, dest_path):
except (urllib.error.HTTPError, urllib.error.URLError):
return False
- with open(dest, 'wb') as f:
- shutil.copyfileobj(response, f)
+ with open(dest, 'wb') as lfile:
+ shutil.copyfileobj(response, lfile)
return True
@@ -72,13 +73,13 @@ def get_resolvconf_ns():
line = rconf.readline()
resolver = dns.resolver.Resolver()
while line:
- ip = re.search(r"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b", line)
- if ip:
- resolver.nameservers = [ip.group(0)]
+ addr_ip = re.search(r"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b", line)
+ if addr_ip:
+ resolver.nameservers = [addr_ip.group(0)]
try:
result = resolver.query('opnfv.org')[0]
if result != "":
- nameservers.append(ip.group())
+ nameservers.append(addr_ip.group())
except dns.exception.Timeout:
pass
line = rconf.readline()
@@ -109,49 +110,50 @@ def execute_command(cmd, info=False, error_msg="",
msg_exec = ("Executing command: '%s'" % cmd)
if verbose:
if info:
- logger.info(msg_exec)
+ LOGGER.info(msg_exec)
else:
- logger.debug(msg_exec)
- p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
+ LOGGER.debug(msg_exec)
+ popen = subprocess.Popen(
+ cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if output_file:
- f = open(output_file, "w")
- for line in iter(p.stdout.readline, b''):
+ ofd = open(output_file, "w")
+ for line in iter(popen.stdout.readline, b''):
if output_file:
- f.write(line)
+ ofd.write(line)
else:
line = line.replace('\n', '')
- print(line)
+ print (line)
sys.stdout.flush()
if output_file:
- f.close()
- p.stdout.close()
- returncode = p.wait()
+ ofd.close()
+ popen.stdout.close()
+ returncode = popen.wait()
if returncode != 0:
if verbose:
- logger.error(error_msg)
+ LOGGER.error(error_msg)
return returncode
def get_dict_by_test(testname):
+ # pylint: disable=bad-continuation
with open(pkg_resources.resource_filename(
- 'functest', 'ci/testcases.yaml')) as f:
- testcases_yaml = yaml.safe_load(f)
+ 'functest', 'ci/testcases.yaml')) as tyaml:
+ testcases_yaml = yaml.safe_load(tyaml)
for dic_tier in testcases_yaml.get("tiers"):
for dic_testcase in dic_tier['testcases']:
if dic_testcase['case_name'] == testname:
return dic_testcase
- logger.error('Project %s is not defined in testcases.yaml' % testname)
+ LOGGER.error('Project %s is not defined in testcases.yaml', testname)
return None
def get_criteria_by_test(testname):
- dict = get_dict_by_test(testname)
- if dict:
- return dict['criteria']
+ tdict = get_dict_by_test(testname)
+ if tdict:
+ return tdict['criteria']
return None
@@ -160,21 +162,20 @@ def get_criteria_by_test(testname):
# YAML UTILS
#
# -----------------------------------------------------------
-def get_parameter_from_yaml(parameter, file):
+def get_parameter_from_yaml(parameter, yfile):
"""
Returns the value of a given parameter in file.yaml
parameter must be given in string format with dots
Example: general.openstack.image_name
"""
- with open(file) as f:
- file_yaml = yaml.safe_load(f)
- f.close()
+ with open(yfile) as yfd:
+ file_yaml = yaml.safe_load(yfd)
value = file_yaml
for element in parameter.split("."):
value = value.get(element)
if value is None:
raise ValueError("The parameter %s is not defined in"
- " %s" % (parameter, file))
+ " %s" % (parameter, yfile))
return value
@@ -184,25 +185,12 @@ def get_functest_config(parameter):
def get_functest_yaml():
- with open(constants.CONST.__getattribute__('CONFIG_FUNCTEST_YAML')) as f:
- functest_yaml = yaml.safe_load(f)
- f.close()
+ # pylint: disable=bad-continuation
+ with open(constants.CONST.__getattribute__(
+ 'CONFIG_FUNCTEST_YAML')) as yaml_fd:
+ functest_yaml = yaml.safe_load(yaml_fd)
return functest_yaml
def print_separator():
- logger.info("==============================================")
-
-
-def timethis(func):
- """Measure the time it takes for a function to complete"""
- @functools.wraps(func)
- def timed(*args, **kwargs):
- ts = time.time()
- result = func(*args, **kwargs)
- te = time.time()
- elapsed = '{0}'.format(te - ts)
- logger.info('{f}(*{a}, **{kw}) took: {t} sec'.format(
- f=func.__name__, a=args, kw=kwargs, t=elapsed))
- return result, elapsed
- return timed
+ LOGGER.info("==============================================")