aboutsummaryrefslogtreecommitdiffstats
path: root/functest/tests
diff options
context:
space:
mode:
Diffstat (limited to 'functest/tests')
-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
6 files changed, 138 insertions, 185 deletions
diff --git a/functest/tests/unit/ci/test_run_tests.py b/functest/tests/unit/ci/test_run_tests.py
index 0bb4315e..bc967743 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 8c73bb5d..3219c726 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 112ce53b..16a60902 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 f0711ca0..fd110432 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 b93ad313..d803d413 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 218d03c4..dd34c90d 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()), \