def test_delete_thread_discards_old_failed(self, mock_conf_file,
                                               mock_sleep):
        mock_conf_file.return_value = 'KEEP_FAILED=10\nKEEP_FAILED_TIMEOUT=3600'
        config.Configuration().reread()

        q = self._make_queue()
        q.addJob('refs/changes/61/65261/7', 'project', 'commit1')
        q.addJob('refs/changes/61/65262/7', 'project', 'commit2')
        with q.db.get_session() as session:
            jobs = session.query(job.Job).all()
            jobs.sort(key=lambda x: x.id)
            jobs[0].state = constants.FINISHED
            jobs[0].node_id = 1
            jobs[0].result = 'Failed'
            jobs[0].updated = time_services.now() - datetime.timedelta(hours=2)
            jobs[1].state = constants.FINISHED
            jobs[1].node_id = 2
            jobs[1].result = 'Failed'
            jobs[1].updated = time_services.now() - datetime.timedelta(
                minutes=1)
        q.nodepool.node_ids.add(1)
        q.nodepool.node_ids.add(2)

        dnt = job_queue.DeleteNodeThread(q)
        dnt._continue = mock.Mock()
        dnt._continue.side_effect = [True, False]
        dnt.run()

        jobs = job.Job.getAllWhere(q.db)
        jobs.sort(key=lambda x: x.id)
        self.assertEquals(0, jobs[0].node_id)
        self.assertEquals(2, jobs[1].node_id)
        self.assertEquals(1, len(q.nodepool.node_ids))
        self.assertIn(2, q.nodepool.node_ids)
        mock_sleep.assert_called_with(60)
    def test_delete_thread_discards_old_failed(self, mock_conf_file, mock_sleep):
        mock_conf_file.return_value = 'KEEP_FAILED=10\nKEEP_FAILED_TIMEOUT=3600'
        config.Configuration().reread()

        q = self._make_queue()
        q.addJob('refs/changes/61/65261/7', 'project', 'commit1')
        q.addJob('refs/changes/61/65262/7', 'project', 'commit2')
        with q.db.get_session() as session:
            jobs = session.query(job.Job).all()
            jobs.sort(key=lambda x: x.id)
            jobs[0].state = constants.FINISHED
            jobs[0].node_id = 1
            jobs[0].result = 'Failed'
            jobs[0].updated = time_services.now() - datetime.timedelta(hours=2)
            jobs[1].state = constants.FINISHED
            jobs[1].node_id = 2
            jobs[1].result = 'Failed'
            jobs[1].updated = time_services.now() - datetime.timedelta(minutes=1)
        q.nodepool.node_ids.add(1)
        q.nodepool.node_ids.add(2)

        dnt = job_queue.DeleteNodeThread(q)
        dnt._continue = mock.Mock()
        dnt._continue.side_effect = [True, False]
        dnt.run()
        
        jobs = job.Job.getAllWhere(q.db)
        jobs.sort(key=lambda x: x.id)
        self.assertEquals(0, jobs[0].node_id)
        self.assertEquals(2, jobs[1].node_id)
        self.assertEquals(1, len(q.nodepool.node_ids))
        self.assertIn(2, q.nodepool.node_ids)
        mock_sleep.assert_called_with(60)
示例#3
0
    def update(self, db, **kwargs):
        if self.state == constants.RUNNING and kwargs.get('state', constants.RUNNING) != constants.RUNNING:
            kwargs['test_stopped'] = time_services.now()

        if kwargs.get('state', None) == constants.RUNNING:
            kwargs['test_started'] = time_services.now()
            kwargs['test_stopped'] = None

        kwargs['updated'] = time_services.now()

        self.update_database_record(db, **kwargs)
    def update(self, db, **kwargs):
        if self.state == constants.RUNNING and kwargs.get('state', constants.RUNNING) != constants.RUNNING:
            kwargs['test_stopped'] = time_services.now()

        if kwargs.get('state', None) == constants.RUNNING:
            kwargs['test_started'] = time_services.now()
            kwargs['test_stopped'] = None

        kwargs['updated'] = time_services.now()

        self.update_database_record(db, **kwargs)
示例#5
0
    def __init__(self, env=None):
        logging.getLogger('sqlalchemy').setLevel(logging.DEBUG)
        env = env or dict()
        self.database = None
        self.queue = None

        dburl = env.get('dburl')

        if dburl:
            log.info('dburl=%s', dburl)
            self.database = db.DB(dburl)
            self.queue = job_queue.JobQueue(
                database=self.database,
                nodepool=None,
                filesystem=None,
                uploader=None,
                executor=None
            )

        self.gerrit_client = gerrit.get_client(env)
        self.event_filter = gerrit.get_filter(env)
        self.error_filter = gerrit.get_error_filter(env)
        log.info("Event filter: %s", self.event_filter)
        self.event_target = event_target.get_target(dict(env, queue=self.queue))
        self.sleep_timeout = int(env.get('sleep_timeout',
                                         self.DEFAULT_SLEEP_TIMEOUT))
        self.last_event = time_services.now()
        recent_seconds = int(env.get('recent_event_time', self.DEFAULT_EVENT_TIME))
        self.recent_event_time = datetime.timedelta(seconds=recent_seconds)
 def getRecent(cls, db, recent=24):
     recent_date = time_services.now() - datetime.timedelta(hours=recent)
     with db.get_session() as session:
         return (
             session
                 .query(cls)
                 .filter(cls.updated > recent_date)
                 .order_by(cls.updated).all()
         )
示例#7
0
 def getRecent(cls, db, recent=24):
     recent_date = time_services.now() - datetime.timedelta(hours=recent)
     with db.get_session() as session:
         return (
             session
                 .query(cls)
                 .filter(cls.updated > recent_date)
                 .order_by(cls.updated).all()
         )
 def __call__(self):
     self.gerrit_client.connect()
     self.last_event = time_services.now()
     try:
         while self.event_seen_recently():
             self.do_event_handling()
             self.sleep()
         log.info("No events seen in %s seconds" % self.recent_event_time)
     except GerritEventError as e:
         log.exception(e)
     self.gerrit_client.disconnect()
示例#9
0
 def __call__(self):
     self.gerrit_client.connect()
     self.last_event = time_services.now()
     try:
         while self.event_seen_recently():
             self.do_event_handling()
             self.sleep()
         log.info("No events seen in %s seconds" % self.recent_event_time)
     except GerritEventError as e:
         log.exception(e)
     self.gerrit_client.disconnect()
示例#10
0
 def __init__(self, change_num=None, change_ref=None, project_name=None, commit_id=None):
     self.project_name = project_name
     self.change_num = change_num
     self.change_ref = change_ref
     self.state = constants.QUEUED
     self.created = time_services.now()
     self.commit_id = commit_id
     self.node_id = None
     self.node_ip = None
     self.result = None
     self.logs_url = None
     self.report_url = None
     self.updated = self.created
 def event_seen_recently(self):
     now = time_services.now()
     return (now - self.last_event) < self.recent_event_time
 def get_event(self):
     event = self.gerrit_client.get_event()
     if event is not None:
         self.last_event = time_services.now()
     return event
示例#13
0
 def event_seen_recently(self):
     now = time_services.now()
     return (now - self.last_event) < self.recent_event_time
示例#14
0
 def get_event(self):
     event = self.gerrit_client.get_event()
     if event is not None:
         self.last_event = time_services.now()
     return event