From 45100df135425f2a314367210bca9056a5026d64 Mon Sep 17 00:00:00 2001 From: bravof Date: Tue, 23 Nov 2021 17:34:49 -0300 Subject: [PATCH] bugfix: sol004 and sol007 accepting zip files when vnfpkg-create or nspkg-create are executed Change-Id: Ic0d6979979b92906c5c4156c93a9044f6ebe41b0 Signed-off-by: bravof --- osmclient/sol005/nsd.py | 2 ++ osmclient/sol005/vnfd.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) 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) -- 2.25.1