Fix: flavour_description is not updated when instantiating

"flavour_description" and other properties for top-level VNFD
should be updated in instantiation. Otherwise, it may fail
with the default of "" (empty string).

This patch fixes the issue for updating the properties in
instantiation and adds a UT case for vnflcm.utils.

Change-Id: I7f2a36cd67eeea5497adc4d38efffd0230e90ec9
Closes-Bug: #1882869
This commit is contained in:
Yoshito Ito 2020-06-15 13:52:38 +09:00
parent 90f267ecea
commit 2274c780be
2 changed files with 30 additions and 6 deletions

View File

@ -47,3 +47,13 @@ class VnfLcmUtilsTestCase(base.TestCase):
extracted_path)
self.assertEqual(expected_image_path,
vnf_software_images['VDU1'].image_path)
def test_get_param_data_with_flavour_description(self):
vnfd_dict = fakes.get_vnfd_dict()
vnfd_dict.update({'imports': []})
instantiate_vnf_req = fakes.get_instantiate_vnf_request_obj()
param_value = vnflcm_utils._get_param_data(vnfd_dict,
instantiate_vnf_req)
expected_flavour_description = 'A simple flavor'
self.assertEqual(expected_flavour_description,
param_value['flavour_description'])

View File

@ -214,6 +214,16 @@ def _get_param_data(vnfd_dict, instantiate_vnf_req):
input_attributes = vnfd_dict.get('topology_template', {}).get('inputs')
if substitution_map is not None:
subs_map_node_type = substitution_map.get('node_type')
# Get properties in lower-level VNFD for top-level VNFD
node_templates = vnfd_dict.get('topology_template',
{}).get('node_templates', {})
for node in node_templates.values():
if node.get('type') == subs_map_node_type:
node_property = node.get('properties', {})
if node_property:
param_value.update(node_property)
# Import `_type.yaml` file and get default properties.
# If new value provided in additional_param, the property is updated.
import_paths = vnfd_dict.get('imports', {})
for imp_path in import_paths:
with open(imp_path) as file_obj:
@ -223,12 +233,16 @@ def _get_param_data(vnfd_dict, instantiate_vnf_req):
for key, value in imp_node_type.items():
if key == subs_map_node_type:
properties = value.get('properties')
for key, prop in properties.items():
if additional_param.get(key):
param_value.update({
key: additional_param.get(key)})
else:
param_value.update({key: prop.get('default')})
if properties:
for key, prop in properties.items():
if additional_param.get(key):
param_value.update({
key: additional_param.get(key)})
# If the parameter is provided in lower-level
# VNFD, use it. Otherwise use the default.
elif not param_value.get(key):
param_value.update(
{key: prop.get('default')})
for input_attr, value in input_attributes.items():
if additional_param.get(input_attr):