示例#1
0
    def test_automation_cleanup(self):

        # make sure a lock uuid is created
        start_remediation_system_manager()
        stop_remediation_system_manager()

        # insert a new work request
        remediation_id = request_remediation(REMEDIATION_TYPE_EMAIL,
                                             '<message_id>',
                                             '<recipient@localhost>',
                                             user_id=saq.test.UNITTEST_USER_ID,
                                             company_id=saq.COMPANY_ID)

        # pretend it started processing
        saq.db.execute(Remediation.__table__.update().values(
            lock=self.system.lock,
            lock_time=func.now(),
            status=REMEDIATION_STATUS_IN_PROGRESS).where(
                and_(Remediation.company_id == saq.COMPANY_ID,
                     Remediation.lock == None,
                     Remediation.status == REMEDIATION_STATUS_NEW)))
        saq.db.commit()

        # start up the system again
        start_remediation_system_manager()

        # and it should process that job
        wait_for(
            lambda: len(
                saq.db.query(Remediation).filter(
                    Remediation.id == remediation_id, Remediation.status ==
                    REMEDIATION_STATUS_COMPLETED).all()) > 0, 1, 5)

        stop_remediation_system_manager()
示例#2
0
    def test_automation_queue(self):
        manager = initialize_remediation_system_manager()
        start_remediation_system_manager()

        remediation_id = request_remediation(REMEDIATION_TYPE_TEST,
                                             '<message_id>',
                                             '<recipient@localhost>',
                                             user_id=saq.test.UNITTEST_USER_ID,
                                             company_id=saq.COMPANY_ID)
        wait_for(
            lambda: len(
                saq.db.query(Remediation).filter(
                    Remediation.id == remediation_id, Remediation.status ==
                    REMEDIATION_STATUS_COMPLETED).all()) > 0, 1, 5)

        stop_remediation_system_manager()
        saq.db.commit()

        self.assertTrue(manager.systems['test'].remediation_executed.is_set())
        self.assertEquals(
            len(
                saq.db.query(Remediation).filter(
                    Remediation.id == remediation_id,
                    Remediation.status == REMEDIATION_STATUS_COMPLETED).all()),
            1)
示例#3
0
    def test_automation_failure(self):
        manager = initialize_remediation_system_manager()
        start_remediation_system_manager()

        remediation_id = request_remediation(REMEDIATION_TYPE_TEST,
                                             '<fail>',
                                             '<recipient@localhost>',
                                             user_id=saq.test.UNITTEST_USER_ID,
                                             company_id=saq.COMPANY_ID)

        wait_for(
            lambda: len(
                saq.db.query(Remediation).filter(
                    Remediation.id == remediation_id, Remediation.status ==
                    REMEDIATION_STATUS_COMPLETED).all()) > 0, 1, 5)

        stop_remediation_system_manager()
        saq.db.commit()

        self.assertFalse(manager.systems['test'].remediation_executed.is_set())
        self.assertEquals(
            len(
                saq.db.query(Remediation).filter(
                    Remediation.id == remediation_id,
                    Remediation.status == REMEDIATION_STATUS_COMPLETED).all()),
            1)
        self.assertEquals(log_count('unable to execute remediation item'), 1)

        saq.db.commit()
        r = saq.db.query(Remediation).filter(
            Remediation.id == remediation_id).one()
        self.assertFalse(r.successful)
        self.assertTrue('forced failure' in r.result)
示例#4
0
    def test_worker_loop(self):

        # test that a single worker can work two items

        # create a single worker
        saq.CONFIG['engine']['max_concurrent_remediation_count'] = '1'

        manager = initialize_remediation_system_manager()
        start_remediation_system_manager()

        remediation_id_1 = request_remediation(
            REMEDIATION_TYPE_TEST,
            '<message_id_1>',
            '<recipient_1@localhost>',
            user_id=saq.test.UNITTEST_USER_ID,
            company_id=saq.COMPANY_ID)

        wait_for(
            lambda: len(
                saq.db.query(Remediation).filter(
                    Remediation.id == remediation_id_1, Remediation.status ==
                    REMEDIATION_STATUS_COMPLETED).all()) > 0, 1, 5)

        remediation_id_2 = request_remediation(
            REMEDIATION_TYPE_TEST,
            '<message_id_2>',
            '<recipient_2@localhost>',
            user_id=saq.test.UNITTEST_USER_ID,
            company_id=saq.COMPANY_ID)

        wait_for(
            lambda: len(
                saq.db.query(Remediation).filter(
                    Remediation.id == remediation_id_2, Remediation.status ==
                    REMEDIATION_STATUS_COMPLETED).all()) > 0, 1, 5)

        saq.db.commit()
        self.assertEquals(
            len(
                saq.db.query(Remediation).filter(
                    Remediation.id == remediation_id_1,
                    Remediation.status == REMEDIATION_STATUS_COMPLETED).all()),
            1)
        self.assertEquals(
            len(
                saq.db.query(Remediation).filter(
                    Remediation.id == remediation_id_2,
                    Remediation.status == REMEDIATION_STATUS_COMPLETED).all()),
            1)

        stop_remediation_system_manager()
示例#5
0
    def test_automation_queue(self):
        start_remediation_system_manager()
        remediation_id = request_remediation(REMEDIATION_TYPE_EMAIL,
                                             '<message_id>',
                                             '<recipient@localhost>',
                                             user_id=saq.test.UNITTEST_USER_ID,
                                             company_id=saq.COMPANY_ID)
        wait_for(
            lambda: len(
                saq.db.query(Remediation).filter(
                    Remediation.id == remediation_id, Remediation.status ==
                    REMEDIATION_STATUS_COMPLETED).all()) > 0, 1, 5)

        stop_remediation_system_manager()
示例#6
0
 def test_automation_start_stop(self):
     start_remediation_system_manager()
     stop_remediation_system_manager()