aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordyh <dengyuanhong@chinamobile.com>2019-10-30 15:15:56 +0800
committerdyh <dengyuanhong@chinamobile.com>2019-10-30 15:22:12 +0800
commit0b6a49e188b44602ca83a5802b6820b32d3e2a35 (patch)
treec7c6c9e67264e89b0e9aaaf8ca73d9da22bb69f0
parentfec58589e6c2493b83743ed35a26b3e76ac996a4 (diff)
Get original vendor package under the ONBOARDING_PACKAGE directory from SDC resource CSAR
Change-Id: I50b346f6f709140363fc86684b1142fb28344a72 Signed-off-by: dyh <dengyuanhong@chinamobile.com> Issue-ID: MODELING-265
-rw-r--r--catalog/packages/biz/sdc_vnf_package.py22
-rw-r--r--catalog/pub/utils/fileutil.py12
2 files changed, 30 insertions, 4 deletions
diff --git a/catalog/packages/biz/sdc_vnf_package.py b/catalog/packages/biz/sdc_vnf_package.py
index 571c3bb..e5be4a1 100644
--- a/catalog/packages/biz/sdc_vnf_package.py
+++ b/catalog/packages/biz/sdc_vnf_package.py
@@ -122,9 +122,25 @@ class NfDistributeThread(threading.Thread):
csar_name = "%s.csar" % artifact.get("name", self.csar_id)
local_file_name = sdc.download_artifacts(artifact["toscaModelURL"], local_path, csar_name)
if local_file_name.endswith(".csar") or local_file_name.endswith(".zip"):
- artifact_vnf_file = fileutil.unzip_file(local_file_name, local_path, "Artifacts/Deployment/OTHER/vnf.csar")
- if os.path.exists(artifact_vnf_file):
- local_file_name = artifact_vnf_file
+ fileutil.unzip_csar(local_file_name, local_path)
+ vendor_vnf_file = ""
+ # find original vendor ETSI package under the ONBOARDING_PACKAGE directory
+ onboarding_package_dir = os.path.join(local_path, "Artifacts/Deployment/ONBOARDED_PACKAGE")
+ if os.path.exists(onboarding_package_dir):
+ files = os.listdir(onboarding_package_dir)
+ for file_name in files:
+ a_file = os.path.join(onboarding_package_dir, file_name)
+ if os.path.isfile(a_file) & file_name.endswith(".csar"):
+ vendor_vnf_file = a_file
+ break
+
+ # find original vendor ETSI package under Artifacts/Deployment/OTHER directory
+ if vendor_vnf_file.isspace():
+ vendor_vnf_file = os.path.join(local_path, "Artifacts/Deployment/OTHER/vnf.csar")
+ if os.path.exists(vendor_vnf_file):
+ local_file_name = vendor_vnf_file
+ else:
+ local_file_name = vendor_vnf_file
vnfd_json = toscaparser.parse_vnfd(local_file_name)
vnfd = json.JSONDecoder().decode(vnfd_json)
diff --git a/catalog/pub/utils/fileutil.py b/catalog/pub/utils/fileutil.py
index 6ddfc72..9344f72 100644
--- a/catalog/pub/utils/fileutil.py
+++ b/catalog/pub/utils/fileutil.py
@@ -19,7 +19,6 @@ import traceback
import urllib
import zipfile
-
logger = logging.getLogger(__name__)
@@ -64,6 +63,17 @@ def unzip_file(zip_src, dst_dir, csar_path):
return ""
+def unzip_csar(zip_src, dst_dir):
+ if os.path.exists(zip_src):
+ fz = zipfile.ZipFile(zip_src, 'r')
+ for file in fz.namelist():
+ fz.extract(file, dst_dir)
+ return dst_dir
+ else:
+ logger.error("%s doesn't exist", zip_src)
+ return ""
+
+
def unzip_csar_to_tmp(zip_src):
dirpath = tempfile.mkdtemp()
zip_ref = zipfile.ZipFile(zip_src, 'r')