feature: sol004 and sol007
Change-Id: Icca9da37cdb97e129e2cb239e1e317e327b266ad
Signed-off-by: bravof <fbravo@whitestack.com>
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
diff --git a/osm_nbi/admin_topics.py b/osm_nbi/admin_topics.py
index 51a6963..c2767c8 100644
--- a/osm_nbi/admin_topics.py
+++ b/osm_nbi/admin_topics.py
@@ -442,7 +442,6 @@
}
content["resources"] = {"compute": compute, "storage": storage, "network": network}
-
return "{}:0".format(content["_id"])
def delete(self, session, _id, dry_run=False, not_send_msg=None):
diff --git a/osm_nbi/descriptor_topics.py b/osm_nbi/descriptor_topics.py
index 8efde1e..deae786 100644
--- a/osm_nbi/descriptor_topics.py
+++ b/osm_nbi/descriptor_topics.py
@@ -16,7 +16,6 @@
import tarfile
import yaml
import json
-import importlib
import copy
# import logging
@@ -26,6 +25,7 @@
from time import time
from uuid import uuid4
from re import fullmatch
+from zipfile import ZipFile
from osm_nbi.validation import (
ValidationError,
pdu_new_schema,
@@ -232,12 +232,19 @@
content_type
and "application/gzip" in content_type
or "application/x-gzip" in content_type
- or "application/zip" in content_type
):
compressed = "gzip"
+ if (
+ content_type
+ and "application/zip" in content_type
+ ):
+ compressed = "zip"
filename = headers.get("Content-Filename")
- if not filename:
- filename = "package.tar.gz" if compressed else "package"
+ if not filename and compressed:
+ filename = "package.tar.gz" if compressed == "gzip" else "package.zip"
+ elif not filename:
+ filename = "package"
+
# TODO change to Content-Disposition filename https://tools.ietf.org/html/rfc6266
file_pkg = None
error_text = ""
@@ -357,6 +364,47 @@
(temp_folder, descriptor_file_name), "r"
) as descriptor_file:
content = descriptor_file.read()
+ elif compressed == "zip":
+ zipfile = ZipFile(file_pkg)
+ descriptor_file_name = None
+ for package_file in zipfile.infolist():
+ zipfilename = package_file.filename
+ file_path = zipfilename.split("/")
+ if (
+ not file_path[0] or ".." in zipfilename
+ ): # if start with "/" means absolute path
+ raise EngineException(
+ "Absolute path or '..' are not allowed for package descriptor zip"
+ )
+
+ if (
+ (
+ zipfilename.endswith(".yaml")
+ or zipfilename.endswith(".json")
+ or zipfilename.endswith(".yml")
+ ) and (
+ zipfilename.find("/") < 0
+ or zipfilename.find("Definitions") >= 0
+ )
+ ):
+ storage["pkg-dir"] = ""
+ if descriptor_file_name:
+ raise EngineException(
+ "Found more than one descriptor file at package descriptor zip"
+ )
+ descriptor_file_name = zipfilename
+ if not descriptor_file_name:
+ raise EngineException(
+ "Not found any descriptor file at package descriptor zip"
+ )
+ storage["descriptor"] = descriptor_file_name
+ storage["zipfile"] = filename
+ self.fs.file_extract(zipfile, temp_folder)
+
+ with self.fs.file_open(
+ (temp_folder, descriptor_file_name), "r"
+ ) as descriptor_file:
+ content = descriptor_file.read()
else:
content = file_pkg.read()
storage["descriptor"] = descriptor_file_name = filename
@@ -791,6 +839,8 @@
):
if not self._validate_package_folders(
storage_params, "charms"
+ ) and not self._validate_package_folders(
+ storage_params, "Scripts/charms"
):
raise EngineException(
"Charm defined in vnf[id={}] but not present in "
@@ -802,6 +852,8 @@
return
if not self._validate_package_folders(
storage_params, "cloud_init", vdu["cloud-init-file"]
+ ) and not self._validate_package_folders(
+ storage_params, "Scripts/cloud_init", vdu["cloud-init-file"]
):
raise EngineException(
"Cloud-init defined in vnf[id={}]:vdu[id={}] but not present in "
@@ -826,14 +878,35 @@
day_1_2_config.get("execution-environment-list", []),
lambda ee: "juju" in ee,
):
- if not self._validate_package_folders(storage_params, "charms"):
+ if not self._validate_package_folders(
+ storage_params, "charms"
+ ) and not self._validate_package_folders(
+ storage_params, "Scripts/charms"
+ ):
raise EngineException(
"Charm defined in vnf[id={}] but not present in "
"package".format(indata["id"])
)
def _validate_package_folders(self, storage_params, folder, file=None):
- if not storage_params or not storage_params.get("pkg-dir"):
+ if not storage_params:
+ return False
+ elif not storage_params.get("pkg-dir"):
+ if self.fs.file_exists("{}_".format(storage_params["folder"]), "dir"):
+ f = "{}_/{}".format(
+ storage_params["folder"], folder
+ )
+ else:
+ f = "{}/{}".format(
+ storage_params["folder"], folder
+ )
+ if file:
+ return self.fs.file_exists("{}/{}".format(f, file), "file")
+ else:
+ f = f+"/"
+ if self.fs.file_exists(f, "dir"):
+ if self.fs.dir_ls(f):
+ return True
return False
else:
if self.fs.file_exists("{}_".format(storage_params["folder"]), "dir"):
diff --git a/osm_nbi/html_out.py b/osm_nbi/html_out.py
index 2d5a929..89e2f67 100644
--- a/osm_nbi/html_out.py
+++ b/osm_nbi/html_out.py
@@ -196,8 +196,11 @@
if "Location" in response.headers:
body += '<a href="{}"> show </a>'.format(response.headers["Location"])
else:
- _id = request.path_info[request.path_info.rfind("/") + 1 :]
- body += '<a href="/osm/{}?METHOD=DELETE"> <img src="/osm/static/delete.png" height="25" width="25"> </a>'.format(
+ _id = request.path_info[request.path_info.rfind("/") + 1:]
+ body += (
+ '<a href="/osm/{}?METHOD=DELETE"> '
+ '<img src="/osm/static/delete.png" height="25" width="25"> </a>'
+ ).format(
request.path_info
)
if request.path_info.startswith(
diff --git a/osm_nbi/tests/run_test.py b/osm_nbi/tests/run_test.py
index f339354..079b129 100755
--- a/osm_nbi/tests/run_test.py
+++ b/osm_nbi/tests/run_test.py
@@ -371,7 +371,7 @@
location = r.headers.get("Location")
if location:
- _id = location[location.rfind("/") + 1 :]
+ _id = location[location.rfind("/") + 1:]
if _id:
self.last_id = str(_id)
if not pooling:
@@ -479,7 +479,10 @@
"Env OSMNBITEST_VIM_URL and OSMNBITEST_VIM_TENANT are needed for create a real VIM"
" to deploy on whit the --test-osm option"
)
- vim_data = "{{schema_version: '1.0', name: '{}', vim_type: {}, vim_url: '{}', vim_tenant_name: '{}', " "vim_user: {}, vim_password: {}".format(
+ vim_data = (
+ "{{schema_version: '1.0', name: '{}', vim_type: {}, vim_url: '{}',"
+ "vim_tenant_name: '{}', " "vim_user: {}, vim_password: {}"
+ ).format(
vim_name,
os.environ.get("OSMNBITEST_VIM_TYPE", "openstack"),
os.environ.get("OSMNBITEST_VIM_URL"),
@@ -3021,7 +3024,9 @@
"vnfd_2vdu_set_ip_mac.yaml",
)
self.nsd_filename = "scenario_2vdu_set_ip_mac.yaml"
- self.descriptor_url = "https://osm.etsi.org/gitweb/?p=osm/RO.git;a=blob_plain;f=test/RO_tests/v3_2vdu_set_ip_mac/"
+ self.descriptor_url = (
+ "https://osm.etsi.org/gitweb/?p=osm/RO.git;a=blob_plain;f=test/RO_tests/v3_2vdu_set_ip_mac/"
+ )
self.commands = {
"1": [
"ls -lrt",