From: David Garcia Date: Thu, 29 Jul 2021 08:28:15 +0000 (+0200) Subject: Avoid adding a charm to the package more than once X-Git-Tag: release-v11.0-start~6 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=8a29667fc3e9222e6ee2288c69d7a450d6bc014a;p=osm%2Fosmclient.git Avoid adding a charm to the package more than once Fix bug 1610 Change-Id: I45ef328cefeff959b0b2d3bcacb75871f780b39e Signed-off-by: David Garcia --- diff --git a/osmclient/common/package_tool.py b/osmclient/common/package_tool.py index 3dedccd..5b56265 100644 --- a/osmclient/common/package_tool.py +++ b/osmclient/common/package_tool.py @@ -495,25 +495,25 @@ class PackageTool(object): :return: Files and Folders not found. In case of override, it will return all file list """ self._logger.debug("") - listCharms = [] + charms_set = set() descriptor_file = False descriptors_paths = [f for f in glob.glob(package_folder + "/*.yaml")] for file in descriptors_paths: if file.endswith("nfd.yaml"): descriptor_file = True - listCharms = self.charms_search(file, "vnf") + charms_set = self.charms_search(file, "vnf") if file.endswith("nsd.yaml"): descriptor_file = True - listCharms = self.charms_search(file, "ns") - print("List of charms in the descriptor: {}".format(listCharms)) + charms_set = self.charms_search(file, "ns") + print("List of charms in the descriptor: {}".format(charms_set)) if not descriptor_file: raise ClientException( 'Descriptor filename is not correct in: {}. It should end with "nfd.yaml" or "nsd.yaml"'.format( package_folder ) ) - if listCharms and not skip_charm_build: - for charmName in listCharms: + if charms_set and not skip_charm_build: + for charmName in charms_set: if os.path.isdir( "{}/charms/layers/{}".format(package_folder, charmName) ): @@ -538,8 +538,8 @@ class PackageTool(object): charmName, package_folder, package_folder ) ) - self._logger.debug("Return list of charms: {}".format(listCharms)) - return listCharms + self._logger.debug("Return list of charms: {}".format(charms_set)) + return charms_set def discover_folder_structure(self, base_directory, name, override): """ @@ -732,6 +732,7 @@ class PackageTool(object): self._logger.debug( "descriptor_file: {}, desc_type: {}".format(descriptor_file, desc_type) ) + charms_set = set() with open("{}".format(descriptor_file)) as yaml_desc: descriptor_dict = yaml.safe_load(yaml_desc) # self._logger.debug("\n"+yaml.safe_dump(descriptor_dict, indent=4, default_flow_style=False)) @@ -749,7 +750,7 @@ class PackageTool(object): or "nsd-catalog" in descriptor_dict ) ): - charms_list = self._charms_search_on_osm_im_dict( + charms_set = self._charms_search_on_osm_im_dict( descriptor_dict, desc_type ) else: @@ -759,12 +760,12 @@ class PackageTool(object): get_charm_list = self._charms_search_on_vnfd_sol006_dict else: raise Exception("Bad descriptor type") - charms_list = get_charm_list(descriptor_dict) - return charms_list + charms_set = get_charm_list(descriptor_dict) + return charms_set def _charms_search_on_osm_im_dict(self, osm_im_dict, desc_type): self._logger.debug("") - charms_list = [] + charms_set = [] for k1, v1 in osm_im_dict.items(): for k2, v2 in v1.items(): for entry in v2: @@ -772,19 +773,19 @@ class PackageTool(object): vnf_config = entry["{}-configuration".format(desc_type)] for k3, v3 in vnf_config.items(): if "charm" in v3: - charms_list.append((v3["charm"])) + charms_set.add((v3["charm"])) if "vdu" in entry: vdus = entry["vdu"] for vdu in vdus: if "vdu-configuration" in vdu: for k4, v4 in vdu["vdu-configuration"].items(): if "charm" in v4: - charms_list.append((v4["charm"])) - return charms_list + charms_set.add((v4["charm"])) + return charms_set def _charms_search_on_vnfd_sol006_dict(self, sol006_dict): self._logger.debug("") - charms_list = [] + charms_set = set() dfs = sol006_dict.get("vnfd", {}).get("df", []) for df in dfs: day_1_2s = ( @@ -797,15 +798,15 @@ class PackageTool(object): exec_env_list = day_1_2.get("execution-environment-list", []) for exec_env in exec_env_list: if "juju" in exec_env and "charm" in exec_env["juju"]: - charms_list.append(exec_env["juju"]["charm"]) - return charms_list + charms_set.add(exec_env["juju"]["charm"]) + return charms_set def _charms_search_on_nsd_sol006_dict(self, sol006_dict): self._logger.debug("") - charms_list = [] + charms_set = set() nsd_list = sol006_dict.get("nsd", {}).get("nsd", []) for nsd in nsd_list: charm = nsd.get("ns-configuration", {}).get("juju", {}).get("charm") if charm: - charms_list.append(charm) - return charms_list + charms_set.add(charm) + return charms_set