summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfujinhua <fu.jinhua@zte.com.cn>2019-04-30 15:18:40 +0800
committerfujinhua <fu.jinhua@zte.com.cn>2019-04-30 15:27:27 +0800
commiteba18f669aca67e09a0c4f0e9375bc477581b419 (patch)
treeee69634c5f28f475084a6e6c8e8e4ce5c3c5a469
parentf35dfbcc2b40c706e4c4bfde58551394e11bd66f (diff)
Add lcm op occ for chg ext conn
Change-Id: Ic2d73af3d8e341c8d6e73f3af6ecdefb7f38edb2 Issue-ID: VFC-1306 Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r--lcm/lcm/nf/biz/change_ext_conn.py29
-rw-r--r--lcm/lcm/nf/biz/operate_vnf_lcm_op_occ.py8
-rw-r--r--lcm/lcm/nf/const.py19
3 files changed, 56 insertions, 0 deletions
diff --git a/lcm/lcm/nf/biz/change_ext_conn.py b/lcm/lcm/nf/biz/change_ext_conn.py
index 3cde0cf7..1b3f9479 100644
--- a/lcm/lcm/nf/biz/change_ext_conn.py
+++ b/lcm/lcm/nf/biz/change_ext_conn.py
@@ -20,12 +20,14 @@ from lcm.nf.biz.common import port_save
from lcm.nf.biz.grant_vnf import grant_resource
from lcm.nf.const import RESOURCE_MAP, GRANT_TYPE, OPERATION_STATE_TYPE
from lcm.nf.const import VNF_STATUS, OPERATION_TASK, OPERATION_TYPE
+from lcm.nf.const import SUB_OPERATION_TASK
from lcm.pub.database.models import VmInstModel, NfInstModel, PortInstModel
from lcm.pub.utils.notificationsutil import NotificationsUtil, prepare_notification
from lcm.pub.utils.values import ignore_case_get
from lcm.pub.utils.timeutil import now_time
from lcm.pub.utils.jobutil import JobUtil
from lcm.pub.exceptions import NFLCMException
+from lcm.pub.exceptions import NFLCMExceptionConflict
from lcm.pub.vimapi import adaptor
from .operate_vnf_lcm_op_occ import VnfLcmOpOcc
@@ -48,6 +50,7 @@ class ChangeExtConn(Thread):
operation=OPERATION_TYPE.CHANGE_EXT_CONN,
task=OPERATION_TASK.CHANGE_EXT_CONN
)
+ self.pre_deal()
def run(self):
try:
@@ -64,6 +67,10 @@ class ChangeExtConn(Thread):
50,
"Start to change ext conn."
)
+ self.lcm_op_occ.upd(
+ sub_operation=SUB_OPERATION_TASK.GRANTED,
+ operation_state=OPERATION_STATE_TYPE.PROCESSING
+ )
self.do_operation()
self.vnf_insts.update(
status='INSTANTIATED',
@@ -75,6 +82,10 @@ class ChangeExtConn(Thread):
100,
"Change ext conn success."
)
+ self.lcm_op_occ.upd(
+ sub_operation=SUB_OPERATION_TASK.SUCCESS,
+ operation_state=OPERATION_STATE_TYPE.COMPLETED
+ )
except NFLCMException as e:
logger.error(e.message)
self.change_ext_conn_failed_handle(e.message)
@@ -83,6 +94,16 @@ class ChangeExtConn(Thread):
logger.error(traceback.format_exc())
self.change_ext_conn_failed_handle(e.message)
+ def pre_deal(self):
+ logger.debug("Start pre deal for VNF change_ext_conn task")
+
+ vnf_is_in_processing, vnf_op = self.lcm_op_occ.is_in_processing()
+ if vnf_is_in_processing:
+ raise NFLCMExceptionConflict('VNF(%s) %s in processing.' % (
+ self.nf_inst_id, vnf_op
+ ))
+ self.lcm_op_occ.add()
+
def apply_grant(self):
vdus = VmInstModel.objects.filter(instid=self.nf_inst_id)
apply_result = grant_resource(
@@ -287,3 +308,11 @@ class ChangeExtConn(Thread):
)
self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.FAILED, error_msg)
JobUtil.add_job_status(self.job_id, 255, error_msg)
+ self.lcm_op_occ.upd(
+ sub_operation=SUB_OPERATION_TASK.ERROR,
+ operation_state=OPERATION_STATE_TYPE.FAILED,
+ error={
+ "status": 500,
+ "detail": error_msg
+ }
+ )
diff --git a/lcm/lcm/nf/biz/operate_vnf_lcm_op_occ.py b/lcm/lcm/nf/biz/operate_vnf_lcm_op_occ.py
index 919a3461..8285f7da 100644
--- a/lcm/lcm/nf/biz/operate_vnf_lcm_op_occ.py
+++ b/lcm/lcm/nf/biz/operate_vnf_lcm_op_occ.py
@@ -93,6 +93,14 @@ class VnfLcmOpOcc:
raise NFLCMExceptionNotFound('Occurrence(%s) does not exist.' % self.lcm_op_id)
return lcm_op_occ_obj
+ def is_in_processing(self):
+ lcm_op_occ = VNFLcmOpOccModel.objects.filter(vnf_instance_id=self.vnf_inst_id)
+
+ for occ in lcm_op_occ:
+ if occ.operation_state not in const.FINAL_STATE_RANGE:
+ return True, occ.operation
+ return False, None
+
def notify_lcm(self, operation_state, error=''):
data = prepare_notification(nfinstid=self.vnf_inst_id,
jobid=self.lcm_op_id,
diff --git a/lcm/lcm/nf/const.py b/lcm/lcm/nf/const.py
index 8c434342..e961bb3e6 100644
--- a/lcm/lcm/nf/const.py
+++ b/lcm/lcm/nf/const.py
@@ -75,6 +75,25 @@ OPERATION_TASK = enum(
TERMINATE="terminate"
)
+SUB_OPERATION_TASK = enum(
+ RETRY="retry",
+ ROLLBACK="rollback",
+ FAIL="fail",
+ CANCEL="cancel",
+ ERROR="error",
+ SUCCESS="success",
+ GRANTED="granted",
+ UNRESOLVABLE_ERROR="unresolvable_error",
+ AUTO_ROLLBACK="auto_rollback",
+)
+
+SUB_OPERATION_TUPLE = (
+ SUB_OPERATION_TASK.RETRY,
+ SUB_OPERATION_TASK.ROLLBACK,
+ SUB_OPERATION_TASK.FAIL,
+ SUB_OPERATION_TASK.CANCEL
+)
+
INSTANTIATION_STATE = enum(
NOT_INSTANTIATED="NOT_INSTANTIATED",
INSTANTIATED="INSTANTIATED"