diff options
author | fujinhua <fu.jinhua@zte.com.cn> | 2017-08-17 16:16:24 +0800 |
---|---|---|
committer | fujinhua <fu.jinhua@zte.com.cn> | 2017-08-17 16:16:24 +0800 |
commit | cde3ca13b46b82e1dd6f96646f289259e2dbca99 (patch) | |
tree | 5a107fe6f881b9f3bb429d8d9378a55883905fc5 | |
parent | 6fca9ad02978dd74df29db8bee011dbaf8cf97a2 (diff) |
Add test case of nf pkg delete
Change-Id: I0f59d8648cc8e87956044231404bcb3824332519
Issue-Id: VFC-104
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r-- | lcm/packages/sdc_nf_package.py | 7 | ||||
-rw-r--r-- | lcm/packages/tests/test_sdc_nf.py | 30 | ||||
-rw-r--r-- | lcm/packages/tests/test_sdc_ns.py | 9 | ||||
-rw-r--r-- | lcm/packages/views.py | 4 |
4 files changed, 35 insertions, 15 deletions
diff --git a/lcm/packages/sdc_nf_package.py b/lcm/packages/sdc_nf_package.py index 5ec066a3..fe257a93 100644 --- a/lcm/packages/sdc_nf_package.py +++ b/lcm/packages/sdc_nf_package.py @@ -171,17 +171,16 @@ class SdcNfPkgDeleteThread(threading.Thread): NfInstModel.objects.filter(package_id=self.csar_id).delete() else: if NfInstModel.objects.filter(package_id=self.csar_id): - raise NSLCMException("NfInst(%s) exists, cannot delete." % self.csar_id) + raise NSLCMException("NfInst by csar(%s) exists, cannot delete." % self.csar_id) JobUtil.add_job_status(self.job_id, 50, "Delete CSAR(%s) from Database." % self.csar_id) - VnfPackageFileModel.objects.filter(vnfpid=csar_id).delete() - NfPackageModel.objects.filter(nfpackageid=csar_id).delete() + NfPackageModel.objects.filter(nfpackageid=self.csar_id).delete() JobUtil.add_job_status(self.job_id, 80, "Delete local CSAR(%s) file." % self.csar_id) csar_save_path = os.path.join(CATALOG_ROOT_PATH, self.csar_id) - fileutil.delete_dirs(self.csar_save_path) + fileutil.delete_dirs(csar_save_path) JobUtil.add_job_status(self.job_id, 100, "Delete CSAR(%s) successfully." % self.csar_id) diff --git a/lcm/packages/tests/test_sdc_nf.py b/lcm/packages/tests/test_sdc_nf.py index 4181910e..151deeb9 100644 --- a/lcm/packages/tests/test_sdc_nf.py +++ b/lcm/packages/tests/test_sdc_nf.py @@ -254,7 +254,7 @@ class TestNfPackage(TestCase): "vimIds": ["1"] }, format='json') self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED) -""" + """ def test_nf_pkg_distribute_when_csar_already_exist(self): NfPackageModel(uuid="1", nfpackageid="1", vnfdid="vcpe_vfw_zte_1_0").save() SdcNfDistributeThread(csar_id="1", @@ -297,7 +297,33 @@ class TestNfPackage(TestCase): lab_vim_id="", job_id="4").run() self.assert_job_result("4", 100, "CSAR(1) distribute successfully.") -""" + """ + + ############################################################################################################### + + @mock.patch.object(SdcNfPkgDeleteThread, 'run') + def test_nf_pkg_delete_normal(self, mock_run): + resp = self.client.delete("/api/nslcm/v1/vnfpackage/1") + self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED) + """ + def test_nf_pkg_normal_delete(self): + NfPackageModel(uuid="2", nfpackageid="2", vnfdid="vcpe_vfw_zte_1_0").save() + SdcNfPkgDeleteThread(csar_id="2", job_id="2", force_delete=False).run() + self.assert_job_result("2", 100, "Delete CSAR(2) successfully.") + + def test_nf_pkg_force_delete(self): + NfPackageModel(uuid="1", nfpackageid="1", vnfdid="vcpe_vfw_zte_1_0").save() + NfInstModel(nfinstid="1", package_id="1").save() + SdcNfPkgDeleteThread(csar_id="1", job_id="2", force_delete=True).run() + self.assert_job_result("2", 100, "Delete CSAR(1) successfully.") + + def test_nf_pkg_delete_when_pkg_in_using(self): + NfPackageModel(uuid="3", nfpackageid="3", vnfdid="vcpe_vfw_zte_1_0").save() + NfInstModel(nfinstid="3", package_id="3").save() + SdcNfPkgDeleteThread(csar_id="3", job_id="2", force_delete=False).run() + self.assert_job_result("2", 255, "NfInst by csar(3) exists, cannot delete.") + """ + diff --git a/lcm/packages/tests/test_sdc_ns.py b/lcm/packages/tests/test_sdc_ns.py index d0cc6a95..f14c6f79 100644 --- a/lcm/packages/tests/test_sdc_ns.py +++ b/lcm/packages/tests/test_sdc_ns.py @@ -452,13 +452,6 @@ class TestSdcNsPackage(TestCase): 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() @@ -475,7 +468,7 @@ class TestSdcNsPackage(TestCase): self.assertEqual("success", resp.data["status"]) self.assertEqual("Delete CSAR(8) successfully.", resp.data["statusDescription"]) - def test_ns_pkg_when_in_using(self): + def test_ns_pkg_delete_when_pkg_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") diff --git a/lcm/packages/views.py b/lcm/packages/views.py index a5d91abf..d1c7ef87 100644 --- a/lcm/packages/views.py +++ b/lcm/packages/views.py @@ -95,7 +95,9 @@ def nf_rd_csar(request, *args, **kwargs): force_delete = csar_id.endswith("force") if force_delete: csar_id = csar_id[:-5] - ret = sdc_nf_package.nf_delete_csar(csar_id, force_delete) + job_id = str(uuid.uuid4()) + sdc_nf_package.SdcNfPkgDeleteThread(csar_id, job_id, force_delete).start() + ret = [0, {"jobId": job_id}] normal_status = status.HTTP_202_ACCEPTED logger.info("Leave %s, Return value is %s", fun_name(), str(ret)) if ret[0] != 0: |