Bug 2189 fixing osm package-build command 82/12682/3
authorgomezchavez <guillermo.gomez.external@atos.net>
Fri, 11 Nov 2022 13:19:46 +0000 (14:19 +0100)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Fri, 25 Nov 2022 12:54:29 +0000 (13:54 +0100)
Change-Id: I91020fb6d0f1b858f438ec0e8994793c770fe507
Signed-off-by: gomezchavez <guillermo.gomez.external@atos.net>
osmclient/common/package_tool.py

index a2cbd87..2531f7a 100644 (file)
@@ -519,13 +519,28 @@ class PackageTool(object):
             ]
         else:
             descriptors_paths = [f for f in glob.glob(package_folder + "/*.yaml")]
-        for file in descriptors_paths:
-            if file.endswith("nfd.yaml"):
-                descriptor_file = True
-                charms_set = self.charms_search(file, "vnf")
-            if file.endswith("nsd.yaml"):
-                descriptor_file = True
-                charms_set = self.charms_search(file, "ns")
+        if len(descriptors_paths) == 1:
+            # The base folder usually has a single yaml file with the descriptor
+            descriptor_file = True
+            pkg_type = utils.get_key_val_from_descriptor(descriptors_paths[0])
+            if pkg_type is None:
+                raise ClientException("Cannot determine package type")
+            if pkg_type["type"] == "nsd":
+                charms_set = self.charms_search(descriptors_paths[0], "ns")
+            else:
+                charms_set = self.charms_search(descriptors_paths[0], "vnf")
+        elif len(descriptors_paths) > 1:
+            for file in descriptors_paths:
+                if file.endswith("nfd.yaml"):
+                    descriptor_file = True
+                    charms_set = self.charms_search(file, "vnf")
+                if file.endswith("nsd.yaml"):
+                    descriptor_file = True
+                    charms_set = self.charms_search(file, "ns")
+        else:
+            raise ClientException(
+                "Package folder does not contain valid descriptor files '*.yaml'"
+            )
         print("List of charms in the descriptor: {}".format(charms_set))
         if not descriptor_file:
             raise ClientException(