Beispiel #1
0
def scan_launch(scan_id):
    with session_transaction() as session:
        scan = None
        try:
            log.debug("scan: %s launching", scan_id)
            # Part for common action for whole scan
            scan = Scan.load_from_ext_id(scan_id, session)
            scan_request = scan_ctrl._create_scan_request(
                    scan.files_ext,
                    scan.get_probelist(),
                    scan.mimetype_filtering)
            scan_request = scan_ctrl._add_empty_results(
                    scan.files_ext,
                    scan_request,
                    scan, session)
            # Nothing to do
            if scan_request.nb_files == 0:
                scan.set_status(IrmaScanStatus.finished)
                log.warning("scan %s: finished nothing to do", scan_id)
                return

            # Part for action file_ext by file_ext
            file_ext_id_list = [file.external_id for file in scan.files_ext]

            celery.group(scan_launch_file_ext.si(file_ext_id)
                         for file_ext_id in file_ext_id_list)()
            scan.set_status(IrmaScanStatus.launched)
            session.commit()
            log.info("scan %s: launched", scan_id)
            return
        except Exception as e:
            log.exception(e)
            if scan is not None:
                scan.set_status(IrmaScanStatus.error)
Beispiel #2
0
 def test_add_empty_results(self, m_add_empty_result, m_celery_brain):
     m_scan, m_session = MagicMock(), MagicMock()
     fw1, fw2 = MagicMock(), MagicMock()
     fw1.file.sha256 = "sha256file1"
     fw1.file.mimetype = "mimetypefile1"
     fw2.file.sha256 = "sha256file2"
     fw2.file.mimetype = "mimetypefile2"
     fw_list = [fw1, fw2]
     probe1, probe2 = "Probe1", "Probe2"
     probelist = [probe1, probe2]
     m_add_empty_result.return_value = probelist
     m_celery_brain.mimetype_filter_scan_request = lambda x: x
     scan_request = module._create_scan_request(fw_list, probelist, True)
     res = module._add_empty_results(fw_list, scan_request, m_scan,
                                     m_session)
     self.assertCountEqual(res.to_dict().values(),
                           scan_request.to_dict().values())
Beispiel #3
0
 def test_add_empty_results(self, m_add_empty_result, m_celery_brain):
     m_scan, m_session = MagicMock(), MagicMock()
     fw1, fw2 = MagicMock(), MagicMock()
     fw1.file.sha256 = "sha256file1"
     fw1.file.mimetype = "mimetypefile1"
     fw2.file.sha256 = "sha256file2"
     fw2.file.mimetype = "mimetypefile2"
     fw_list = [fw1, fw2]
     probe1, probe2 = "Probe1", "Probe2"
     probelist = [probe1, probe2]
     m_add_empty_result.return_value = probelist
     m_celery_brain.mimetype_filter_scan_request = lambda x: x
     scan_request = module._create_scan_request(fw_list, probelist, True)
     res = module._add_empty_results(fw_list, scan_request,
                                     m_scan, m_session)
     self.assertCountEqual(res.to_dict().values(),
                           scan_request.to_dict().values())