summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
authorfujinhua <fu.jinhua@zte.com.cn>2019-04-11 09:28:16 +0800
committerfujinhua <fu.jinhua@zte.com.cn>2019-04-11 09:40:17 +0800
commitbeae7e20ec71783a787c26a848699ecad4ac2915 (patch)
treeccc4f8f1f24b40f2a72ecdb2788b2694fb74bee2 /lcm
parenta45a1f81d8eb4a369d36eaea6cd52ef3c5e8d26e (diff)
Add precheck logic to terminate vnf
Change-Id: If391dad2eebd1980701c8bd52456b9bcb7511c89 Issue-ID: VFC-1306 Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
Diffstat (limited to 'lcm')
-rw-r--r--lcm/lcm/nf/tests/test_terminate_vnf.py13
-rw-r--r--lcm/lcm/nf/views/terminate_vnf_view.py18
2 files changed, 29 insertions, 2 deletions
diff --git a/lcm/lcm/nf/tests/test_terminate_vnf.py b/lcm/lcm/nf/tests/test_terminate_vnf.py
index b5f75f32..59b7ead9 100644
--- a/lcm/lcm/nf/tests/test_terminate_vnf.py
+++ b/lcm/lcm/nf/tests/test_terminate_vnf.py
@@ -98,10 +98,19 @@ class TestNFTerminate(TestCase):
"terminationType": "GRACEFUL",
"gracefulTerminationTimeout": 120
}
- NfInstModel(nfinstid='12', nf_name='VNF1').save()
+ NfInstModel(nfinstid='12',
+ nf_name='VNF1',
+ nf_desc="VNF DESC",
+ vnfdid="1",
+ netype="XGW",
+ vendor="ZTE",
+ vnfSoftwareVersion="V1",
+ version="V1",
+ package_id="2",
+ status='INSTANTIATED').save()
mock_run.re.return_value = None
response = self.client.post("/api/vnflcm/v1/vnf_instances/12/terminate", data=req_data, format='json')
- self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
+ self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content)
def test_terminate_vnf_when_inst_id_not_exist(self):
data = {
diff --git a/lcm/lcm/nf/views/terminate_vnf_view.py b/lcm/lcm/nf/views/terminate_vnf_view.py
index 0530437f..de3122e2 100644
--- a/lcm/lcm/nf/views/terminate_vnf_view.py
+++ b/lcm/lcm/nf/views/terminate_vnf_view.py
@@ -22,8 +22,12 @@ from rest_framework.views import APIView
from lcm.nf.biz.terminate_vnf import TerminateVnf
from lcm.nf.serializers.terminate_vnf_req import TerminateVnfRequestSerializer
from lcm.nf.serializers.job_identifier import JobIdentifierSerializer
+from lcm.pub.database.models import NfInstModel
from lcm.pub.exceptions import NFLCMException
+from lcm.pub.exceptions import NFLCMExceptionConflict
+from lcm.pub.exceptions import NFLCMExceptionNotFound
from lcm.pub.utils.jobutil import JobUtil
+from lcm.nf.const import VNF_STATUS
from .common import view_safe_call_with_log
logger = logging.getLogger(__name__)
@@ -47,6 +51,8 @@ class TerminateVnfView(APIView):
job_id = JobUtil.create_job('NF', 'TERMINATE', instanceid)
JobUtil.add_job_status(job_id, 0, "TERM_VNF_READY")
+
+ self.terminate_pre_check(instanceid, job_id)
TerminateVnf(terminate_vnf_request_serializer.data, instanceid, job_id).start()
terminate_vnf_response_serializer = JobIdentifierSerializer(data={"jobId": job_id})
@@ -54,3 +60,15 @@ class TerminateVnfView(APIView):
raise NFLCMException(terminate_vnf_response_serializer.errors)
return Response(data=terminate_vnf_response_serializer.data, status=status.HTTP_202_ACCEPTED)
+
+ def terminate_pre_check(self, nf_inst_id, job_id):
+ vnf_insts = NfInstModel.objects.filter(nfinstid=nf_inst_id)
+ if not vnf_insts.exists():
+ raise NFLCMExceptionNotFound("VNF nf_inst_id does not exist.")
+
+ if vnf_insts[0].status != 'INSTANTIATED':
+ raise NFLCMExceptionConflict("VNF instantiationState is not INSTANTIATED.")
+
+ vnf_insts.update(status=VNF_STATUS.TERMINATING)
+ JobUtil.add_job_status(job_id, 15, 'Nf terminating pre-check finish')
+ logger.info("Nf terminating pre-check finish")