def test_delete(self): db = DB('sqlite://') db.create_schema() job = Job(change_num="change_num", project_name="project") with db.get_session() as session: session.add(job) job.db = db jobs = Job.getAllWhere(db) self.assertEqual(len(jobs), 1) Job.deleteWhere(db) jobs = Job.getAllWhere(db) self.assertEqual(len(jobs), 0)
def func_failures(options, queue): table = PrettyTable(["Project", "Change", "State", "Result", "Age", "Duration", "URL"]) table.align = 'l' now = time.time() all_jobs = Job.getAllWhere(queue.db) for job in all_jobs: if not job.result or (job.result != 'Failed' and job.result.find('Aborted') != 0): continue updated = time.mktime(job.updated.timetuple()) age_hours = (now - updated) / 3600 if options.recent: if age_hours > int(options.recent): continue age = '%.02f' % (age_hours) duration = '-' if job.test_started and job.test_stopped: started = time.mktime(job.test_started.timetuple()) stopped = time.mktime(job.test_stopped.timetuple()) duration = "%.02f"%((stopped - started)/3600) table.add_row([job.project_name, job.change_num, constants.STATES[job.state], job.result, age, duration, job.logs_url]) return str(table)
def get_jobs(self): ret_list = [] collectingJobs = Job.getAllWhere(self.jobQueue.db, state=constants.COLLECTING) for job in collectingJobs: ret_list.append(job) return ret_list
def processResults(self): allJobs = Job.getAllWhere(self.db, state=constants.RUNNING) self.log.info('%d jobs running...' % len(allJobs)) for job in allJobs: if job.isRunning(self.db): continue job.update(self.db, state=constants.COLLECTING) self.log.info('Tests for %s are done! Collecting' % job)
def processResults(self): allJobs = Job.getAllWhere(self.db, state=constants.RUNNING) self.log.info('%d jobs running...'%len(allJobs)) for job in allJobs: if job.isRunning(self.db): continue job.update(self.db, state=constants.COLLECTING) self.log.info('Tests for %s are done! Collecting'%job)
def func_show(options, queue): table = PrettyTable() table.add_column('Key', ['Project name', 'Change num', 'Change ref', 'state', 'created', 'Commit id', 'Node id', 'Node ip', 'Result', 'Logs', 'Report', 'Updated', 'Gerrit URL']) job = Job.getAllWhere(queue.db, change_ref=options.change_ref)[0] url = 'https://review.openstack.org/%s'%job.change_num table.add_column('Value', [job.project_name, job.change_num, job.change_ref, constants.STATES[job.state], job.created, job.commit_id, job.node_id, job.node_ip, job.result, job.logs_url, job.report_url, job.updated, url]) table.align = 'l' return str(table)
def func_list(options, queue): table = PrettyTable(["Project", "Change", "State", "IP", "Result", "Age (hours)", "Duration"]) table.align = 'l' now = time.time() all_jobs = Job.getAllWhere(queue.db) state_dict = {} result_dict = {} if options.states and len(options.states) > 0: states = options.states.split(',') else: states = None for job in all_jobs: updated = time.mktime(job.updated.timetuple()) age_hours = (now - updated) / 3600 if options.recent: if age_hours > int(options.recent): continue state_count = state_dict.get(constants.STATES[job.state], 0) + 1 state_dict[constants.STATES[job.state]] = state_count result_count = result_dict.get(job.result, 0)+1 result_dict[job.result] = result_count if states and constants.STATES[job.state] not in states: continue if job.node_id: node_ip = job.node_ip else: node_ip = '(%s)'%job.node_ip age = '%.02f' % (age_hours) duration = '-' if job.test_started and job.test_stopped: started = time.mktime(job.test_started.timetuple()) stopped = time.mktime(job.test_stopped.timetuple()) if started < stopped: duration = "%.02f"%((stopped - started)/3600) table.add_row([job.project_name, job.change_ref, constants.STATES[job.state], node_ip, job.result, age, duration]) output_str = str(state_dict)+"\n" output_str = output_str + str(result_dict)+"\n" output_str = output_str + str(table) return output_str
def func_show(options, queue): output_str = '' jobs = Job.getAllWhere(queue.db, change_ref=options.change_ref) for job in jobs: table = PrettyTable() table.add_column('Key', ['ID', 'Project name', 'Change num', 'Change ref', 'state', 'created', 'Commit id', 'Node id', 'Node ip', 'Result', 'Logs', 'Report', 'Updated', 'Gerrit URL', 'Failures']) url = 'https://review.openstack.org/%s'%job.change_num table.add_column('Value', [job.id, job.project_name, job.change_num, job.change_ref, constants.STATES[job.state], job.created, job.commit_id, job.node_id, job.node_ip, job.result, job.logs_url, job.report_url, job.updated, url, job.failed]) table.align = 'l' output_str = output_str + str(table)+'\n' return output_str
def postResults(self): allJobs = Job.getAllWhere(self.db, state=constants.COLLECTED) self.log.info('%d jobs ready to be posted...'%len(allJobs)) for job in allJobs: if job.result.find('Aborted') == 0: logging.info('Not voting on aborted job %s (%s)', job, job.result) job.update(self.db, state=constants.FINISHED) continue if Configuration().get_bool('VOTE'): message = Configuration().VOTE_MESSAGE % {'result':job.result, 'report': job.report_url, 'log':job.logs_url} vote_num = "+1" if job.result == 'Passed' else "-1" if ((vote_num == '+1') or (not Configuration().get_bool('VOTE_PASSED_ONLY'))): logging.info('Posting results for %s (%s)', job, job.result) vote(job.commit_id, vote_num, message) job.update(self.db, state=constants.FINISHED)
def func_show(options, queue): output_str = '' jobs = Job.getAllWhere(queue.db, change_ref=options.change_ref) for job in jobs: table = PrettyTable() table.add_column('Key', [ 'ID', 'Project name', 'Change num', 'Change ref', 'state', 'created', 'Commit id', 'Node id', 'Node ip', 'Result', 'Logs', 'Report', 'Updated', 'Gerrit URL', 'Failures' ]) url = 'https://review.openstack.org/%s' % job.change_num table.add_column('Value', [ job.id, job.project_name, job.change_num, job.change_ref, constants.STATES[job.state], job.created, job.commit_id, job.node_id, job.node_ip, job.result, job.logs_url, job.report_url, job.updated, url, job.failed ]) table.align = 'l' output_str = output_str + str(table) + '\n' return output_str
def postResults(self): allJobs = Job.getAllWhere(self.db, state=constants.COLLECTED) self.log.info("%d jobs ready to be posted..." % len(allJobs)) for job in allJobs: if job.result.find("Aborted") == 0: logging.info("Not voting on aborted job %s (%s)", job, job.result) job.update(self.db, state=constants.FINISHED) continue if Configuration().get_bool("VOTE"): message = Configuration().VOTE_MESSAGE % { "result": job.result, "report": job.report_url, "log": job.logs_url, } vote_num = "+1" if job.result == "Passed" else "-1" if (vote_num == "+1") or (not Configuration().get_bool("VOTE_PASSED_ONLY")): logging.info("Posting results for %s (%s)", job, job.result) vote(job.commit_id, vote_num, message) job.update(self.db, state=constants.FINISHED)
def postResults(self): allJobs = Job.getAllWhere(self.db, state=constants.COLLECTED) self.log.info('%d jobs ready to be posted...' % len(allJobs)) for job in allJobs: if job.result.find('Aborted') == 0: logging.info('Not voting on aborted job %s (%s)', job, job.result) job.update(self.db, state=constants.FINISHED) continue if Configuration().get_bool('VOTE'): message = Configuration().VOTE_MESSAGE % { 'result': job.result, 'report': job.report_url, 'log': job.logs_url } vote_num = "+1" if job.result == 'Passed' else "-1" if ((vote_num == '+1') or (not Configuration().get_bool('VOTE_PASSED_ONLY'))): logging.info('Posting results for %s (%s)', job, job.result) vote(job.commit_id, vote_num, message) job.update(self.db, state=constants.FINISHED)
def recheckJob(self, job_id): allJobs = Job.getAllWhere(self.db, id=job_id) for job in allJobs: self.addJob(job.change_ref, job.project_name, job.commit_id)
def get_queued_enabled_jobs(self): allJobs = Job.getAllWhere(self.db, state=constants.QUEUED) self.log.info('%d jobs queued...'%len(allJobs)) if self.jobs_enabled: return allJobs return []
def get_queued_enabled_jobs(self): allJobs = Job.getAllWhere(self.db, state=constants.QUEUED) self.log.info('%d jobs queued...' % len(allJobs)) if Configuration().get_bool('RUN_TESTS'): return allJobs return []
def triggerJob(self, job_id): allJobs = Job.getAllWhere(self.db, id=job_id) for job in allJobs: job.runJob(self.db, self.nodepool)
def get_queued_enabled_jobs(self): allJobs = Job.getAllWhere(self.db, state=constants.QUEUED) self.log.info("%d jobs queued..." % len(allJobs)) if Configuration().get_bool("RUN_TESTS"): return allJobs return []