aboutsummaryrefslogtreecommitdiffstats
path: root/functest/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'functest/tests/unit')
-rw-r--r--functest/tests/unit/utils/test_functest_utils.py43
-rw-r--r--functest/tests/unit/vnf/router/__init__.py0
-rw-r--r--functest/tests/unit/vnf/router/test_cloudify_vrouter.py140
-rw-r--r--functest/tests/unit/vnf/router/test_vrouter_base.py28
4 files changed, 171 insertions, 40 deletions
diff --git a/functest/tests/unit/utils/test_functest_utils.py b/functest/tests/unit/utils/test_functest_utils.py
index cd3693c7..17fb4c1f 100644
--- a/functest/tests/unit/utils/test_functest_utils.py
+++ b/functest/tests/unit/utils/test_functest_utils.py
@@ -97,42 +97,6 @@ class FunctestUtilsTesting(unittest.TestCase):
m.assert_called_once_with(dest, 'wb')
self.assertTrue(mock_sh.called)
- @mock.patch('functest.utils.functest_utils.logger.error')
- def test_get_installer_type_failed(self, mock_logger_error):
- with mock.patch.dict(os.environ,
- {},
- clear=True):
- self.assertEqual(functest_utils.get_installer_type(),
- "Unknown_installer")
- mock_logger_error.assert_called_once_with("Impossible to retrieve"
- " the installer type")
-
- def test_get_installer_type_default(self):
- with mock.patch.dict(os.environ,
- {'INSTALLER_TYPE': 'test_installer'},
- clear=True):
- self.assertEqual(functest_utils.get_installer_type(),
- self.installer)
-
- @mock.patch('functest.utils.functest_utils.logger.info')
- def test_get_scenario_failed(self, mock_logger_info):
- with mock.patch.dict(os.environ,
- {},
- clear=True):
- self.assertEqual(functest_utils.get_scenario(),
- "os-nosdn-nofeature-noha")
- mock_logger_info.assert_called_once_with("Impossible to retrieve "
- "the scenario.Use "
- "default "
- "os-nosdn-nofeature-noha")
-
- def test_get_scenario_default(self):
- with mock.patch.dict(os.environ,
- {'DEPLOY_SCENARIO': 'test_scenario'},
- clear=True):
- self.assertEqual(functest_utils.get_scenario(),
- self.scenario)
-
def test_get_version_daily_job(self):
CONST.__setattr__('BUILD_TAG', self.build_tag)
self.assertEqual(functest_utils.get_version(), self.version)
@@ -154,10 +118,9 @@ class FunctestUtilsTesting(unittest.TestCase):
CONST.__setattr__('results_test_db_url', self.db_url)
CONST.__setattr__('BUILD_TAG', self.build_tag)
CONST.__setattr__('NODE_NAME', self.node_name)
- with mock.patch('functest.utils.functest_utils.get_scenario',
- return_value=self.scenario), \
- mock.patch('functest.utils.functest_utils.get_version',
- return_value=self.version):
+ CONST.__setattr__('DEPLOY_SCENARIO', self.scenario)
+ with mock.patch('functest.utils.functest_utils.get_version',
+ return_value=self.version):
functest_utils.logger_test_results(self.project, self.case_name,
self.status, self.details)
mock_logger_info.assert_called_once_with(
diff --git a/functest/tests/unit/vnf/router/__init__.py b/functest/tests/unit/vnf/router/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/functest/tests/unit/vnf/router/__init__.py
diff --git a/functest/tests/unit/vnf/router/test_cloudify_vrouter.py b/functest/tests/unit/vnf/router/test_cloudify_vrouter.py
new file mode 100644
index 00000000..7f2091be
--- /dev/null
+++ b/functest/tests/unit/vnf/router/test_cloudify_vrouter.py
@@ -0,0 +1,140 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2017 Okinawa Open Laboratory and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+import logging
+import unittest
+
+import mock
+
+from functest.core import vnf
+from functest.opnfv_tests.vnf.router import cloudify_vrouter
+
+from snaps.openstack.os_credentials import OSCreds
+
+
+class CloudifyVrouterTesting(unittest.TestCase):
+
+ def setUp(self):
+
+ self.tenant = 'cloudify_vrouter'
+ self.creds = {'username': 'user',
+ 'password': 'pwd'}
+ self.orchestrator = {'name': 'cloudify',
+ 'version': '4.0',
+ 'object': 'foo',
+ 'requirements': {'flavor': {'name': 'm1.medium',
+ 'ram_min': 4096},
+ 'os_image': 'manager_4.0'}}
+
+ self.vnf = {'name': 'vrouter',
+ 'descriptor': {'version': '100',
+ 'file_name': 'function-test-' +
+ 'openstack-blueprint.yaml',
+ 'name': 'vrouter-opnfv',
+ 'url': 'https://foo',
+ 'requirements': {'flavor':
+ {'name': 'm1.medium',
+ 'ram_min': 2048}}}}
+
+ with mock.patch('functest.opnfv_tests.vnf.router.cloudify_vrouter.'
+ 'os.makedirs'), \
+ 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'}):
+
+ self.router_vnf = cloudify_vrouter.CloudifyVrouter()
+
+ self.images = {'image1': 'url1',
+ 'image2': 'url2'}
+ self.details = {'orchestrator': {'status': 'PASS', 'duration': 120},
+ 'vnf': {},
+ 'test_vnf': {}}
+
+ @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
+ return_value='test')
+ @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
+ return_value=True)
+ @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
+ return_value=True)
+ @mock.patch('functest.core.vnf.os_utils.get_credentials',
+ return_value={'auth_url': 'test/v1'})
+ @mock.patch('snaps.openstack.create_image.OpenStackImage.create')
+ def test_prepare_default(self, *args):
+ self.assertIsNone(self.router_vnf.prepare())
+ args[4].assert_called_once_with()
+
+ @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
+ return_value='test')
+ @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
+ return_value=True)
+ @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
+ return_value=True)
+ @mock.patch('functest.core.vnf.os_utils.get_credentials',
+ return_value={'auth_url': 'test/no_v'})
+ @mock.patch('snaps.openstack.create_image.OpenStackImage.create')
+ def test_prepare_bad_auth_url(self, *args):
+ with self.assertRaises(Exception):
+ self.router_vnf.image_creator(
+ OSCreds(username='user', password='pass', auth_url='url',
+ project_name='project', identity_api_version=3),
+ mock.Mock())
+ args[0].assert_not_called()
+
+ def test_prepare_missing_param(self):
+ with self.assertRaises(vnf.VnfPreparationException):
+ self.router_vnf.prepare()
+
+ @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
+ side_effect=Exception)
+ def test_prepare_keystone_exception(self, *args):
+ with self.assertRaises(vnf.VnfPreparationException):
+ self.router_vnf.prepare()
+ args[0].assert_called_once_with()
+
+ @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
+ return_value='test')
+ @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
+ side_effect=Exception)
+ def test_prepare_tenant_exception(self, *args):
+ with self.assertRaises(vnf.VnfPreparationException):
+ self.router_vnf.prepare()
+ args[1].assert_called_once_with()
+
+ @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
+ return_value='test')
+ @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
+ return_value=True)
+ @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
+ side_effect=Exception)
+ def test_prepare_user_exception(self, *args):
+ with self.assertRaises(vnf.VnfPreparationException):
+ self.router_vnf.prepare()
+ args[2].assert_called_once_with()
+
+ @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
+ return_value='test')
+ @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
+ return_value=True)
+ @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
+ return_value=True)
+ @mock.patch('functest.core.vnf.os_utils.get_credentials',
+ side_effect=Exception)
+ def test_prepare_credentials_exception(self, *args):
+ with self.assertRaises(vnf.VnfPreparationException):
+ self.router_vnf.prepare()
+ args[0].assert_called_once_with()
+
+
+if __name__ == "__main__":
+ logging.disable(logging.CRITICAL)
+ unittest.main(verbosity=2)
diff --git a/functest/tests/unit/vnf/router/test_vrouter_base.py b/functest/tests/unit/vnf/router/test_vrouter_base.py
new file mode 100644
index 00000000..def201d1
--- /dev/null
+++ b/functest/tests/unit/vnf/router/test_vrouter_base.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2017 Okinawa Open Laboratory and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+import logging
+import unittest
+
+import mock
+
+from functest.opnfv_tests.vnf.router import vrouter_base
+
+
+class VrouterOnBoardingBaseTesting(unittest.TestCase):
+
+ def setUp(self):
+ with mock.patch('functest.opnfv_tests.vnf.router.cloudify_vrouter.'
+ 'os.makedirs'):
+ self.vrouter_vnf = vrouter_base.VrouterOnBoardingBase()
+
+
+if __name__ == "__main__":
+ logging.disable(logging.CRITICAL)
+ unittest.main(verbosity=2)