def test005_scan_cancel(self, m_sync_call): arg = "test" result = module.scan_cancel(arg) m_sync_call.assert_called_once_with(self.m_brain_app, BRAIN_SCAN_TASKS, "scan_cancel", self.m_timeout, args=[arg]) self.assertEqual(result, m_sync_call())
def test005_scan_cancel(self): arg = "test" expected = ((self.m_brain_app, "brain.tasks", "scan_cancel", self.m_timeout), {"args": [arg]}) with patch("frontend.controllers.braintasks.sync_call") as mock: result = module.scan_cancel(arg) self.assertTrue(mock.called) self.assertEqual(mock.call_args, expected) self.assertEqual(result, mock())
def cancel(scan, session): """ cancel all remaining jobs for specified scan :param scanid: id returned by scan_new :rtype: dict of 'cancel_details': total':int, 'finished':int, 'cancelled':int :return: informations about number of cancelled jobs by irma-brain :raise: IrmaDatabaseError, IrmaTaskError """ log.debug("scanid: %s", scan.external_id) if scan.status < IrmaScanStatus.uploaded: # If not launched answer directly scan.set_status(IrmaScanStatus.cancelled) session.commit() return None if scan.status != IrmaScanStatus.launched: # If too late answer directly status_str = IrmaScanStatus.label[scan.status] if IrmaScanStatus.is_error(scan.status): # let the cancel finish and keep the error status return None else: reason = "can not cancel scan in {0} status".format(status_str) raise IrmaValueError(reason) # Else ask brain for job cancel (retcode, res) = celery_brain.scan_cancel(scan.external_id) if retcode == IrmaReturnCode.success: s_processed = IrmaScanStatus.label[IrmaScanStatus.processed] if 'cancel_details' in res: scan.set_status(IrmaScanStatus.cancelled) session.commit() return res['cancel_details'] elif res['status'] == s_processed: # if scan is finished for the brain # it means we are just waiting for results scan.set_status(IrmaScanStatus.processed) session.commit() reason = "can not cancel scan in {0} status".format(res['status']) raise IrmaValueError(reason) else: raise IrmaTaskError(res)