bugfix: sol004 and sol007 accepting zip files when vnfpkg-create or nspkg-create... 22/11422/1 v11.0.0 v11.0.0rc2
authorbravof <fbravo@whitestack.com>
Tue, 23 Nov 2021 20:34:49 +0000 (17:34 -0300)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Fri, 26 Nov 2021 14:41:28 +0000 (15:41 +0100)
Change-Id: Ic0d6979979b92906c5c4156c93a9044f6ebe41b0
Signed-off-by: bravof <fbravo@whitestack.com>
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
osmclient/sol005/nsd.py
osmclient/sol005/vnfd.py

index 7c29252..5ccbe78 100644 (file)
@@ -152,6 +152,8 @@ class Nsd(object):
                 headers["Content-Type"] = "text/plain"
             elif mime_type in ["application/gzip", "application/x-gzip"]:
                 headers["Content-Type"] = "application/gzip"
+            elif mime_type in ["application/zip"]:
+                headers["Content-Type"] = "application/zip"
             else:
                 raise ClientException(
                     "Unexpected MIME type for file {}: MIME type {}".format(
index 39f4c59..0a2b772 100644 (file)
@@ -30,6 +30,7 @@ import os.path
 from urllib.parse import quote
 import tarfile
 from osm_im.validation import Validation as validation_im
+from zipfile import ZipFile
 
 
 class Vnfd(object):
@@ -168,6 +169,8 @@ class Vnfd(object):
                 headers["Content-Type"] = "text/plain"
             elif mime_type in ["application/gzip", "application/x-gzip"]:
                 headers["Content-Type"] = "application/gzip"
+            elif mime_type in ["application/zip"]:
+                headers["Content-Type"] = "application/zip"
             else:
                 raise ClientException(
                     "Unexpected MIME type for file {}: MIME type {}".format(
@@ -202,6 +205,38 @@ class Vnfd(object):
                     with tar_object.extractfile(descriptor_list[0]) as df:
                         descriptor_data = df.read()
                     tar_object.close()
+                elif mime_type in ["application/zip"]:
+                    package_zip = ZipFile(filename)
+                    package_files = package_zip.infolist()
+
+                    descriptors = []
+                    if (
+                        "Definitions" in package_files
+                        and "TOSCA-Metadata" in package_files
+                    ):
+                        descriptors = [
+                            definition
+                            for definition in package_files
+                            if "Definitions/" in definition
+                            and (
+                                definition.endswith(".yaml")
+                                or definition.endswith(".yml")
+                            )
+                        ]
+                    else:
+                        descriptors = [
+                            definition
+                            for definition in package_files
+                            if definition.endswith(".yaml")
+                            or definition.endswith(".yml")
+                        ]
+                    if len(descriptors) < 1:
+                        raise ClientException(
+                            "No descriptor found on this package, OSM was expecting at least 1"
+                        )
+                    descriptor_data = package_zip.open(descriptors[0])
+                    package_zip.close()
+
                 if not descriptor_data:
                     raise ClientException("Descriptor could not be read")
                 desc_type, vnfd = validation_im().yaml_validation(descriptor_data)