Remove duplication of getting HOT templates

Previously get_base_nest_hot_dict() was called by vnflcm_driver
and openstack infra_driver redundantly.

This patch remove calling get_base_nest_hot_dict() from
vnflcm_driver because HOT is openstack specific.
base_hot_dict parameter of infra_driver interface is removed
at the same time.
Note that vnf_package_path parameter is passed to infra_driver
always since it is used by both openstack and kubernetes.

Change-Id: I94fc914f58747ae75651480ec11b177140fa849a
changes/20/773820/2
Itsuro Oda 2 years ago
parent 0e16ab16fc
commit 9204d07e5c
  1. 48
      tacker/tests/unit/vnfm/infra_drivers/openstack/test_openstack_driver.py
  2. 12
      tacker/vnflcm/vnflcm_driver.py
  3. 10
      tacker/vnfm/infra_drivers/kubernetes/kubernetes_driver.py
  4. 9
      tacker/vnfm/infra_drivers/openstack/openstack.py

@ -166,7 +166,6 @@ class TestOpenStack(base.FixturedTestCase):
vnf = utils.get_dummy_vnf_etsi(instance_id=self.instance_uuid,
flavour='simple')
vnf['placement_attr'] = {'region_name': 'dummy_region'}
base_hot_dict_test = self._read_file()
vnf_package_path_test = os.path.abspath(
os.path.join(os.path.dirname(__file__),
"../../../../etc/samples/etsi/nfv",
@ -187,7 +186,6 @@ class TestOpenStack(base.FixturedTestCase):
self.openstack.create(self.plugin, self.context, vnf,
self.auth_attr, inst_req_info=inst_req_info_test,
vnf_package_path=vnf_package_path_test,
base_hot_dict=base_hot_dict_test,
grant_info=grant_info_test,
vnf_instance=vnf_instance)
@ -210,7 +208,6 @@ class TestOpenStack(base.FixturedTestCase):
vnf = utils.get_dummy_vnf_etsi(instance_id=self.instance_uuid,
flavour='simple')
vnf['placement_attr'] = {'region_name': 'dummy_region'}
base_hot_dict_test = self._read_file()
vnf_package_path_test = os.path.abspath(
os.path.join(os.path.dirname(__file__),
"../../../../etc/samples/etsi/nfv",
@ -295,7 +292,6 @@ class TestOpenStack(base.FixturedTestCase):
self.openstack.create(self.plugin, self.context, vnf,
self.auth_attr, inst_req_info=inst_req_info_test,
vnf_package_path=vnf_package_path_test,
base_hot_dict=base_hot_dict_test,
grant_info=grant_info_test,
vnf_instance=vnf_instance)
@ -303,16 +299,14 @@ class TestOpenStack(base.FixturedTestCase):
def test_create_heat_stack(self, mock_OpenstackClients_heat):
vnf = utils.get_dummy_vnf(instance_id=self.instance_uuid)
vnf['placement_attr'] = {'region_name': 'dummy_region'}
base_hot_dict = None
vnf_package_path = None
self.openstack.create(self.plugin, self.context, vnf,
self.auth_attr, base_hot_dict, vnf_package_path)
self.auth_attr, vnf_package_path)
@mock.patch('tacker.common.clients.OpenstackClients')
def test_create_userdata_none(self, mock_OpenstackClients_heat):
vnf = utils.get_dummy_vnf(instance_id=self.instance_uuid)
vnf['placement_attr'] = {'region_name': 'dummy_region'}
base_hot_dict_test = self._read_file()
vnf_package_path_test = os.path.abspath(
os.path.join(os.path.dirname(__file__),
"../../../../etc/samples/etsi/nfv",
@ -329,7 +323,7 @@ class TestOpenStack(base.FixturedTestCase):
self.assertRaises(vnfm.LCMUserDataFailed,
self.openstack.create,
self.plugin, self.context, vnf,
self.auth_attr, base_hot_dict_test,
self.auth_attr,
vnf_package_path_test,
inst_req_info=inst_req_info_test,
grant_info=grant_info_test)
@ -338,7 +332,6 @@ class TestOpenStack(base.FixturedTestCase):
def test_create_userdataclass_none(self, mock_OpenstackClients_heat):
vnf = utils.get_dummy_vnf(instance_id=self.instance_uuid)
vnf['placement_attr'] = {'region_name': 'dummy_region'}
base_hot_dict_test = self._read_file()
vnf_package_path_test = os.path.abspath(
os.path.join(os.path.dirname(__file__),
"../../../../etc/samples/etsi/nfv",
@ -355,7 +348,7 @@ class TestOpenStack(base.FixturedTestCase):
self.assertRaises(vnfm.LCMUserDataFailed,
self.openstack.create,
self.plugin, self.context, vnf,
self.auth_attr, base_hot_dict_test,
self.auth_attr,
vnf_package_path_test,
inst_req_info=inst_req_info_test,
grant_info=grant_info_test)
@ -367,7 +360,6 @@ class TestOpenStack(base.FixturedTestCase):
vnf = utils.get_dummy_vnf_etsi(instance_id=self.instance_uuid,
flavour='simple')
vnf['placement_attr'] = {'region_name': 'dummy_region'}
base_hot_dict_test = self._read_file()
vnf_package_path_test = os.path.abspath(
os.path.join(os.path.dirname(__file__),
"../../../../etc/samples/etsi/nfv",
@ -389,7 +381,7 @@ class TestOpenStack(base.FixturedTestCase):
self.assertRaises(vnfm.LCMUserDataFailed,
self.openstack.create,
self.plugin, self.context, vnf,
self.auth_attr, base_hot_dict_test,
self.auth_attr,
vnf_package_path_test,
inst_req_info=inst_req_info_test,
grant_info=grant_info_test,
@ -402,7 +394,6 @@ class TestOpenStack(base.FixturedTestCase):
vnf = utils.get_dummy_vnf_etsi(instance_id=self.instance_uuid,
flavour='simple')
vnf['placement_attr'] = {'region_name': 'dummy_region'}
base_hot_dict_test = self._read_file()
vnf_package_path_test = os.path.abspath(
os.path.join(os.path.dirname(__file__),
"../../../../etc/samples/etsi/nfv",
@ -424,7 +415,7 @@ class TestOpenStack(base.FixturedTestCase):
self.assertRaises(vnfm.LCMUserDataFailed,
self.openstack.create,
self.plugin, self.context, vnf,
self.auth_attr, base_hot_dict_test,
self.auth_attr,
vnf_package_path_test,
inst_req_info=inst_req_info_test,
grant_info=grant_info_test,
@ -437,7 +428,6 @@ class TestOpenStack(base.FixturedTestCase):
vnf = utils.get_dummy_vnf_etsi(instance_id=self.instance_uuid,
flavour='simple')
vnf['placement_attr'] = {'region_name': 'dummy_region'}
base_hot_dict_test = self._read_file()
vnf_package_path_test = os.path.abspath(
os.path.join(os.path.dirname(__file__),
"../../../../etc/samples/etsi/nfv",
@ -458,7 +448,7 @@ class TestOpenStack(base.FixturedTestCase):
self.assertRaises(vnfm.LCMUserDataFailed,
self.openstack.create,
self.plugin, self.context, vnf,
self.auth_attr, base_hot_dict_test,
self.auth_attr,
vnf_package_path_test,
inst_req_info=inst_req_info_test,
grant_info=grant_info_test,
@ -471,7 +461,6 @@ class TestOpenStack(base.FixturedTestCase):
vnf = utils.get_dummy_vnf_etsi(instance_id=self.instance_uuid,
flavour='simple')
vnf['placement_attr'] = {'region_name': 'dummy_region'}
base_hot_dict_test = self._read_file()
vnf_package_path_test = os.path.abspath(
os.path.join(os.path.dirname(__file__),
"../../../../etc/samples/etsi/nfv",
@ -492,7 +481,7 @@ class TestOpenStack(base.FixturedTestCase):
self.assertRaises(vnfm.LCMUserDataFailed,
self.openstack.create,
self.plugin, self.context, vnf,
self.auth_attr, base_hot_dict_test,
self.auth_attr,
vnf_package_path_test,
inst_req_info=inst_req_info_test,
grant_info=grant_info_test,
@ -505,7 +494,6 @@ class TestOpenStack(base.FixturedTestCase):
vnf = utils.get_dummy_vnf_etsi(instance_id=self.instance_uuid,
flavour='simple')
vnf['placement_attr'] = {'region_name': 'dummy_region'}
base_hot_dict_test = self._read_file()
vnf_package_path_test = os.path.abspath(
os.path.join(os.path.dirname(__file__),
"../../../../etc/samples/etsi/nfv",
@ -528,7 +516,6 @@ class TestOpenStack(base.FixturedTestCase):
self.plugin, self.context, vnf,
self.auth_attr, inst_req_info=inst_req_info_test,
vnf_package_path=vnf_package_path_test,
base_hot_dict=base_hot_dict_test,
grant_info=grant_info_test,
vnf_instance=vnf_instance)
@ -539,7 +526,6 @@ class TestOpenStack(base.FixturedTestCase):
vnf = utils.get_dummy_vnf_etsi(instance_id=self.instance_uuid,
flavour='simple')
vnf['placement_attr'] = {'region_name': 'dummy_region'}
base_hot_dict_test = self._read_file()
vnf_package_path_test = os.path.abspath(
os.path.join(os.path.dirname(__file__),
"../../../../etc/samples/etsi/nfv",
@ -564,7 +550,6 @@ class TestOpenStack(base.FixturedTestCase):
self.plugin, self.context, vnf,
self.auth_attr, inst_req_info=inst_req_info_test,
vnf_package_path=vnf_package_path_test,
base_hot_dict=base_hot_dict_test,
grant_info=grant_info_test,
vnf_instance=vnf_instance)
@ -580,7 +565,6 @@ class TestOpenStack(base.FixturedTestCase):
'instantiate_vnf_request_lcm_userdata.json')
inst_req_info_test.additional_params = test_json['additionalParams']
inst_req_info_test.flavour_id = test_json['flavourId']
base_hot_dict_test = None
vnf_package_path_test = None
grant_info_test = None
nested_hot_dict = {}
@ -590,7 +574,7 @@ class TestOpenStack(base.FixturedTestCase):
self.assertRaises(vnfm.LCMUserDataFailed,
self.openstack.create,
self.plugin, self.context, vnf,
self.auth_attr, base_hot_dict_test,
self.auth_attr,
vnf_package_path_test,
inst_req_info=inst_req_info_test,
grant_info=grant_info_test,
@ -603,7 +587,6 @@ class TestOpenStack(base.FixturedTestCase):
vnf = utils.get_dummy_vnf_etsi(instance_id=self.instance_uuid,
flavour='simple')
vnf['placement_attr'] = {'region_name': 'dummy_region'}
base_hot_dict_test = self._read_file()
vnf_package_path_test = os.path.abspath(
os.path.join(os.path.dirname(__file__),
"../../../../etc/samples/etsi/nfv",
@ -626,7 +609,7 @@ class TestOpenStack(base.FixturedTestCase):
self.assertRaises(vnfm.LCMUserDataFailed,
self.openstack.create,
self.plugin, self.context, vnf,
self.auth_attr, base_hot_dict_test,
self.auth_attr,
vnf_package_path_test,
inst_req_info=inst_req_info_test,
grant_info=grant_info_test,
@ -640,7 +623,6 @@ class TestOpenStack(base.FixturedTestCase):
vnf = utils.get_dummy_vnf_etsi(instance_id=self.instance_uuid,
flavour='simple')
vnf['placement_attr'] = {'region_name': 'dummy_region'}
base_hot_dict_test = self._read_file()
vnf_package_path_test = os.path.abspath(
os.path.join(os.path.dirname(__file__),
"../../../../etc/samples/etsi/nfv",
@ -663,7 +645,7 @@ class TestOpenStack(base.FixturedTestCase):
self.assertRaises(vnfm.LCMUserDataFailed,
self.openstack.create,
self.plugin, self.context, vnf,
self.auth_attr, base_hot_dict_test,
self.auth_attr,
vnf_package_path_test,
inst_req_info=inst_req_info_test,
grant_info=grant_info_test,
@ -676,7 +658,6 @@ class TestOpenStack(base.FixturedTestCase):
vnf = utils.get_dummy_vnf_etsi(instance_id=self.instance_uuid,
flavour='simple')
vnf['placement_attr'] = {'region_name': 'dummy_region'}
base_hot_dict_test = self._read_file()
vnf_package_path_test = os.path.abspath(
os.path.join(os.path.dirname(__file__),
"../../../../etc/samples/etsi/nfv",
@ -704,7 +685,6 @@ class TestOpenStack(base.FixturedTestCase):
self.plugin, self.context, vnf,
self.auth_attr, inst_req_info=inst_req_info_test,
vnf_package_path=vnf_package_path_test,
base_hot_dict=base_hot_dict_test,
grant_info=grant_info_test,
vnf_instance=vnf_instance)
@ -727,11 +707,10 @@ class TestOpenStack(base.FixturedTestCase):
inst_req_info_test.additional_params = test_json['additionalParams']
inst_req_info_test.ext_virtual_links = test_json['extVirtualLinks']
base_hot_dict = None
self.assertRaises(BaseException,
self.openstack.create,
self.plugin, self.context, vnf,
self.auth_attr, base_hot_dict,
self.auth_attr,
vnf_package_path=vnf_package_path_test,
inst_req_info=inst_req_info_test)
@ -746,11 +725,10 @@ class TestOpenStack(base.FixturedTestCase):
inst_req_info_test = type('', (), {})
inst_req_info_test.additional_params = None
inst_req_info_test.ext_virtual_links = None
base_hot_dict = None
self.assertRaises(BaseException,
self.openstack.create,
self.plugin, self.context, vnf,
self.auth_attr, base_hot_dict,
self.auth_attr,
vnf_package_path=vnf_package_path_test,
inst_req_info=inst_req_info_test)
@ -761,7 +739,6 @@ class TestOpenStack(base.FixturedTestCase):
vnf = utils.get_dummy_vnf_etsi(instance_id=self.instance_uuid,
flavour='simple')
vnf['placement_attr'] = {'region_name': 'dummy_region'}
base_hot_dict_test = self._read_file()
vnf_package_path_test = os.path.abspath(
os.path.join(os.path.dirname(__file__),
"../../../../etc/samples/etsi/nfv",
@ -786,7 +763,6 @@ class TestOpenStack(base.FixturedTestCase):
self.plugin, self.context, vnf,
self.auth_attr, inst_req_info=inst_req_info_test,
vnf_package_path=vnf_package_path_test,
base_hot_dict=base_hot_dict_test,
grant_info=grant_info_test,
vnf_instance=vnf_instance)

@ -302,15 +302,8 @@ class VnfLcmDriver(abstract_driver.VnfInstanceAbstractDriver):
vim_connection_info, instantiate_vnf_req):
vnfd_dict = vnflcm_utils._get_vnfd_dict(context, vnf_instance.vnfd_id,
instantiate_vnf_req.flavour_id)
base_hot_dict, nested_hot_dict = \
vnflcm_utils.get_base_nest_hot_dict(
context,
instantiate_vnf_req.flavour_id,
vnf_instance.vnfd_id)
vnf_package_path = None
if base_hot_dict is not None:
vnf_package_path = vnflcm_utils._get_vnf_package_path(
context, vnf_instance.vnfd_id)
vnf_package_path = vnflcm_utils._get_vnf_package_path(
context, vnf_instance.vnfd_id)
param_for_subs_map = vnflcm_utils._get_param_data(vnfd_dict,
instantiate_vnf_req)
@ -344,7 +337,6 @@ class VnfLcmDriver(abstract_driver.VnfInstanceAbstractDriver):
vnf_instance=vnf_instance,
vnfd_dict=final_vnf_dict, grant_response=vnf_resources,
vim_connection_info=vim_connection_info,
base_hot_dict=base_hot_dict,
vnf_package_path=vnf_package_path,
instantiate_vnf_req=instantiate_vnf_req)
except Exception as exp:

@ -34,7 +34,6 @@ from tacker import objects
from tacker.objects import vnf_package as vnf_package_obj
from tacker.objects import vnf_package_vnfd as vnfd_obj
from tacker.objects import vnf_resources as vnf_resource_obj
from tacker.vnflcm import utils as vnflcm_utils
from tacker.vnfm.infra_drivers import abstract_driver
from tacker.vnfm.infra_drivers.kubernetes.k8s import translate_outputs
from tacker.vnfm.infra_drivers.kubernetes import translate_template
@ -1223,10 +1222,6 @@ class Kubernetes(abstract_driver.VnfAbstractDriver,
bool(urlparse(target_k8s_file).netloc))):
file_content = urllib2.urlopen(target_k8s_file).read()
else:
if vnf_package_path is None:
vnf_package_path = \
vnflcm_utils._get_vnf_package_path(
context, vnf_instance.vnfd_id)
target_k8s_file_path = os.path.join(
vnf_package_path, target_k8s_file)
with open(target_k8s_file_path, 'r') as f:
@ -1257,7 +1252,7 @@ class Kubernetes(abstract_driver.VnfAbstractDriver,
def instantiate_vnf(self, context, vnf_instance, vnfd_dict,
vim_connection_info, instantiate_vnf_req,
grant_response, vnf_package_path, base_hot_dict,
grant_response, vnf_package_path,
plugin=None):
target_k8s_files = self._get_target_k8s_files(instantiate_vnf_req)
auth_attr = vim_connection_info.access_info
@ -1270,9 +1265,6 @@ class Kubernetes(abstract_driver.VnfAbstractDriver,
else:
auth_cred, file_descriptor = self._get_auth_creds(auth_attr)
k8s_client_dict = self.kubernetes.get_k8s_client_dict(auth_cred)
if vnf_package_path is None:
vnf_package_path = vnflcm_utils._get_vnf_package_path(
context, vnf_instance.vnfd_id)
transformer = translate_outputs.Transformer(
None, None, None, k8s_client_dict)
deployment_dict_list = list()

@ -131,7 +131,7 @@ class OpenStack(abstract_driver.VnfAbstractDriver,
@log.log
def create(self, plugin, context, vnf, auth_attr,
base_hot_dict=None, vnf_package_path=None,
vnf_package_path=None,
inst_req_info=None, grant_info=None,
vnf_instance=None):
LOG.debug('vnf %s', vnf)
@ -178,9 +178,6 @@ class OpenStack(abstract_driver.VnfAbstractDriver,
error_reason = _("failed to get Base HOT.")
raise vnfm.LCMUserDataFailed(reason=error_reason)
if base_hot_dict is None:
nested_hot_dict = {}
for name, hot in nested_hot_dict.items():
vnf['attributes'][name] = self._format_base_hot(hot)
@ -893,7 +890,7 @@ class OpenStack(abstract_driver.VnfAbstractDriver,
def instantiate_vnf(self, context, vnf_instance, vnfd_dict,
vim_connection_info, instantiate_vnf_req,
grant_response, plugin,
base_hot_dict=None, vnf_package_path=None):
vnf_package_path=None):
access_info = vim_connection_info.access_info
region_name = access_info.get('region')
placement_attr = vnfd_dict.get('placement_attr', {})
@ -901,7 +898,7 @@ class OpenStack(abstract_driver.VnfAbstractDriver,
vnfd_dict['placement_attr'] = placement_attr
instance_id = self.create(plugin, context, vnfd_dict,
access_info, base_hot_dict, vnf_package_path,
access_info, vnf_package_path,
inst_req_info=instantiate_vnf_req,
grant_info=grant_response,
vnf_instance=vnf_instance)

Loading…
Cancel
Save