summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2017-02-24 16:04:07 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2017-02-24 16:04:07 +0800
commit5d7d95aaa0b4e3ccf016c275a686d02e80d744b7 (patch)
tree13792fab36bc25acf7b1d4a99babe5c660aa56e6 /lcm
parentcf4883f5f2b1588f802d2c25231dd5cc27821b5b (diff)
Modify code and testcase of terminate_vnf_precheck
Change-Id: I9019f65eb04f6964c10978ce9e65e021c1f042d6 Issue-Id: GVNFM-21 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'lcm')
-rw-r--r--lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py75
-rw-r--r--lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py32
2 files changed, 43 insertions, 64 deletions
diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py b/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py
index cdb4094c..2f139e56 100644
--- a/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py
+++ b/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py
@@ -74,49 +74,32 @@ class TestNFTerminate(TestCase):
self.failUnlessEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
self.assertEqual("Don't allow to delete vnf(status:[NOT_INSTANTIATED])", response.data["error"])
-# @mock.patch.object(TermVnf, 'run')
-# def test_terminate_vnf(self, mock_run):
-# mock_run.re.return_value = None
-# response = self.client.post("/openoapi/vnflcm/v1/vnf_instances/12/terminate", data={}, format='json')
-# self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
-#
-# def test_terminate_vnf_when_inst_id_not_exist(self):
-# data = {"terminationType": "GRACEFUL",
-# "gracefulTerminationTimeout": 120}
-# self.nf_inst_id = str(uuid.uuid4())
-# self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
-# JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")
-# TermVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
-# self.assert_job_result(self.job_id, 255, "VnfInst(%s) does not exist" % self.nf_inst_id)
-#
-# def test_instantiate_vnf_when_get_nfvo_config_failed(self):
-# NfInstModel.objects.create(nfinstid='1111', mnfinstid='1111', nf_name='2222',
-# package_id='todo', vnfm_inst_id='todo', version='', vendor='',
-# producttype='', netype='', vnfd_model='',
-# instantiationState='VNF_INSTANTIATED', nf_desc='', vnfdid='',
-# vnfSoftwareVersion='', vnfConfigurableProperties='todo',
-# localizationLanguage='EN_US', create_time=now_time())
-# data = {"terminationType": "FORCEFUL",
-# "gracefulTerminationTimeout": 120}
-# self.nf_inst_id = '1111'
-# self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
-# JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")
-# TermVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
-# self.assert_job_result(self.job_id, 255, "Nfvo was not registered")
-#
-# def test_terminate_vnf_success(self):
-# NfInstModel.objects.create(nfinstid='1111', mnfinstid='1111', nf_name='2222',
-# package_id='todo', vnfm_inst_id='todo', version='', vendor='',
-# producttype='', netype='', vnfd_model='',
-# instantiationState='VNF_INSTANTIATED', nf_desc='', vnfdid='',
-# vnfSoftwareVersion='', vnfConfigurableProperties='todo',
-# localizationLanguage='EN_US', create_time=now_time())
-# NfvoRegInfoModel.objects.create(nfvoid='nfvo111', vnfminstid='vnfm111', apiurl='http://10.74.44.11',
-# nfvouser='root', nfvopassword='root123')
-# data = {"terminationType": "FORCEFUL",
-# "gracefulTerminationTimeout": 120}
-# self.nf_inst_id = '1111'
-# self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
-# JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")
-# TermVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
-# self.assert_job_result(self.job_id, 100, "Terminate Vnf success.")
+ @mock.patch.object(TermVnf, 'run')
+ def test_terminate_vnf(self, mock_run):
+ mock_run.re.return_value = None
+ response = self.client.post("/openoapi/vnflcm/v1/vnf_instances/12/terminate", data={}, format='json')
+ self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
+
+ def test_terminate_vnf_when_inst_id_not_exist(self):
+ data = {"terminationType": "GRACEFUL",
+ "gracefulTerminationTimeout": 120}
+ self.nf_inst_id = str(uuid.uuid4())
+ self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
+ JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")
+ TermVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
+ self.assert_job_result(self.job_id, 255, "VnfInst(%s) does not exist" % self.nf_inst_id)
+
+
+
+ def test_terminate_vnf_success(self):
+ NfInstModel.objects.create(nfinstid='1111', nf_name='2222', package_id='todo', version='', vendor='',
+ netype='', vnfd_model='', status='VNF_INSTANTIATED', nf_desc='', vnfdid='',
+ vnfSoftwareVersion='', vnfConfigurableProperties='todo',
+ localizationLanguage='EN_US', create_time=now_time())
+ data = {"terminationType": "FORCEFUL",
+ "gracefulTerminationTimeout": 120}
+ self.nf_inst_id = '1111'
+ self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
+ JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")
+ TermVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
+ self.assert_job_result(self.job_id, 100, "Terminate Vnf success.")
diff --git a/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py b/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py
index 80cbe075..4b83fa02 100644
--- a/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py
+++ b/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py
@@ -45,7 +45,7 @@ class TermVnf(Thread):
def run(self):
try:
self.term_pre()
- self.query_inst_resource(self.nf_inst_id)
+ # self.query_inst_resource(self.nf_inst_id)
# self.grant_resource()
JobUtil.add_job_status(self.job_id, 100, "Terminate Vnf success.")
is_exist = JobStatusModel.objects.filter(jobid=self.job_id).exists()
@@ -60,20 +60,16 @@ class TermVnf(Thread):
logger.error(traceback.format_exc())
def term_pre(self):
- vnf_insts = NfInstModel.objects.filter(pk=self.nf_inst_id)
+ vnf_insts = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
if not vnf_insts.exists():
raise NFLCMException('VnfInst(%s) does not exist' % self.nf_inst_id)
sel_vnf = vnf_insts[0]
- if sel_vnf.instantiationState != 'VNF_INSTANTIATED':
- raise NFLCMException("No instantiated vnf")
+ if sel_vnf.status != 'VNF_INSTANTIATED':
+ raise NFLCMException("Don't allow to delete vnf(status:[%s])" % sel_vnf.status)
if self.terminationType == 'GRACEFUL' and not self.gracefulTerminationTimeout:
raise NFLCMException("Graceful termination must set timeout")
- # get nfvo info
- JobUtil.add_job_status(self.job_id, 5, 'Get nfvo connection info')
- self.load_nfvo_config()
NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(status=VNF_STATUS.TERMINATING)
-
JobUtil.add_job_status(self.job_id, 10, 'Nf terminating pre-check finish')
logger.info("Nf terminating pre-check finish")
@@ -170,13 +166,13 @@ class TermVnf(Thread):
logger.error("nf_cancel_task grant_resource failed.[%s]" % str(rsp[1]))
logger.info("nf_cancel_task grant_resource end")
- def load_nfvo_config(self):
- logger.info("[NF instantiation]get nfvo connection info start")
- reg_info = NfvoRegInfoModel.objects.filter(vnfminstid='vnfm111').first()
- if reg_info:
- self.vnfm_inst_id = reg_info.vnfminstid
- self.nfvo_inst_id = reg_info.nfvoid
- logger.info("[NF instantiation] Registered nfvo id is [%s]" % self.nfvo_inst_id)
- else:
- raise NFLCMException("Nfvo was not registered")
- logger.info("[NF instantiation]get nfvo connection info end")
+ # def load_nfvo_config(self):
+ # logger.info("[NF instantiation]get nfvo connection info start")
+ # reg_info = NfvoRegInfoModel.objects.filter(vnfminstid='vnfm111').first()
+ # if reg_info:
+ # self.vnfm_inst_id = reg_info.vnfminstid
+ # self.nfvo_inst_id = reg_info.nfvoid
+ # logger.info("[NF instantiation] Registered nfvo id is [%s]" % self.nfvo_inst_id)
+ # else:
+ # raise NFLCMException("Nfvo was not registered")
+ # logger.info("[NF instantiation]get nfvo connection info end")