diff options
author | fujinhua <fu.jinhua@zte.com.cn> | 2018-11-22 09:20:21 +0800 |
---|---|---|
committer | fujinhua <fu.jinhua@zte.com.cn> | 2018-11-22 10:11:02 +0800 |
commit | b2c15bc4a66f804d462e213a7cd16aa5abe24931 (patch) | |
tree | 7486697bff95dba41c4d45726473e13ceb2d06ce | |
parent | 1cbfeb8366d32855c1d4daf4e7371bb4081f89de (diff) |
Fix vnf heal logic
Change-Id: I05edef058cceef70f250731bde114534eadbfe4d
Issue-ID: VFC-1163
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r-- | lcm/lcm/nf/biz/heal_vnf.py | 27 | ||||
-rw-r--r-- | lcm/lcm/nf/tests/test_heal_vnf.py | 9 | ||||
-rw-r--r-- | lcm/lcm/nf/views/heal_vnf_view.py | 3 | ||||
-rw-r--r-- | lcm/lcm/pub/vimapi/adaptor.py | 10 |
4 files changed, 24 insertions, 25 deletions
diff --git a/lcm/lcm/nf/biz/heal_vnf.py b/lcm/lcm/nf/biz/heal_vnf.py index 4b503424..4d32d509 100644 --- a/lcm/lcm/nf/biz/heal_vnf.py +++ b/lcm/lcm/nf/biz/heal_vnf.py @@ -70,7 +70,7 @@ class HealVnf(Thread): def heal_pre(self): if self.action not in (HEAL_ACTION_TYPE.START, HEAL_ACTION_TYPE.RESTART): - raise NFLCMException("Action type in Request in invalid. Should be %s or %s" % (HEAL_ACTION_TYPE.START, HEAL_ACTION_TYPE.RESTART)) + raise NFLCMException("Action should be %s or %s" % (HEAL_ACTION_TYPE.START, HEAL_ACTION_TYPE.RESTART)) self.vm_id = ignore_case_get(self.affectedvm, "vmid") self.vdu_id = ignore_case_get(self.affectedvm, "vduid") @@ -83,21 +83,24 @@ class HealVnf(Thread): def apply_grant(self): if self.action == HEAL_ACTION_TYPE.RESTART: - self.vdu = VmInstModel.objects.filter(instid=self.nf_inst_id, vmid=self.vm_id, vmname=self.vm_name) + self.vdu = VmInstModel.objects.filter(instid=self.nf_inst_id, resourceid=self.vm_id) if not self.vdu: - raise NFLCMException("VNF Vm does not exist.") + raise NFLCMException("VNF Vm(%s) does not exist." % self.vm_id) self.vimid = self.vdu[0].vimid self.tenant = self.vdu[0].tenant - elif self.action == HEAL_ACTION_TYPE.START: - vdus = ignore_case_get(self.vnfd_info, "vdus") - self.vdu = [elem for elem in vdus if ignore_case_get(elem, "vdu_id") == self.vdu_id] - if not self.vdu: - raise NFLCMException("VNF Vm does not exist.") + logger.debug("Get heal vnf vm(%s,%s) info successfully.", self.vm_id, self.vm_name) + JobUtil.add_job_status(self.job_id, 20, 'Nf Healing get vnf vm info finish') + return + + vdus = ignore_case_get(self.vnfd_info, "vdus") + self.vdu = [elem for elem in vdus if ignore_case_get(elem, "vdu_id") == self.vdu_id] + if not self.vdu: + raise NFLCMException("VNF Vdu(%s) does not exist." % self.vdu_id) apply_result = grant_resource(data=self.data, nf_inst_id=self.nf_inst_id, job_id=self.job_id, grant_type=self.grant_type, vdus=self.vdu) - if self.action == HEAL_ACTION_TYPE.START: - self.vimid = ignore_case_get(apply_result, "vimid"), - self.tenant = ignore_case_get(apply_result, "tenant") + + self.vimid = ignore_case_get(apply_result, "vimid"), + self.tenant = ignore_case_get(apply_result, "tenant") logger.info("Grant resource, response: %s" % apply_result) JobUtil.add_job_status(self.job_id, 20, 'Nf Healing grant_resource finish') @@ -133,7 +136,7 @@ class HealVnf(Thread): chtype = CHANGE_TYPE.MODIFIED vnfcs = VNFCInstModel.objects.filter(instid=self.nf_inst_id, vmid=self.vm_id) vm_resource = {} - vm = VmInstModel.objects.filter(instid=self.nf_inst_id, vmid=self.vm_id) + vm = VmInstModel.objects.filter(instid=self.nf_inst_id, resourceid=self.vm_id) if vm: vm_resource = { 'vimConnectionId': vm[0].vimid, diff --git a/lcm/lcm/nf/tests/test_heal_vnf.py b/lcm/lcm/nf/tests/test_heal_vnf.py index 27cce093..08721b71 100644 --- a/lcm/lcm/nf/tests/test_heal_vnf.py +++ b/lcm/lcm/nf/tests/test_heal_vnf.py @@ -54,13 +54,6 @@ class TestNFInstantiate(TestCase): response = self.client.post("/api/vnflcm/v1/vnf_instances/12/heal", data=req_data, format='json')
self.failUnlessEqual(status.HTTP_404_NOT_FOUND, response.status_code)
- def test_heal_vnf_conflict(self):
- req_data = {}
- NfInstModel(nfinstid='12', nf_name='VNF1', status='NOT_INSTANTIATED').save()
- response = self.client.post("/api/vnflcm/v1/vnf_instances/12/heal", data=req_data, format='json')
- self.failUnlessEqual(status.HTTP_409_CONFLICT, response.status_code)
- NfInstModel(nfinstid='12', nf_name='VNF1', status='NOT_INSTANTIATED').delete()
-
@mock.patch.object(HealVnf, 'run')
def test_heal_vnf_success(self, mock_run):
req_data = {}
@@ -96,7 +89,7 @@ class TestNFInstantiate(TestCase): VmInstModel.objects.create(vmid="1",
vimid="vimid_1",
- resourceid="11",
+ resourceid="1",
insttype=0,
instid="1111",
vmname="vduinstname",
diff --git a/lcm/lcm/nf/views/heal_vnf_view.py b/lcm/lcm/nf/views/heal_vnf_view.py index 6b3b3139..4c2fad0e 100644 --- a/lcm/lcm/nf/views/heal_vnf_view.py +++ b/lcm/lcm/nf/views/heal_vnf_view.py @@ -81,9 +81,6 @@ class HealVnfView(APIView): 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.")
-
NfInstModel.objects.filter(nfinstid=nf_inst_id).update(status=VNF_STATUS.HEALING)
JobUtil.add_job_status(job_id, 15, 'Nf healing pre-check finish')
logger.info("Nf healing pre-check finish")
diff --git a/lcm/lcm/pub/vimapi/adaptor.py b/lcm/lcm/pub/vimapi/adaptor.py index 3b959c45..bffdcbe6 100644 --- a/lcm/lcm/pub/vimapi/adaptor.py +++ b/lcm/lcm/pub/vimapi/adaptor.py @@ -88,6 +88,7 @@ def action_vm(action_type, server, vimId, tenantId): else: param["reboot"]["type"] = "HARD" res_id = server["id"] + logger.debug("%s,%s,%s,%s", vimId, tenantId, res_id, param) api.action_vm(vimId, tenantId, res_id, param) @@ -116,15 +117,20 @@ def heal_vim_res(vdus, vnfd_info, do_notify, data, vim_cache, res_cache): vimid = data["vimid"] tenant = data["tenant"] actionType = data["action"] + resid = '' if actionType == HEAL_ACTION_TYPE.START: + resid = vdus[0]["vdu_id"] create_vm(vim_cache, res_cache, vnfd_info, vdus[0], do_notify, RES_VM) elif actionType == HEAL_ACTION_TYPE.RESTART: + resid = vdus[0].resourceid + logger.debug("Start restart vm(%s)", resid) vm_info = api.get_vm(vimid, tenant, vdus[0].resourceid) + logger.debug("vminfo=%s", vm_info) action_vm(ACTION_TYPE.REBOOT, vm_info, vimid, tenant) except VimException as e: - logger.error("Failed to Heal %s(%s)", RES_VM, vdus[0]["vdu_id"]) + logger.error("Failed to Heal %s(%s)", RES_VM, resid) logger.error("%s:%s", e.http_code, e.message) - raise NFLCMException("Failed to Heal %s(%s)", RES_VM, vdus[0]["vdu_id"]) + raise NFLCMException("Failed to Heal %s(%s)" % (RES_VM, resid)) def create_vim_res(data, do_notify, vim_cache={}, res_cache={}): |