Exemplo n.º 1
0
def _resubmit_files(scan, parent_file, resubmit_fws, hash_uploaded, session):
    fws = parent_file.files_web
    if len(fws) == 0:
        log.error("file %s not found in scan", parent_file.sha256)
        return
    fws_filtered = []
    for fw in resubmit_fws:
        # Either fw is already in scan and duplicate result
        if fw.file.sha256 in hash_uploaded:
            # grab probelist from filewebs linked to the same file
            # in current scan
            probelist = [
                p.name for p in _fetch_known_results(fw.file, scan, session)
            ]
            # and add link to their results
            _add_empty_result(fw, probelist, scan, session)
        else:
            # if new to scan, build a new one
            # (done later in _add_empty_results)
            fws_filtered.append(fw)

    log.debug("scan %s: %d new files to resubmit", scan.external_id,
              len(fws_filtered))
    if len(fws_filtered) != 0:
        scan_request = _create_scan_request(fws_filtered, scan.get_probelist(),
                                            scan.mimetype_filtering)
        scan_request = _add_empty_results(fws_filtered, scan_request, scan,
                                          session)
        celery_brain.scan_launch(scan.external_id, scan_request.to_dict())
    return
Exemplo n.º 2
0
def launch_asynchronous(scanid):
    log.debug("scanid: %s", scanid)
    with session_transaction() as session:
        scan = Scan.load_from_ext_id(scanid, session=session)
        IrmaScanStatus.filter_status(scan.status, IrmaScanStatus.ready,
                                     IrmaScanStatus.ready)
        scan_request = _create_scan_request(scan.files_web,
                                            scan.get_probelist(),
                                            scan.mimetype_filtering)
        scan_request = _add_empty_results(scan.files_web, scan_request, scan,
                                          session)
        # Nothing to do
        if scan_request.nb_files == 0:
            scan.set_status(IrmaScanStatus.finished)
            session.commit()
            log.warning("scanid: %s finished nothing to do", scanid)
            return

        try:
            upload_list = list()
            for file in scan.files:
                upload_list.append(file.path)
            ftp_ctrl.upload_scan(scanid, upload_list)
        except IrmaFtpError as e:
            log.error("scanid: %s ftp upload error %s", scanid, str(e))
            scan.set_status(IrmaScanStatus.error_ftp_upload)
            session.commit()
            return

        # launch new celery scan task on brain
        celery_brain.scan_launch(scanid, scan_request.to_dict())
        scan.set_status(IrmaScanStatus.uploaded)
        session.commit()
        log.info("scanid: %s uploaded", scanid)
        return
Exemplo n.º 3
0
 def test006_scan_launch(self, m_async_call):
     args = ["test1", "test2"]
     result = module.scan_launch(*args)
     m_async_call.assert_called_once_with(self.m_brain_app,
                                          BRAIN_SCAN_TASKS,
                                          "scan",
                                          args=args)
     self.assertEqual(result, m_async_call())
Exemplo n.º 4
0
 def test006_scan_launch(self, m_async_call):
     args = ["test1", "test2"]
     result = module.scan_launch(*args)
     m_async_call.assert_called_once_with(self.m_brain_app,
                                          BRAIN_SCAN_TASKS,
                                          "scan",
                                          args=args)
     self.assertEqual(result, m_async_call())
Exemplo n.º 5
0
 def test006_scan_launch(self):
     args = ["test1", "test2"]
     expected = ((self.m_brain_app, "brain.tasks", "scan"), {"args": args})
     with patch("frontend.controllers.braintasks.async_call") as mock:
         result = module.scan_launch(*args)
     self.assertTrue(mock.called)
     self.assertEqual(mock.call_args, expected)
     self.assertEqual(result, mock())