当前位置: 首页>>代码示例>>Python>>正文


Python Job.getRecent方法代码示例

本文整理汇总了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)
开发者ID:citrix-openstack,项目名称:openstack-citrix-ci,代码行数:20,代码来源:test_job.py

示例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
开发者ID:citrix-openstack,项目名称:openstack-citrix-ci,代码行数:46,代码来源:reports.py

示例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
开发者ID:citrix-openstack,项目名称:openstack-citrix-ci,代码行数:69,代码来源:reports.py


注:本文中的osci.job.Job.getRecent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。