From: bravof Date: Tue, 23 Nov 2021 20:34:49 +0000 (-0300) Subject: bugfix: sol004 and sol007 accepting zip files when vnfpkg-create or nspkg-create... X-Git-Tag: v11.0.0rc2^0 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=928173cd1d215feb3988f351b54788e79af8d4a5;p=osm%2Fosmclient.git bugfix: sol004 and sol007 accepting zip files when vnfpkg-create or nspkg-create are executed Change-Id: Ic0d6979979b92906c5c4156c93a9044f6ebe41b0 Signed-off-by: bravof Signed-off-by: garciadeblas --- diff --git a/osmclient/sol005/nsd.py b/osmclient/sol005/nsd.py index 7c29252..5ccbe78 100644 --- a/osmclient/sol005/nsd.py +++ b/osmclient/sol005/nsd.py @@ -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( diff --git a/osmclient/sol005/vnfd.py b/osmclient/sol005/vnfd.py index 39f4c59..0a2b772 100644 --- a/osmclient/sol005/vnfd.py +++ b/osmclient/sol005/vnfd.py @@ -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)