def execute(self, **kwargs): """Interface function for action execution. :param dict kwargs: Parameters provided to the action, if any. :returns: A tuple containing the result and the related reason. """ # Since node.cluster_id could be reset to '' during action execution, # we record it here for policy check and cluster lock release. forced = (self.action in [consts.NODE_DELETE, consts.NODE_OPERATION]) saved_cluster_id = self.entity.cluster_id if saved_cluster_id: if self.cause == consts.CAUSE_RPC: res = senlin_lock.cluster_lock_acquire(self.context, self.entity.cluster_id, self.id, self.owner, senlin_lock.NODE_SCOPE, False) if not res: return self.RES_RETRY, 'Failed in locking cluster' try: self.policy_check(self.entity.cluster_id, 'BEFORE') finally: if self.data['status'] != pb.CHECK_OK: # Don't emit message since policy_check should have # done it senlin_lock.cluster_lock_release( saved_cluster_id, self.id, senlin_lock.NODE_SCOPE) return self.RES_ERROR, ('Policy check: ' + self.data['reason']) elif self.cause == consts.CAUSE_DERIVED_LCH: self.policy_check(saved_cluster_id, 'BEFORE') try: res = senlin_lock.node_lock_acquire(self.context, self.entity.id, self.id, self.owner, forced) if not res: res = self.RES_RETRY reason = 'Failed in locking node' else: res, reason = self._execute() if saved_cluster_id and self.cause == consts.CAUSE_RPC: self.policy_check(saved_cluster_id, 'AFTER') if self.data['status'] != pb.CHECK_OK: res = self.RES_ERROR reason = 'Policy check: ' + self.data['reason'] finally: senlin_lock.node_lock_release(self.entity.id, self.id) if saved_cluster_id and self.cause == consts.CAUSE_RPC: senlin_lock.cluster_lock_release(saved_cluster_id, self.id, senlin_lock.NODE_SCOPE) return res, reason
def execute(self, **kwargs): """Interface function for action execution. :param dict kwargs: Parameters provided to the action, if any. :returns: A tuple containing the result and the related reason. """ # Since node.cluster_id could be reset to None in _execute progress, # we record it here for policy check and cluster lock release. saved_cluster_id = self.node.cluster_id if self.node.cluster_id: if self.cause == base.CAUSE_RPC: res = senlin_lock.cluster_lock_acquire( self.context, self.node.cluster_id, self.id, self.owner, senlin_lock.NODE_SCOPE, False) if not res: return self.RES_RETRY, _('Failed in locking cluster') self.policy_check(self.node.cluster_id, 'BEFORE') if self.data['status'] != policy_mod.CHECK_OK: # Don't emit message here since policy_check should have # done it if self.cause == base.CAUSE_RPC: senlin_lock.cluster_lock_release( self.node.cluster_id, self.id, senlin_lock.NODE_SCOPE) return self.RES_ERROR, 'Policy check: ' + self.data['reason'] reason = '' try: res = senlin_lock.node_lock_acquire(self.context, self.node.id, self.id, self.owner, False) if not res: res = self.RES_ERROR reason = _('Failed in locking node') else: res, reason = self._execute() if res == self.RES_OK and saved_cluster_id is not None: self.policy_check(saved_cluster_id, 'AFTER') if self.data['status'] != policy_mod.CHECK_OK: res = self.RES_ERROR reason = 'Policy check: ' + self.data['reason'] else: res = self.RES_OK finally: senlin_lock.node_lock_release(self.node.id, self.id) if saved_cluster_id is not None and self.cause == base.CAUSE_RPC: senlin_lock.cluster_lock_release(saved_cluster_id, self.id, senlin_lock.NODE_SCOPE) return res, reason
def execute(self, **kwargs): # Since node.cluster_id could be reset to None in _execute progress, # we record it here for policy check and cluster lock release. saved_cluster_id = self.node.cluster_id if self.node.cluster_id: if self.cause == base.CAUSE_RPC: res = senlin_lock.cluster_lock_acquire( self.node.cluster_id, self.id, senlin_lock.NODE_SCOPE, False) if not res: return self.RES_RETRY, _('Failed in locking cluster') self.policy_check(self.node.cluster_id, 'BEFORE') if self.data['status'] != policy_mod.CHECK_OK: # Don't emit message here since policy_check should have # done it if self.cause == base.CAUSE_RPC: senlin_lock.cluster_lock_release( self.node.cluster_id, self.id, senlin_lock.NODE_SCOPE) return self.RES_ERROR, 'Policy check: ' + self.data['reason'] reason = '' try: res = senlin_lock.node_lock_acquire(self.node.id, self.id, False) if not res: res = self.RES_ERROR reason = _('Failed in locking node') else: res, reason = self._execute() if res == self.RES_OK and saved_cluster_id is not None: self.policy_check(saved_cluster_id, 'AFTER') if self.data['status'] != policy_mod.CHECK_OK: res = self.RES_ERROR reason = 'Policy check: ' + self.data['reason'] else: res = self.RES_OK finally: senlin_lock.node_lock_release(self.node.id, self.id) if saved_cluster_id is not None and self.cause == base.CAUSE_RPC: senlin_lock.cluster_lock_release(saved_cluster_id, self.id, senlin_lock.NODE_SCOPE) return res, reason
def test_node_lock_release(self, mock_release): actual = lockm.node_lock_release('C', 'A') self.assertEqual(mock_release.return_value, actual) mock_release.assert_called_once_with('C', 'A')