diff options
author | fujinhua <fu.jinhua@zte.com.cn> | 2017-08-16 17:29:47 +0800 |
---|---|---|
committer | fujinhua <fu.jinhua@zte.com.cn> | 2017-08-16 17:29:47 +0800 |
commit | 33db783e9b66d55ed580c234e7e4f1fa38b7a06a (patch) | |
tree | 03dfe03b1e2175a135df84fafeddbb6b91c96f68 | |
parent | 8a195817b8891861d821f1672cb8ee5d96a86de8 (diff) |
Add ns pkg delete logic
Change-Id: If8db3c031ac7d9e60a9cdd885b46cb0b614cbf0b
Issue-Id: VFC-100
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r-- | lcm/packages/sdc_ns_package.py | 1 | ||||
-rw-r--r-- | lcm/packages/tests/test_sdc_ns.py | 38 | ||||
-rw-r--r-- | lcm/packages/urls.py | 5 | ||||
-rw-r--r-- | lcm/packages/views.py | 38 |
4 files changed, 73 insertions, 9 deletions
diff --git a/lcm/packages/sdc_ns_package.py b/lcm/packages/sdc_ns_package.py index 872f7005..d8960dd9 100644 --- a/lcm/packages/sdc_ns_package.py +++ b/lcm/packages/sdc_ns_package.py @@ -135,6 +135,7 @@ class SdcNsPackage(object): if NSInstModel.objects.filter(nspackage_id=csar_id): raise NSLCMException("CSAR(%s) is in using, cannot be deleted." % csar_id) NSDModel.objects.filter(id=csar_id).delete() + return [0, "Delete CSAR(%s) successfully." % csar_id] def get_csars(self): diff --git a/lcm/packages/tests/test_sdc_ns.py b/lcm/packages/tests/test_sdc_ns.py index 0a2f415f..c932759d 100644 --- a/lcm/packages/tests/test_sdc_ns.py +++ b/lcm/packages/tests/test_sdc_ns.py @@ -451,4 +451,42 @@ class TestSdcNsPackage(TestCase): self.assertEqual("success", resp.data["status"]) self.assertEqual("CSAR(1) distributed successfully.", resp.data["statusDescription"]) + ############################################################################################################### + def test_ns_pkg_force_delete(self): + NfPackageModel(uuid="1", nfpackageid="1", vnfdid="vcpe_vfw_zte_1_0").save() + NSDModel(id="8", nsd_id="2").save() + resp = self.client.delete("/api/nslcm/v1/nspackage/8force") + self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED) + self.assertEqual("success", resp.data["status"]) + self.assertEqual("Delete CSAR(8) successfully.", resp.data["statusDescription"]) + + def test_ns_pkg_normal_delete(self): + NSDModel(id="8", nsd_id="2").save() + resp = self.client.delete("/api/nslcm/v1/nspackage/8") + self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED) + self.assertEqual("success", resp.data["status"]) + self.assertEqual("Delete CSAR(8) successfully.", resp.data["statusDescription"]) + + def test_ns_pkg_force_delete(self): + NSInstModel(id="1", nspackage_id="8").save() + NSDModel(id="8", nsd_id="2").save() + resp = self.client.delete("/api/nslcm/v1/nspackage/8force") + self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED) + self.assertEqual("success", resp.data["status"]) + self.assertEqual("Delete CSAR(8) successfully.", resp.data["statusDescription"]) + + def test_ns_pkg_when_in_using(self): + NSInstModel(id="1", nspackage_id="8").save() + NSDModel(id="8", nsd_id="2").save() + resp = self.client.delete("/api/nslcm/v1/nspackage/8") + self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED) + self.assertEqual("failed", resp.data["status"]) + self.assertEqual("CSAR(8) is in using, cannot be deleted.", resp.data["statusDescription"]) + + + + + + + diff --git a/lcm/packages/urls.py b/lcm/packages/urls.py index d4b139eb..bef33f39 100644 --- a/lcm/packages/urls.py +++ b/lcm/packages/urls.py @@ -17,8 +17,9 @@ from rest_framework.urlpatterns import format_suffix_patterns from lcm.packages import views urlpatterns = [ - url(r'^api/nslcm/v1/nspackage$', views.ns_distribute, name='ns_distribute'), - url(r'^api/nslcm/v1/vnfpackage$', views.nf_distribute, name='nf_distribute'), + url(r'^api/nslcm/v1/nspackage$', views.ns_distribute_get, name='ns_distribute_get'), + url(r'^api/nslcm/v1/nspackage/(?P<csarId>[0-9a-zA-Z\-\_]+)$', views.ns_rd_csar, name='ns_rd_csar'), + url(r'^api/nslcm/v1/vnfpackage$', views.nf_distribute_get, name='nf_distribute_get'), ######################################################################################### url(r'^api/nslcm/v0/nspackage/(?P<csarId>[0-9a-zA-Z\-\_]+)$', views.ns_access_csar, name='ns_access_csar'), url(r'^api/nslcm/v0/nspackage$', views.ns_on_boarding, name='ns_on_boarding'), diff --git a/lcm/packages/views.py b/lcm/packages/views.py index 28a9bf66..119eed44 100644 --- a/lcm/packages/views.py +++ b/lcm/packages/views.py @@ -25,21 +25,45 @@ from lcm.packages import ns_package, nf_package, sdc_ns_package, sdc_nf_package logger = logging.getLogger(__name__) -@api_view(http_method_names=['POST']) -def ns_distribute(request, *args, **kwargs): +@api_view(http_method_names=['POST', 'GET']) +def ns_distribute_get(request, *args, **kwargs): + logger.debug("Enter %s, method is %s", fun_name(), request.method) + if request.method == 'GET': + ret = sdc_ns_package.SdcNsPackage().get_csars() + logger.debug("csars=%s", ret) + return Response(data=ret, status=status.HTTP_200_OK) csar_id = ignore_case_get(request.data, "csarId") - logger.info("Enter %s, method is %s, csar_id is %s", fun_name(), request.method, csar_id) + logger.debug("csar_id is %s", csar_id) ret = sdc_ns_package.ns_on_distribute(csar_id) - logger.info("Leave %s, Return value is %s", fun_name(), ret) + logger.debug("Leave %s, Return value is %s", fun_name(), ret) if ret[0] != 0: return Response(data={'error': ret[1]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) return Response(data=ret[1], status=status.HTTP_202_ACCEPTED) +@api_view(http_method_names=['GET', 'DELETE']) +def ns_rd_csar(request, *args, **kwargs): + csar_id = ignore_case_get(kwargs, "csarId") + logger.info("Enter %s, method is %s, csar_id is %s", fun_name(), request.method, csar_id) + ret, normal_status = None, None + if request.method == 'GET': + ret = sdc_ns_package.ns_get_csar(csar_id) + normal_status = status.HTTP_200_OK + else: + force_delete = csar_id.endswith("force") + if force_delete: + csar_id = csar_id[:-5] + ret = sdc_ns_package.ns_delete_csar(csar_id, force_delete) + normal_status = status.HTTP_202_ACCEPTED + logger.info("Leave %s, Return value is %s", fun_name(), str(ret)) + if ret[0] != 0: + return Response(data={'error': ret[1]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + return Response(data=ret[1], status=normal_status) + #################################################################################################### @api_view(http_method_names=['POST', 'GET']) -def nf_distribute(request, *args, **kwargs): - logger.info("Enter %s%s, method is %s", fun_name(), request.data, request.method) +def nf_distribute_get(request, *args, **kwargs): + logger.debug("Enter %s%s, method is %s", fun_name(), request.data, request.method) if request.method == 'GET': ret = sdc_nf_package.SdcNfPackage().get_csars() logger.debug("csars=%s", ret) @@ -50,7 +74,7 @@ def nf_distribute(request, *args, **kwargs): job_id = str(uuid.uuid4()) sdc_nf_package.SdcNfDistributeThread(csar_id, vim_ids, lab_vim_id, job_id).start() ret = {"jobId": job_id} - logger.info("Leave %s, Return value is %s", fun_name(), ret) + logger.debug("Leave %s, Return value is %s", fun_name(), ret) return Response(data=ret, status=status.HTTP_202_ACCEPTED) |