From: garciadeblas Date: Wed, 2 Dec 2020 22:37:18 +0000 (+0000) Subject: Fix VNF package generation for SOL006 and previous OSM packages when they contain... X-Git-Tag: release-v9.0-start~2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F71%2F10071%2F2;p=osm%2Fosmclient.git Fix VNF package generation for SOL006 and previous OSM packages when they contain charms Change-Id: I9df6508036967ee2c9f16b9247a1be3686070bed Signed-off-by: garciadeblas --- diff --git a/osmclient/common/package_tool.py b/osmclient/common/package_tool.py index 568880c..7229565 100644 --- a/osmclient/common/package_tool.py +++ b/osmclient/common/package_tool.py @@ -441,13 +441,17 @@ class PackageTool(object): return directory_name, package_name def charms_search(self, descriptor_file, desc_type): - self._logger.debug("") + self._logger.debug("descriptor_file: {}, desc_type: {}".format(descriptor_file, + desc_type)) with open("{}".format(descriptor_file)) as yaml_desc: descriptor_dict = yaml.safe_load(yaml_desc) - if "catalog" in descriptor_dict: # Match OSM-IM vnfd-catalog and nsd-catalog - charms_list = self._charms_search_on_sol006_dict(descriptor_dict, desc_type) - else: + #self._logger.debug("\n"+yaml.safe_dump(descriptor_dict, indent=4, default_flow_style=False)) + + if ( (desc_type=="vnf" and ("vnfd:vnfd-catalog" in descriptor_dict or "vnfd-catalog" in descriptor_dict)) or + (desc_type=="ns" and ( "nsd:nsd-catalog" in descriptor_dict or "nsd-catalog" in descriptor_dict)) ): charms_list = self._charms_search_on_osm_im_dict(descriptor_dict, desc_type) + else: + charms_list = self._charms_search_on_sol006_dict(descriptor_dict, desc_type) return charms_list diff --git a/osmclient/sol005/osmrepo.py b/osmclient/sol005/osmrepo.py index 3aa3720..aa2a5f0 100644 --- a/osmclient/sol005/osmrepo.py +++ b/osmclient/sol005/osmrepo.py @@ -187,10 +187,10 @@ class OSMRepo(Repo): hash_md5.update(chunk) return hash_md5.hexdigest() - def fields_building(self, descriptor_json, file, package_type): + def fields_building(self, descriptor_dict, file, package_type): """ From an artifact descriptor, obtain the fields required for indexing - :param descriptor_json: artifact description + :param descriptor_dict: artifact description :param file: artifact package :param package_type: type of artifact (vnf or ns) :return: fields @@ -200,20 +200,20 @@ class OSMRepo(Repo): base_path = '/{}/'.format(package_type) aux_dict = {} if package_type == "vnf": - if descriptor_json.get('vnfd-catalog', False): - aux_dict = descriptor_json.get('vnfd-catalog', {}).get('vnfd', [{}])[0] + if descriptor_dict.get('vnfd-catalog', False): + aux_dict = descriptor_dict.get('vnfd-catalog', {}).get('vnfd', [{}])[0] else: - aux_dict = descriptor_json.get('vnfd:vnfd-catalog', {}).get('vnfd', [{}])[0] + aux_dict = descriptor_dict.get('vnfd:vnfd-catalog', {}).get('vnfd', [{}])[0] images = [] for vdu in aux_dict.get('vdu', ()): images.append(vdu.get('image')) fields['images'] = images if package_type == "ns": - if descriptor_json.get('nsd-catalog', False): - aux_dict = descriptor_json.get('nsd-catalog', {}).get('nsd', [{}])[0] + if descriptor_dict.get('nsd-catalog', False): + aux_dict = descriptor_dict.get('nsd-catalog', {}).get('nsd', [{}])[0] else: - aux_dict = descriptor_json.get('nsd:nsd-catalog', {}).get('nsd', [{}])[0] + aux_dict = descriptor_dict.get('nsd:nsd-catalog', {}).get('nsd', [{}])[0] vnfs = [] @@ -269,16 +269,16 @@ class OSMRepo(Repo): with open(descriptor_file, 'r') as f: descriptor_data = f.read() validation = validation_im() - desc_type, descriptor_data = validation.yaml_validation(descriptor_data) - validation_im.pyangbind_validation(self, desc_type, descriptor_data) - if 'vnf' in list(descriptor_data.keys())[0]: + desc_type, descriptor_dict = validation.yaml_validation(descriptor_data) + validation_im.pyangbind_validation(self, desc_type, descriptor_dict) + if 'vnf' in list(descriptor_dict.keys())[0]: package_type = 'vnf' else: # raise ClientException("Not VNF package") package_type = 'ns' - self._logger.debug("Descriptor: {}".format(descriptor_data)) - fields = self.fields_building(descriptor_data, path, package_type) + self._logger.debug("Descriptor: {}".format(descriptor_dict)) + fields = self.fields_building(descriptor_dict, path, package_type) self._logger.debug("Descriptor sucessfully validated") return {"detail": "{}D successfully validated".format(package_type.upper()), "code": "OK"}, True, fields, package_type