本文整理汇总了Python中osci.job.Job.getRecent方法的典型用法代码示例。如果您正苦于以下问题:Python Job.getRecent方法的具体用法?Python Job.getRecent怎么用?Python Job.getRecent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osci.job.Job
的用法示例。
在下文中一共展示了Job.getRecent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_recent_jobs
# 需要导入模块: from osci.job import Job [as 别名]
# 或者: from osci.job.Job import getRecent [as 别名]
def test_recent_jobs(self, now):
now.return_value = NOW
db = DB('sqlite://')
db.create_schema()
job1 = Job(change_num="change_num1", project_name="project")
job2 = Job(change_num="change_num2", project_name="project")
with db.get_session() as session:
session.add(job1)
job1.created=PAST
job1.db = db
job1.state=constants.RUNNING
job1.updated=PAST
session.add(job2)
recent_jobs = Job.getRecent(db)
self.assertEqual(len(recent_jobs), 1)
recent_jobs = Job.getRecent(db, 200000)
self.assertEqual(len(recent_jobs), 2)
示例2: func_list
# 需要导入模块: from osci.job import Job [as 别名]
# 或者: from osci.job.Job import getRecent [as 别名]
def func_list(options, queue):
table = PrettyTable(["ID", "Project", "Change", "State", "IP", "Result",
"Age (hours)", "Duration"])
table.align = 'l'
now = time.time()
all_jobs = Job.getRecent(queue.db, int(options.recent))
state_dict = {}
result_dict = {}
if options.states and len(options.states) > 0:
states = options.states.split(',')
else:
# Default should be everything except obsolete jobs
states = constants.STATES.values()
states.remove(constants.STATES[constants.OBSOLETE])
for job in all_jobs:
updated = time.mktime(job.updated.timetuple())
age_hours = (now - updated) / 3600
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.id, 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
示例3: func_failures
# 需要导入模块: from osci.job import Job [as 别名]
# 或者: from osci.job.Job import getRecent [as 别名]
def func_failures(options, queue):
output_str = ''
table = PrettyTable(["ID", "Project", "Change", "State", "Result", "Age",
"Duration", "URL"])
table.align = 'l'
now = time.time()
all_jobs = Job.getRecent(queue.db, int(options.recent))
all_failed_tests = {}
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
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)
job_failed = job.failed if job.failed is not None else ''
failed_tests = [m.group(0) for m in re.finditer('tempest.[^ ()]+', job_failed)]
if options.withfail is not None:
if len(options.withfail) == 0:
if len(failed_tests) != 0:
continue
else:
if options.withfail not in job.failed:
continue
table.add_row([job.id, job.project_name, job.change_num,
constants.STATES[job.state], job.result, age,
duration, job.logs_url])
if len(failed_tests) == 0:
failed_tests = ['No tempest failures detected']
elif int(options.max_fails) > 0 and len(failed_tests) > int(options.max_fails):
failed_tests = ['More than %s failures'%options.max_fails]
for failed_test in failed_tests:
# Treat JSON and XML as the same since we're only interested in driver failures
failed_test = failed_test.replace('JSON', '')
failed_test = failed_test.replace('XML', '')
cur_count = all_failed_tests.get(failed_test, 0)
all_failed_tests[failed_test] = cur_count + 1
if options.min_dup:
msg='Fewer than %s duplicates'%options.min_dup
for failed_test in list(all_failed_tests.keys()):
if all_failed_tests[failed_test] < int(options.min_dup):
cur_count = all_failed_tests.get(msg, 0)
all_failed_tests[msg] = cur_count + 1
del all_failed_tests[failed_test]
output_str += str(table) + '\n'
output_str += '\n'
output_str += 'Failures\n'
output_str += '-------------------\n'
single_count =0
sorted_tests = sorted(all_failed_tests, key=all_failed_tests.get, reverse=True)
for failed_test in sorted_tests:
output_str += "%3d %s\n"%(all_failed_tests[failed_test], failed_test)
return output_str