summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--functest/ci/config_functest.yaml5
-rw-r--r--functest/ci/run_tests.py46
-rw-r--r--functest/core/feature.py5
-rw-r--r--functest/core/robotframework.py5
-rw-r--r--functest/core/vnf.py50
-rw-r--r--functest/energy/energy.py47
-rw-r--r--functest/opnfv_tests/sdn/odl/odl.py11
-rw-r--r--functest/opnfv_tests/vnf/epc/juju_epc.py12
-rw-r--r--functest/tests/unit/ci/test_run_tests.py36
-rw-r--r--functest/tests/unit/core/test_feature.py9
-rw-r--r--functest/tests/unit/core/test_vnf.py16
-rw-r--r--functest/tests/unit/energy/test_functest_energy.py82
-rw-r--r--functest/tests/unit/odl/test_odl.py152
-rw-r--r--functest/tests/unit/utils/test_functest_utils.py28
-rw-r--r--functest/utils/functest_utils.py23
15 files changed, 228 insertions, 299 deletions
diff --git a/functest/ci/config_functest.yaml b/functest/ci/config_functest.yaml
index 928da8f93..be7a2db58 100644
--- a/functest/ci/config_functest.yaml
+++ b/functest/ci/config_functest.yaml
@@ -184,8 +184,3 @@ example:
router_name: example-router
sg_name: example-sg
sg_desc: Example Security group
-
-energy_recorder:
- api_url: http://energy.opnfv.fr/resources
- api_user: ""
- api_password: ""
diff --git a/functest/ci/run_tests.py b/functest/ci/run_tests.py
index 89c74a975..ff38720d6 100644
--- a/functest/ci/run_tests.py
+++ b/functest/ci/run_tests.py
@@ -25,17 +25,13 @@ import pkg_resources
import enum
import prettytable
+import yaml
import functest.ci.tier_builder as tb
import functest.core.testcase as testcase
-import functest.utils.functest_utils as ft_utils
-from functest.utils.constants import CONST
-# __name__ cannot be used here
LOGGER = logging.getLogger('functest.ci.run_tests')
-
-CONFIG_FUNCTEST_PATH = pkg_resources.resource_filename(
- 'functest', 'ci/config_functest.yaml')
+ENV_FILE = "/home/opnfv/functest/conf/env_file"
class Result(enum.Enum):
@@ -93,14 +89,18 @@ class Runner(object):
self.clean_flag = True
self.report_flag = False
self.tiers = tb.TierBuilder(
- CONST.__getattribute__('INSTALLER_TYPE'),
- CONST.__getattribute__('DEPLOY_SCENARIO'),
+ os.environ.get('INSTALLER_TYPE', None),
+ os.environ.get('DEPLOY_SCENARIO', None),
pkg_resources.resource_filename('functest', 'ci/testcases.yaml'))
@staticmethod
- def source_envfile(rc_file):
+ def source_envfile(rc_file=ENV_FILE):
"""Source the env file passed as arg"""
+ if not os.path.isfile(rc_file):
+ LOGGER.debug("No env file %s found", rc_file)
+ return
with open(rc_file, "r") as rcfd:
+ LOGGER.info("Sourcing env file %s", rc_file)
for line in rcfd:
var = (line.rstrip('"\n').replace('export ', '').split(
"=") if re.search(r'(.*)=(.*)', line) else None)
@@ -111,13 +111,25 @@ class Runner(object):
key = re.sub(r'^["\' ]*|[ \'"]*$', '', var[0])
value = re.sub(r'^["\' ]*|[ \'"]*$', '', "".join(var[1:]))
os.environ[key] = value
- setattr(CONST, key, value)
+
+ @staticmethod
+ def get_dict_by_test(testname):
+ # pylint: disable=bad-continuation,missing-docstring
+ with open(pkg_resources.resource_filename(
+ '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)
+ return None
@staticmethod
def get_run_dict(testname):
"""Obtain the 'run' block of the testcase from testcases.yaml"""
try:
- dic_testcase = ft_utils.get_dict_by_test(testname)
+ dic_testcase = Runner.get_dict_by_test(testname)
if not dic_testcase:
LOGGER.error("Cannot get %s's config options", testname)
elif 'run' in dic_testcase:
@@ -139,7 +151,7 @@ class Runner(object):
try:
module = importlib.import_module(run_dict['module'])
cls = getattr(module, run_dict['class'])
- test_dict = ft_utils.get_dict_by_test(test.get_name())
+ test_dict = Runner.get_dict_by_test(test.get_name())
test_case = cls(**test_dict)
self.executed_test_cases[test.get_name()] = test_case
try:
@@ -195,9 +207,9 @@ class Runner(object):
field_names=['tiers', 'order', 'CI Loop', 'description',
'testcases'])
for tier in self.tiers.get_tiers():
+ ci_loop = os.environ.get('CI_LOOP', 'daily')
if (tier.get_tests() and
- re.search(CONST.__getattribute__('CI_LOOP'),
- tier.get_ci_loop()) is not None):
+ re.search(ci_loop, tier.get_ci_loop()) is not None):
tiers_to_run.append(tier)
msg.add_row([tier.get_name(), tier.get_order(),
tier.get_ci_loop(),
@@ -217,7 +229,7 @@ class Runner(object):
try:
if 'test' in kwargs:
LOGGER.debug("Sourcing the credential file...")
- self.source_envfile(getattr(CONST, 'env_file'))
+ self.source_envfile()
LOGGER.debug("Test args: %s", kwargs['test'])
if self.tiers.get_tier(kwargs['test']):
@@ -235,7 +247,7 @@ class Runner(object):
LOGGER.error("Unknown test case or tier '%s', or not "
"supported by the given scenario '%s'.",
kwargs['test'],
- CONST.__getattribute__('DEPLOY_SCENARIO'))
+ os.environ.get('DEPLOY_SCENARIO', ""))
LOGGER.debug("Available tiers are:\n\n%s",
self.tiers)
return Result.EX_ERROR
@@ -258,7 +270,7 @@ class Runner(object):
field_names=['env var', 'value'])
for env_var in ['INSTALLER_TYPE', 'DEPLOY_SCENARIO', 'BUILD_TAG',
'CI_LOOP']:
- msg.add_row([env_var, CONST.__getattribute__(env_var)])
+ msg.add_row([env_var, os.environ.get(env_var, "")])
LOGGER.info("Deployment description:\n\n%s\n", msg)
msg = prettytable.PrettyTable(
header_style='upper', padding_width=5,
diff --git a/functest/core/feature.py b/functest/core/feature.py
index 3200dad85..65fd5a084 100644
--- a/functest/core/feature.py
+++ b/functest/core/feature.py
@@ -18,7 +18,6 @@ import subprocess
import time
import functest.core.testcase as base
-from functest.utils.constants import CONST
__author__ = ("Serena Feng <feng.xiaowei@zte.com.cn>, "
"Cedric Ollivier <cedric.ollivier@orange.com>")
@@ -28,11 +27,11 @@ class Feature(base.TestCase):
"""Base model for single feature."""
__logger = logging.getLogger(__name__)
+ dir_results = "/home/opnfv/functest/results"
def __init__(self, **kwargs):
super(Feature, self).__init__(**kwargs)
- self.result_file = "{}/{}.log".format(
- CONST.__getattribute__('dir_results'), self.case_name)
+ self.result_file = "{}/{}.log".format(self.dir_results, self.case_name)
try:
module = kwargs['run']['module']
self.logger = logging.getLogger(module)
diff --git a/functest/core/robotframework.py b/functest/core/robotframework.py
index ccfa26b71..54574a683 100644
--- a/functest/core/robotframework.py
+++ b/functest/core/robotframework.py
@@ -22,7 +22,6 @@ from robot.utils.robottime import timestamp_to_secs
from six import StringIO
from functest.core import testcase
-from functest.utils import constants
__author__ = "Cedric Ollivier <cedric.ollivier@orange.com>"
@@ -54,10 +53,10 @@ class RobotFramework(testcase.TestCase):
"""RobotFramework runner."""
__logger = logging.getLogger(__name__)
+ dir_results = "/home/opnfv/functest/results"
def __init__(self, **kwargs):
- self.res_dir = os.path.join(
- constants.CONST.__getattribute__('dir_results'), 'robot')
+ self.res_dir = os.path.join(self.dir_results, 'robot')
self.xml_file = os.path.join(self.res_dir, 'output.xml')
super(RobotFramework, self).__init__(**kwargs)
diff --git a/functest/core/vnf.py b/functest/core/vnf.py
index 0e2e30134..0da8f6db1 100644
--- a/functest/core/vnf.py
+++ b/functest/core/vnf.py
@@ -13,14 +13,14 @@ import logging
import time
import uuid
-import functest.core.testcase as base
-from functest.utils.constants import CONST
from snaps.config.user import UserConfig
from snaps.config.project import ProjectConfig
from snaps.openstack.create_user import OpenStackUser
from snaps.openstack.create_project import OpenStackProject
from snaps.openstack.tests import openstack_tests
+from functest.core import testcase
+
__author__ = ("Morgan Richomme <morgan.richomme@orange.com>, "
"Valentin Boucher <valentin.boucher@orange.com>")
@@ -41,18 +41,22 @@ class VnfTestException(Exception):
"""Raise when VNF cannot be tested."""
-class VnfOnBoarding(base.TestCase):
+class VnfOnBoarding(testcase.TestCase):
+ # pylint: disable=too-many-instance-attributes
"""Base model for VNF test cases."""
__logger = logging.getLogger(__name__)
+ env_file = "/home/opnfv/functest/conf/env_file"
def __init__(self, **kwargs):
super(VnfOnBoarding, self).__init__(**kwargs)
- self.tenant_name = CONST.__getattribute__(
- 'vnf_{}_tenant_name'.format(self.case_name))
+ self.user_name = self.case_name
+ self.tenant_name = self.case_name
self.snaps_creds = {}
self.created_object = []
self.os_project = None
+ self.tenant_description = "Created by OPNFV Functest: {}".format(
+ self.case_name)
def run(self, **kwargs):
"""
@@ -79,15 +83,14 @@ class VnfOnBoarding(base.TestCase):
self.stop_time = time.time()
# Calculation with different weight depending on the steps TODO
self.result = 100
- return base.TestCase.EX_OK
- else:
- self.result = 0
- self.stop_time = time.time()
- return base.TestCase.EX_TESTCASE_FAILED
+ return testcase.TestCase.EX_OK
+ self.result = 0
+ self.stop_time = time.time()
+ return testcase.TestCase.EX_TESTCASE_FAILED
except Exception: # pylint: disable=broad-except
self.stop_time = time.time()
self.__logger.exception("Exception on VNF testing")
- return base.TestCase.EX_TESTCASE_FAILED
+ return testcase.TestCase.EX_TESTCASE_FAILED
def prepare(self):
"""
@@ -102,36 +105,31 @@ class VnfOnBoarding(base.TestCase):
Raise VnfPreparationException in case of problem
"""
try:
- tenant_description = CONST.__getattribute__(
- 'vnf_{}_tenant_description'.format(self.case_name))
- self.__logger.info("Prepare VNF: %s, description: %s",
- self.tenant_name, tenant_description)
+ self.__logger.info(
+ "Prepare VNF: %s, description: %s", self.tenant_name,
+ self.tenant_description)
snaps_creds = openstack_tests.get_credentials(
- os_env_file=CONST.__getattribute__('env_file'))
+ os_env_file=self.env_file)
- project_creator = OpenStackProject(
+ self.os_project = OpenStackProject(
snaps_creds,
ProjectConfig(
name=self.tenant_name,
- description=tenant_description
+ description=self.tenant_description
))
- project_creator.create()
- self.created_object.append(project_creator)
- self.os_project = project_creator
-
+ self.os_project.create()
+ self.created_object.append(self.os_project)
user_creator = OpenStackUser(
snaps_creds,
UserConfig(
- name=self.tenant_name,
+ name=self.user_name,
password=str(uuid.uuid4()),
roles={'admin': self.tenant_name}))
-
user_creator.create()
self.created_object.append(user_creator)
-
self.snaps_creds = user_creator.get_os_creds(self.tenant_name)
- return base.TestCase.EX_OK
+ return testcase.TestCase.EX_OK
except Exception: # pylint: disable=broad-except
self.__logger.exception("Exception raised during VNF preparation")
raise VnfPreparationException
diff --git a/functest/energy/energy.py b/functest/energy/energy.py
index 2835e05c1..c7da8f046 100644
--- a/functest/energy/energy.py
+++ b/functest/energy/energy.py
@@ -12,14 +12,13 @@
import json
import logging
+import os
+import traceback
from functools import wraps
import requests
from six.moves import urllib
-from functest.utils.constants import CONST
-import functest.utils.functest_utils as ft_utils
-
def finish_session(current_scenario):
"""Finish a recording session."""
@@ -94,23 +93,18 @@ class EnergyRecorder(object):
# Singleton pattern for energy_recorder_api static member
# Load only if not previouly done
if EnergyRecorder.energy_recorder_api is None:
- environment = CONST.__getattribute__('NODE_NAME')
+ assert os.environ['NODE_NAME']
+ assert os.environ["ENERGY_RECORDER_API_URL"]
+ environment = os.environ['NODE_NAME']
+ energy_recorder_uri = os.environ["ENERGY_RECORDER_API_URL"]
- # API URL
- energy_recorder_uri = ft_utils.get_functest_config(
- "energy_recorder.api_url")
- assert energy_recorder_uri
- assert environment
+ # Creds
+ creds_usr = os.environ.get("ENERGY_RECORDER_API_USER", "")
+ creds_pass = os.environ.get("ENERGY_RECORDER_API_PASSWORD", "")
uri_comp = "/recorders/environment/"
uri_comp += urllib.parse.quote_plus(environment)
- # Creds
- creds_usr = ft_utils.get_functest_config(
- "energy_recorder.api_user")
- creds_pass = ft_utils.get_functest_config(
- "energy_recorder.api_password")
-
if creds_usr != "" and creds_pass != "":
energy_recorder_api_auth = (creds_usr, creds_pass)
else:
@@ -184,8 +178,9 @@ class EnergyRecorder(object):
except Exception: # pylint: disable=broad-except
# Default exception handler to ensure that method
# is safe for caller
- EnergyRecorder.logger.exception(
- "Error while submitting scenarion to energy recorder API"
+ EnergyRecorder.logger.info(
+ "Error while submitting scenarion to energy recorder API\n%s",
+ traceback.format_exc()
)
return_status = False
return return_status
@@ -210,8 +205,9 @@ class EnergyRecorder(object):
except Exception: # pylint: disable=broad-except
# Default exception handler to ensure that method
# is safe for caller
- EnergyRecorder.logger.exception(
- "Error while starting energy recorder API"
+ EnergyRecorder.logger.info(
+ "Error while starting energy recorder API\n%s",
+ traceback.format_exc()
)
return_status = False
return return_status
@@ -246,8 +242,9 @@ class EnergyRecorder(object):
except Exception: # pylint: disable=broad-except
# Default exception handler to ensure that method
# is safe for caller
- EnergyRecorder.logger.exception(
- "Error while stoping energy recorder API"
+ EnergyRecorder.logger.info(
+ "Error while stoping energy recorder API\n%s",
+ traceback.format_exc()
)
return_status = False
return return_status
@@ -288,8 +285,9 @@ class EnergyRecorder(object):
except Exception: # pylint: disable=broad-except
# Default exception handler to ensure that method
# is safe for caller
- EnergyRecorder.logger.exception(
- "Error while setting step on energy recorder API"
+ EnergyRecorder.logger.info(
+ "Error while setting step on energy recorder API\n%s",
+ traceback.format_exc()
)
return_status = False
return return_status
@@ -328,8 +326,9 @@ class EnergyRecorder(object):
except Exception: # pylint: disable=broad-except
# Default exception handler to ensure that method
# is safe for caller
- EnergyRecorder.logger.exception(
+ EnergyRecorder.logger.info(
"Error while getting current scenario from energy recorder API"
+ "\n%s", traceback.format_exc()
)
return_value = None
return return_value
diff --git a/functest/opnfv_tests/sdn/odl/odl.py b/functest/opnfv_tests/sdn/odl/odl.py
index f25dfe5ec..25cc758ea 100644
--- a/functest/opnfv_tests/sdn/odl/odl.py
+++ b/functest/opnfv_tests/sdn/odl/odl.py
@@ -26,10 +26,11 @@ import re
import sys
from six.moves import urllib
+from snaps.openstack.utils import keystone_utils
from functest.core import robotframework
+from functest.opnfv_tests.openstack.snaps import snaps_utils
from functest.utils import constants
-import functest.utils.openstack_utils as op_utils
__author__ = "Cedric Ollivier <cedric.ollivier@orange.com>"
@@ -155,8 +156,9 @@ class ODLTests(robotframework.RobotFramework):
suites = kwargs["suites"]
except KeyError:
pass
- kwargs = {'neutronurl': op_utils.get_endpoint(
- service_type='network')}
+ snaps_creds = snaps_utils.get_credentials()
+ kwargs = {'neutronurl': keystone_utils.get_endpoint(
+ snaps_creds, 'network')}
kwargs['odlip'] = urllib.parse.urlparse(
kwargs['neutronurl']).hostname
kwargs['odlwebport'] = '8080'
@@ -274,7 +276,6 @@ def main():
return result
if args['pushtodb']:
return odl.push_to_db()
- else:
- return result
+ return result
except Exception: # pylint: disable=broad-except
return robotframework.RobotFramework.EX_RUN_ERROR
diff --git a/functest/opnfv_tests/vnf/epc/juju_epc.py b/functest/opnfv_tests/vnf/epc/juju_epc.py
index c373eee46..283a152fd 100644
--- a/functest/opnfv_tests/vnf/epc/juju_epc.py
+++ b/functest/opnfv_tests/vnf/epc/juju_epc.py
@@ -153,13 +153,11 @@ class JujuEpc(vnf.VnfOnBoarding):
self.__logger.info("Creating Credentials for Abot-epc .....")
user_creator = self._bypass_juju_network_discovery_bug(
'juju_network_discovery_bug')
- snaps_creds = user_creator.get_os_creds('juju_network_discovery_bug')
+ snaps_creds = user_creator.get_os_creds(self.snaps_creds.project_name)
credentials_yaml = os.path.join(self.res_dir, "credentials.yaml")
- # 'tenant_n' should habe been equal to snaps_creds.project_name
- # user_creator.get_os_creds() must be checked
creds_data = {
'pass': snaps_creds.password,
- 'tenant_n': self.snaps_creds.project_name,
+ 'tenant_n': snaps_creds.project_name,
'user_n': snaps_creds.username}
with open(credentials_yaml, 'w') as yfile:
yfile.write(CREDS_TEMPLATE2.format(**creds_data))
@@ -172,13 +170,11 @@ class JujuEpc(vnf.VnfOnBoarding):
self.__logger.info("Creating Credentials for Abot-epc .....")
user_creator = self._bypass_juju_network_discovery_bug(
'juju_network_discovery_bug')
- snaps_creds = user_creator.get_os_creds('juju_network_discovery_bug')
+ snaps_creds = user_creator.get_os_creds(self.snaps_creds.project_name)
credentials_yaml = os.path.join(self.res_dir, "credentials.yaml")
- # 'tenant_n' should habe been equal to snaps_creds.project_name
- # user_creator.get_os_creds() must be checked
creds_data = {
'pass': snaps_creds.password,
- 'tenant_n': self.snaps_creds.project_name,
+ 'tenant_n': snaps_creds.project_name,
'user_n': snaps_creds.username,
'project_domain_n': snaps_creds.project_domain_name,
'user_domain_n': snaps_creds.user_domain_name}
diff --git a/functest/tests/unit/ci/test_run_tests.py b/functest/tests/unit/ci/test_run_tests.py
index 0bb4315ee..bc9677433 100644
--- a/functest/tests/unit/ci/test_run_tests.py
+++ b/functest/tests/unit/ci/test_run_tests.py
@@ -14,7 +14,6 @@ import os
import mock
from functest.ci import run_tests
-from functest.utils.constants import CONST
from functest.core.testcase import TestCase
@@ -55,7 +54,7 @@ class RunTestsTesting(unittest.TestCase):
self.run_tests_parser = run_tests.RunTestsParser()
- @mock.patch('functest.ci.run_tests.ft_utils.get_dict_by_test')
+ @mock.patch('functest.ci.run_tests.Runner.get_dict_by_test')
def test_get_run_dict(self, *args):
retval = {'run': mock.Mock()}
args[0].return_value = retval
@@ -63,7 +62,7 @@ class RunTestsTesting(unittest.TestCase):
args[0].assert_called_once_with('test_name')
@mock.patch('functest.ci.run_tests.LOGGER.error')
- @mock.patch('functest.ci.run_tests.ft_utils.get_dict_by_test',
+ @mock.patch('functest.ci.run_tests.Runner.get_dict_by_test',
return_value=None)
def test_get_run_dict_config_ko(self, *args):
testname = 'test_name'
@@ -77,7 +76,7 @@ class RunTestsTesting(unittest.TestCase):
args[1].assert_has_calls(calls)
@mock.patch('functest.ci.run_tests.LOGGER.exception')
- @mock.patch('functest.ci.run_tests.ft_utils.get_dict_by_test',
+ @mock.patch('functest.ci.run_tests.Runner.get_dict_by_test',
side_effect=Exception)
def test_get_run_dict_exception(self, *args):
testname = 'test_name'
@@ -93,7 +92,8 @@ class RunTestsTesting(unittest.TestCase):
envfile = 'rc_file'
with mock.patch('six.moves.builtins.open',
mock.mock_open(read_data=msg),
- create=True) as mock_method:
+ create=True) as mock_method,\
+ mock.patch('os.path.isfile', return_value=True):
mock_method.return_value.__iter__ = lambda self: iter(
self.readline, '')
self.runner.source_envfile(envfile)
@@ -113,6 +113,19 @@ class RunTestsTesting(unittest.TestCase):
self._test_source_envfile(
'export "\'OS_TENANT_NAME\'" = "\'admin\'"')
+ def test_get_dict_by_test(self):
+ with mock.patch('six.moves.builtins.open', mock.mock_open()), \
+ mock.patch('yaml.safe_load') as mock_yaml:
+ mock_obj = mock.Mock()
+ testcase_dict = {'case_name': 'testname',
+ 'criteria': 50}
+ attrs = {'get.return_value': [{'testcases': [testcase_dict]}]}
+ mock_obj.configure_mock(**attrs)
+ mock_yaml.return_value = mock_obj
+ self.assertDictEqual(
+ run_tests.Runner.get_dict_by_test('testname'),
+ testcase_dict)
+
@mock.patch('functest.ci.run_tests.Runner.get_run_dict',
return_value=None)
def test_run_tests_import_exception(self, *args):
@@ -129,7 +142,7 @@ class RunTestsTesting(unittest.TestCase):
@mock.patch('importlib.import_module', name="module",
return_value=mock.Mock(test_class=mock.Mock(
side_effect=FakeModule)))
- @mock.patch('functest.utils.functest_utils.get_dict_by_test')
+ @mock.patch('functest.ci.run_tests.Runner.get_dict_by_test')
def test_run_tests_default(self, *args):
mock_test = mock.Mock()
kwargs = {'get_name.return_value': 'test_name',
@@ -164,7 +177,7 @@ class RunTestsTesting(unittest.TestCase):
@mock.patch('functest.ci.run_tests.Runner.run_tier')
@mock.patch('functest.ci.run_tests.Runner.summary')
def test_run_all_default(self, *mock_methods):
- CONST.__setattr__('CI_LOOP', 'test_ci_loop')
+ os.environ['CI_LOOP'] = 'test_ci_loop'
self.runner.run_all()
mock_methods[1].assert_not_called()
self.assertTrue(mock_methods[2].called)
@@ -172,7 +185,7 @@ class RunTestsTesting(unittest.TestCase):
@mock.patch('functest.ci.run_tests.LOGGER.info')
@mock.patch('functest.ci.run_tests.Runner.summary')
def test_run_all_missing_tier(self, *mock_methods):
- CONST.__setattr__('CI_LOOP', 'loop_re_not_available')
+ os.environ['CI_LOOP'] = 'loop_re_not_available'
self.runner.run_all()
self.assertTrue(mock_methods[1].called)
@@ -187,8 +200,7 @@ class RunTestsTesting(unittest.TestCase):
self.runner.tiers.configure_mock(**args)
self.assertEqual(self.runner.main(**kwargs),
run_tests.Result.EX_ERROR)
- mock_methods[1].assert_called_once_with(
- '/home/opnfv/functest/conf/env_file')
+ mock_methods[1].assert_called_once_with()
@mock.patch('functest.ci.run_tests.Runner.source_envfile')
@mock.patch('functest.ci.run_tests.Runner.run_test',
@@ -237,7 +249,7 @@ class RunTestsTesting(unittest.TestCase):
run_tests.Result.EX_OK)
args[0].assert_called_once_with(None)
args[1].assert_called_once_with()
- args[2].assert_called_once_with('/home/opnfv/functest/conf/env_file')
+ args[2].assert_called_once_with()
@mock.patch('functest.ci.run_tests.Runner.source_envfile')
def test_main_any_tier_test_ko(self, *args):
@@ -248,7 +260,7 @@ class RunTestsTesting(unittest.TestCase):
self.assertEqual(
self.runner.main(test='any', noclean=True, report=True),
run_tests.Result.EX_ERROR)
- args[0].assert_called_once_with('/home/opnfv/functest/conf/env_file')
+ args[0].assert_called_once_with()
if __name__ == "__main__":
diff --git a/functest/tests/unit/core/test_feature.py b/functest/tests/unit/core/test_feature.py
index 8c73bb5d5..3219c7265 100644
--- a/functest/tests/unit/core/test_feature.py
+++ b/functest/tests/unit/core/test_feature.py
@@ -55,6 +55,9 @@ class FeatureTestingBase(unittest.TestCase):
class FeatureTesting(FeatureTestingBase):
def setUp(self):
+ # logging must be disabled else it calls time.time()
+ # what will break these unit tests.
+ logging.disable(logging.CRITICAL)
with mock.patch('six.moves.builtins.open'):
self.feature = feature.Feature(
project_name=self._project_name, case_name=self._case_name)
@@ -74,6 +77,9 @@ class FeatureTesting(FeatureTestingBase):
class BashFeatureTesting(FeatureTestingBase):
def setUp(self):
+ # logging must be disabled else it calls time.time()
+ # what will break these unit tests.
+ logging.disable(logging.CRITICAL)
with mock.patch('six.moves.builtins.open'):
self.feature = feature.BashFeature(
project_name=self._project_name, case_name=self._case_name)
@@ -108,7 +114,4 @@ class BashFeatureTesting(FeatureTestingBase):
if __name__ == "__main__":
- # logging must be disabled else it calls time.time()
- # what will break these unit tests.
- logging.disable(logging.CRITICAL)
unittest.main(verbosity=2)
diff --git a/functest/tests/unit/core/test_vnf.py b/functest/tests/unit/core/test_vnf.py
index 112ce53b7..16a609027 100644
--- a/functest/tests/unit/core/test_vnf.py
+++ b/functest/tests/unit/core/test_vnf.py
@@ -16,7 +16,6 @@ import mock
from functest.core import vnf
from functest.core import testcase
-from functest.utils import constants
from snaps.openstack.os_credentials import OSCreds
@@ -29,9 +28,6 @@ class VnfBaseTesting(unittest.TestCase):
tenant_description = 'description'
def setUp(self):
- constants.CONST.__setattr__("vnf_foo_tenant_name", self.tenant_name)
- constants.CONST.__setattr__(
- "vnf_foo_tenant_description", self.tenant_description)
self.test = vnf.VnfOnBoarding(project='functest', case_name='foo')
def test_run_deploy_orch_exc(self):
@@ -117,8 +113,7 @@ class VnfBaseTesting(unittest.TestCase):
def test_prepare_exc1(self, *args):
with self.assertRaises(Exception):
self.test.prepare()
- args[0].assert_called_with(
- os_env_file=constants.CONST.__getattribute__('env_file'))
+ args[0].assert_called_with(os_env_file=vnf.VnfOnBoarding.env_file)
args[1].assert_not_called()
args[2].assert_not_called()
@@ -128,8 +123,7 @@ class VnfBaseTesting(unittest.TestCase):
def test_prepare_exc2(self, *args):
with self.assertRaises(Exception):
self.test.prepare()
- args[0].assert_called_with(
- os_env_file=constants.CONST.__getattribute__('env_file'))
+ args[0].assert_called_with(os_env_file=vnf.VnfOnBoarding.env_file)
args[1].assert_called_with(mock.ANY, mock.ANY)
args[2].assert_not_called()
@@ -139,8 +133,7 @@ class VnfBaseTesting(unittest.TestCase):
def test_prepare_exc3(self, *args):
with self.assertRaises(Exception):
self.test.prepare()
- args[0].assert_called_with(
- os_env_file=constants.CONST.__getattribute__('env_file'))
+ args[0].assert_called_with(os_env_file=vnf.VnfOnBoarding.env_file)
args[1].assert_called_with(mock.ANY, mock.ANY)
args[2].assert_called_with(mock.ANY, mock.ANY)
@@ -149,8 +142,7 @@ class VnfBaseTesting(unittest.TestCase):
@mock.patch('snaps.openstack.tests.openstack_tests.get_credentials')
def test_prepare_default(self, *args):
self.assertEqual(self.test.prepare(), testcase.TestCase.EX_OK)
- args[0].assert_called_with(
- os_env_file=constants.CONST.__getattribute__('env_file'))
+ args[0].assert_called_with(os_env_file=vnf.VnfOnBoarding.env_file)
args[1].assert_called_with(mock.ANY, mock.ANY)
args[2].assert_called_with(mock.ANY, mock.ANY)
diff --git a/functest/tests/unit/energy/test_functest_energy.py b/functest/tests/unit/energy/test_functest_energy.py
index f0711ca0c..fd1104327 100644
--- a/functest/tests/unit/energy/test_functest_energy.py
+++ b/functest/tests/unit/energy/test_functest_energy.py
@@ -11,14 +11,14 @@
"""Unitary test for energy module."""
# pylint: disable=unused-argument
import logging
-import requests
+import os
import unittest
import mock
+import requests
from functest.energy.energy import EnergyRecorder
import functest.energy.energy as energy
-from functest.utils.constants import CONST
CASE_NAME = "UNIT_TEST_CASE"
STEP_NAME = "UNIT_TEST_STEP"
@@ -61,26 +61,6 @@ RECORDER_NOT_FOUND = MockHttpResponse(
)
-def config_loader_mock(config_key):
- """Return mocked config values."""
- if config_key == "energy_recorder.api_url":
- return "http://pod-uri:8888"
- elif config_key == "energy_recorder.api_user":
- return "user"
- elif config_key == "energy_recorder.api_password":
- return "password"
-
-
-def config_loader_mock_no_creds(config_key):
- """Return mocked config values."""
- if config_key == "energy_recorder.api_url":
- return "http://pod-uri:8888"
- elif config_key == "energy_recorder.api_user":
- return ""
- elif config_key == "energy_recorder.api_password":
- return ""
-
-
# pylint: disable=too-many-public-methods
class EnergyRecorderTest(unittest.TestCase):
"""Energy module unitary test suite."""
@@ -90,6 +70,20 @@ class EnergyRecorderTest(unittest.TestCase):
returned_value_to_preserve = "value"
exception_message_to_preserve = "exception_message"
+ @staticmethod
+ def _set_env_creds():
+ """Set config values."""
+ os.environ["ENERGY_RECORDER_API_URL"] = "http://pod-uri:8888"
+ os.environ["ENERGY_RECORDER_API_USER"] = "user"
+ os.environ["ENERGY_RECORDER_API_PASSWORD"] = "password"
+
+ @staticmethod
+ def _set_env_nocreds():
+ """Set config values."""
+ os.environ["ENERGY_RECORDER_API_URL"] = "http://pod-uri:8888"
+ del os.environ["ENERGY_RECORDER_API_USER"]
+ del os.environ["ENERGY_RECORDER_API_PASSWORD"]
+
@mock.patch('functest.energy.energy.requests.post',
return_value=RECORDER_OK)
def test_start(self, post_mock=None, get_mock=None):
@@ -253,14 +247,12 @@ class EnergyRecorderTest(unittest.TestCase):
return_value={"scenario": PREVIOUS_SCENARIO,
"step": PREVIOUS_STEP})
@mock.patch("functest.energy.energy.EnergyRecorder")
- @mock.patch("functest.utils.functest_utils.get_functest_config",
- side_effect=config_loader_mock)
def test_decorators_with_previous(self,
- loader_mock=None,
recorder_mock=None,
cur_scenario_mock=None):
"""Test energy module decorators."""
- CONST.__setattr__('NODE_NAME', 'MOCK_POD')
+ os.environ['NODE_NAME'] = 'MOCK_POD'
+ self._set_env_creds()
self.__decorated_method()
calls = [mock.call.start(self.case_name),
mock.call.submit_scenario(PREVIOUS_SCENARIO,
@@ -286,13 +278,12 @@ class EnergyRecorderTest(unittest.TestCase):
)
self.assertTrue(finish_mock.called)
- @mock.patch("functest.utils.functest_utils.get_functest_config",
- side_effect=config_loader_mock)
@mock.patch("functest.energy.energy.requests.get",
return_value=API_OK)
def test_load_config(self, loader_mock=None, get_mock=None):
"""Test load config."""
- CONST.__setattr__('NODE_NAME', 'MOCK_POD')
+ os.environ['NODE_NAME'] = 'MOCK_POD'
+ self._set_env_creds()
EnergyRecorder.energy_recorder_api = None
EnergyRecorder.load_config()
@@ -305,13 +296,12 @@ class EnergyRecorderTest(unittest.TestCase):
"http://pod-uri:8888/recorders/environment/MOCK_POD"
)
- @mock.patch("functest.utils.functest_utils.get_functest_config",
- side_effect=config_loader_mock_no_creds)
@mock.patch("functest.energy.energy.requests.get",
return_value=API_OK)
def test_load_config_no_creds(self, loader_mock=None, get_mock=None):
"""Test load config without creds."""
- CONST.__setattr__('NODE_NAME', 'MOCK_POD')
+ os.environ['NODE_NAME'] = 'MOCK_POD'
+ self._set_env_nocreds()
EnergyRecorder.energy_recorder_api = None
EnergyRecorder.load_config()
self.assertEquals(EnergyRecorder.energy_recorder_api["auth"], None)
@@ -320,37 +310,33 @@ class EnergyRecorderTest(unittest.TestCase):
"http://pod-uri:8888/recorders/environment/MOCK_POD"
)
- @mock.patch("functest.utils.functest_utils.get_functest_config",
- return_value=None)
@mock.patch("functest.energy.energy.requests.get",
return_value=API_OK)
def test_load_config_ex(self, loader_mock=None, get_mock=None):
"""Test load config with exception."""
- CONST.__setattr__('NODE_NAME', 'MOCK_POD')
- with self.assertRaises(AssertionError):
- EnergyRecorder.energy_recorder_api = None
- EnergyRecorder.load_config()
- self.assertEquals(EnergyRecorder.energy_recorder_api, None)
-
- @mock.patch("functest.utils.functest_utils.get_functest_config",
- side_effect=config_loader_mock)
+ for key in ['NODE_NAME', 'ENERGY_RECORDER_API_URL']:
+ os.environ[key] = ''
+ with self.assertRaises(AssertionError):
+ EnergyRecorder.energy_recorder_api = None
+ EnergyRecorder.load_config()
+ self.assertEquals(EnergyRecorder.energy_recorder_api, None)
+
@mock.patch("functest.energy.energy.requests.get",
return_value=API_KO)
def test_load_config_api_ko(self, loader_mock=None, get_mock=None):
"""Test load config with API unavailable."""
- CONST.__setattr__('NODE_NAME', 'MOCK_POD')
+ os.environ['NODE_NAME'] = 'MOCK_POD'
+ self._set_env_creds()
EnergyRecorder.energy_recorder_api = None
EnergyRecorder.load_config()
self.assertEquals(EnergyRecorder.energy_recorder_api["available"],
False)
- @mock.patch("functest.utils.functest_utils.get_functest_config",
- return_value=None)
@mock.patch('functest.energy.energy.requests.get',
return_value=RECORDER_OK)
def test_get_current_scenario(self, loader_mock=None, get_mock=None):
"""Test get_current_scenario."""
- CONST.__setattr__('NODE_NAME', 'MOCK_POD')
+ os.environ['NODE_NAME'] = 'MOCK_POD'
self.test_load_config()
scenario = EnergyRecorder.get_current_scenario()
self.assertTrue(scenario is not None)
@@ -359,7 +345,7 @@ class EnergyRecorderTest(unittest.TestCase):
return_value=RECORDER_NOT_FOUND)
def test_current_scenario_not_found(self, get_mock=None):
"""Test get current scenario not existing."""
- CONST.__setattr__('NODE_NAME', 'MOCK_POD')
+ os.environ['NODE_NAME'] = 'MOCK_POD'
self.test_load_config()
scenario = EnergyRecorder.get_current_scenario()
self.assertTrue(scenario is None)
@@ -368,7 +354,7 @@ class EnergyRecorderTest(unittest.TestCase):
return_value=RECORDER_KO)
def test_current_scenario_api_error(self, get_mock=None):
"""Test get current scenario with API error."""
- CONST.__setattr__('NODE_NAME', 'MOCK_POD')
+ os.environ['NODE_NAME'] = 'MOCK_POD'
self.test_load_config()
scenario = EnergyRecorder.get_current_scenario()
self.assertTrue(scenario is None)
diff --git a/functest/tests/unit/odl/test_odl.py b/functest/tests/unit/odl/test_odl.py
index b93ad3133..d803d4131 100644
--- a/functest/tests/unit/odl/test_odl.py
+++ b/functest/tests/unit/odl/test_odl.py
@@ -33,7 +33,7 @@ class ODLTesting(unittest.TestCase):
logging.disable(logging.CRITICAL)
_keystone_ip = "127.0.0.1"
- _neutron_url = "http://127.0.0.2:9696"
+ _neutron_url = u"https://127.0.0.1:9696"
_sdn_controller_ip = "127.0.0.3"
_os_auth_url = "http://{}:5000/v3".format(_keystone_ip)
_os_projectname = "admin"
@@ -269,65 +269,68 @@ class ODLRunTesting(ODLTesting):
"""The class testing ODLTests.run()."""
# pylint: disable=missing-docstring
- def _test_no_env_var(self, var):
- with mock.patch('functest.utils.openstack_utils.get_endpoint',
- return_value=ODLTesting._neutron_url):
- del os.environ[var]
- self.assertEqual(self.test.run(),
- testcase.TestCase.EX_RUN_ERROR)
-
+ @mock.patch('snaps.openstack.utils.keystone_utils.get_endpoint',
+ return_value=ODLTesting._neutron_url)
+ @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
+ 'get_credentials')
+ def _test_no_env_var(self, var, *args):
+ del os.environ[var]
+ self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
+ args[0].assert_called_once_with()
+ args[1].assert_called_once_with(mock.ANY, 'network')
+
+ @mock.patch('snaps.openstack.utils.keystone_utils.get_endpoint',
+ return_value=ODLTesting._neutron_url)
+ @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
+ 'get_credentials')
def _test_run(self, status=testcase.TestCase.EX_OK,
- exception=None, **kwargs):
+ exception=None, *args, **kwargs):
odlip = kwargs['odlip'] if 'odlip' in kwargs else '127.0.0.3'
odlwebport = kwargs['odlwebport'] if 'odlwebport' in kwargs else '8080'
odlrestconfport = (kwargs['odlrestconfport']
if 'odlrestconfport' in kwargs else '8181')
-
- with mock.patch('functest.utils.openstack_utils.get_endpoint',
- return_value=ODLTesting._neutron_url):
- if exception:
- self.test.run_suites = mock.Mock(side_effect=exception)
- else:
- self.test.run_suites = mock.Mock(return_value=status)
- self.assertEqual(self.test.run(), status)
- self.test.run_suites.assert_called_once_with(
- odl.ODLTests.default_suites,
- neutronurl=self._neutron_url,
- odlip=odlip, odlpassword=self._odl_password,
- odlrestconfport=odlrestconfport,
- odlusername=self._odl_username, odlwebport=odlwebport,
- osauthurl=self._os_auth_url,
- ospassword=self._os_password,
- osprojectname=self._os_projectname,
- osusername=self._os_username,
- osprojectdomainname=self._os_projectdomainname,
- osuserdomainname=self._os_userdomainname)
-
+ if exception:
+ self.test.run_suites = mock.Mock(side_effect=exception)
+ else:
+ self.test.run_suites = mock.Mock(return_value=status)
+ self.assertEqual(self.test.run(), status)
+ self.test.run_suites.assert_called_once_with(
+ odl.ODLTests.default_suites, neutronurl=self._neutron_url,
+ odlip=odlip, odlpassword=self._odl_password,
+ odlrestconfport=odlrestconfport, odlusername=self._odl_username,
+ odlwebport=odlwebport, osauthurl=self._os_auth_url,
+ ospassword=self._os_password, osprojectname=self._os_projectname,
+ osusername=self._os_username,
+ osprojectdomainname=self._os_projectdomainname,
+ osuserdomainname=self._os_userdomainname)
+ args[0].assert_called_once_with()
+ args[1].assert_called_once_with(mock.ANY, 'network')
+
+ @mock.patch('snaps.openstack.utils.keystone_utils.get_endpoint',
+ return_value=ODLTesting._neutron_url)
+ @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
+ 'get_credentials')
def _test_multiple_suites(self, suites,
- status=testcase.TestCase.EX_OK, **kwargs):
+ status=testcase.TestCase.EX_OK, *args, **kwargs):
odlip = kwargs['odlip'] if 'odlip' in kwargs else '127.0.0.3'
odlwebport = kwargs['odlwebport'] if 'odlwebport' in kwargs else '8080'
odlrestconfport = (kwargs['odlrestconfport']
if 'odlrestconfport' in kwargs else '8181')
- with mock.patch('functest.utils.openstack_utils.get_endpoint',
- return_value=ODLTesting._neutron_url):
- self.test.run_suites = mock.Mock(return_value=status)
- self.assertEqual(self.test.run(suites=suites), status)
- self.test.run_suites.assert_called_once_with(
- suites,
- neutronurl=self._neutron_url,
- odlip=odlip, odlpassword=self._odl_password,
- odlrestconfport=odlrestconfport,
- odlusername=self._odl_username, odlwebport=odlwebport,
- osauthurl=self._os_auth_url,
- ospassword=self._os_password,
- osprojectname=self._os_projectname,
- osusername=self._os_username,
- osprojectdomainname=self._os_projectdomainname,
- osuserdomainname=self._os_userdomainname)
+ self.test.run_suites = mock.Mock(return_value=status)
+ self.assertEqual(self.test.run(suites=suites), status)
+ self.test.run_suites.assert_called_once_with(
+ suites, neutronurl=self._neutron_url, odlip=odlip,
+ odlpassword=self._odl_password, odlrestconfport=odlrestconfport,
+ odlusername=self._odl_username, odlwebport=odlwebport,
+ osauthurl=self._os_auth_url, ospassword=self._os_password,
+ osprojectname=self._os_projectname, osusername=self._os_username,
+ osprojectdomainname=self._os_projectdomainname,
+ osuserdomainname=self._os_userdomainname)
+ args[0].assert_called_once_with()
+ args[1].assert_called_once_with(mock.ANY, 'network')
def test_exc(self):
- with mock.patch('functest.utils.openstack_utils.get_endpoint',
+ with mock.patch('snaps.openstack.utils.keystone_utils.get_endpoint',
side_effect=auth_plugins.MissingAuthPlugin()):
self.assertEqual(self.test.run(),
testcase.TestCase.EX_RUN_ERROR)
@@ -346,27 +349,24 @@ class ODLRunTesting(ODLTesting):
def test_run_suites_false(self):
os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
- self._test_run(testcase.TestCase.EX_RUN_ERROR,
+ self._test_run(testcase.TestCase.EX_RUN_ERROR, None,
odlip=self._sdn_controller_ip,
odlwebport=self._odl_webport)
def test_run_suites_exc(self):
with self.assertRaises(Exception):
os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
- self._test_run(status=testcase.TestCase.EX_RUN_ERROR,
- exception=Exception(),
+ self._test_run(testcase.TestCase.EX_RUN_ERROR,
+ Exception(),
odlip=self._sdn_controller_ip,
odlwebport=self._odl_webport)
def test_no_sdn_controller_ip(self):
- with mock.patch('functest.utils.openstack_utils.get_endpoint',
- return_value=ODLTesting._neutron_url):
- self.assertEqual(self.test.run(),
- testcase.TestCase.EX_RUN_ERROR)
+ self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
def test_without_installer_type(self):
os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
- self._test_run(testcase.TestCase.EX_OK,
+ self._test_run(testcase.TestCase.EX_OK, None,
odlip=self._sdn_controller_ip,
odlwebport=self._odl_webport)
@@ -380,69 +380,57 @@ class ODLRunTesting(ODLTesting):
def test_fuel(self):
os.environ["INSTALLER_TYPE"] = "fuel"
- self._test_run(testcase.TestCase.EX_OK,
+ self._test_run(testcase.TestCase.EX_OK, None,
odlip=urllib.parse.urlparse(self._neutron_url).hostname,
odlwebport='8181',
odlrestconfport='8282')
def test_apex_no_controller_ip(self):
- with mock.patch('functest.utils.openstack_utils.get_endpoint',
- return_value=ODLTesting._neutron_url):
- os.environ["INSTALLER_TYPE"] = "apex"
- self.assertEqual(self.test.run(),
- testcase.TestCase.EX_RUN_ERROR)
+ os.environ["INSTALLER_TYPE"] = "apex"
+ self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
def test_apex(self):
os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
os.environ["INSTALLER_TYPE"] = "apex"
- self._test_run(testcase.TestCase.EX_OK,
+ self._test_run(testcase.TestCase.EX_OK, None,
odlip=self._sdn_controller_ip, odlwebport='8081',
odlrestconfport='8081')
def test_netvirt_no_controller_ip(self):
- with mock.patch('functest.utils.openstack_utils.get_endpoint',
- return_value=ODLTesting._neutron_url):
- os.environ["INSTALLER_TYPE"] = "netvirt"
- self.assertEqual(self.test.run(),
- testcase.TestCase.EX_RUN_ERROR)
+ os.environ["INSTALLER_TYPE"] = "netvirt"
+ self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
def test_netvirt(self):
os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
os.environ["INSTALLER_TYPE"] = "netvirt"
- self._test_run(testcase.TestCase.EX_OK,
+ self._test_run(testcase.TestCase.EX_OK, None,
odlip=self._sdn_controller_ip, odlwebport='8081',
odlrestconfport='8081')
def test_joid_no_controller_ip(self):
- with mock.patch('functest.utils.openstack_utils.get_endpoint',
- return_value=ODLTesting._neutron_url):
- os.environ["INSTALLER_TYPE"] = "joid"
- self.assertEqual(self.test.run(),
- testcase.TestCase.EX_RUN_ERROR)
+ os.environ["INSTALLER_TYPE"] = "joid"
+ self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
def test_joid(self):
os.environ["SDN_CONTROLLER"] = self._sdn_controller_ip
os.environ["INSTALLER_TYPE"] = "joid"
- self._test_run(testcase.TestCase.EX_OK,
+ self._test_run(testcase.TestCase.EX_OK, None,
odlip=self._sdn_controller_ip, odlwebport='8080')
def test_compass(self):
os.environ["INSTALLER_TYPE"] = "compass"
- self._test_run(testcase.TestCase.EX_OK,
+ self._test_run(testcase.TestCase.EX_OK, None,
odlip=urllib.parse.urlparse(self._neutron_url).hostname,
odlrestconfport='8080')
def test_daisy_no_controller_ip(self):
- with mock.patch('functest.utils.openstack_utils.get_endpoint',
- return_value=ODLTesting._neutron_url):
- os.environ["INSTALLER_TYPE"] = "daisy"
- self.assertEqual(self.test.run(),
- testcase.TestCase.EX_RUN_ERROR)
+ os.environ["INSTALLER_TYPE"] = "daisy"
+ self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
def test_daisy(self):
os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
os.environ["INSTALLER_TYPE"] = "daisy"
- self._test_run(testcase.TestCase.EX_OK,
+ self._test_run(testcase.TestCase.EX_OK, None,
odlip=self._sdn_controller_ip, odlwebport='8181',
odlrestconfport='8087')
diff --git a/functest/tests/unit/utils/test_functest_utils.py b/functest/tests/unit/utils/test_functest_utils.py
index 218d03c42..dd34c90dc 100644
--- a/functest/tests/unit/utils/test_functest_utils.py
+++ b/functest/tests/unit/utils/test_functest_utils.py
@@ -55,8 +55,6 @@ class FunctestUtilsTesting(unittest.TestCase):
self.cmd = 'test_cmd'
self.output_file = 'test_output_file'
self.testname = 'testname'
- self.testcase_dict = {'case_name': 'testname',
- 'criteria': self.criteria}
self.parameter = 'general.openstack.image_name'
self.config_yaml = pkg_resources.resource_filename(
'functest', 'ci/config_functest.yaml')
@@ -255,32 +253,6 @@ class FunctestUtilsTesting(unittest.TestCase):
def _get_functest_config(self, var):
return var
- @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') \
- as mock_yaml:
- mock_obj = mock.Mock()
- attrs = {'get.return_value': [{'testcases': [self.testcase_dict]}]}
- mock_obj.configure_mock(**attrs)
-
- mock_yaml.return_value = mock_obj
-
- self.assertDictEqual(functest_utils.
- get_dict_by_test(self.testname),
- self.testcase_dict)
-
- @mock.patch('functest.utils.functest_utils.get_dict_by_test')
- def test_get_criteria_by_test_default(self, mock_get_dict_by_test):
- mock_get_dict_by_test.return_value = self.testcase_dict
- self.assertEqual(functest_utils.get_criteria_by_test(self.testname),
- self.criteria)
-
- @mock.patch('functest.utils.functest_utils.get_dict_by_test')
- def test_get_criteria_by_test_failed(self, mock_get_dict_by_test):
- mock_get_dict_by_test.return_value = None
- self.assertIsNone(functest_utils.get_criteria_by_test(self.testname))
-
def test_get_parameter_from_yaml_failed(self):
self.file_yaml['general'] = None
with mock.patch('six.moves.builtins.open', mock.mock_open()), \
diff --git a/functest/utils/functest_utils.py b/functest/utils/functest_utils.py
index c14918554..e84a2b426 100644
--- a/functest/utils/functest_utils.py
+++ b/functest/utils/functest_utils.py
@@ -17,7 +17,6 @@ import shutil
import subprocess
import sys
-import pkg_resources
import dns.resolver
from six.moves import urllib
import yaml
@@ -135,28 +134,6 @@ def execute_command(cmd, info=False, 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 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)
- return None
-
-
-def get_criteria_by_test(testname):
- tdict = get_dict_by_test(testname)
- if tdict:
- return tdict['criteria']
- return None
-
-
# ----------------------------------------------------------
#
# YAML UTILS