aboutsummaryrefslogtreecommitdiffstats
path: root/functest/tests/unit/odl/test_odl.py
diff options
context:
space:
mode:
Diffstat (limited to 'functest/tests/unit/odl/test_odl.py')
-rw-r--r--functest/tests/unit/odl/test_odl.py283
1 files changed, 188 insertions, 95 deletions
diff --git a/functest/tests/unit/odl/test_odl.py b/functest/tests/unit/odl/test_odl.py
index 6304d37a3..c675c2988 100644
--- a/functest/tests/unit/odl/test_odl.py
+++ b/functest/tests/unit/odl/test_odl.py
@@ -14,6 +14,7 @@ import os
import unittest
import mock
+import munch
from robot.errors import RobotError
import six
from six.moves import urllib
@@ -32,9 +33,10 @@ class ODLTesting(unittest.TestCase):
logging.disable(logging.CRITICAL)
_keystone_ip = "127.0.0.1"
- _neutron_url = u"https://127.0.0.1:9696"
+ _neutron_url = "https://127.0.0.1:9696"
+ _neutron_id = "dummy"
_sdn_controller_ip = "127.0.0.3"
- _os_auth_url = "http://{}:5000/v3".format(_keystone_ip)
+ _os_auth_url = f"http://{_keystone_ip}:5000/v3"
_os_projectname = "admin"
_os_username = "admin"
_os_password = "admin"
@@ -44,9 +46,10 @@ class ODLTesting(unittest.TestCase):
_odl_password = "admin"
_os_userdomainname = 'Default'
_os_projectdomainname = 'Default'
+ _os_interface = "public"
def setUp(self):
- for var in ("INSTALLER_TYPE", "SDN_CONTROLLER", "SDN_CONTROLLER_IP"):
+ for var in ("SDN_CONTROLLER", "SDN_CONTROLLER_IP"):
if var in os.environ:
del os.environ[var]
os.environ["OS_AUTH_URL"] = self._os_auth_url
@@ -56,11 +59,11 @@ class ODLTesting(unittest.TestCase):
os.environ["OS_PROJECT_NAME"] = self._os_projectname
os.environ["OS_PROJECT_DOMAIN_NAME"] = self._os_projectdomainname
os.environ["OS_PASSWORD"] = self._os_password
+ os.environ["OS_INTERFACE"] = self._os_interface
self.test = odl.ODLTests(case_name='odl', project_name='functest')
self.defaultargs = {'odlusername': self._odl_username,
'odlpassword': self._odl_password,
- 'neutronurl': "http://{}:9696".format(
- self._keystone_ip),
+ 'neutronurl': f"http://{self._keystone_ip}:9696",
'osauthurl': self._os_auth_url,
'osusername': self._os_username,
'osuserdomainname': self._os_userdomainname,
@@ -101,7 +104,7 @@ class ODLRobotTesting(ODLTesting):
mock_method.assert_called_once_with(
os.path.join(odl.ODLTests.odl_test_repo,
'csit/variables/Variables.robot'), inplace=True)
- self.assertEqual(args[0].getvalue(), "{}\n".format(msg2))
+ self.assertEqual(args[0].getvalue(), f"{msg2}\n")
def test_set_vars_auth_default(self):
self._test_set_vars(
@@ -156,19 +159,19 @@ class ODLMainTesting(ODLTesting):
args[0].assert_called_once_with(self.test.odl_variables_file)
if len(args) > 1:
variable = [
- 'KEYSTONEURL:{}://{}'.format(
- urllib.parse.urlparse(self._os_auth_url).scheme,
- urllib.parse.urlparse(self._os_auth_url).netloc),
- 'NEUTRONURL:{}'.format(self._neutron_url),
- 'OS_AUTH_URL:"{}"'.format(self._os_auth_url),
- 'OSUSERNAME:"{}"'.format(self._os_username),
- 'OSUSERDOMAINNAME:"{}"'.format(self._os_userdomainname),
- 'OSTENANTNAME:"{}"'.format(self._os_projectname),
- 'OSPROJECTDOMAINNAME:"{}"'.format(self._os_projectdomainname),
- 'OSPASSWORD:"{}"'.format(self._os_password),
- 'ODL_SYSTEM_IP:{}'.format(self._sdn_controller_ip),
- 'PORT:{}'.format(self._odl_webport),
- 'RESTCONFPORT:{}'.format(self._odl_restconfport)]
+ ('KEYSTONEURL:'
+ f'{urllib.parse.urlparse(self._os_auth_url).scheme}://'
+ f'{urllib.parse.urlparse(self._os_auth_url).netloc}'),
+ f'NEUTRONURL:{self._neutron_url}',
+ f'OS_AUTH_URL:"{self._os_auth_url}"',
+ f'OSUSERNAME:"{self._os_username}"',
+ f'OSUSERDOMAINNAME:"{self._os_userdomainname}"',
+ f'OSTENANTNAME:"{self._os_projectname}"',
+ f'OSPROJECTDOMAINNAME:"{self._os_projectdomainname}"',
+ f'OSPASSWORD:"{self._os_password}"',
+ f'ODL_SYSTEM_IP:{self._sdn_controller_ip}',
+ f'PORT:{self._odl_webport}',
+ f'RESTCONFPORT:{self._odl_restconfport}']
args[1].assert_called_once_with(
odl.ODLTests.basic_suite_dir, odl.ODLTests.neutron_suite_dir,
include=[],
@@ -221,6 +224,7 @@ class ODLMainTesting(ODLTesting):
self._odl_username, self._odl_password)
args[0].assert_called_once_with(self.test.odl_variables_file)
+ @mock.patch('os.makedirs')
@mock.patch('robot.run', side_effect=RobotError)
@mock.patch('os.path.isfile', return_value=True)
def test_run_ko(self, *args):
@@ -229,6 +233,7 @@ class ODLMainTesting(ODLTesting):
self.assertRaises(RobotError):
self._test_run_suites(testcase.TestCase.EX_RUN_ERROR, *args)
+ @mock.patch('os.makedirs')
@mock.patch('robot.run')
@mock.patch('os.path.isfile', return_value=True)
def test_parse_results_ko(self, *args):
@@ -238,62 +243,157 @@ class ODLMainTesting(ODLTesting):
side_effect=RobotError):
self._test_run_suites(testcase.TestCase.EX_RUN_ERROR, *args)
+ @mock.patch('os.makedirs')
+ @mock.patch('robot.run')
+ @mock.patch('os.path.isfile', return_value=True)
+ def test_generate_report_ko(self, *args):
+ with mock.patch.object(self.test, 'set_robotframework_vars',
+ return_value=True), \
+ mock.patch.object(self.test, 'parse_results'), \
+ mock.patch.object(self.test, 'generate_report',
+ return_value=1):
+ self._test_run_suites(testcase.TestCase.EX_OK, *args)
+
+ @mock.patch('os.makedirs')
+ @mock.patch('robot.run')
+ @mock.patch('os.path.isfile', return_value=True)
+ def test_generate_report_exc(self, *args):
+ with mock.patch.object(self.test, 'set_robotframework_vars',
+ return_value=True), \
+ mock.patch.object(self.test, 'parse_results'), \
+ mock.patch.object(self.test, 'generate_report',
+ side_effect=Exception):
+ self._test_run_suites(testcase.TestCase.EX_RUN_ERROR, *args)
+
+ @mock.patch('os.makedirs')
@mock.patch('robot.run')
@mock.patch('os.path.isfile', return_value=True)
def test_ok(self, *args):
with mock.patch.object(self.test, 'set_robotframework_vars',
return_value=True), \
- mock.patch.object(self.test, 'parse_results'):
+ mock.patch.object(self.test, 'parse_results'), \
+ mock.patch.object(self.test, 'generate_report',
+ return_value=0):
self._test_run_suites(testcase.TestCase.EX_OK, *args)
+ @mock.patch('os.makedirs')
@mock.patch('robot.run')
@mock.patch('os.path.isfile', return_value=False)
def test_ok_no_creds(self, *args):
with mock.patch.object(self.test, 'set_robotframework_vars',
return_value=True) as mock_method, \
- mock.patch.object(self.test, 'parse_results'):
+ mock.patch.object(self.test, 'parse_results'), \
+ mock.patch.object(self.test, 'generate_report',
+ return_value=0):
self._test_run_suites(testcase.TestCase.EX_OK, *args)
mock_method.assert_not_called()
+ @mock.patch('os.makedirs')
@mock.patch('robot.run', return_value=1)
@mock.patch('os.path.isfile', return_value=True)
def test_testcases_in_failure(self, *args):
with mock.patch.object(self.test, 'set_robotframework_vars',
return_value=True), \
- mock.patch.object(self.test, 'parse_results'):
+ mock.patch.object(self.test, 'parse_results'), \
+ mock.patch.object(self.test, 'generate_report',
+ return_value=0):
self._test_run_suites(testcase.TestCase.EX_OK, *args)
class ODLRunTesting(ODLTesting):
-
"""The class testing ODLTests.run()."""
- # pylint: disable=missing-docstring
+ # pylint: disable=too-many-public-methods,missing-docstring
- @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')
+ @mock.patch('os_client_config.make_shade', side_effect=Exception)
+ def test_no_cloud(self, *args):
+ self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
+ args[0].assert_called_once_with()
+
+ @mock.patch('os_client_config.make_shade')
+ def test_no_service1(self, *args):
+ args[0].return_value.search_services.return_value = None
+ self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
+ args[0].return_value.search_services.assert_called_once_with('neutron')
+ args[0].return_value.search_endpoints.assert_not_called()
+
+ @mock.patch('os_client_config.make_shade')
+ def test_no_service2(self, *args):
+ args[0].return_value.search_services.return_value = []
+ self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
+ args[0].return_value.search_services.assert_called_once_with('neutron')
+ args[0].return_value.search_endpoints.assert_not_called()
+
+ @mock.patch('os_client_config.make_shade')
+ def test_no_service3(self, *args):
+ args[0].return_value.search_services.return_value = [
+ munch.Munch()]
+ self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
+ args[0].return_value.search_services.assert_called_once_with('neutron')
+ args[0].return_value.search_endpoints.assert_not_called()
+
+ @mock.patch('os_client_config.make_shade')
+ def test_no_endpoint1(self, *args):
+ args[0].return_value.search_services.return_value = [
+ munch.Munch(id=self._neutron_id)]
+ args[0].return_value.search_endpoints.return_value = None
+ self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
+ args[0].return_value.search_services.assert_called_once_with('neutron')
+ args[0].return_value.search_endpoints.assert_called_once_with(
+ filters={'interface': self._os_interface,
+ 'service_id': self._neutron_id})
+
+ @mock.patch('os_client_config.make_shade')
+ def test_no_endpoint2(self, *args):
+ args[0].return_value.search_services.return_value = [
+ munch.Munch(id=self._neutron_id)]
+ args[0].return_value.search_endpoints.return_value = []
+ self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
+ args[0].return_value.search_services.assert_called_once_with('neutron')
+ args[0].return_value.search_endpoints.assert_called_once_with(
+ filters={'interface': self._os_interface,
+ 'service_id': self._neutron_id})
+
+ @mock.patch('os_client_config.make_shade')
+ def test_no_endpoint3(self, *args):
+ args[0].return_value.search_services.return_value = [
+ munch.Munch(id=self._neutron_id)]
+ args[0].return_value.search_endpoints.return_value = [munch.Munch()]
+ self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
+ args[0].return_value.search_services.assert_called_once_with('neutron')
+ args[0].return_value.search_endpoints.assert_called_once_with(
+ filters={'interface': self._os_interface,
+ 'service_id': self._neutron_id})
+
+ @mock.patch('os_client_config.make_shade')
+ def test_endpoint_interface(self, *args):
+ args[0].return_value.search_services.return_value = [
+ munch.Munch(id=self._neutron_id)]
+ args[0].return_value.search_endpoints.return_value = [munch.Munch()]
+ self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
+ args[0].return_value.search_services.assert_called_once_with('neutron')
+ args[0].return_value.search_endpoints.assert_called_once_with(
+ filters={'interface': self._os_interface,
+ 'service_id': self._neutron_id})
+
+ @mock.patch('os_client_config.make_shade')
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')
+ @mock.patch('os_client_config.make_shade')
def _test_missing_value(self, *args):
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')
+ @mock.patch('os_client_config.make_shade')
def _test_run(self, status=testcase.TestCase.EX_OK,
exception=None, *args, **kwargs):
+ # pylint: disable=keyword-arg-before-vararg
+ args[0].return_value.search_services.return_value = [
+ munch.Munch(id=self._neutron_id)]
+ args[0].return_value.search_endpoints.return_value = [
+ munch.Munch(url=self._neutron_url)]
odlip = kwargs['odlip'] if 'odlip' in kwargs else '127.0.0.3'
odlwebport = kwargs['odlwebport'] if 'odlwebport' in kwargs else '8080'
odlrestconfport = (kwargs['odlrestconfport']
@@ -313,14 +413,21 @@ class ODLRunTesting(ODLTesting):
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')
+ args[0].return_value.search_services.assert_called_once_with('neutron')
+ args[0].return_value.search_endpoints.assert_called_once_with(
+ filters={
+ 'interface': os.environ.get(
+ "OS_INTERFACE", "public").replace('URL', ''),
+ 'service_id': self._neutron_id})
+
+ @mock.patch('os_client_config.make_shade')
def _test_multiple_suites(self, suites,
status=testcase.TestCase.EX_OK, *args, **kwargs):
+ # pylint: disable=keyword-arg-before-vararg
+ args[0].return_value.search_endpoints.return_value = [
+ munch.Munch(url=self._neutron_url)]
+ args[0].return_value.search_services.return_value = [
+ munch.Munch(id=self._neutron_id)]
odlip = kwargs['odlip'] if 'odlip' in kwargs else '127.0.0.3'
odlwebport = kwargs['odlwebport'] if 'odlwebport' in kwargs else '8080'
odlrestconfport = (kwargs['odlrestconfport']
@@ -336,10 +443,13 @@ class ODLRunTesting(ODLTesting):
osprojectdomainname=self._os_projectdomainname,
osuserdomainname=self._os_userdomainname)
args[0].assert_called_once_with()
- args[1].assert_called_once_with(mock.ANY, 'network')
+ args[0].return_value.search_services.assert_called_once_with('neutron')
+ args[0].return_value.search_endpoints.assert_called_once_with(
+ filters={'interface': os.environ.get("OS_INTERFACE", "public"),
+ 'service_id': self._neutron_id})
def test_exc(self):
- with mock.patch('snaps.openstack.utils.keystone_utils.get_endpoint',
+ with mock.patch('os_client_config.make_shade',
side_effect=Exception()):
self.assertEqual(self.test.run(),
testcase.TestCase.EX_RUN_ERROR)
@@ -379,65 +489,48 @@ class ODLRunTesting(ODLTesting):
odlip=self._sdn_controller_ip,
odlwebport=self._odl_webport)
- def test_suites(self):
+ def test_without_os_interface(self):
+ del os.environ["OS_INTERFACE"]
os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
- self._test_multiple_suites(
- [odl.ODLTests.basic_suite_dir],
- testcase.TestCase.EX_OK,
- odlip=self._sdn_controller_ip,
- odlwebport=self._odl_webport)
-
- def test_fuel_no_controller_ip(self):
- os.environ["INSTALLER_TYPE"] = "fuel"
- self._test_missing_value()
+ self._test_run(testcase.TestCase.EX_OK, None,
+ odlip=self._sdn_controller_ip,
+ odlwebport=self._odl_webport)
- def test_fuel(self):
+ def test_os_interface_public(self):
+ os.environ["OS_INTERFACE"] = "public"
os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
- os.environ["INSTALLER_TYPE"] = "fuel"
self._test_run(testcase.TestCase.EX_OK, None,
odlip=self._sdn_controller_ip,
- odlwebport='8282',
- odlrestconfport='8282')
-
- def test_apex_no_controller_ip(self):
- os.environ["INSTALLER_TYPE"] = "apex"
- self._test_missing_value()
+ odlwebport=self._odl_webport)
- def test_apex(self):
+ def test_os_interface_publicurl(self):
+ os.environ["OS_INTERFACE"] = "publicURL"
os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
- os.environ["INSTALLER_TYPE"] = "apex"
self._test_run(testcase.TestCase.EX_OK, None,
- odlip=self._sdn_controller_ip, odlwebport='8081',
- odlrestconfport='8081')
-
- def test_netvirt_no_controller_ip(self):
- os.environ["INSTALLER_TYPE"] = "netvirt"
- self._test_missing_value()
+ odlip=self._sdn_controller_ip,
+ odlwebport=self._odl_webport)
- def test_netvirt(self):
+ def test_os_interface_internal(self):
+ os.environ["OS_INTERFACE"] = "internal"
os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
- os.environ["INSTALLER_TYPE"] = "netvirt"
self._test_run(testcase.TestCase.EX_OK, None,
- odlip=self._sdn_controller_ip, odlwebport='8081',
- odlrestconfport='8081')
+ odlip=self._sdn_controller_ip,
+ odlwebport=self._odl_webport)
- def test_compass(self):
+ def test_os_interface_admin(self):
+ os.environ["OS_INTERFACE"] = "admin"
os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
- os.environ["INSTALLER_TYPE"] = "compass"
self._test_run(testcase.TestCase.EX_OK, None,
odlip=self._sdn_controller_ip,
- odlrestconfport='8080')
-
- def test_daisy_no_controller_ip(self):
- os.environ["INSTALLER_TYPE"] = "daisy"
- self._test_missing_value()
+ odlwebport=self._odl_webport)
- def test_daisy(self):
+ def test_suites(self):
os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
- os.environ["INSTALLER_TYPE"] = "daisy"
- self._test_run(testcase.TestCase.EX_OK, None,
- odlip=self._sdn_controller_ip, odlwebport='8181',
- odlrestconfport='8087')
+ self._test_multiple_suites(
+ [odl.ODLTests.basic_suite_dir],
+ testcase.TestCase.EX_OK,
+ odlip=self._sdn_controller_ip,
+ odlwebport=self._odl_webport)
class ODLArgParserTesting(ODLTesting):
@@ -447,7 +540,7 @@ class ODLArgParserTesting(ODLTesting):
def setUp(self):
self.parser = odl.ODLParser()
- super(ODLArgParserTesting, self).setUp()
+ super().setUp()
def test_default(self):
self.assertEqual(self.parser.parse_args(), self.defaultargs)
@@ -457,8 +550,8 @@ class ODLArgParserTesting(ODLTesting):
self.defaultargs['odlip'] = self._sdn_controller_ip
self.assertEqual(
self.parser.parse_args(
- ["--neutronurl={}".format(self._neutron_url),
- "--odlip={}".format(self._sdn_controller_ip)]),
+ [f"--neutronurl={self._neutron_url}",
+ f"--odlip={self._sdn_controller_ip}"]),
self.defaultargs)
@mock.patch('sys.stderr', new_callable=six.StringIO)
@@ -471,7 +564,7 @@ class ODLArgParserTesting(ODLTesting):
def _test_arg(self, arg, value):
self.defaultargs[arg] = value
self.assertEqual(
- self.parser.parse_args(["--{}={}".format(arg, value)]),
+ self.parser.parse_args([f"--{arg}={value}"]),
self.defaultargs)
def test_odlusername(self):
@@ -512,7 +605,7 @@ class ODLArgParserTesting(ODLTesting):
def test_pushtodb(self):
self.defaultargs['pushtodb'] = True
- self.assertEqual(self.parser.parse_args(["--{}".format('pushtodb')]),
+ self.assertEqual(self.parser.parse_args(["--pushtodb"]),
self.defaultargs)
def test_multiple_args(self):
@@ -520,8 +613,8 @@ class ODLArgParserTesting(ODLTesting):
self.defaultargs['odlip'] = self._sdn_controller_ip
self.assertEqual(
self.parser.parse_args(
- ["--neutronurl={}".format(self._neutron_url),
- "--odlip={}".format(self._sdn_controller_ip)]),
+ [f"--neutronurl={self._neutron_url}",
+ f"--odlip={self._sdn_controller_ip}"]),
self.defaultargs)