コード例 #1
0
 def test_scan_cancel(self):
     scanid = scan_ctrl.new(self.scanid, self.userid, 10)
     for code in IrmaScanStatus.label.keys():
         scan_ctrl.error(scanid, code)
         with session_query() as session:
             scan = Scan.load(scanid, session)
             self.assertEqual(scan.status, code)
コード例 #2
0
ファイル: jobctrl.py プロジェクト: dewiestr/irma-brain
def info(job_id):
    with session_query() as session:
        job = Job.load(job_id, session)
        frontend_scan_id = job.scan.scan_id
        filename = job.filename
        probe = job.probename
        return (frontend_scan_id, filename, probe)
コード例 #3
0
ファイル: userctrl.py プロジェクト: dewiestr/irma-brain
def get_quota(user_id):
    with session_query() as session:
        user = User.load(user_id, session)
        quota = user.quota
        remaining = None
        if quota is not None:
            remaining = user.remaining_quota(session)
        return (remaining, quota)
コード例 #4
0
ファイル: test_sql.py プロジェクト: quarkslab/irma
 def test004_query_error(self, m_session):
     exception = IrmaDatabaseError
     with self.assertRaises(exception):
         with module.session_query():
             raise exception
     m_session.commit.assert_not_called()
     m_session.rollback.assert_not_called()
     m_session.close.assert_not_called()
コード例 #5
0
ファイル: test_sql.py プロジェクト: deloittem/irma-brain
 def test003_query(self, m_SQLDatabase):
     m_db_session = MagicMock()
     m_SQLDatabase.get_session.return_value = m_db_session
     with module.session_query():
         pass
     m_db_session.commit.assert_not_called()
     m_db_session.rollback.assert_not_called()
     m_db_session.close.assert_not_called()
コード例 #6
0
ファイル: test_sql.py プロジェクト: deloittem/irma-brain
 def test003_query(self, m_SQLDatabase):
     m_db_session = MagicMock()
     m_SQLDatabase.get_session.return_value = m_db_session
     with module.session_query():
         pass
     m_db_session.commit.assert_not_called()
     m_db_session.rollback.assert_not_called()
     m_db_session.close.assert_not_called()
コード例 #7
0
 def test_scan_new_status(self):
     # test we have corrects fields
     scanid = scan_ctrl.new(self.scanid, self.userid, 10)
     with session_query() as session:
         scan = Scan.load(scanid, session)
         self.assertIsNotNone(scan.timestamp)
         self.assertEqual(scan.status, IrmaScanStatus.empty)
         self.assertEqual(scan.nb_files, 10)
         self.assertIsNotNone(scan.nb_jobs)
コード例 #8
0
ファイル: test_sql.py プロジェクト: deloittem/irma-brain
 def test004_query_error(self, m_SQLDatabase):
     m_db_session = MagicMock()
     m_SQLDatabase.get_session.return_value = m_db_session
     exception = IrmaDatabaseError
     with self.assertRaises(exception):
         with module.session_query():
             raise exception
     m_db_session.commit.assert_not_called()
     m_db_session.rollback.assert_not_called()
     m_db_session.close.assert_not_called()
コード例 #9
0
ファイル: results_tasks.py プロジェクト: vaginessa/irma
def job_error(parent_taskid, file, probe):
    try:
        log.info("file:%s probe %s", file, probe)
        with session_query() as session:
            result = probe_ctrl.create_error_results(probe, "job error",
                                                     session)
            celery_frontend.scan_result(file, probe, result)
    except Exception as e:
        log.exception(e)
        raise job_error.retry(countdown=5, max_retries=3, exc=e)
コード例 #10
0
ファイル: test_sql.py プロジェクト: deloittem/irma-brain
 def test004_query_error(self, m_SQLDatabase):
     m_db_session = MagicMock()
     m_SQLDatabase.get_session.return_value = m_db_session
     exception = IrmaDatabaseError
     with self.assertRaises(exception):
         with module.session_query():
             raise exception
     m_db_session.commit.assert_not_called()
     m_db_session.rollback.assert_not_called()
     m_db_session.close.assert_not_called()
コード例 #11
0
 def test_scan_launched(self):
     scan_id = scan_ctrl.new(self.scanid, self.userid, 10)
     for i in xrange(0, 10):
         for probe in ['probe1', 'probe2']:
             job_ctrl.new(scan_id, "file-{0}".format(i), probe, 1)
     scan_ctrl.launched(scan_id)
     with session_query() as session:
         scan = Scan.load(scan_id, session)
         self.assertEqual(scan.status, IrmaScanStatus.launched)
         self.assertEqual(scan.nb_files, 10)
         self.assertEqual(scan.nb_jobs, 20)
