summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlaili <lai.li@zte.com.cn>2018-08-24 20:27:23 +0800
committerlaili <lai.li@zte.com.cn>2018-08-27 09:34:52 +0800
commit083f361ccba199c8df0aba4a9033b59fa4594bed (patch)
tree24fa4e9c2685b70929e15bb0c15195ccae2dc047
parent1208c9e6e845fc4f4de561db0c7f1d29af20d5a9 (diff)
Ns descriptor related stuffs.
Modify the biz of deletion. Add a test to deletion of single pnfd. Change-Id: If3b8aba27791a66842f6e8781bdda43db5ff8323 Issue-ID: VFC-1037 Signed-off-by: laili <lai.li@zte.com.cn>
-rw-r--r--catalog/packages/biz/ns_descriptor.py4
-rw-r--r--catalog/packages/biz/pnf_descriptor.py18
-rw-r--r--catalog/packages/tests/test_pnf_descriptor.py16
3 files changed, 32 insertions, 6 deletions
diff --git a/catalog/packages/biz/ns_descriptor.py b/catalog/packages/biz/ns_descriptor.py
index daf287e0..ff25c4b6 100644
--- a/catalog/packages/biz/ns_descriptor.py
+++ b/catalog/packages/biz/ns_descriptor.py
@@ -68,6 +68,7 @@ def query_single(nsd_info_id):
def delete_single(nsd_info_id):
ns_pkgs = NSPackageModel.objects.filter(nsPackageId=nsd_info_id)
if not ns_pkgs.exists():
+ logger.debug('NS descriptor (%s) is deleted.' % nsd_info_id)
return
if ns_pkgs[0].onboardingState == 'ONBOARDED':
raise CatalogException('The NS descriptor (%s) shall be non-ONBOARDED.' % nsd_info_id)
@@ -76,6 +77,9 @@ def delete_single(nsd_info_id):
if ns_pkgs[0].usageState != 'NOT_IN_USE':
raise CatalogException('The NS descriptor (%s) shall be NOT_IN_USE.' % nsd_info_id)
ns_pkgs.delete()
+ ns_pkg_path = os.path.join(CATALOG_ROOT_PATH, nsd_info_id)
+ fileutil.delete_dirs(ns_pkg_path)
+ logger.debug('NS descriptor (%s) is deleted.' % nsd_info_id)
def process(nsd_info_id, local_file_name):
diff --git a/catalog/packages/biz/pnf_descriptor.py b/catalog/packages/biz/pnf_descriptor.py
index fc112233..eb9a2a97 100644
--- a/catalog/packages/biz/pnf_descriptor.py
+++ b/catalog/packages/biz/pnf_descriptor.py
@@ -21,7 +21,7 @@ import uuid
from catalog.pub.config.config import CATALOG_ROOT_PATH
from catalog.pub.utils import fileutil
from catalog.pub.utils.values import ignore_case_get
-from catalog.pub.database.models import PnfPackageModel
+from catalog.pub.database.models import NSPackageModel, PnfPackageModel
from catalog.pub.exceptions import CatalogException
from catalog.pub.utils import toscaparser
@@ -119,13 +119,21 @@ def download(pnfd_info_id):
def delete_pnf(pnfd_info_id):
# TODO
- pnf_pkg = PnfPackageModel.objects.filter(pnfPackageId=pnfd_info_id)
- if not pnf_pkg.exists():
- logger.debug('PNF resource(%s) is deleted.' % pnfd_info_id)
+ pnf_pkgs = PnfPackageModel.objects.filter(pnfPackageId=pnfd_info_id)
+ if not pnf_pkgs.exists():
+ logger.debug('PNF descriptor (%s) is deleted.' % pnfd_info_id)
return
- pnf_pkg.delete()
+ if pnf_pkgs[0].usageState != 'NOT_IN_USE':
+ raise CatalogException('The PNF descriptor (%s) shall be NOT_IN_USE.' % pnfd_info_id)
+ ns_pkgs = NSPackageModel.objects.all()
+ for ns_pkg in ns_pkgs:
+ if pnfd_info_id in ns_pkg.pnfdInfoIds:
+ raise CatalogException('The PNF descriptor (%s) is referenced.' % pnfd_info_id)
+ break
+ pnf_pkgs.delete()
vnf_pkg_path = os.path.join(CATALOG_ROOT_PATH, pnfd_info_id)
fileutil.delete_dirs(vnf_pkg_path)
+ logger.debug('PNF descriptor (%s) is deleted.' % pnfd_info_id)
def fill_response_data(pnf_pkg):
diff --git a/catalog/packages/tests/test_pnf_descriptor.py b/catalog/packages/tests/test_pnf_descriptor.py
index e5c48f1d..4245645e 100644
--- a/catalog/packages/tests/test_pnf_descriptor.py
+++ b/catalog/packages/tests/test_pnf_descriptor.py
@@ -141,7 +141,21 @@ class TestPnfDescriptor(TestCase):
self.assertEqual(expected_reponse_data, response.data)
def test_delete_single_pnfd_normal(self):
- pass
+ user_defined_data = {
+ 'key1': 'value1',
+ 'key2': 'value2',
+ 'key3': 'value3',
+ }
+ user_defined_data = json.JSONEncoder().encode(user_defined_data)
+ PnfPackageModel(
+ pnfPackageId='22',
+ usageState='NOT_IN_USE',
+ userDefinedData=user_defined_data,
+ pnfdModel='test'
+ ).save()
+ resp = self.client.delete("/api/nsd/v1/pnf_descriptors/22", format='json')
+ self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)
+ self.assertEqual(None, resp.data)
def test_pnfd_content_upload_normal(self):
user_defined_data_json = json.JSONEncoder().encode(self.user_defined_data)