diff options
author | biancunkang <bian.cunkang@zte.com.cn> | 2018-08-28 19:29:21 +0800 |
---|---|---|
committer | biancunkang <bian.cunkang@zte.com.cn> | 2018-08-28 19:29:21 +0800 |
commit | 18380b1d587c0f6162468bb05689b7b52069db8d (patch) | |
tree | 28d7d5a68ac9a19ae524600be0cb0e938158c6f6 | |
parent | 9561f157bcc0876e38f2ecd6b0906e99317970d6 (diff) |
Deal with nfPackage
Add some onboardingState in upload
Change-Id: Ib3638a842dd912d5e1dbcbb06f5b5ccc3b952552
Issue-ID: VFC-1038
Signed-off-by: biancunkang <bian.cunkang@zte.com.cn>
-rw-r--r-- | catalog/packages/biz/vnf_package.py | 8 | ||||
-rw-r--r-- | catalog/packages/views/vnf_package_views.py | 6 |
2 files changed, 13 insertions, 1 deletions
diff --git a/catalog/packages/biz/vnf_package.py b/catalog/packages/biz/vnf_package.py index da5cc566..7f3511d8 100644 --- a/catalog/packages/biz/vnf_package.py +++ b/catalog/packages/biz/vnf_package.py @@ -89,6 +89,8 @@ def delete_vnf_pkg(vnf_pkg_id): def parse_vnfd_and_save(vnf_pkg_id, vnf_pkg_path): + vnf_pkg = VnfPackageModel.objects.filter(vnfPackageId=vnf_pkg_id) + vnf_pkg.update(onboardingState="PROCESSING") vnfd_json = toscaparser.parse_vnfd(vnf_pkg_path) vnfd = json.JSONDecoder().decode(vnfd_json) @@ -136,6 +138,7 @@ class VnfPkgUploadThread(threading.Thread): vnf_pkg = VnfPackageModel.objects.filter(vnfPackageId=self.vnf_pkg_id) if vnf_pkg[0].onboardingState != "CREATED": raise CatalogException("VNF package (%s) is not created" % self.vnf_pkg_id) + vnf_pkg.update(onboardingState="UPLOADING") uri = ignore_case_get(self.data, "addressInformation") upload_path = os.path.join(CATALOG_ROOT_PATH, self.vnf_pkg_id) if not os.path.exists(upload_path): @@ -194,3 +197,8 @@ def fetch_vnf_pkg(request, vnf_pkg_id): response['Content-Type'] = 'application/octet-stream' response['Content-Disposition'] = 'attachment; filename=%s' % file_name.encode('utf-8') return response + + +def handle_upload_failed(vnf_pkg_id): + vnf_pkg = VnfPackageModel.objects.filter(vnfPackageId=vnf_pkg_id) + vnf_pkg.update(onboardingState="CREATED") diff --git a/catalog/packages/views/vnf_package_views.py b/catalog/packages/views/vnf_package_views.py index 2bdd3eb8..26244dd9 100644 --- a/catalog/packages/views/vnf_package_views.py +++ b/catalog/packages/views/vnf_package_views.py @@ -27,7 +27,7 @@ from catalog.packages.serializers.create_vnf_pkg_info_req import CreateVnfPkgInf from catalog.packages.serializers.vnf_pkg_info import VnfPkgInfoSerializer from catalog.packages.serializers.vnf_pkg_infos import VnfPkgInfosSerializer from catalog.packages.biz.vnf_package import create_vnf_pkg, query_multiple, VnfPkgUploadThread, \ - query_single, delete_vnf_pkg, parse_vnfd_and_save, fetch_vnf_pkg + query_single, delete_vnf_pkg, parse_vnfd_and_save, fetch_vnf_pkg, handle_upload_failed from catalog.pub.database.models import VnfPackageModel logger = logging.getLogger(__name__) @@ -128,10 +128,12 @@ def upload_vnf_pkg_content(request, vnfPkgId): parse_vnfd_and_save(vnfPkgId, upload_file_name) return Response(None, status=status.HTTP_202_ACCEPTED) except CatalogException: + handle_upload_failed(vnfPkgId) logger.error(traceback.format_exc()) return Response(data={'error': 'Upload VNF package failed.'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) except Exception as e: + handle_upload_failed(vnfPkgId) logger.error(e.message) logger.error(traceback.format_exc()) return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) @@ -168,9 +170,11 @@ def upload_vnf_pkg_from_uri(request, vnfPkgId): VnfPkgUploadThread(req_serializer.data, vnfPkgId).start() return Response(None, status=status.HTTP_202_ACCEPTED) except CatalogException: + handle_upload_failed(vnfPkgId) logger.error(traceback.format_exc()) return Response(data={'error': 'Upload VNF package failed.'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) except Exception as e: + handle_upload_failed(vnfPkgId) logger.error(e.message) logger.error(traceback.format_exc()) return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) |