コード例 #12
0
ファイル: scanctrl.py プロジェクト: dewiestr/irma-brain
def progress(scan_id):
    with session_query() as session:
        scan = Scan.load(scan_id, session)
        if IrmaScanStatus.is_error(scan.status):
            status_str = IrmaScanStatus.label[scan.status]
            raise IrmaValueError(status_str)
        status = IrmaScanStatus.label[scan.status]
        progress_details = None
        if scan.status == IrmaScanStatus.launched:
            (total, finished, success) = scan.progress()
            progress_details = {}
            progress_details['total'] = total
            progress_details['finished'] = finished
            progress_details['successful'] = success
        return (status, progress_details)
コード例 #13
0
 def test_user_quota_update(self):
     # test update quota
     (before, _) = user_ctrl.get_quota(self.userid)
     scanid = scan_ctrl.new(self.scanid, self.userid, 2)
     for i in xrange(0, 10):
         for probe in ['probe1', 'probe2']:
             job_ctrl.new(scanid, "file-{0}".format(i), probe, 1)
     scan_ctrl.launched(scanid)
     (after, _) = user_ctrl.get_quota(self.userid)
     self.assertEqual(before - after, 20)
     with session_query() as session:
         user = User.load(self.userid, session)
         scan_ids = [scan.id for scan in user.scans]
         self.assertNotEqual(scan_ids, [])
         self.assertTrue(scanid in scan_ids)
コード例 #14
0
 def test_scan_job_error(self):
     scan_id = scan_ctrl.new(self.scanid, self.userid, 10)
     job_ids = []
     for i in xrange(0, 10):
         for probe in ['probe1', 'probe2']:
             job_ids.append(job_ctrl.new(scan_id, "file-{0}".format(i),
                                         probe, 1))
     scan_ctrl.launched(scan_id)
     shuffle(job_ids)
     for job_id in job_ids:
         job_ctrl.error(job_id)
     self.assertTrue(scan_ctrl.check_finished(scan_id))
     with session_query() as session:
         scan = Scan.load(scan_id, session)
         self.assertEqual(scan.status, IrmaScanStatus.processed)
         self.assertEqual(scan.nb_files, 10)
         self.assertEqual(scan.nb_jobs, 20)
コード例 #15
0
ファイル: results_tasks.py プロジェクト: deloittem/irma-brain
def job_error(parent_taskid, frontend_scan_id, filename, probename):
    try:
        log.info("scanid %s: filename:%s probe %s", frontend_scan_id, filename,
                 probename)
        with session_query() as session:
            probe = Probe.get_by_name(probename, session)
            result = {}
            result['status'] = -1
            result['name'] = probe.display_name
            result['type'] = probe.category
            result['error'] = "job error"
            result['duration'] = None
            celery_frontend.scan_result(frontend_scan_id, filename, probe,
                                        result)
    except Exception as e:
        log.exception(e)
        raise job_error.retry(countdown=5, max_retries=3, exc=e)
コード例 #16
0
ファイル: scanctrl.py プロジェクト: dewiestr/irma-brain
def get_scan_id(frontend_scan_id, user_id):
    with session_query() as session:
        scan = Scan.get_scan(frontend_scan_id, user_id, session)
        return scan.id
コード例 #17
0
ファイル: scanctrl.py プロジェクト: dewiestr/irma-brain
def get_pending_jobs(scan_id):
    with session_query() as session:
        scan = Scan.load(scan_id, session)
        return scan.get_pending_jobs_taskid()
コード例 #18
0
ファイル: scanctrl.py プロジェクト: dewiestr/irma-brain
def get_nbjobs(scan_id):
    with session_query() as session:
        scan = Scan.load(scan_id, session)
        return scan.nb_jobs
コード例 #19
0
ファイル: test_sql.py プロジェクト: quarkslab/irma
 def test003_query(self, m_session):
     with module.session_query():
         pass
     m_session.commit.assert_not_called()
     m_session.rollback.assert_not_called()
     m_session.close.assert_not_called()
コード例 #20
0
ファイル: jobctrl.py プロジェクト: dewiestr/irma-brain
def duration(job_id):
    with session_query() as session:
        job = Job.load(job_id, session)
        return (job.ts_end - job.ts_start)
コード例 #21
0
ファイル: userctrl.py プロジェクト: dewiestr/irma-brain
def get_userid(rmqvhost):
    with session_query() as session:
        user = User.get_by_rmqvhost(rmqvhost, session)
        return user.id
コード例 #22
0
ファイル: userctrl.py プロジェクト: dewiestr/irma-brain
def get_ftpuser(user_id):
    with session_query() as session:
        user = User.load(user_id, session)
        return user.ftpuser