def test_action_proc_fail_acquire(self, mock_acquire, mock_load, mock_clock): action = action_base.Action('OBJID', 'OBJECT_ACTION', self.ctx) mock_clock.return_value = 'TIMESTAMP' mock_acquire.return_value = None mock_load.return_value = action res = action_base.ActionProc(self.ctx, 'ACTION', 'WORKER') self.assertFalse(res) mock_clock.assert_called_once_with() mock_acquire.assert_called_once_with(action.context, 'ACTION', 'WORKER', 'TIMESTAMP')
def test_action_proc_failed_error(self, mock_mark, mock_load, mock_info): action = ab.Action(OBJID, 'CLUSTER_ACTION', self.ctx, id=ACTION_ID) action.entity = mock.Mock(id=CLUSTER_ID, name='fake-cluster') self.patchobject(action, 'execute', side_effect=Exception('Boom!')) mock_status = self.patchobject(action, 'set_status') mock_load.return_value = action res = ab.ActionProc(self.ctx, 'ACTION') self.assertFalse(res) mock_load.assert_called_once_with(self.ctx, action_id='ACTION') mock_info.assert_called_once_with(action, 'start') mock_status.assert_called_once_with(action.RES_ERROR, 'Boom!')
def test_action_proc_failed_error(self, mock_mark, mock_load, mock_event_info): action = ab.Action('OBJID', 'OBJECT_ACTION', self.ctx) action.owner = 'WORKER' action.start_time = 123456 self.patchobject(action, 'execute', side_effect=Exception('Boom!')) mock_load.return_value = action res = ab.ActionProc(self.ctx, 'ACTION') self.assertFalse(res) mock_load.assert_called_once_with(self.ctx, action_id='ACTION') self.assertEqual(action.FAILED, action.status) self.assertEqual('Boom!', action.status_reason)
def test_action_proc_successful(self, mock_mark, mock_load, mock_event_info): action = ab.Action(OBJID, 'OBJECT_ACTION', self.ctx) mock_obj = mock.Mock() action.entity = mock_obj self.patchobject(action, 'execute', return_value=(action.RES_OK, 'BIG SUCCESS')) mock_status = self.patchobject(action, 'set_status') mock_load.return_value = action res = ab.ActionProc(self.ctx, 'ACTION_ID') self.assertTrue(res) mock_load.assert_called_once_with(self.ctx, action_id='ACTION_ID') mock_event_info.assert_called_once_with(action, 'start') mock_status.assert_called_once_with(action.RES_OK, 'BIG SUCCESS')
def test_action_proc_failed_error(self, mock_mark, mock_load, mock_event_info): action = ab.Action(OBJID, 'CLUSTER_ACTION', self.ctx) action.id = '5eb0c9a5-149a-4cd7-875f-0351c3cc69d5' action.owner = OWNER_ID action.start_time = 123456 action.cluster = mock.Mock(id=CLUSTER_ID) action.cluster.name = 'fake-cluster' self.patchobject(action, 'execute', side_effect=Exception('Boom!')) mock_load.return_value = action res = ab.ActionProc(self.ctx, 'ACTION') self.assertFalse(res) mock_load.assert_called_once_with(self.ctx, action_id='ACTION') self.assertEqual(action.FAILED, action.status) self.assertEqual('Boom!', action.status_reason)
def test_action_proc_successful(self, mock_mark, mock_load, mock_event_info): action = ab.Action('OBJID', 'OBJECT_ACTION', self.ctx) action.owner = 'WORKER' action.start_time = 123456 self.patchobject(action, 'execute', return_value=(action.RES_OK, 'BIG SUCCESS')) mock_load.return_value = action res = ab.ActionProc(self.ctx, 'ACTION') self.assertTrue(res) mock_load.assert_called_once_with(self.ctx, action_id='ACTION') self.assertEqual(action.SUCCEEDED, action.status) self.assertEqual('WORKER', action.owner) self.assertEqual(123456, action.start_time) self.assertEqual('BIG SUCCESS', action.status_reason)
def test_action_proc_failed_error(self, mock_mark, mock_load, mock_acquire, mock_clock, mock_event_info): action = action_base.Action('OBJID', 'OBJECT_ACTION', self.ctx) self.patchobject(action, 'execute', side_effect=Exception('Boom!')) mock_clock.return_value = 'TIMESTAMP' mock_db_action = mock.Mock() mock_acquire.return_value = mock_db_action mock_load.return_value = action res = action_base.ActionProc(self.ctx, 'ACTION', 'WORKER') self.assertFalse(res) mock_acquire.assert_called_once_with(action.context, 'ACTION', 'WORKER', 'TIMESTAMP') mock_load.assert_called_once_with(self.ctx, action_id='ACTION') self.assertEqual(action.FAILED, action.status) self.assertEqual('Boom!', action.status_reason)
def test_action_proc_is_cancelled(self, mock_mark, mock_load, mock_info): action = ab.Action(OBJID, 'CLUSTER_ACTION', self.ctx, id=ACTION_ID) action.is_cancelled = mock.Mock() action.is_cancelled.return_value = True action.entity = mock.Mock(id=CLUSTER_ID, name='fake-cluster') mock_status = self.patchobject(action, 'set_status') mock_load.return_value = action res = ab.ActionProc(self.ctx, 'ACTION') self.assertIs(True, res) mock_load.assert_called_once_with(self.ctx, action_id='ACTION', project_safe=False) mock_info.assert_not_called() mock_status.assert_called_once_with( action.RES_CANCEL, 'CLUSTER_ACTION [%s] cancelled' % ACTION_ID[:8])
def test_action_proc_successful(self, mock_mark, mock_load, mock_acquire, mock_clock, mock_event_info): action = action_base.Action('OBJID', 'OBJECT_ACTION', self.ctx) self.patchobject(action, 'execute', return_value=(action.RES_OK, 'BIG SUCCESS')) mock_clock.return_value = 'TIMESTAMP' mock_db_action = mock.Mock() mock_db_action.owner = 'WORKER' mock_db_action.start_time = 123456 mock_acquire.return_value = mock_db_action mock_load.return_value = action res = action_base.ActionProc(self.ctx, 'ACTION', 'WORKER') self.assertTrue(res) mock_acquire.assert_called_once_with(action.context, 'ACTION', 'WORKER', 'TIMESTAMP') mock_load.assert_called_once_with(self.ctx, action_id='ACTION') self.assertEqual(action.SUCCEEDED, action.status) self.assertEqual('WORKER', action.owner) self.assertEqual(123456, action.start_time) self.assertEqual('BIG SUCCESS', action.status_reason)