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)
예제 #2
0
 def __init__(self, env=None):
     env = env or dict()
     self.executor = executor.create_executor(env.get('executor'))
     config = osci_config.Configuration()
     self.node = node.Node(dict(
             node_username=config.NODE_USERNAME,
             node_host=env['node_host'],
             node_keyfile=config.NODE_KEY
         )
     )
예제 #3
0
 def __init__(self, env=None):
     env = env or dict()
     self.executor = executor.create_executor(env.get('executor'))
     self.node = node.Node(env)
     self.node.keyfile = osci_config.Configuration().NODE_KEY
     self.change_ref = env.get('change_ref')
     self.project_name = env.get('project_name')
     self.test_runner_url = env.get(
         'test_runner_url',
         'https://git.openstack.org/stackforge/xenapi-os-testing'
     )
예제 #4
0
def watch_gerrit():
    c = config.Configuration()
    env = dict(gerrit_client='pygerrit',
               gerrit_host=c.get('GERRIT_HOST'),
               event_target='queue',
               gerrit_port=c.get('GERRIT_PORT'),
               gerrit_username=c.get('GERRIT_USERNAME'),
               dburl=c.get('DATABASE_URL'),
               comment_re=c.get('RECHECK_REGEXP'),
               ignore_usernames=c.get('IGNORE_USERNAMES'),
               projects=c.get('PROJECT_CONFIG'),
               recent_event_time=c.get('GERRIT_EVENT_TIMEOUT'),
               sleep_timeout=c.get('POLL'))
    sys.exit(run_command(commands.WatchGerrit, env=env))
    def test_delete_thread_keep_none(self, mock_conf_file, mock_sleep):
        mock_conf_file.return_value = 'KEEP_FAILED=0'
        config.Configuration().reread()

        q = self._make_queue()
        q.addJob('refs/changes/61/65261/7', 'project', 'commit1')
        with q.db.get_session() as session:
            jobs = session.query(job.Job).all()
            jobs[0].state = constants.FINISHED
            jobs[0].node_id = 1
            jobs[0].result = 'Failed'
        q.nodepool.node_ids.add(1)

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

        job1, = job.Job.getAllWhere(q.db)
        self.assertEquals(0, job1.node_id)
        self.assertEquals(0, len(q.nodepool.node_ids))
        mock_sleep.assert_called_with(60)
예제 #6
0
 def setUp(self):
     # Always start with a blank config otherwise
     # the mocked tests might pollute the happy path
     self.conf = config.Configuration()
     self.conf.reread()
예제 #7
0
def create_dbschema():
    env = dict(dburl=config.Configuration().get('DATABASE_URL'))
    sys.exit(run_command(commands.CreateDBSchema, env=env))