Rename heat unit tests to openstack
Followup patch to [1] [1] https://review.openstack.org/#/c/367599/ Partial-bug: #1618724 Partially Implements: blueprint infra-driver-refactor Change-Id: I9453c0a981056ea87ede802628b1070e8eced2d2
This commit is contained in:
parent
2f98f410d9
commit
4556f940a1
|
@ -50,7 +50,7 @@ tacker.openstack.common.cache.backends =
|
|||
tacker.tacker.device.drivers =
|
||||
noop = tacker.vnfm.infra_drivers.noop:DeviceNoop
|
||||
nova = tacker.vnfm.infra_drivers.nova.nova:DeviceNova
|
||||
heat = tacker.vnfm.infra_drivers.vim_heat.vim_heat:VimHeat
|
||||
heat = tacker.vnfm.infra_drivers.heat.heat:DeviceHeat
|
||||
openstack = tacker.vnfm.infra_drivers.openstack.openstack:OpenStack
|
||||
tacker.tacker.mgmt.drivers =
|
||||
noop = tacker.vnfm.mgmt_drivers.noop:DeviceMgmtNoop
|
||||
|
@ -67,7 +67,7 @@ oslo.config.opts =
|
|||
tacker.vnfm.monitor = tacker.vnfm.monitor:config_opts
|
||||
tacker.vnfm.plugin = tacker.vm.plugin:config_opts
|
||||
tacker.vnfm.vim_client = tacker.vnfm.vim_client:config_opts
|
||||
tacker.vnfm.infra_drivers.heat.heat= tacker.vnfm.infra_drivers.vim_heat.vim_heat:config_opts
|
||||
tacker.vnfm.infra_drivers.heat.heat= tacker.vnfm.infra_drivers.heat.heat:config_opts
|
||||
tacker.vnfm.infra_drivers.openstack.openstack= tacker.vnfm.infra_drivers.openstack.openstack:config_opts
|
||||
tacker.vnfm.mgmt_drivers.openwrt.openwrt = tacker.vnfm.mgmt_drivers.openwrt.openwrt:config_opts
|
||||
tacker.vnfm.monitor_drivers.http_ping.http_ping = tacker.vnfm.monitor_drivers.http_ping.http_ping:config_opts
|
||||
|
|
|
@ -21,7 +21,7 @@ import yaml
|
|||
def _get_template(name):
|
||||
filename = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"../vm/infra_drivers/heat/data/", name)
|
||||
"../vm/infra_drivers/openstack/data/", name)
|
||||
f = codecs.open(filename, encoding='utf-8', errors='strict')
|
||||
return f.read()
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ from tacker import context
|
|||
from tacker.extensions import vnfm
|
||||
from tacker.tests.unit import base
|
||||
from tacker.tests.unit.db import utils
|
||||
from tacker.vnfm.infra_drivers.openstack import openstack
|
||||
from tacker.vnfm.infra_drivers.heat import heat
|
||||
|
||||
|
||||
class FakeHeatClient(mock.Mock):
|
||||
|
@ -42,12 +42,12 @@ class FakeHeatClient(mock.Mock):
|
|||
|
||||
def _get_template(name):
|
||||
filename = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)), "data/", name)
|
||||
os.path.dirname(os.path.abspath(__file__)), "../openstack/data/", name)
|
||||
f = codecs.open(filename, encoding='utf-8', errors='strict')
|
||||
return f.read()
|
||||
|
||||
|
||||
class TestOpenStack(base.TestCase):
|
||||
class TestDeviceHeat(base.TestCase):
|
||||
hot_template = _get_template('hot_tosca_openwrt.yaml')
|
||||
hot_param_template = _get_template('hot_openwrt_params.yaml')
|
||||
hot_ipparam_template = _get_template('hot_openwrt_ipparams.yaml')
|
||||
|
@ -55,9 +55,9 @@ class TestOpenStack(base.TestCase):
|
|||
config_data = _get_template('config_data.yaml')
|
||||
|
||||
def setUp(self):
|
||||
super(TestOpenStack, self).setUp()
|
||||
super(TestDeviceHeat, self).setUp()
|
||||
self.context = context.get_admin_context()
|
||||
self.infra_driver = openstack.OpenStack()
|
||||
self.heat_driver = heat.DeviceHeat()
|
||||
self._mock_heat_client()
|
||||
self.addCleanup(mock.patch.stopall)
|
||||
|
||||
|
@ -84,19 +84,19 @@ class TestOpenStack(base.TestCase):
|
|||
|
||||
def _get_expected_fields(self):
|
||||
return {'stack_name':
|
||||
'tacker.vnfm.infra_drivers.openstack.openstack_OpenStack'
|
||||
'-eb84260e-5ff7-4332-b032-50a14d6c1123', 'template':
|
||||
self.hot_template}
|
||||
'tacker.vnfm.infra_drivers.openstack.openstack_DeviceHeat'
|
||||
'-eb84260e-5ff7-4332-b032-50a14d6c1123',
|
||||
'template': self.hot_template}
|
||||
|
||||
def _get_expected_fields_user_data(self):
|
||||
return {'stack_name':
|
||||
'tacker.vnfm.infra_drivers.openstack.openstack_OpenStack'
|
||||
'tacker.vnfm.infra_drivers.openstack.openstack_DeviceHeat'
|
||||
'-18685f68-2b2a-4185-8566-74f54e548811',
|
||||
'template': self.hot_param_template}
|
||||
|
||||
def _get_expected_fields_ipaddr_data(self):
|
||||
return {'stack_name':
|
||||
'tacker.vnfm.infra_drivers.openstack.openstack_OpenStack'
|
||||
'tacker.vnfm.infra_drivers.openstack.openstack_DeviceHeat'
|
||||
'-d1337add-d5a1-4fd4-9447-bb9243c8460b',
|
||||
'template': self.hot_ipparam_template}
|
||||
|
||||
|
@ -170,7 +170,7 @@ class TestOpenStack(base.TestCase):
|
|||
vnf_obj = utils.get_dummy_device_obj()
|
||||
expected_result = '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'
|
||||
expected_fields = self._get_expected_fields()
|
||||
result = self.infra_driver.create(plugin=None, context=self.context,
|
||||
result = self.heat_driver.create(plugin=None, context=self.context,
|
||||
vnf=vnf_obj,
|
||||
auth_attr=utils.get_vim_auth_obj())
|
||||
self.heat_client.create.assert_called_once_with(expected_fields)
|
||||
|
@ -180,7 +180,7 @@ class TestOpenStack(base.TestCase):
|
|||
vnf_obj = utils.get_dummy_device_obj_userdata_attr()
|
||||
expected_result = '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'
|
||||
expected_fields = self._get_expected_fields_user_data()
|
||||
result = self.infra_driver.create(plugin=None, context=self.context,
|
||||
result = self.heat_driver.create(plugin=None, context=self.context,
|
||||
vnf=vnf_obj,
|
||||
auth_attr=utils.get_vim_auth_obj())
|
||||
self.heat_client.create.assert_called_once_with(expected_fields)
|
||||
|
@ -190,7 +190,7 @@ class TestOpenStack(base.TestCase):
|
|||
vnf_obj = utils.get_dummy_device_obj_ipaddr_attr()
|
||||
expected_result = '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'
|
||||
expected_fields = self._get_expected_fields_ipaddr_data()
|
||||
result = self.infra_driver.create(plugin=None, context=self.context,
|
||||
result = self.heat_driver.create(plugin=None, context=self.context,
|
||||
vnf=vnf_obj,
|
||||
auth_attr=utils.get_vim_auth_obj())
|
||||
self.heat_client.create.assert_called_once_with(expected_fields)
|
||||
|
@ -200,7 +200,7 @@ class TestOpenStack(base.TestCase):
|
|||
vnf_obj = utils.get_dummy_device_obj()
|
||||
expected_result = self._get_expected_vnf_wait_obj()
|
||||
vnf_id = '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'
|
||||
self.infra_driver.create_wait(plugin=None,
|
||||
self.heat_driver.create_wait(plugin=None,
|
||||
context=self.context,
|
||||
vnf_dict=vnf_obj,
|
||||
vnf_id=vnf_id,
|
||||
|
@ -209,7 +209,7 @@ class TestOpenStack(base.TestCase):
|
|||
|
||||
def test_delete(self):
|
||||
vnf_id = '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'
|
||||
self.infra_driver.delete(plugin=None, context=self.context,
|
||||
self.heat_driver.delete(plugin=None, context=self.context,
|
||||
vnf_id=vnf_id,
|
||||
auth_attr=utils.get_vim_auth_obj())
|
||||
self.heat_client.delete.assert_called_once_with(vnf_id)
|
||||
|
@ -219,7 +219,7 @@ class TestOpenStack(base.TestCase):
|
|||
vnf_config_obj = utils.get_dummy_device_update_config_attr()
|
||||
expected_vnf_update = self._get_expected_vnf_update_obj()
|
||||
vnf_id = '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'
|
||||
self.infra_driver.update(plugin=None, context=self.context,
|
||||
self.heat_driver.update(plugin=None, context=self.context,
|
||||
vnf_id=vnf_id, vnf_dict=vnf_obj,
|
||||
vnf=vnf_config_obj,
|
||||
auth_attr=utils.get_vim_auth_obj())
|
||||
|
@ -227,7 +227,7 @@ class TestOpenStack(base.TestCase):
|
|||
|
||||
def _get_expected_fields_tosca(self, template):
|
||||
return {'stack_name':
|
||||
'tacker.vnfm.infra_drivers.openstack.openstack_OpenStack'
|
||||
'tacker.vnfm.infra_drivers.openstack.openstack_DeviceHeat'
|
||||
'-eb84260e'
|
||||
'-5ff7-4332-b032-50a14d6c1123',
|
||||
'template': _get_template(template)}
|
||||
|
@ -293,7 +293,7 @@ class TestOpenStack(base.TestCase):
|
|||
hot_tpl_name,
|
||||
input_params,
|
||||
is_monitor)
|
||||
result = self.infra_driver.create(plugin=None, context=self.context,
|
||||
result = self.heat_driver.create(plugin=None, context=self.context,
|
||||
vnf=vnf,
|
||||
auth_attr=utils.get_vim_auth_obj())
|
||||
actual_fields = self.heat_client.create.call_args[0][0]
|
||||
|
@ -428,9 +428,8 @@ class TestOpenStack(base.TestCase):
|
|||
|
||||
def test_get_resource_info(self):
|
||||
vnf_obj = self._get_expected_active_vnf()
|
||||
print(vnf_obj)
|
||||
self.assertRaises(vnfm.InfraDriverUnreachable,
|
||||
self.infra_driver.get_resource_info,
|
||||
self.heat_driver.get_resource_info,
|
||||
plugin=None, context=self.context, vnf_info=vnf_obj,
|
||||
auth_attr=utils.get_vim_auth_obj(),
|
||||
region_name=None)
|
||||
|
|
|
@ -0,0 +1,441 @@
|
|||
# Copyright 2015 Brocade Communications System, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import codecs
|
||||
import json
|
||||
import mock
|
||||
import os
|
||||
import yaml
|
||||
|
||||
from tacker import context
|
||||
from tacker.extensions import vnfm
|
||||
from tacker.tests.unit import base
|
||||
from tacker.tests.unit.db import utils
|
||||
from tacker.vnfm.infra_drivers.openstack import openstack
|
||||
|
||||
|
||||
class FakeHeatClient(mock.Mock):
|
||||
|
||||
class Stack(mock.Mock):
|
||||
stack_status = 'CREATE_COMPLETE'
|
||||
outputs = [{u'output_value': u'192.168.120.31', u'description':
|
||||
u'management ip address', u'output_key': u'mgmt_ip-vdu1'}]
|
||||
|
||||
def create(self, *args, **kwargs):
|
||||
return {'stack': {'id': '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'}}
|
||||
|
||||
def get(self, id):
|
||||
return self.Stack()
|
||||
|
||||
|
||||
def _get_template(name):
|
||||
filename = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)), "data/", name)
|
||||
f = codecs.open(filename, encoding='utf-8', errors='strict')
|
||||
return f.read()
|
||||
|
||||
|
||||
class TestOpenStack(base.TestCase):
|
||||
hot_template = _get_template('hot_tosca_openwrt.yaml')
|
||||
hot_param_template = _get_template('hot_openwrt_params.yaml')
|
||||
hot_ipparam_template = _get_template('hot_openwrt_ipparams.yaml')
|
||||
vnfd_openwrt = _get_template('test_tosca_openwrt.yaml')
|
||||
config_data = _get_template('config_data.yaml')
|
||||
|
||||
def setUp(self):
|
||||
super(TestOpenStack, self).setUp()
|
||||
self.context = context.get_admin_context()
|
||||
self.infra_driver = openstack.OpenStack()
|
||||
self._mock_heat_client()
|
||||
self.addCleanup(mock.patch.stopall)
|
||||
|
||||
def _mock_heat_client(self):
|
||||
self.heat_client = mock.Mock(wraps=FakeHeatClient())
|
||||
fake_heat_client = mock.Mock()
|
||||
fake_heat_client.return_value = self.heat_client
|
||||
self._mock(
|
||||
'tacker.vnfm.infra_drivers.openstack.openstack.HeatClient',
|
||||
fake_heat_client)
|
||||
|
||||
def _mock(self, target, new=mock.DEFAULT):
|
||||
patcher = mock.patch(target, new)
|
||||
return patcher.start()
|
||||
|
||||
def _get_vnfd(self, template):
|
||||
return {'vnfd': {'attributes': {'vnfd': template}}}
|
||||
|
||||
def _get_expected_vnfd(self, template):
|
||||
return {'vnfd': {'attributes': {'vnfd': template},
|
||||
'description': 'OpenWRT with services',
|
||||
'mgmt_driver': 'openwrt',
|
||||
'name': 'OpenWRT'}}
|
||||
|
||||
def _get_expected_fields(self):
|
||||
return {'stack_name':
|
||||
'tacker.vnfm.infra_drivers.openstack.openstack_OpenStack'
|
||||
'-eb84260e-5ff7-4332-b032-50a14d6c1123', 'template':
|
||||
self.hot_template}
|
||||
|
||||
def _get_expected_fields_user_data(self):
|
||||
return {'stack_name':
|
||||
'tacker.vnfm.infra_drivers.openstack.openstack_OpenStack'
|
||||
'-18685f68-2b2a-4185-8566-74f54e548811',
|
||||
'template': self.hot_param_template}
|
||||
|
||||
def _get_expected_fields_ipaddr_data(self):
|
||||
return {'stack_name':
|
||||
'tacker.vnfm.infra_drivers.openstack.openstack_OpenStack'
|
||||
'-d1337add-d5a1-4fd4-9447-bb9243c8460b',
|
||||
'template': self.hot_ipparam_template}
|
||||
|
||||
def _get_expected_vnf_wait_obj(self, param_values=''):
|
||||
return {'status': 'PENDING_CREATE',
|
||||
'instance_id': None,
|
||||
'name': u'test_openwrt',
|
||||
'tenant_id': u'ad7ebc56538745a08ef7c5e97f8bd437',
|
||||
'vnfd_id': u'eb094833-995e-49f0-a047-dfb56aaf7c4e',
|
||||
'vnfd': {
|
||||
'service_types': [{
|
||||
'service_type': u'vnfd',
|
||||
'id': u'4a4c2d44-8a52-4895-9a75-9d1c76c3e738'}],
|
||||
'description': u'OpenWRT with services',
|
||||
'tenant_id': u'ad7ebc56538745a08ef7c5e97f8bd437',
|
||||
'mgmt_driver': u'openwrt',
|
||||
'attributes': {u'vnfd': self.vnfd_openwrt},
|
||||
'id': u'fb048660-dc1b-4f0f-bd89-b023666650ec',
|
||||
'name': u'openwrt_services'},
|
||||
'mgmt_url': '{"vdu1": "192.168.120.31"}',
|
||||
'service_context': [],
|
||||
'attributes': {u'param_values': param_values},
|
||||
'id': 'eb84260e-5ff7-4332-b032-50a14d6c1123',
|
||||
'description': u'OpenWRT with services'}
|
||||
|
||||
def _get_expected_vnf_update_obj(self):
|
||||
return {'status': 'PENDING_CREATE', 'instance_id': None, 'name':
|
||||
u'test_openwrt', 'tenant_id':
|
||||
u'ad7ebc56538745a08ef7c5e97f8bd437', 'vnfd_id':
|
||||
u'eb094833-995e-49f0-a047-dfb56aaf7c4e', 'vnfd': {
|
||||
'service_types': [{'service_type': u'vnfd', 'id':
|
||||
u'4a4c2d44-8a52-4895-9a75-9d1c76c3e738'}], 'description':
|
||||
u'OpenWRT with services', 'tenant_id':
|
||||
u'ad7ebc56538745a08ef7c5e97f8bd437', 'mgmt_driver': u'openwrt',
|
||||
'attributes': {u'vnfd': self.vnfd_openwrt},
|
||||
'id': u'fb048660-dc1b-4f0f-bd89-b023666650ec', 'name':
|
||||
u'openwrt_services'}, 'mgmt_url': None, 'service_context': [],
|
||||
'attributes': {u'config': 'vdus:\n vdu1:\n config: {firewall: '
|
||||
'"package firewall\\n\\nconfig defaults'
|
||||
'\\n option syn_flood\\\n '
|
||||
'\\ \'10\'\\n option input '
|
||||
'\'REJECT\'\\n option output '
|
||||
'\'REJECT\'\\n \\\n \\ '
|
||||
'option forward \'REJECT\'\\n"}\n'},
|
||||
'id': 'eb84260e-5ff7-4332-b032-50a14d6c1123', 'description':
|
||||
u'OpenWRT with services'}
|
||||
|
||||
def _get_expected_active_vnf(self):
|
||||
return {'status': 'ACTIVE',
|
||||
'instance_id': None,
|
||||
'name': u'test_openwrt',
|
||||
'tenant_id': u'ad7ebc56538745a08ef7c5e97f8bd437',
|
||||
'vnfd_id': u'eb094833-995e-49f0-a047-dfb56aaf7c4e',
|
||||
'vnfd': {
|
||||
'service_types': [{
|
||||
'service_type': u'vnfd',
|
||||
'id': u'4a4c2d44-8a52-4895-9a75-9d1c76c3e738'}],
|
||||
'description': u'OpenWRT with services',
|
||||
'tenant_id': u'ad7ebc56538745a08ef7c5e97f8bd437',
|
||||
'mgmt_driver': u'openwrt',
|
||||
'infra_driver': u'heat',
|
||||
'attributes': {u'vnfd': self.vnfd_openwrt},
|
||||
'id': u'fb048660-dc1b-4f0f-bd89-b023666650ec',
|
||||
'name': u'openwrt_services'},
|
||||
'mgmt_url': '{"vdu1": "192.168.120.31"}',
|
||||
'service_context': [],
|
||||
'id': 'eb84260e-5ff7-4332-b032-50a14d6c1123',
|
||||
'description': u'OpenWRT with services'}
|
||||
|
||||
def test_create(self):
|
||||
vnf_obj = utils.get_dummy_device_obj()
|
||||
expected_result = '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'
|
||||
expected_fields = self._get_expected_fields()
|
||||
result = self.infra_driver.create(plugin=None, context=self.context,
|
||||
vnf=vnf_obj,
|
||||
auth_attr=utils.get_vim_auth_obj())
|
||||
self.heat_client.create.assert_called_once_with(expected_fields)
|
||||
self.assertEqual(expected_result, result)
|
||||
|
||||
def test_create_user_data_param_attr(self):
|
||||
vnf_obj = utils.get_dummy_device_obj_userdata_attr()
|
||||
expected_result = '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'
|
||||
expected_fields = self._get_expected_fields_user_data()
|
||||
result = self.infra_driver.create(plugin=None, context=self.context,
|
||||
vnf=vnf_obj,
|
||||
auth_attr=utils.get_vim_auth_obj())
|
||||
self.heat_client.create.assert_called_once_with(expected_fields)
|
||||
self.assertEqual(expected_result, result)
|
||||
|
||||
def test_create_ip_addr_param_attr(self):
|
||||
vnf_obj = utils.get_dummy_device_obj_ipaddr_attr()
|
||||
expected_result = '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'
|
||||
expected_fields = self._get_expected_fields_ipaddr_data()
|
||||
result = self.infra_driver.create(plugin=None, context=self.context,
|
||||
vnf=vnf_obj,
|
||||
auth_attr=utils.get_vim_auth_obj())
|
||||
self.heat_client.create.assert_called_once_with(expected_fields)
|
||||
self.assertEqual(expected_result, result)
|
||||
|
||||
def test_create_wait(self):
|
||||
vnf_obj = utils.get_dummy_device_obj()
|
||||
expected_result = self._get_expected_vnf_wait_obj()
|
||||
vnf_id = '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'
|
||||
self.infra_driver.create_wait(plugin=None,
|
||||
context=self.context,
|
||||
vnf_dict=vnf_obj,
|
||||
vnf_id=vnf_id,
|
||||
auth_attr=utils.get_vim_auth_obj())
|
||||
self.assertEqual(expected_result, vnf_obj)
|
||||
|
||||
def test_delete(self):
|
||||
vnf_id = '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'
|
||||
self.infra_driver.delete(plugin=None, context=self.context,
|
||||
vnf_id=vnf_id,
|
||||
auth_attr=utils.get_vim_auth_obj())
|
||||
self.heat_client.delete.assert_called_once_with(vnf_id)
|
||||
|
||||
def test_update(self):
|
||||
vnf_obj = utils.get_dummy_device_obj_config_attr()
|
||||
vnf_config_obj = utils.get_dummy_device_update_config_attr()
|
||||
expected_vnf_update = self._get_expected_vnf_update_obj()
|
||||
vnf_id = '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'
|
||||
self.infra_driver.update(plugin=None, context=self.context,
|
||||
vnf_id=vnf_id, vnf_dict=vnf_obj,
|
||||
vnf=vnf_config_obj,
|
||||
auth_attr=utils.get_vim_auth_obj())
|
||||
self.assertEqual(expected_vnf_update, vnf_obj)
|
||||
|
||||
def _get_expected_fields_tosca(self, template):
|
||||
return {'stack_name':
|
||||
'tacker.vnfm.infra_drivers.openstack.openstack_OpenStack'
|
||||
'-eb84260e'
|
||||
'-5ff7-4332-b032-50a14d6c1123',
|
||||
'template': _get_template(template)}
|
||||
|
||||
def _get_expected_tosca_vnf(self,
|
||||
tosca_tpl_name,
|
||||
hot_tpl_name,
|
||||
param_values='',
|
||||
is_monitor=True):
|
||||
tosca_tpl = _get_template(tosca_tpl_name)
|
||||
exp_tmpl = self._get_expected_vnfd(tosca_tpl)
|
||||
tosca_hw_dict = yaml.safe_load(_get_template(hot_tpl_name))
|
||||
dvc = {
|
||||
'vnfd': exp_tmpl['vnfd'],
|
||||
'description': u'OpenWRT with services',
|
||||
'attributes': {
|
||||
'heat_template': tosca_hw_dict,
|
||||
'param_values': param_values
|
||||
},
|
||||
'id': 'eb84260e-5ff7-4332-b032-50a14d6c1123',
|
||||
'instance_id': None,
|
||||
'mgmt_url': None,
|
||||
'name': u'test_openwrt',
|
||||
'service_context': [],
|
||||
'status': 'PENDING_CREATE',
|
||||
'vnfd_id': u'eb094833-995e-49f0-a047-dfb56aaf7c4e',
|
||||
'tenant_id': u'ad7ebc56538745a08ef7c5e97f8bd437'
|
||||
}
|
||||
# Add montitoring attributes for those yaml, which are having it
|
||||
if is_monitor:
|
||||
dvc['attributes'].update(
|
||||
{'monitoring_policy': '{"vdus": {"VDU1": {"ping": {"name": '
|
||||
'"ping", "actions": {"failure": '
|
||||
'"respawn"}, "parameters": {"count": 3, '
|
||||
'"interval": 10}, "monitoring_params": '
|
||||
'{"count": 3, "interval": 10}}}}}'})
|
||||
|
||||
return dvc
|
||||
|
||||
def _get_dummy_tosca_vnf(self, template, input_params=''):
|
||||
|
||||
tosca_template = _get_template(template)
|
||||
vnf = utils.get_dummy_device_obj()
|
||||
dtemplate = self._get_expected_vnfd(tosca_template)
|
||||
dtemplate['service_types'] = [{'service_type': 'vnfd', 'id':
|
||||
'4a4c2d44-8a52-4895-9a75-9d1c76c3e738'}]
|
||||
dtemplate['tenant_id'] = 'ad7ebc56538745a08ef7c5e97f8bd437'
|
||||
vnf['vnfd'] = dtemplate['vnfd']
|
||||
vnf['attributes'] = {}
|
||||
vnf['attributes']['param_values'] = input_params
|
||||
return vnf
|
||||
|
||||
def _test_assert_equal_for_tosca_templates(self,
|
||||
tosca_tpl_name,
|
||||
hot_tpl_name,
|
||||
input_params='',
|
||||
files=None,
|
||||
is_monitor=True):
|
||||
vnf = self._get_dummy_tosca_vnf(tosca_tpl_name, input_params)
|
||||
expected_result = '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'
|
||||
expected_fields = self._get_expected_fields_tosca(hot_tpl_name)
|
||||
expected_vnf = self._get_expected_tosca_vnf(tosca_tpl_name,
|
||||
hot_tpl_name,
|
||||
input_params,
|
||||
is_monitor)
|
||||
result = self.infra_driver.create(plugin=None, context=self.context,
|
||||
vnf=vnf,
|
||||
auth_attr=utils.get_vim_auth_obj())
|
||||
actual_fields = self.heat_client.create.call_args[0][0]
|
||||
actual_fields["template"] = yaml.safe_load(actual_fields["template"])
|
||||
expected_fields["template"] = \
|
||||
yaml.safe_load(expected_fields["template"])
|
||||
|
||||
if files:
|
||||
for k, v in actual_fields["files"].items():
|
||||
actual_fields["files"][k] = yaml.safe_load(v)
|
||||
|
||||
expected_fields["files"] = {}
|
||||
for k, v in files.items():
|
||||
expected_fields["files"][k] = yaml.safe_load(_get_template(v))
|
||||
|
||||
self.assertEqual(expected_fields, actual_fields)
|
||||
vnf["attributes"]["heat_template"] = yaml.safe_load(
|
||||
vnf["attributes"]["heat_template"])
|
||||
self.heat_client.create.assert_called_once_with(expected_fields)
|
||||
self.assertEqual(expected_result, result)
|
||||
|
||||
if files:
|
||||
expected_fields["files"] = {}
|
||||
for k, v in files.items():
|
||||
expected_vnf["attributes"][k] = yaml.safe_load(
|
||||
_get_template(v))
|
||||
vnf["attributes"][k] = yaml.safe_load(
|
||||
vnf["attributes"][k])
|
||||
expected_vnf["attributes"]['scaling_group_names'] = {
|
||||
'SP1': 'G1'}
|
||||
vnf["attributes"]['scaling_group_names'] = json.loads(
|
||||
vnf["attributes"]['scaling_group_names']
|
||||
)
|
||||
self.assertEqual(expected_vnf, vnf)
|
||||
|
||||
def test_create_tosca(self):
|
||||
# self.skipTest("Not ready yet")
|
||||
self._test_assert_equal_for_tosca_templates('test_tosca_openwrt.yaml',
|
||||
'hot_tosca_openwrt.yaml')
|
||||
|
||||
def test_create_tosca_with_userdata(self):
|
||||
self._test_assert_equal_for_tosca_templates(
|
||||
'test_tosca_openwrt_userdata.yaml',
|
||||
'hot_tosca_openwrt_userdata.yaml')
|
||||
|
||||
def test_create_tosca_with_new_flavor(self):
|
||||
self._test_assert_equal_for_tosca_templates('test_tosca_flavor.yaml',
|
||||
'hot_flavor.yaml')
|
||||
|
||||
def test_create_tosca_with_new_flavor_with_defaults(self):
|
||||
self._test_assert_equal_for_tosca_templates(
|
||||
'test_tosca_flavor_defaults.yaml',
|
||||
'hot_flavor_defaults.yaml')
|
||||
|
||||
def test_create_tosca_with_flavor_and_capabilities(self):
|
||||
self._test_assert_equal_for_tosca_templates(
|
||||
'test_tosca_flavor_and_capabilities.yaml',
|
||||
'hot_flavor_and_capabilities.yaml')
|
||||
|
||||
def test_create_tosca_with_flavor_no_units(self):
|
||||
self._test_assert_equal_for_tosca_templates(
|
||||
'test_tosca_flavor_no_units.yaml',
|
||||
'hot_flavor_no_units.yaml')
|
||||
|
||||
def test_create_tosca_with_flavor_extra_specs_all_numa_count(self):
|
||||
self._test_assert_equal_for_tosca_templates(
|
||||
'tosca_flavor_all_numa_count.yaml',
|
||||
'hot_tosca_flavor_all_numa_count.yaml')
|
||||
|
||||
def test_create_tosca_with_flavor_extra_specs_all_numa_nodes(self):
|
||||
self._test_assert_equal_for_tosca_templates(
|
||||
'tosca_flavor_all_numa_nodes.yaml',
|
||||
'hot_tosca_flavor_all_numa_nodes.yaml')
|
||||
|
||||
def test_create_tosca_with_flavor_extra_specs_numa_node_count_trumps(self):
|
||||
self._test_assert_equal_for_tosca_templates(
|
||||
'tosca_flavor_numa_nodes_count.yaml',
|
||||
'hot_tosca_flavor_numa_nodes_count.yaml')
|
||||
|
||||
def test_create_tosca_with_flavor_extra_specs_huge_pages(self):
|
||||
self._test_assert_equal_for_tosca_templates(
|
||||
'tosca_flavor_huge_pages.yaml',
|
||||
'hot_tosca_flavor_huge_pages.yaml')
|
||||
|
||||
def test_create_tosca_with_flavor_extra_specs_cpu_allocations(self):
|
||||
self._test_assert_equal_for_tosca_templates(
|
||||
'tosca_flavor_cpu_allocations.yaml',
|
||||
'hot_tosca_flavor_cpu_allocations.yaml')
|
||||
|
||||
def test_create_tosca_with_flavor_extra_specs_numa_nodes(self):
|
||||
self._test_assert_equal_for_tosca_templates(
|
||||
'tosca_flavor_numa_nodes.yaml',
|
||||
'hot_tosca_flavor_numa_nodes.yaml')
|
||||
|
||||
def test_create_tosca_with_new_image(self):
|
||||
self._test_assert_equal_for_tosca_templates('test_tosca_image.yaml',
|
||||
'hot_tosca_image.yaml')
|
||||
|
||||
def test_create_tosca_sriov(self):
|
||||
self._test_assert_equal_for_tosca_templates(
|
||||
'tosca_sriov.yaml',
|
||||
'hot_tosca_sriov.yaml'
|
||||
)
|
||||
|
||||
def test_create_tosca_vnic_normal(self):
|
||||
self._test_assert_equal_for_tosca_templates(
|
||||
'tosca_vnic_port.yaml',
|
||||
'hot_tosca_vnic_normal.yaml'
|
||||
)
|
||||
|
||||
def test_create_tosca_mgmt_sriov_port(self):
|
||||
self._test_assert_equal_for_tosca_templates(
|
||||
'tosca_mgmt_sriov.yaml',
|
||||
'hot_tosca_mgmt_sriov.yaml'
|
||||
)
|
||||
|
||||
def test_tosca_params(self):
|
||||
input_params = 'image: cirros\nflavor: m1.large'
|
||||
self._test_assert_equal_for_tosca_templates(
|
||||
'tosca_generic_vnfd_params.yaml',
|
||||
'hot_tosca_generic_vnfd_params.yaml',
|
||||
input_params
|
||||
)
|
||||
|
||||
def test_create_tosca_scale(self):
|
||||
self._test_assert_equal_for_tosca_templates(
|
||||
'tosca_scale.yaml',
|
||||
'hot_scale_main.yaml',
|
||||
files={'scaling.yaml': 'hot_scale_custom.yaml'},
|
||||
is_monitor=False
|
||||
)
|
||||
|
||||
def test_get_resource_info(self):
|
||||
vnf_obj = self._get_expected_active_vnf()
|
||||
self.assertRaises(vnfm.InfraDriverUnreachable,
|
||||
self.infra_driver.get_resource_info,
|
||||
plugin=None, context=self.context, vnf_info=vnf_obj,
|
||||
auth_attr=utils.get_vim_auth_obj(),
|
||||
region_name=None)
|
||||
|
||||
def test_create_port_with_security_groups(self):
|
||||
self._test_assert_equal_for_tosca_templates(
|
||||
'test_tosca_security_groups.yaml',
|
||||
'hot_tosca_security_groups.yaml'
|
||||
)
|
|
@ -24,7 +24,7 @@ from translator.hot import tosca_translator
|
|||
def _get_template(name):
|
||||
filename = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"infra_drivers/heat/data/", name)
|
||||
"infra_drivers/openstack/data/", name)
|
||||
f = codecs.open(filename, encoding='utf-8', errors='strict')
|
||||
return f.read()
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ def config_opts():
|
|||
return [('tacker_heat', OPTS)]
|
||||
|
||||
|
||||
class VimHeat(openstack.OpenStack):
|
||||
class DeviceHeat(openstack.OpenStack):
|
||||
"""Heat driver of hosting vnf."""
|
||||
|
||||
@versionutils.deprecated(
|
||||
|
@ -54,7 +54,7 @@ class VimHeat(openstack.OpenStack):
|
|||
in_favor_of='infra_driver openstack',
|
||||
remove_in=+1)
|
||||
def __init__(self):
|
||||
super(VimHeat, self).__init__()
|
||||
super(DeviceHeat, self).__init__()
|
||||
self.STACK_RETRIES = cfg.CONF.tacker_heat.stack_retries
|
||||
self.STACK_RETRY_WAIT = cfg.CONF.tacker_heat.stack_retry_wait
|
||||
self.STACK_FLAVOR_EXTRA = cfg.CONF.tacker_heat.flavor_extra_specs
|
Loading…
Reference in New Issue