aboutsummaryrefslogtreecommitdiffstats
path: root/functest/tests/unit
diff options
context:
space:
mode:
authorboucherv <valentin.boucher@orange.com>2017-06-21 16:37:56 +0200
committerboucherv <valentin.boucher@orange.com>2017-07-03 17:50:36 +0200
commit642987dcca77cdf1ae551d824ab44272f3406f70 (patch)
tree20a0b1d146316c0bd858eee1bc1d45cdf35e3788 /functest/tests/unit
parent3ccd401b18775cf152e883c44cc4937287f4e62d (diff)
[cloudify_ims] Support Cloudify 4.0
- Delete all shell commands to use cloudify python lib - Cloudify Manager installation with a packaged image - SNAPS integration - Adapt test_vnf unit tests - Initiate test cloudify_ims unit tests (to be completed) JIRA: FUNCTEST-838 Change-Id: Ia4b499d4155e6af5d37d6d5cf4310a5a9693c7ce Signed-off-by: boucherv <valentin.boucher@orange.com> Signed-off-by: Morgan Richomme <morgan.richomme@orange.com>
Diffstat (limited to 'functest/tests/unit')
-rw-r--r--functest/tests/unit/core/test_vnf.py404
-rw-r--r--functest/tests/unit/vnf/ims/test_clearwater.py85
-rw-r--r--functest/tests/unit/vnf/ims/test_cloudify_ims.py630
-rw-r--r--functest/tests/unit/vnf/ims/test_orchestrator_cloudify.py176
4 files changed, 360 insertions, 935 deletions
diff --git a/functest/tests/unit/core/test_vnf.py b/functest/tests/unit/core/test_vnf.py
index f061c409..403c452f 100644
--- a/functest/tests/unit/core/test_vnf.py
+++ b/functest/tests/unit/core/test_vnf.py
@@ -1,210 +1,194 @@
-#!/usr/bin/env python
-
-# Copyright (c) 2016 Orange 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
-
-# pylint: disable=missing-docstring
-
-import logging
-import unittest
-
-import mock
-
-from functest.core import vnf
-from functest.core import testcase
-from functest.utils import constants
-
-
-class VnfBaseTesting(unittest.TestCase):
- """The class testing VNF."""
- # pylint: disable=missing-docstring,too-many-public-methods
-
- tenant_name = 'test_tenant_name'
- 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_vnf_exc(self):
- with mock.patch.object(self.test, 'prepare'),\
- mock.patch.object(self.test, 'deploy_orchestrator',
- return_value=None), \
- mock.patch.object(self.test, 'deploy_vnf',
- side_effect=Exception):
- self.assertEqual(self.test.run(),
- testcase.TestCase.EX_TESTCASE_FAILED)
-
- def test_run_test_vnf_exc(self):
- with mock.patch.object(self.test, 'prepare'),\
- mock.patch.object(self.test, 'deploy_orchestrator',
- return_value=None), \
- mock.patch.object(self.test, 'deploy_vnf'), \
- mock.patch.object(self.test, 'test_vnf',
- side_effect=Exception):
- self.assertEqual(self.test.run(),
- testcase.TestCase.EX_TESTCASE_FAILED)
-
- def test_run_deploy_orch_ko(self):
- with mock.patch.object(self.test, 'prepare'),\
- mock.patch.object(self.test, 'deploy_orchestrator',
- return_value=False), \
- mock.patch.object(self.test, 'deploy_vnf',
- return_value=True), \
- mock.patch.object(self.test, 'test_vnf',
- return_value=True):
- self.assertEqual(self.test.run(),
- testcase.TestCase.EX_TESTCASE_FAILED)
-
- def test_run_vnf_deploy_ko(self):
- with mock.patch.object(self.test, 'prepare'),\
- mock.patch.object(self.test, 'deploy_orchestrator',
- return_value=True), \
- mock.patch.object(self.test, 'deploy_vnf',
- return_value=False), \
- mock.patch.object(self.test, 'test_vnf',
- return_value=True):
- self.assertEqual(self.test.run(),
- testcase.TestCase.EX_TESTCASE_FAILED)
-
- def test_run_vnf_test_ko(self):
- with mock.patch.object(self.test, 'prepare'),\
- mock.patch.object(self.test, 'deploy_orchestrator',
- return_value=True), \
- mock.patch.object(self.test, 'deploy_vnf',
- return_value=True), \
- mock.patch.object(self.test, 'test_vnf',
- return_value=False):
- self.assertEqual(self.test.run(),
- testcase.TestCase.EX_TESTCASE_FAILED)
-
- def test_run_default(self):
- with mock.patch.object(self.test, 'prepare'),\
- mock.patch.object(self.test, 'deploy_orchestrator',
- return_value=True), \
- mock.patch.object(self.test, 'deploy_vnf',
- return_value=True), \
- mock.patch.object(self.test, 'test_vnf',
- return_value=True):
- self.assertEqual(self.test.run(), testcase.TestCase.EX_OK)
-
- def test_deploy_vnf_unimplemented(self):
- with self.assertRaises(vnf.VnfDeploymentException):
- self.test.deploy_vnf()
-
- def test_test_vnf_unimplemented(self):
- with self.assertRaises(vnf.VnfTestException):
- self.test.test_vnf()
-
- @mock.patch('functest.core.vnf.os_utils.get_keystone_client')
- @mock.patch('functest.core.vnf.os_utils.delete_user',
- return_value=True)
- def test_clean_user_set(self, *args):
- self.test.user_created = True
- self.test.clean()
- args[0].assert_called_once_with(mock.ANY, self.tenant_name)
- args[1].assert_called_once_with()
-
- @mock.patch('functest.core.vnf.os_utils.get_keystone_client')
- @mock.patch('functest.core.vnf.os_utils.delete_user',
- return_value=True)
- def test_clean_user_unset(self, *args):
- self.test.user_created = False
- self.test.clean()
- args[0].assert_not_called()
- args[1].assert_called_once_with()
-
- @mock.patch('functest.core.vnf.os_utils.get_keystone_client')
- @mock.patch('functest.core.vnf.os_utils.delete_tenant',
- return_value=True)
- def test_clean_tenant_set(self, *args):
- self.test.tenant_created = True
- self.test.clean()
- args[0].assert_called_once_with(mock.ANY, self.tenant_name)
- args[1].assert_called_once_with()
-
- @mock.patch('functest.core.vnf.os_utils.get_keystone_client')
- @mock.patch('functest.core.vnf.os_utils.delete_tenant',
- return_value=True)
- def test_clean_tenant_unset(self, *args):
- self.test.tenant_created = False
- self.test.clean()
- args[0].assert_not_called()
- args[1].assert_called_once_with()
-
- def test_deploy_orch_unimplemented(self):
- self.assertTrue(self.test.deploy_orchestrator())
-
- @mock.patch('functest.core.vnf.os_utils.get_credentials',
- return_value={'creds': 'test'})
- @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=0)
- @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
- return_value=0)
- def test_prepare(self, *args):
- self.assertEqual(self.test.prepare(),
- testcase.TestCase.EX_OK)
- args[0].assert_called_once_with('test', self.tenant_name)
- args[1].assert_called_once_with(
- 'test', self.tenant_name, self.tenant_description)
- args[2].assert_called_once_with()
- args[3].assert_called_once_with()
-
- @mock.patch('functest.core.vnf.os_utils.get_credentials',
- side_effect=Exception)
- def test_prepare_admin_creds_ko(self, *args):
- with self.assertRaises(vnf.VnfPreparationException):
- self.test.prepare()
- args[0].assert_called_once_with()
-
- @mock.patch('functest.core.vnf.os_utils.get_credentials',
- return_value='creds')
- @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
- side_effect=Exception)
- def test_prepare_keystone_client_ko(self, *args):
- with self.assertRaises(vnf.VnfPreparationException):
- self.test.prepare()
- args[0].assert_called_once_with()
- args[1].assert_called_once_with()
-
- @mock.patch('functest.core.vnf.os_utils.get_credentials',
- return_value='creds')
- @mock.patch('functest.core.vnf.os_utils.get_keystone_client')
- @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
- side_effect=Exception)
- def test_prepare_tenant_creation_ko(self, *args):
- with self.assertRaises(vnf.VnfPreparationException):
- self.test.prepare()
- args[0].assert_called_once_with(
- mock.ANY, self.tenant_name, self.tenant_description)
- args[1].assert_called_once_with()
- args[2].assert_called_once_with()
-
- @mock.patch('functest.core.vnf.os_utils.get_credentials',
- return_value='creds')
- @mock.patch('functest.core.vnf.os_utils.get_keystone_client')
- @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
- return_value=0)
- @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
- side_effect=Exception)
- def test_prepare_user_creation_ko(self, *args):
- with self.assertRaises(vnf.VnfPreparationException):
- self.test.prepare()
- args[0].assert_called_once_with(mock.ANY, self.tenant_name)
- args[1].assert_called_once_with(
- mock.ANY, self.tenant_name, self.tenant_description)
- args[2].assert_called_once_with()
- args[3].assert_called_once_with()
-
-
-if __name__ == "__main__":
- logging.disable(logging.CRITICAL)
- unittest.main(verbosity=2)
+#!/usr/bin/env python
+
+# Copyright (c) 2016 Orange 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
+
+# pylint: disable=missing-docstring
+
+import logging
+import unittest
+
+import mock
+
+from functest.core import vnf
+from functest.core import testcase
+from functest.utils import constants
+
+
+class VnfBaseTesting(unittest.TestCase):
+ """The class testing VNF."""
+ # pylint: disable=missing-docstring,too-many-public-methods
+
+ tenant_name = 'test_tenant_name'
+ 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_vnf_exc(self):
+ with mock.patch.object(self.test, 'prepare'),\
+ mock.patch.object(self.test, 'deploy_orchestrator',
+ return_value=None), \
+ mock.patch.object(self.test, 'deploy_vnf',
+ side_effect=Exception):
+ self.assertEqual(self.test.run(),
+ testcase.TestCase.EX_TESTCASE_FAILED)
+
+ def test_run_test_vnf_exc(self):
+ with mock.patch.object(self.test, 'prepare'),\
+ mock.patch.object(self.test, 'deploy_orchestrator',
+ return_value=None), \
+ mock.patch.object(self.test, 'deploy_vnf'), \
+ mock.patch.object(self.test, 'test_vnf',
+ side_effect=Exception):
+ self.assertEqual(self.test.run(),
+ testcase.TestCase.EX_TESTCASE_FAILED)
+
+ def test_run_deploy_orch_ko(self):
+ with mock.patch.object(self.test, 'prepare'),\
+ mock.patch.object(self.test, 'deploy_orchestrator',
+ return_value=False), \
+ mock.patch.object(self.test, 'deploy_vnf',
+ return_value=True), \
+ mock.patch.object(self.test, 'test_vnf',
+ return_value=True):
+ self.assertEqual(self.test.run(),
+ testcase.TestCase.EX_TESTCASE_FAILED)
+
+ def test_run_vnf_deploy_ko(self):
+ with mock.patch.object(self.test, 'prepare'),\
+ mock.patch.object(self.test, 'deploy_orchestrator',
+ return_value=True), \
+ mock.patch.object(self.test, 'deploy_vnf',
+ return_value=False), \
+ mock.patch.object(self.test, 'test_vnf',
+ return_value=True):
+ self.assertEqual(self.test.run(),
+ testcase.TestCase.EX_TESTCASE_FAILED)
+
+ def test_run_vnf_test_ko(self):
+ with mock.patch.object(self.test, 'prepare'),\
+ mock.patch.object(self.test, 'deploy_orchestrator',
+ return_value=True), \
+ mock.patch.object(self.test, 'deploy_vnf',
+ return_value=True), \
+ mock.patch.object(self.test, 'test_vnf',
+ return_value=False):
+ self.assertEqual(self.test.run(),
+ testcase.TestCase.EX_TESTCASE_FAILED)
+
+ def test_run_default(self):
+ with mock.patch.object(self.test, 'prepare'),\
+ mock.patch.object(self.test, 'deploy_orchestrator',
+ return_value=True), \
+ mock.patch.object(self.test, 'deploy_vnf',
+ return_value=True), \
+ mock.patch.object(self.test, 'test_vnf',
+ return_value=True):
+ self.assertEqual(self.test.run(), testcase.TestCase.EX_OK)
+
+ def test_deploy_vnf_unimplemented(self):
+ with self.assertRaises(vnf.VnfDeploymentException):
+ self.test.deploy_vnf()
+
+ def test_test_vnf_unimplemented(self):
+ with self.assertRaises(vnf.VnfTestException):
+ self.test.test_vnf()
+
+ @mock.patch('functest.core.vnf.os_utils.get_keystone_client')
+ @mock.patch('functest.core.vnf.os_utils.delete_user',
+ return_value=True)
+ def test_clean_user_already_exist(self, *args):
+ self.test.exist_obj['user'] = True
+ self.test.clean()
+ args[0].assert_not_called()
+ args[1].assert_called_once_with()
+
+ @mock.patch('functest.core.vnf.os_utils.get_keystone_client')
+ @mock.patch('functest.core.vnf.os_utils.delete_user',
+ return_value=True)
+ def test_clean_user_created(self, *args):
+ self.test.exist_obj['user'] = False
+ self.test.clean()
+ args[0].assert_called_once_with(mock.ANY, self.tenant_name)
+ args[1].assert_called_once_with()
+
+ @mock.patch('functest.core.vnf.os_utils.get_keystone_client')
+ @mock.patch('functest.core.vnf.os_utils.delete_tenant',
+ return_value=True)
+ def test_clean_tenant_already_exist(self, *args):
+ self.test.exist_obj['tenant'] = True
+ self.test.clean()
+ args[0].assert_not_called()
+ args[1].assert_called_once_with()
+
+ @mock.patch('functest.core.vnf.os_utils.get_keystone_client')
+ @mock.patch('functest.core.vnf.os_utils.delete_tenant',
+ return_value=True)
+ def test_clean_tenant_created(self, *args):
+ self.test.exist_obj['tenant'] = False
+ self.test.clean()
+ args[0].assert_called_once_with(mock.ANY, self.tenant_name)
+ args[1].assert_called_once_with()
+
+ def test_deploy_orch_unimplemented(self):
+ self.assertTrue(self.test.deploy_orchestrator())
+
+ @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'})
+ def test_prepare(self, *args):
+ self.assertEqual(self.test.prepare(),
+ testcase.TestCase.EX_OK)
+ args[0].assert_called_once_with()
+ args[1].assert_called_once_with('test', self.tenant_name)
+ args[2].assert_called_once_with(
+ 'test', self.tenant_name, self.tenant_description)
+ args[3].assert_called_once_with()
+
+ @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
+ side_effect=Exception)
+ def test_prepare_keystone_client_ko(self, *args):
+ with self.assertRaises(vnf.VnfPreparationException):
+ self.test.prepare()
+ args[0].assert_called_once_with()
+
+ @mock.patch('functest.core.vnf.os_utils.get_keystone_client')
+ @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
+ side_effect=Exception)
+ def test_prepare_tenant_creation_ko(self, *args):
+ with self.assertRaises(vnf.VnfPreparationException):
+ self.test.prepare()
+ args[0].assert_called_once_with(
+ mock.ANY, self.tenant_name, self.tenant_description)
+ args[1].assert_called_once_with()
+
+ @mock.patch('functest.core.vnf.os_utils.get_keystone_client')
+ @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
+ return_value=0)
+ @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
+ side_effect=Exception)
+ def test_prepare_user_creation_ko(self, *args):
+ with self.assertRaises(vnf.VnfPreparationException):
+ self.test.prepare()
+ args[0].assert_called_once_with(mock.ANY, self.tenant_name)
+ args[1].assert_called_once_with(
+ mock.ANY, self.tenant_name, self.tenant_description)
+ args[2].assert_called_once_with()
+
+
+if __name__ == "__main__":
+ logging.disable(logging.CRITICAL)
+ unittest.main(verbosity=2)
diff --git a/functest/tests/unit/vnf/ims/test_clearwater.py b/functest/tests/unit/vnf/ims/test_clearwater.py
deleted file mode 100644
index bc31c33e..00000000
--- a/functest/tests/unit/vnf/ims/test_clearwater.py
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/usr/bin/env python
-
-# 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.ims import clearwater
-from functest.opnfv_tests.vnf.ims import orchestrator_cloudify
-
-
-class ClearwaterTesting(unittest.TestCase):
-
- def setUp(self):
- self.clearwater = clearwater.Clearwater()
- self.orchestrator = orchestrator_cloudify.Orchestrator('test_dir')
- self.clearwater.orchestrator = self.orchestrator
- self.clearwater.dep_name = 'test_dep_name'
- self.bp = {'file_name': 'test_file',
- 'destination_folder': 'test_folder',
- 'url': 'test_url',
- 'branch': 'test_branch'}
-
- def test_deploy_vnf_blueprint_download_failed(self):
- with mock.patch.object(self.clearwater.orchestrator,
- 'download_upload_and_deploy_blueprint',
- return_value='error'):
- self.assertEqual(self.clearwater.deploy_vnf(self.bp),
- 'error')
-
- def test_deploy_vnf_blueprint_download_passed(self):
- with mock.patch.object(self.clearwater.orchestrator,
- 'download_upload_and_deploy_blueprint',
- return_value=''):
- self.clearwater.deploy_vnf(self.bp)
- self.assertEqual(self.clearwater.deploy, True)
-
- def test_undeploy_vnf_deployment_passed(self):
- with mock.patch.object(self.clearwater.orchestrator,
- 'undeploy_deployment'):
- self.clearwater.deploy = True
- self.clearwater.undeploy_vnf()
- self.assertEqual(self.clearwater.deploy, False)
-
- def test_undeploy_vnf_deployment_with_undeploy(self):
- with mock.patch.object(self.clearwater.orchestrator,
- 'undeploy_deployment') as m:
- self.clearwater.deploy = False
- self.clearwater.undeploy_vnf(),
- self.assertEqual(self.clearwater.deploy, False)
- self.assertFalse(m.called)
-
- self.clearwater.orchestrator = None
- self.clearwater.deploy = True
- self.clearwater.undeploy_vnf(),
- self.assertEqual(self.clearwater.deploy, True)
-
- self.clearwater.deploy = False
- self.clearwater.undeploy_vnf(),
- self.assertEqual(self.clearwater.deploy, False)
-
- def test_set_methods(self):
- self.clearwater.set_orchestrator(self.orchestrator)
- self.assertTrue(self.clearwater.orchestrator, self.orchestrator)
- self.clearwater.set_flavor_id('test_flavor_id')
- self.assertTrue(self.clearwater.config['flavor_id'], 'test_flavor_id')
- self.clearwater.set_image_id('test_image_id')
- self.assertTrue(self.clearwater.config['image_id'], 'test_image_id')
- self.clearwater.set_agent_user('test_user')
- self.assertTrue(self.clearwater.config['agent_user'], 'test_user')
- self.clearwater.set_external_network_name('test_network')
- self.assertTrue(self.clearwater.config['external_network_name'],
- 'test_network')
- self.clearwater.set_public_domain('test_domain')
- self.assertTrue(self.clearwater.config['public_domain'],
- 'test_domain')
-
-if __name__ == "__main__":
- logging.disable(logging.CRITICAL)
- unittest.main(verbosity=2)
diff --git a/functest/tests/unit/vnf/ims/test_cloudify_ims.py b/functest/tests/unit/vnf/ims/test_cloudify_ims.py
index 2156a122..3a135d18 100644
--- a/functest/tests/unit/vnf/ims/test_cloudify_ims.py
+++ b/functest/tests/unit/vnf/ims/test_cloudify_ims.py
@@ -1,464 +1,166 @@
-#!/usr/bin/env python
-
-# 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.ims import cloudify_ims
-
-
-class CloudifyImsTesting(unittest.TestCase):
-
- def setUp(self):
- with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os.makedirs'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'get_config', return_value='config_value'):
- self.ims_vnf = cloudify_ims.CloudifyIms()
- self.neutron_client = mock.Mock()
- self.glance_client = mock.Mock()
- self.keystone_client = mock.Mock()
- self.nova_client = mock.Mock()
- self.orchestrator = {'requirements': {'ram_min': 2,
- 'os_image': 'test_os_image'},
- 'blueprint': {'url': 'test_url',
- 'branch': 'test_branch'},
- 'inputs': {'public_domain': 'test_domain'},
- 'object': 'test_object',
- 'deployment_name': 'test_deployment_name'}
- self.ims_vnf.orchestrator = self.orchestrator
- self.ims_vnf.images = {'test_image': 'test_url'}
- self.ims_vnf.vnf = self.orchestrator
- self.ims_vnf.tenant_name = 'test_tenant'
- self.ims_vnf.inputs = {'public_domain': 'test_domain'}
- self.ims_vnf.glance_client = self.glance_client
- self.ims_vnf.neutron_client = self.neutron_client
- self.ims_vnf.keystone_client = self.keystone_client
- self.ims_vnf.nova_client = self.nova_client
- self.ims_vnf.admin_creds = 'test_creds'
-
- self.mock_post = mock.Mock()
- attrs = {'status_code': 201,
- 'cookies': ""}
- self.mock_post.configure_mock(**attrs)
-
- self.mock_post_200 = mock.Mock()
- attrs = {'status_code': 200,
- 'cookies': ""}
- self.mock_post_200.configure_mock(**attrs)
-
- def test_deploy_orchestrator_missing_image(self):
- with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_neutron_client',
- return_value=self.neutron_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_glance_client',
- return_value=self.glance_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_keystone_client',
- return_value=self.keystone_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_nova_client',
- return_value=self.nova_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_image_id',
- return_value=''), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.os_utils.'
- 'download_and_add_image_on_glance') as m, \
- self.assertRaises(Exception) as context:
- self.ims_vnf.deploy_orchestrator()
- self.assertTrue(m.called)
- msg = "Failed to find or upload required OS "
- msg += "image for this deployment"
- self.assertTrue(msg in context.exception)
-
- def test_deploy_orchestrator_extend_quota_fail(self):
- with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_neutron_client',
- return_value=self.neutron_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_glance_client',
- return_value=self.glance_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_keystone_client',
- return_value=self.keystone_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_nova_client',
- return_value=self.nova_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_image_id',
- return_value='image_id'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_tenant_id',
- return_value='tenant_id'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.update_sg_quota',
- return_value=False), \
- self.assertRaises(Exception) as context:
- self.ims_vnf.deploy_orchestrator()
- msg = "Failed to update security group quota"
- msg += " for tenant test_tenant"
- self.assertTrue(msg in context.exception)
-
- def _get_image_id(self, client, name):
- if name == 'test_image':
- return 'image_id'
- else:
- return ''
-
- def test_deploy_orchestrator_missing_flavor(self):
- with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_neutron_client',
- return_value=self.neutron_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_glance_client',
- return_value=self.glance_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_keystone_client',
- return_value=self.keystone_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_nova_client',
- return_value=self.nova_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_image_id',
- side_effect=self._get_image_id), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_tenant_id',
- return_value='tenant_id'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.update_sg_quota',
- return_value=True), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_endpoint',
- return_value='public_auth_url'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'Orchestrator', return_value=mock.Mock()) as m, \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_or_create_flavor',
- return_value=(False, '')), \
- self.assertRaises(Exception) as context:
- self.ims_vnf.deploy_orchestrator()
- self.assertTrue(m.set_credentials.called)
- msg = "Failed to find required flavorfor this deployment"
- self.assertTrue(msg in context.exception)
-
- def test_deploy_orchestrator_missing_os_image(self):
- with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_neutron_client',
- return_value=self.neutron_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_glance_client',
- return_value=self.glance_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_keystone_client',
- return_value=self.keystone_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_nova_client',
- return_value=self.nova_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_image_id',
- side_effect=self._get_image_id), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_tenant_id',
- return_value='tenant_id'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.update_sg_quota',
- return_value=True), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_endpoint',
- return_value='public_auth_url'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'Orchestrator', return_value=mock.Mock()) as m, \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_or_create_flavor',
- return_value=(True, 'flavor_id')), \
- self.assertRaises(Exception) as context:
- self.ims_vnf.deploy_orchestrator()
- self.assertTrue(m.set_credentials.called)
- self.assertTrue(m.set_flavor_id.called)
- msg = "Failed to find required OS image for cloudify manager"
- self.assertTrue(msg in context.exception)
-
- def test_deploy_orchestrator_get_ext_network_fail(self):
- with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_neutron_client',
- return_value=self.neutron_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_glance_client',
- return_value=self.glance_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_keystone_client',
- return_value=self.keystone_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_nova_client',
- return_value=self.nova_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_image_id',
- return_value='image_id'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_tenant_id',
- return_value='tenant_id'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.update_sg_quota',
- return_value=True), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_endpoint',
- return_value='public_auth_url'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'Orchestrator', return_value=mock.Mock()) as m, \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_or_create_flavor',
- return_value=(True, 'flavor_id')), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_external_net',
- return_value=''), \
- self.assertRaises(Exception) as context:
- self.ims_vnf.deploy_orchestrator()
- self.assertTrue(m.set_credentials.called)
- self.assertTrue(m.set_flavor_id.called)
- self.assertTrue(m.set_image_id.called)
- msg = "Failed to get external network"
- self.assertTrue(msg in context.exception)
-
- def test_deploy_orchestrator_with_error(self):
- with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_neutron_client',
- return_value=self.neutron_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_glance_client',
- return_value=self.glance_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_keystone_client',
- return_value=self.keystone_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_nova_client',
- return_value=self.nova_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_image_id',
- return_value='image_id'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_tenant_id',
- return_value='tenant_id'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.update_sg_quota',
- return_value=True), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_endpoint',
- return_value='public_auth_url'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'Orchestrator') as m, \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_or_create_flavor',
- return_value=(True, 'flavor_id')), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_external_net',
- return_value='ext_net'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'ft_utils.get_resolvconf_ns',
- return_value=True), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'ft_utils.execute_command'):
- mock_obj = mock.Mock()
- attrs = {'deploy_manager.return_value': 'error'}
- mock_obj.configure_mock(**attrs)
-
- m.return_value = mock_obj
-
- self.assertEqual(self.ims_vnf.deploy_orchestrator(),
- {'status': 'FAIL', 'result': 'error'})
-
- def test_deploy_orchestrator_default(self):
- with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_neutron_client',
- return_value=self.neutron_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_glance_client',
- return_value=self.glance_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_keystone_client',
- return_value=self.keystone_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_nova_client',
- return_value=self.nova_client), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_image_id',
- return_value='image_id'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_tenant_id',
- return_value='tenant_id'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.update_sg_quota',
- return_value=True), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_endpoint',
- return_value='public_auth_url'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'Orchestrator') as m, \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_or_create_flavor',
- return_value=(True, 'flavor_id')), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_external_net',
- return_value='ext_net'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'ft_utils.get_resolvconf_ns',
- return_value=True), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'ft_utils.execute_command'):
- mock_obj = mock.Mock()
- attrs = {'deploy_manager.return_value': ''}
- mock_obj.configure_mock(**attrs)
-
- m.return_value = mock_obj
-
- self.assertEqual(self.ims_vnf.deploy_orchestrator(),
- {'status': 'PASS', 'result': ''})
-
- def test_deploy_vnf_missing_flavor(self):
- with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'Clearwater', return_value=mock.Mock()), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_or_create_flavor',
- return_value=(False, '')), \
- self.assertRaises(Exception) as context:
- self.ims_vnf.deploy_vnf()
- msg = "Failed to find required flavor for this deployment"
- self.assertTrue(msg in context.exception)
-
- def test_deploy_vnf_missing_os_image(self):
- with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'Clearwater', return_value=mock.Mock()) as m, \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_or_create_flavor',
- return_value=(True, 'test_flavor')), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_image_id',
- return_value=''), \
- self.assertRaises(Exception) as context:
- self.ims_vnf.deploy_vnf()
- msg = "Failed to find required OS image"
- msg += " for clearwater VMs"
- self.assertTrue(msg in context.exception)
- self.assertTrue(m.set_flavor_id.called)
-
- def test_deploy_vnf_missing_get_ext_net(self):
- with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'Clearwater', return_value=mock.Mock()) as m, \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_or_create_flavor',
- return_value=(True, 'test_flavor')), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_image_id',
- return_value='image_id'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_external_net',
- return_value=''), \
- self.assertRaises(Exception) as context:
- self.ims_vnf.deploy_vnf()
- msg = "Failed to get external network"
- self.assertTrue(msg in context.exception)
- self.assertTrue(m.set_flavor_id.called)
- self.assertTrue(m.set_image_id.called)
-
- def test_deploy_vnf_with_error(self):
- with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'Clearwater') as m, \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_or_create_flavor',
- return_value=(True, 'test_flavor')), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_image_id',
- return_value='image_id'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_external_net',
- return_value='ext_net'):
- mock_obj = mock.Mock()
- attrs = {'deploy_vnf.return_value': 'error'}
- mock_obj.configure_mock(**attrs)
-
- m.return_value = mock_obj
-
- self.assertEqual(self.ims_vnf.deploy_vnf(),
- {'status': 'FAIL', 'result': 'error'})
-
- def test_deploy_vnf_default(self):
- with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'Clearwater') as m, \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_or_create_flavor',
- return_value=(True, 'test_flavor')), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_image_id',
- return_value='image_id'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os_utils.get_external_net',
- return_value='ext_net'):
- mock_obj = mock.Mock()
- attrs = {'deploy_vnf.return_value': ''}
- mock_obj.configure_mock(**attrs)
-
- m.return_value = mock_obj
-
- self.assertEqual(self.ims_vnf.deploy_vnf(),
- {'status': 'PASS', 'result': ''})
-
- def test_test_vnf_ip_retrieval_failure(self):
- with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os.popen', side_effect=Exception), \
- self.assertRaises(Exception) as context:
- msg = "Unable to retrieve the IP of the "
- msg += "cloudify manager server !"
- self.ims_vnf.test_vnf()
- self.assertTrue(msg in context.exception)
-
- def test_test_vnf_fail(self):
- with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os.popen'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'requests.get') as mock_get, \
- mock.patch.object(self.ims_vnf, 'config_ellis'), \
- mock.patch.object(self.ims_vnf,
- 'run_clearwater_live_test') as clearwater_obj:
- clearwater_obj.return_value = ''
-
- mock_obj2 = mock.Mock()
- attrs = {'json.return_value': {'outputs':
- {'dns_ip': 'test_dns_ip',
- 'ellis_ip': 'test_ellis_ip'}}}
- mock_obj2.configure_mock(**attrs)
- mock_get.return_value = mock_obj2
-
- self.assertEqual(self.ims_vnf.test_vnf(),
- {'status': 'FAIL', 'result': ''})
-
- def test_test_vnf_pass(self):
- with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'os.popen'), \
- mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
- 'requests.get') as mock_get, \
- mock.patch.object(self.ims_vnf, 'config_ellis'), \
- mock.patch.object(self.ims_vnf,
- 'run_clearwater_live_test') as clearwater_obj:
- clearwater_obj.return_value = 'vims_test_result'
-
- mock_obj2 = mock.Mock()
- attrs = {'json.return_value': {'outputs':
- {'dns_ip': 'test_dns_ip',
- 'ellis_ip': 'test_ellis_ip'}}}
- mock_obj2.configure_mock(**attrs)
- mock_get.return_value = mock_obj2
-
- self.assertEqual(self.ims_vnf.test_vnf(),
- {'status': 'PASS',
- 'result': 'vims_test_result'})
-
-
-if __name__ == "__main__":
- logging.disable(logging.CRITICAL)
- unittest.main(verbosity=2)
+#!/usr/bin/env python
+
+# 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.ims import cloudify_ims
+
+
+class CloudifyImsTesting(unittest.TestCase):
+
+ def setUp(self):
+
+ self.tenant = 'cloudify_ims'
+ 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': 'clearwater',
+ 'descriptor': {'version': '108',
+ 'file_name': 'openstack-blueprint.yaml',
+ 'name': 'clearwater-opnfv',
+ 'url': 'https://foo',
+ 'requirements': {'flavor':
+ {'name': 'm1.medium',
+ 'ram_min': 2048}}}}
+
+ with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
+ 'os.makedirs'), \
+ mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
+ 'get_config', return_value={
+ 'tenant_images': 'foo',
+ 'orchestrator': self.orchestrator,
+ 'vnf': self.vnf,
+ 'vnf_test_suite': '',
+ 'version': 'whatever'}):
+
+ self.ims_vnf = cloudify_ims.CloudifyIms()
+
+ 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.ims_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.ims_vnf.prepare()
+ args[0].assert_not_called()
+
+ def test_prepare_missing_param(self):
+ with self.assertRaises(vnf.VnfPreparationException):
+ self.ims_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.ims_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.ims_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.ims_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.ims_vnf.prepare()
+ args[0].assert_called_once_with()
+
+ # @mock.patch('snaps.openstack.create_keypairs.OpenStackKeypair',
+ # side_effect=Exception)
+ # def test_deploy_orchestrator_keypair_exception(self, *args):
+ # with self.assertRaises(vnf.OrchestratorDeploymentException):
+ # self.ims_vnf.deploy_orchestrator()
+
+ # def test_deploy_orchestrator_network_creation_fail(self):
+ # def test_deploy_orchestrator_floatting_ip_creation_fail(self):
+ # def test_deploy_orchestrator_flavor_fail(self):
+ # def test_deploy_orchestrator_get_image_id_fail(self):
+ # def test_deploy_orchestrator_create_instance_fail(self):
+ # def test_deploy_orchestrator_secgroup_fail(self):
+ # def test_deploy_orchestrator_add_floating_ip_fail(self):
+ # def test_deploy_orchestrator_get_endpoint_fail(self):
+ # def test_deploy_orchestrator_initiate CloudifyClient_fail(self):
+ # def test_deploy_orchestrator_get_status_fail(self):
+ #
+
+ # def test_deploy_vnf(self):
+ # def test_deploy_vnf_publish_fail(self):
+ # def test_deploy_vnf_get_flavor_fail(self):
+ # def test_deploy_vnf_get_external_net_fail(self):
+ # def test_deploy_vnf_deployment_create_fail(self):
+ # def test_deploy_vnf_start_fail(self):
+ #
+ # def test_test_vnf(self):
+ # def test_test_vnf_deployment_get_fail(self):
+ # def test_test_vnf_run_live_test_fail(self):
+ #
+ # def test_clean(self):
+ # def test_clean_execution_start_fail(self):
+ # def test_clean_deployment_delete_fail(self):
+ # def test_clean_blueprint_delete_fail(self):
+
+
+if __name__ == "__main__":
+ logging.disable(logging.CRITICAL)
+ unittest.main(verbosity=2)
diff --git a/functest/tests/unit/vnf/ims/test_orchestrator_cloudify.py b/functest/tests/unit/vnf/ims/test_orchestrator_cloudify.py
deleted file mode 100644
index 57064664..00000000
--- a/functest/tests/unit/vnf/ims/test_orchestrator_cloudify.py
+++ /dev/null
@@ -1,176 +0,0 @@
-#!/usr/bin/env python
-
-# 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 subprocess32 as subprocess
-import unittest
-
-import mock
-
-from functest.opnfv_tests.vnf.ims import orchestrator_cloudify
-
-
-class ImsVnfTesting(unittest.TestCase):
-
- def setUp(self):
- self.orchestrator = orchestrator_cloudify.Orchestrator('test_dir')
- self.bp = {'file_name': 'test_file',
- 'destination_folder': 'test_folder',
- 'url': 'test_url',
- 'branch': 'test_branch'}
-
- def test_download_manager_blueprint_download_blueprint_failed(self):
- self.orchestrator.manager_blueprint = False
- with mock.patch.object(self.orchestrator, '_download_blueprints',
- return_value=False), \
- mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
- 'exit') as mock_exit:
- self.orchestrator.download_manager_blueprint('test_url',
- 'test_branch')
- mock_exit.assert_any_call(-1)
-
- def test_download_manager_blueprint_download_blueprint_passed(self):
- self.orchestrator.manager_blueprint = False
- with mock.patch.object(self.orchestrator, '_download_blueprints',
- return_value=True):
- self.orchestrator.download_manager_blueprint('test_url',
- 'test_branch')
- self.assertEqual(self.orchestrator.manager_blueprint,
- True)
-
- def test_deploy_manager_failed(self):
- self.orchestrator.manager_blueprint = True
- with mock.patch('__builtin__.open', mock.mock_open()), \
- mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
- 'os.remove'), \
- mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
- 'execute_command', return_value='error'):
- self.assertEqual(self.orchestrator.deploy_manager(),
- 'error')
- self.assertEqual(self.orchestrator.manager_up,
- False)
-
- def test_deploy_manager_passed(self):
- self.orchestrator.manager_blueprint = True
- with mock.patch('__builtin__.open', mock.mock_open()), \
- mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
- 'os.remove'), \
- mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
- 'execute_command', return_value=''):
- self.orchestrator.deploy_manager()
- self.assertEqual(self.orchestrator.manager_up,
- True)
-
- def test_undeploy_manager_passed(self):
- with mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
- 'execute_command', return_value=''):
- self.orchestrator.deploy_manager()
- self.assertEqual(self.orchestrator.manager_up,
- False)
-
- def test_dwnld_upload_and_depl_blueprint_dwnld_blueprint_failed(self):
- with mock.patch.object(self.orchestrator, '_download_blueprints',
- return_value=False), \
- mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
- 'exit', side_effect=Exception) as mock_exit, \
- self.assertRaises(Exception):
- self.orchestrator.download_upload_and_deploy_blueprint(self.bp,
- 'cfig',
- 'bpn',
- 'dpn')
- mock_exit.assert_any_call(-1)
-
- def test_dwnld_upload_and_depl_blueprint_failed(self):
- with mock.patch.object(self.orchestrator, '_download_blueprints',
- return_value=True), \
- mock.patch('__builtin__.open', mock.mock_open()), \
- mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
- 'execute_command', return_value='error'):
- r = self.orchestrator.download_upload_and_deploy_blueprint(self.bp,
- 'cfig',
- 'bpn',
- 'dpn')
- self.assertEqual(r, 'error')
-
- def test__download_blueprints_failed(self):
- with mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
- 'shutil.rmtree'), \
- mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
- 'Repo.clone_from', side_effect=Exception):
- self.assertEqual(self.orchestrator._download_blueprints('bp_url',
- 'branch',
- 'dest'),
- False)
-
- def test__download_blueprints_passed(self):
- with mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
- 'shutil.rmtree'), \
- mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
- 'Repo.clone_from'):
- self.assertEqual(self.orchestrator._download_blueprints('bp_url',
- 'branch',
- 'dest'),
- True)
-
- def test_execute_command_failed(self):
- with mock.patch('__builtin__.open',
- mock.mock_open(read_data='test_data\n')):
- subprocess.call = mock.create_autospec(subprocess.call,
- return_value=0)
- mock_log = mock.Mock()
- cmd = 'test_cmd -e test_env bash_script'
- ret = orchestrator_cloudify.execute_command(cmd, mock_log,
- timeout=100)
- self.assertEqual(ret, False)
-
- def test_execute_command_default(self):
- with mock.patch('__builtin__.open',
- mock.mock_open(read_data='test_data\n')):
- subprocess.call = mock. \
- create_autospec(subprocess.call,
- return_value=subprocess.TimeoutExpired)
- mock_log = mock.Mock()
- cmd = 'test_cmd -e test_env bash_script'
- ret = orchestrator_cloudify.execute_command(cmd, mock_log,
- timeout=100)
- self.assertEqual(ret, ['test_data\n'])
-
- def test_set_methods(self):
- self.orchestrator.set_credentials('test_username', 'test_password',
- 'test_tenant_name', 'test_auth_url')
- self.assertTrue(self.orchestrator.config['keystone_username'],
- 'test_username')
- self.assertTrue(self.orchestrator.config['keystone_password'],
- 'test_password')
- self.assertTrue(self.orchestrator.config['keystone_url'],
- 'test_auth_url')
- self.assertTrue(self.orchestrator.config['keystone_tenant_name'],
- 'test_tenant_name')
- self.orchestrator.set_flavor_id('test_flavor_id')
- self.assertTrue(self.orchestrator.config['flavor_id'],
- 'test_flavor_id')
- self.orchestrator.set_image_id('test_image_id')
- self.assertTrue(self.orchestrator.config['image_id'], 'test_image_id')
- self.orchestrator.set_external_network_name('test_network')
- self.assertTrue(self.orchestrator.config['external_network_name'],
- 'test_network')
- self.orchestrator.set_ssh_user('test_user')
- self.assertTrue(self.orchestrator.config['ssh_user'],
- 'test_user')
- self.orchestrator.set_nova_url('test_nova_url')
- self.assertTrue(self.orchestrator.config['nova_url'],
- 'test_nova_url')
- self.orchestrator.set_neutron_url('test_neutron_url')
- self.assertTrue(self.orchestrator.config['neutron_url'],
- 'test_neutron_url')
- self.orchestrator.set_nameservers(['test_subnet'])
- self.assertTrue(self.orchestrator.config['dns_subnet_1'],
- 'test_subnet')
-
-if __name__ == "__main__":
- logging.disable(logging.CRITICAL)
- unittest.main(verbosity=2)