From cdada88cbef275918215fd80b1d947a8dfd82cd8 Mon Sep 17 00:00:00 2001 From: Hiroo Kitamura Date: Tue, 12 May 2020 09:16:14 +0900 Subject: [PATCH] Add UT instead of deleting FT related with Mistral This patch deletes the FT related with Mistral for the following reasons. - Other OpenStack-PJs (e.g. nova and heat) that have Action definition in mistral([1]) do not implement FT in each PJ. - These functional tests are carried out in the mistral-tempest-plugin. However, at the moment, only core PJs (e.g. nova and heat) are targeted in [2], and it's necessary to aim to add tacker here in the future. In this patch, instead of deleting FT, the viewpoint of unittest is added to confirm that mistral-client is called as expected. The code is modified so that the anchor notation is not used because not supported by mistral in [3]. [1]: https://opendev.org/openstack/mistral-extra/src/branch/master/mistral_extra/actions/openstack/mapping.json [2]: https://opendev.org/openstack/mistral-tempest-plugin/src/branch/master/mistral_tempest_tests/tests/scenario/engine/actions/v2/test_openstack_actions.py [3]: https://opendev.org/openstack/mistral/commit/eac23d9e774f658f9d4743c99aa2743eb104c3f9 Closes-Bug: #1878309 Change-Id: Ie8eab1b262c15f7b53796a287b333e60ffee1c31 --- lower-constraints.txt | 2 +- requirements.txt | 2 +- tacker/nfvo/drivers/vim/openstack_driver.py | 1 + .../vim_monitor/vim_monitor_utils.py | 1 + tacker/tests/functional/nfvo/test_nfvo.py | 51 ---- tacker/tests/unit/nfvo/test_nfvo_plugin.py | 219 ++++++++++++++++-- 6 files changed, 206 insertions(+), 70 deletions(-) diff --git a/lower-constraints.txt b/lower-constraints.txt index 223383722..4e1e0c138 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -119,7 +119,7 @@ python-subunit==1.0.0 python-swiftclient==3.5.0 python-tackerclient==0.8.0 pytz==2018.3 -PyYAML==3.12 +PyYAML==5.1 reno==2.7.0 repoze.lru==0.7 requests-oauthlib==0.8.0 diff --git a/requirements.txt b/requirements.txt index 4bf5861bd..3fefd0c55 100644 --- a/requirements.txt +++ b/requirements.txt @@ -52,7 +52,7 @@ castellan>=0.16.0 # Apache-2.0 kubernetes>=5.0.0 # Apache-2.0 setuptools!=24.0.0,!=34.0.0,!=34.0.1,!=34.0.2,!=34.0.3,!=34.1.0,!=34.1.1,!=34.2.0,!=34.3.0,!=34.3.1,!=34.3.2,!=36.2.0,>=21.0.0 # PSF/ZPL tooz>=1.58.0 # Apache-2.0 -PyYAML>=3.12 # MIT +PyYAML>=5.1 # MIT # Glance Store glance-store>=0.26.1 # Apache-2.0 diff --git a/tacker/nfvo/drivers/vim/openstack_driver.py b/tacker/nfvo/drivers/vim/openstack_driver.py index b543bec3a..d7cca2a80 100644 --- a/tacker/nfvo/drivers/vim/openstack_driver.py +++ b/tacker/nfvo/drivers/vim/openstack_driver.py @@ -731,6 +731,7 @@ class OpenStack_Driver(abstract_vim_driver.VimAbstractDriver, wg.task(**kwargs) if not wg.get_tasks(): raise nfvo.NoTasksException(resource=resource, action=action) + yaml.SafeDumper.ignore_aliases = lambda self, data: True definition_yaml = yaml.safe_dump(wg.definition) workflow = mistral_client.workflows.create(definition_yaml) return {'id': workflow[0].id, 'input': wg.get_input_dict()} diff --git a/tacker/nfvo/workflows/vim_monitor/vim_monitor_utils.py b/tacker/nfvo/workflows/vim_monitor/vim_monitor_utils.py index e6b4f67ae..4d0f6264d 100644 --- a/tacker/nfvo/workflows/vim_monitor/vim_monitor_utils.py +++ b/tacker/nfvo/workflows/vim_monitor/vim_monitor_utils.py @@ -35,6 +35,7 @@ def prepare_and_create_workflow(mistral_client, vim_id, action, kwargs): wg = workflow_generator.WorkflowGenerator(vim_id, action) wg.task(**kwargs) + yaml.SafeDumper.ignore_aliases = lambda self, data: True definition_yaml = yaml.safe_dump(wg.definition, default_flow_style=False) LOG.debug('vim monitor workflow: %s', definition_yaml) workflow = mistral_client.workflows.create(definition_yaml) diff --git a/tacker/tests/functional/nfvo/test_nfvo.py b/tacker/tests/functional/nfvo/test_nfvo.py index b7650ee95..bb797f81b 100644 --- a/tacker/tests/functional/nfvo/test_nfvo.py +++ b/tacker/tests/functional/nfvo/test_nfvo.py @@ -208,54 +208,3 @@ class NsdTestCreate(base.BaseTackerTest): self._test_delete_nsd(nsd_id) self._test_delete_vnfd(vnfd1_id) self._test_delete_vnfd(vnfd2_id) - - def test_create_delete_network_service(self): - self._test_create_delete_ns('test-ns-nsd.yaml', - 'test-ns-onboarded', - template_source='onboarded') - time.sleep(1) - self._test_create_delete_ns('test-ns-nsd.yaml', - 'test-ns-inline', - template_source='inline') - - def _wait_for_server_active(self, server_id, target_status='ACTIVE', - timeout=60, sleep_interval=2): - start_time = int(time.time()) - while True: - server_info = self.novaclient().servers.get(server_id) - if (server_info.status == target_status) or ( - (int(time.time()) - start_time) > timeout): - break - time.sleep(sleep_interval) - - def test_create_delete_ns_vnffg(self): - net = self.neutronclient().list_networks() - for network in net['networks']: - if network['name'] == 'net0': - net_id = network['id'] - networks = [{'net-id': net_id}] - img = self.glanceclient().images.list( - name='cirros-0.4.0-x86_64-disk').next() - http_client = self.novaclient().servers.create(name='http_client', - image=img['id'], - flavor=1, - nics=networks) - http_server = self.novaclient().servers.create(name='http_server', - image=img['id'], - flavor=1, - nics=networks) - self._wait_for_server_active(http_client.id) - self._wait_for_server_active(http_server.id) - port_list = self.neutronclient().list_ports() - source_port_id = None - dest_ip_prefix = http_server.networks['net0'][0] + '/24' - for port in port_list['ports']: - if port['fixed_ips'][0]['ip_address'] == \ - http_client.networks['net0'][0]: - source_port_id = port['id'] - - self._test_create_delete_ns_vnffg('tosca-ns-vnffg.yaml', - 'tosca-ns-vnffg', - source_port_id, dest_ip_prefix) - self.novaclient().servers.delete(http_server.id) - self.novaclient().servers.delete(http_client.id) diff --git a/tacker/tests/unit/nfvo/test_nfvo_plugin.py b/tacker/tests/unit/nfvo/test_nfvo_plugin.py index d9ae6a249..c3da8fd7b 100644 --- a/tacker/tests/unit/nfvo/test_nfvo_plugin.py +++ b/tacker/tests/unit/nfvo/test_nfvo_plugin.py @@ -29,8 +29,10 @@ from tacker.db.nfvo import ns_db from tacker.db.nfvo import vnffg_db from tacker.extensions import nfvo from tacker.manager import TackerManager +from tacker.nfvo.drivers.vim import openstack_driver from tacker.nfvo import nfvo_plugin from tacker.plugins.common import constants +from tacker.tests import constants as test_constants from tacker.tests.unit.db import base as db_base from tacker.tests.unit.db import utils from tacker.vnfm import vim_client @@ -217,15 +219,7 @@ class TestNfvoPlugin(db_base.SqlTestCase): super(TestNfvoPlugin, self).setUp() self.addCleanup(mock.patch.stopall) self.context = context.get_admin_context() - self._mock_driver_manager() - mock.patch('tacker.nfvo.nfvo_plugin.NfvoPlugin._get_vim_from_vnf', - side_effect=dummy_get_vim).start() self.nfvo_plugin = nfvo_plugin.NfvoPlugin() - mock.patch('tacker.db.common_services.common_services_db_plugin.' - 'CommonServicesPluginDb.create_event' - ).start() - self._cos_db_plugin =\ - common_services_db_plugin.CommonServicesPluginDb() def _mock_driver_manager(self): self._driver_manager = mock.Mock(wraps=FakeDriverManager()) @@ -286,6 +280,15 @@ class TestNfvoPlugin(db_base.SqlTestCase): def test_create_vim(self): vim_dict = utils.get_vim_obj() vim_type = 'openstack' + self._mock_driver_manager() + mock.patch('tacker.nfvo.nfvo_plugin.NfvoPlugin._get_vim_from_vnf', + side_effect=dummy_get_vim).start() + self.nfvo_plugin = nfvo_plugin.NfvoPlugin() + mock.patch('tacker.db.common_services.common_services_db_plugin.' + 'CommonServicesPluginDb.create_event' + ).start() + self._cos_db_plugin =\ + common_services_db_plugin.CommonServicesPluginDb() res = self.nfvo_plugin.create_vim(self.context, vim_dict) self._cos_db_plugin.create_event.assert_any_call( self.context, evt_type=constants.RES_EVT_CREATE, res_id=mock.ANY, @@ -308,6 +311,15 @@ class TestNfvoPlugin(db_base.SqlTestCase): vim_id = '6261579e-d6f3-49ad-8bc3-a9cb974778ff' self.context.tenant_id = 'ad7ebc56538745a08ef7c5e97f8bd437' vim_obj = self.nfvo_plugin._get_vim(self.context, vim_id) + self._mock_driver_manager() + mock.patch('tacker.nfvo.nfvo_plugin.NfvoPlugin._get_vim_from_vnf', + side_effect=dummy_get_vim).start() + self.nfvo_plugin = nfvo_plugin.NfvoPlugin() + mock.patch('tacker.db.common_services.common_services_db_plugin.' + 'CommonServicesPluginDb.create_event' + ).start() + self._cos_db_plugin =\ + common_services_db_plugin.CommonServicesPluginDb() self.nfvo_plugin.delete_vim(self.context, vim_id) self._driver_manager.invoke.assert_called_once_with( vim_type, 'deregister_vim', @@ -327,6 +339,15 @@ class TestNfvoPlugin(db_base.SqlTestCase): vim_project = vim_dict['vim']['vim_project'] self._insert_dummy_vim() self.context.tenant_id = 'ad7ebc56538745a08ef7c5e97f8bd437' + self._mock_driver_manager() + mock.patch('tacker.nfvo.nfvo_plugin.NfvoPlugin._get_vim_from_vnf', + side_effect=dummy_get_vim).start() + self.nfvo_plugin = nfvo_plugin.NfvoPlugin() + mock.patch('tacker.db.common_services.common_services_db_plugin.' + 'CommonServicesPluginDb.create_event' + ).start() + self._cos_db_plugin =\ + common_services_db_plugin.CommonServicesPluginDb() res = self.nfvo_plugin.update_vim(self.context, vim_dict['vim']['id'], vim_dict) vim_obj = self.nfvo_plugin._get_vim( @@ -359,6 +380,15 @@ class TestNfvoPlugin(db_base.SqlTestCase): self.context.tenant_id = 'ad7ebc56538745a08ef7c5e97f8bd437' old_vim_obj = self.nfvo_plugin._get_vim( self.context, vim_dict['vim']['id']) + self._mock_driver_manager() + mock.patch('tacker.nfvo.nfvo_plugin.NfvoPlugin._get_vim_from_vnf', + side_effect=dummy_get_vim).start() + self.nfvo_plugin = nfvo_plugin.NfvoPlugin() + mock.patch('tacker.db.common_services.common_services_db_plugin.' + 'CommonServicesPluginDb.create_event' + ).start() + self._cos_db_plugin =\ + common_services_db_plugin.CommonServicesPluginDb() res = self.nfvo_plugin.update_vim(self.context, vim_dict['vim']['id'], vim_dict) vim_obj = self.nfvo_plugin._get_vim( @@ -593,6 +623,15 @@ class TestNfvoPlugin(db_base.SqlTestCase): self.assertEqual('example_vnffgd', result['name']) def test_create_vnffg_abstract_types(self): + self._mock_driver_manager() + mock.patch('tacker.nfvo.nfvo_plugin.NfvoPlugin._get_vim_from_vnf', + side_effect=dummy_get_vim).start() + self.nfvo_plugin = nfvo_plugin.NfvoPlugin() + mock.patch('tacker.db.common_services.common_services_db_plugin.' + 'CommonServicesPluginDb.create_event' + ).start() + self._cos_db_plugin =\ + common_services_db_plugin.CommonServicesPluginDb() with patch.object(TackerManager, 'get_service_plugins') as \ mock_plugins: mock_plugins.return_value = {'VNFM': FakeVNFMPlugin()} @@ -617,6 +656,15 @@ class TestNfvoPlugin(db_base.SqlTestCase): @mock.patch('tacker.nfvo.nfvo_plugin.NfvoPlugin.create_vnffgd') def test_create_vnffg_abstract_types_inline(self, mock_create_vnffgd): + self._mock_driver_manager() + mock.patch('tacker.nfvo.nfvo_plugin.NfvoPlugin._get_vim_from_vnf', + side_effect=dummy_get_vim).start() + self.nfvo_plugin = nfvo_plugin.NfvoPlugin() + mock.patch('tacker.db.common_services.common_services_db_plugin.' + 'CommonServicesPluginDb.create_event' + ).start() + self._cos_db_plugin =\ + common_services_db_plugin.CommonServicesPluginDb() with patch.object(TackerManager, 'get_service_plugins') as \ mock_plugins: mock_plugins.return_value = {'VNFM': FakeVNFMPlugin()} @@ -644,6 +692,15 @@ class TestNfvoPlugin(db_base.SqlTestCase): correlation=mock.ANY) def test_create_vnffg_param_values(self): + self._mock_driver_manager() + mock.patch('tacker.nfvo.nfvo_plugin.NfvoPlugin._get_vim_from_vnf', + side_effect=dummy_get_vim).start() + self.nfvo_plugin = nfvo_plugin.NfvoPlugin() + mock.patch('tacker.db.common_services.common_services_db_plugin.' + 'CommonServicesPluginDb.create_event' + ).start() + self._cos_db_plugin =\ + common_services_db_plugin.CommonServicesPluginDb() with patch.object(TackerManager, 'get_service_plugins') as \ mock_plugins: mock_plugins.return_value = {'VNFM': FakeVNFMPlugin()} @@ -667,6 +724,15 @@ class TestNfvoPlugin(db_base.SqlTestCase): correlation=mock.ANY) def test_create_vnffg_no_classifier(self): + self._mock_driver_manager() + mock.patch('tacker.nfvo.nfvo_plugin.NfvoPlugin._get_vim_from_vnf', + side_effect=dummy_get_vim).start() + self.nfvo_plugin = nfvo_plugin.NfvoPlugin() + mock.patch('tacker.db.common_services.common_services_db_plugin.' + 'CommonServicesPluginDb.create_event' + ).start() + self._cos_db_plugin =\ + common_services_db_plugin.CommonServicesPluginDb() with patch.object(TackerManager, 'get_service_plugins') as \ mock_plugins: mock_plugins.return_value = {'VNFM': FakeVNFMPlugin()} @@ -710,6 +776,15 @@ class TestNfvoPlugin(db_base.SqlTestCase): self.context, vnffg_obj) def test_create_vnffg_vnf_mapping(self): + self._mock_driver_manager() + mock.patch('tacker.nfvo.nfvo_plugin.NfvoPlugin._get_vim_from_vnf', + side_effect=dummy_get_vim).start() + self.nfvo_plugin = nfvo_plugin.NfvoPlugin() + mock.patch('tacker.db.common_services.common_services_db_plugin.' + 'CommonServicesPluginDb.create_event' + ).start() + self._cos_db_plugin =\ + common_services_db_plugin.CommonServicesPluginDb() with patch.object(TackerManager, 'get_service_plugins') as \ mock_plugins: mock_plugins.return_value = {'VNFM': FakeVNFMPlugin()} @@ -814,6 +889,15 @@ class TestNfvoPlugin(db_base.SqlTestCase): self.context, vnffg['id'], updated_vnffg) def test_update_vnffg_vnf_mapping(self): + self._mock_driver_manager() + mock.patch('tacker.nfvo.nfvo_plugin.NfvoPlugin._get_vim_from_vnf', + side_effect=dummy_get_vim).start() + self.nfvo_plugin = nfvo_plugin.NfvoPlugin() + mock.patch('tacker.db.common_services.common_services_db_plugin.' + 'CommonServicesPluginDb.create_event' + ).start() + self._cos_db_plugin =\ + common_services_db_plugin.CommonServicesPluginDb() with patch.object(TackerManager, 'get_service_plugins') as \ mock_plugins: mock_plugins.return_value = {'VNFM': FakeVNFMPlugin()} @@ -849,6 +933,15 @@ class TestNfvoPlugin(db_base.SqlTestCase): auth_attr=mock.ANY) def test_update_vnffg_vnffgd_template(self): + self._mock_driver_manager() + mock.patch('tacker.nfvo.nfvo_plugin.NfvoPlugin._get_vim_from_vnf', + side_effect=dummy_get_vim).start() + self.nfvo_plugin = nfvo_plugin.NfvoPlugin() + mock.patch('tacker.db.common_services.common_services_db_plugin.' + 'CommonServicesPluginDb.create_event' + ).start() + self._cos_db_plugin =\ + common_services_db_plugin.CommonServicesPluginDb() with patch.object(TackerManager, 'get_service_plugins') as \ mock_plugins: mock_plugins.return_value = {'VNFM': FakeVNFMPlugin()} @@ -880,6 +973,15 @@ class TestNfvoPlugin(db_base.SqlTestCase): auth_attr=mock.ANY) def test_update_vnffg_legacy_vnffgd_template(self): + self._mock_driver_manager() + mock.patch('tacker.nfvo.nfvo_plugin.NfvoPlugin._get_vim_from_vnf', + side_effect=dummy_get_vim).start() + self.nfvo_plugin = nfvo_plugin.NfvoPlugin() + mock.patch('tacker.db.common_services.common_services_db_plugin.' + 'CommonServicesPluginDb.create_event' + ).start() + self._cos_db_plugin =\ + common_services_db_plugin.CommonServicesPluginDb() with patch.object(TackerManager, 'get_service_plugins') as \ mock_plugins: mock_plugins.return_value = {'VNFM': FakeVNFMPlugin()} @@ -895,6 +997,15 @@ class TestNfvoPlugin(db_base.SqlTestCase): def test_delete_vnffg(self): self._insert_dummy_vnffg_template() vnffg = self._insert_dummy_vnffg() + self._mock_driver_manager() + mock.patch('tacker.nfvo.nfvo_plugin.NfvoPlugin._get_vim_from_vnf', + side_effect=dummy_get_vim).start() + self.nfvo_plugin = nfvo_plugin.NfvoPlugin() + mock.patch('tacker.db.common_services.common_services_db_plugin.' + 'CommonServicesPluginDb.create_event' + ).start() + self._cos_db_plugin =\ + common_services_db_plugin.CommonServicesPluginDb() self.nfvo_plugin.delete_vnffg(self.context, vnffg['id']) self._driver_manager.invoke.assert_called_with(mock.ANY, mock.ANY, fc_id=mock.ANY, @@ -1048,9 +1159,14 @@ class TestNfvoPlugin(db_base.SqlTestCase): self.assertIn('updated_at', result) @mock.patch.object(nfvo_plugin.NfvoPlugin, 'get_auth_dict') - @mock.patch.object(vim_client.VimClient, 'get_vim') + @mock.patch.object(vim_client.VimClient, 'get_vim', + return_value={"vim_type": "openstack"}) @mock.patch.object(nfvo_plugin.NfvoPlugin, '_get_by_name') - def test_create_ns(self, mock_get_by_name, mock_get_vimi, mock_auth_dict): + @mock.patch.object(openstack_driver.OpenStack_Driver, 'get_mistral_client') + @mock.patch.object(uuidutils, 'generate_uuid', + return_value=test_constants.UUID) + def test_create_ns(self, mock_uuid, mock_mistral_client, + mock_get_by_name, mock_get_vimi, mock_auth_dict): self._insert_dummy_ns_template() self._insert_dummy_vim() mock_auth_dict.return_value = { @@ -1059,6 +1175,63 @@ class TestNfvoPlugin(db_base.SqlTestCase): 'project_domain_name': 'dummy_domain', 'project_name': 'dummy_project' } + + sample_yaml = 'std.create_ns' + test_constants.UUID + ':\n '\ + 'input:\n - ns\n output:\n mgmt_ip_address_VNF1: '\ + '<% $.mgmt_ip_address_VNF1 %>\n mgmt_ip_address_VNF2: '\ + '<% $.mgmt_ip_address_VNF2 %>\n status_VNF1: '\ + '<% $.status_VNF1 %>\n status_VNF2: '\ + '<% $.status_VNF2 %>\n vim_id_VNF1: <% $.vim_id_VNF1 %>\n'\ + ' vim_id_VNF2: <% $.vim_id_VNF2 %>\n vnf_id_VNF1: '\ + '<% $.vnf_id_VNF1 %>\n vnf_id_VNF2: <% $.vnf_id_VNF2 %>\n '\ + 'tasks:\n create_ns_VNF1:\n action: tacker.create_vnf '\ + 'body=<% $.ns.VNF1 %>\n input:\n body: '\ + '<% $.ns.VNF1 %>\n on-success:\n '\ + '- wait_vnf_active_VNF1\n publish:\n '\ + 'mgmt_ip_address_VNF1: <% task(create_ns_VNF1).result.'\ + 'vnf.mgmt_ip_address %>\n status_VNF1: <% '\ + 'task(create_ns_VNF1).result.vnf.status %>\n'\ + ' vim_id_VNF1: <% task(create_ns_VNF1).'\ + 'result.vnf.vim_id %>\n vnf_id_VNF1: <% '\ + 'task(create_ns_VNF1).result.vnf.id %>\n'\ + ' create_ns_VNF2:\n action: tacker.create_vnf '\ + 'body=<% $.ns.VNF2 %>\n input:\n '\ + 'body: <% $.ns.VNF2 %>\n on-success:\n'\ + ' - wait_vnf_active_VNF2\n publish:\n '\ + 'mgmt_ip_address_VNF2: <% task(create_ns_VNF2).result.vnf.'\ + 'mgmt_ip_address %>\n status_VNF2: <% task(create_ns_VNF2)'\ + '.result.vnf.status %>\n vim_id_VNF2: <% '\ + 'task(create_ns_VNF2).result.vnf.vim_id %>\n'\ + ' vnf_id_VNF2: <% task(create_ns_VNF2).result.vnf.id '\ + '%>\n delete_vnf_VNF1:\n action: tacker.delete_vnf vnf'\ + '=<% $.vnf_id_VNF1%>\n input:\n body:\n '\ + 'vnf:\n attributes:\n force: false\n'\ + ' delete_vnf_VNF2:\n action: tacker.delete_vnf'\ + ' vnf=<% $.vnf_id_VNF2%>\n input:\n body:\n'\ + ' vnf:\n attributes:\n '\ + 'force: false\n wait_vnf_active_VNF1:\n action:'\ + ' tacker.show_vnf vnf=<% $.vnf_id_VNF1 %>\n on-success:\n'\ + ' - delete_vnf_VNF1: <% $.status_VNF1="ERROR" %>\n '\ + 'publish:\n mgmt_ip_address_VNF1: \' <% '\ + 'task(wait_vnf_active_VNF1).result.vnf.mgmt_ip_address\n'\ + ' %>\'\n status_VNF1: <% '\ + 'task(wait_vnf_active_VNF1).result.vnf.status %>\n '\ + 'retry:\n break-on: <% $.status_VNF1 = "ERROR"'\ + ' %>\n continue-on: <% $.status_VNF1 = "PENDING_CREATE" '\ + '%>\n count: 10\n delay: 10\n '\ + 'wait_vnf_active_VNF2:\n action: tacker.show_vnf vnf=<% '\ + '$.vnf_id_VNF2 %>\n on-success:\n '\ + '- delete_vnf_VNF2: <% $.status_VNF2="ERROR" %>\n '\ + 'publish:\n mgmt_ip_address_VNF2: \' <% '\ + 'task(wait_vnf_active_VNF2).result.vnf.mgmt_ip_address\n'\ + ' %>\'\n status_VNF2: '\ + '<% task(wait_vnf_active_VNF2).result.vnf.status %>\n'\ + ' retry:\n break-on: <% $.status_VNF2 = '\ + '"ERROR" %>\n continue-on: '\ + '<% $.status_VNF2 = "PENDING_CREATE" %>\n '\ + 'count: 10\n '\ + 'delay: 10\n type: direct\nversion: \'2.0\'\n' + with patch.object(TackerManager, 'get_service_plugins') as \ mock_plugins: mock_plugins.return_value = {'VNFM': FakeVNFMPlugin()} @@ -1072,11 +1245,16 @@ class TestNfvoPlugin(db_base.SqlTestCase): self.assertEqual(ns_obj['ns']['name'], result['name']) self.assertIn('status', result) self.assertIn('tenant_id', result) + mock_mistral_client().workflows.create.\ + assert_called_with(sample_yaml) @mock.patch.object(nfvo_plugin.NfvoPlugin, 'get_auth_dict') - @mock.patch.object(vim_client.VimClient, 'get_vim') + @mock.patch.object(vim_client.VimClient, 'get_vim', + return_value={"vim_type": "openstack"}) @mock.patch.object(nfvo_plugin.NfvoPlugin, '_get_by_name') - def test_create_ns_empty_description(self, mock_get_by_name, + @mock.patch.object(openstack_driver.OpenStack_Driver, 'get_mistral_client') + def test_create_ns_empty_description(self, mock_mistral_client, + mock_get_by_name, mock_get_vimi, mock_auth_dict): self._insert_dummy_ns_template() self._insert_dummy_vim() @@ -1100,10 +1278,12 @@ class TestNfvoPlugin(db_base.SqlTestCase): @mock.patch('tacker.nfvo.nfvo_plugin.NfvoPlugin.create_nsd') @mock.patch.object(nfvo_plugin.NfvoPlugin, 'get_auth_dict') - @mock.patch.object(vim_client.VimClient, 'get_vim') + @mock.patch.object(vim_client.VimClient, 'get_vim', + return_value={"vim_type": "openstack"}) @mock.patch.object(nfvo_plugin.NfvoPlugin, '_get_by_name') - def test_create_ns_inline(self, mock_get_by_name, mock_get_vimi, - mock_auth_dict, mock_create_nsd): + @mock.patch.object(openstack_driver.OpenStack_Driver, 'get_mistral_client') + def test_create_ns_inline(self, mock_mistral_client, mock_get_by_name, + mock_get_vimi, mock_auth_dict, mock_create_nsd): self._insert_dummy_ns_template_inline() self._insert_dummy_vim() mock_auth_dict.return_value = { @@ -1131,10 +1311,15 @@ class TestNfvoPlugin(db_base.SqlTestCase): mock_create_nsd.assert_called_once_with(mock.ANY, mock.ANY) @mock.patch.object(nfvo_plugin.NfvoPlugin, 'get_auth_dict') - @mock.patch.object(vim_client.VimClient, 'get_vim') + @mock.patch.object(vim_client.VimClient, 'get_vim', + return_value={"vim_type": "openstack"}) @mock.patch.object(nfvo_plugin.NfvoPlugin, '_get_by_name') + @mock.patch('tacker.common.driver_manager.DriverManager.invoke', + side_effect=nfvo.NoTasksException(action='create', + resource='ns')) def test_create_ns_workflow_no_task_exception( - self, mock_get_by_name, mock_get_vimi, mock_auth_dict): + self, mock_mistral_client, mock_get_by_name, + mock_get_vimi, mock_auth_dict): self._insert_dummy_ns_template() self._insert_dummy_vim() mock_auth_dict.return_value = {