summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhewei-cmss <hewei@cmss.chinamobile.com>2019-10-15 09:31:44 +0800
committerhewei-cmss <hewei@cmss.chinamobile.com>2019-10-15 10:33:48 +0800
commit430c96c6ac4d8f07bc39a50e7dc9735ce899e976 (patch)
treebab959b4a1730301a1ce10b6a3f614726685255e
parent621d3a6ac812ecc59ae1579cd6c9fd5f65345943 (diff)
add terminate ns package state
Issue-ID: VFC-1504 Signed-off-by: hewei-cmss <hewei@cmss.chinamobile.com> Change-Id: I10a77a659cfff434b9908c80c5792156da58603f
-rw-r--r--lcm/ns/biz/ns_terminate.py8
-rw-r--r--lcm/ns/tests/tests_ns_terminate.py5
-rw-r--r--lcm/pub/msapi/sdc_run_catalog.py4
3 files changed, 14 insertions, 3 deletions
diff --git a/lcm/ns/biz/ns_terminate.py b/lcm/ns/biz/ns_terminate.py
index 06e84b7e..32845ddc 100644
--- a/lcm/ns/biz/ns_terminate.py
+++ b/lcm/ns/biz/ns_terminate.py
@@ -21,6 +21,7 @@ from lcm.jobs.const import JOB_INSTANCE_RESPONSE_ID_URI
from lcm.pub.database.models import NSInstModel, VLInstModel, FPInstModel, NfInstModel
from lcm.pub.exceptions import NSLCMException
from lcm.pub.msapi.nslcm import call_from_ns_cancel_resource
+from lcm.pub.msapi import sdc_run_catalog
from lcm.pub.utils.jobutil import JobUtil
from lcm.pub.utils.values import ignore_case_get
from lcm.pub.utils import restcall
@@ -57,6 +58,7 @@ class TerminateNsService(threading.Thread):
self.cancel_vl_list()
self.cancel_pnf_list()
+ self.modify_package_state()
NSInstModel.objects.filter(id=self.ns_inst_id).update(status='NOT_INSTANTIATED')
JobUtil.add_job_status(self.job_id, JOB_PROGRESS.FINISHED, "ns terminate ends.", '')
NsLcmOpOcc.update(self.occ_id, "COMPLETED")
@@ -71,6 +73,12 @@ class TerminateNsService(threading.Thread):
NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.args[0])
build_in.post_deal(self.ns_inst_id, "false")
+ def modify_package_state(self):
+ ns_inst = NSInstModel.objects.filter(id=self.ns_inst_id)
+ ns_insts = NSInstModel.objects.filter(nspackage_id=ns_inst[0].nspackage_id)
+ if len(ns_insts) == 1:
+ sdc_run_catalog.modify_nsd_state(ns_inst[0].nspackage_id, 0)
+
def cancel_vl_list(self):
array_vlinst = VLInstModel.objects.filter(ownertype=OWNER_TYPE.NS, ownerid=self.ns_inst_id)
if not array_vlinst:
diff --git a/lcm/ns/tests/tests_ns_terminate.py b/lcm/ns/tests/tests_ns_terminate.py
index d7ce54a7..25d8d871 100644
--- a/lcm/ns/tests/tests_ns_terminate.py
+++ b/lcm/ns/tests/tests_ns_terminate.py
@@ -84,7 +84,10 @@ class TestTerminateNsViews(TestCase):
"status": JOB_MODEL_STATUS.PROCESSING,
"responseid": "2",
"statusdescription": "creating",
- "errorcode": "0"}]}}), '200']}
+ "errorcode": "0"}]}}), '200'],
+ "/api/catalog/v1/ns_descriptors/None":
+ [0, json.JSONEncoder().encode({}), '202'],
+ }
def side_effect(*args):
return mock_vals[args[4]]
diff --git a/lcm/pub/msapi/sdc_run_catalog.py b/lcm/pub/msapi/sdc_run_catalog.py
index d1b26070..0013d2c8 100644
--- a/lcm/pub/msapi/sdc_run_catalog.py
+++ b/lcm/pub/msapi/sdc_run_catalog.py
@@ -69,8 +69,8 @@ def query_pnf_descriptor(filter=None):
return json.JSONDecoder().decode(ret[1])
-def modify_nsd_state(csar_id):
- req_param = json.JSONEncoder().encode({"usageState": 1})
+def modify_nsd_state(csar_id, usage_state=1):
+ req_param = json.JSONEncoder().encode({"usageState": usage_state})
ret = req_by_msb("/api/catalog/v1/ns_descriptors/%s" % csar_id, "PUT", req_param)
if ret[0] != 0:
logger.error("Status code is %s, detail is %s.", ret[2], ret[1])