Ejemplo n.º 1
0
def run(args):
    # entry point for the command line
    import getopt
    options, value = getopt.gnu_getopt(args, 'h:p:c:o:')

    query_dict = {}

    if len(value) < 1:
        sys.stderr.write("must specify test_run\n")
        return 1

    output = sys.stdout

    for x, y in options:
        if x == '-c':
            query_dict['context'] = y
        elif x == '-h':
            query_dict['host'] = y
        elif x == '-m':
            query_dict['custom'] = y
        elif x == '-o':
            output = open(y, "w")
        elif x == '-p':
            query_dict['project'] = y

    for name in value:
        name = common.find_test_run(value[0])
        c = pdk_db.execute(
            'SELECT test_run FROM distinct_test_run WHERE test_run LIKE :1 ORDER BY test_run',
            (name,
             ))
        for test_run in c:
            test_run = test_run[0]
            sys.stderr.write('test_run %s\n' % test_run)
            query_dict['test_run'] = test_run
            where_text, where_dict = pdk_db.where_dict(
                [(x, query_dict[x]) for x in query_dict])

            do_export(output, where_text, where_dict)
Ejemplo n.º 2
0
def run(args):

    spec = {
        '-v': '',
        '-h': '=+',
        '-p': '=+',
        '-c': '=+',

        '--help': '',

        '--host': '-h',
        '--project': '-p',
        '--context': '-c',
        '--verbose': '-v',     # arg is an alias for some other arg
        '-help': '--help',
    }

    opt, args = easyargs.get(spec, args)

    if opt['--help']:
        print(__doc__)
        return

    verbose = opt['-v']

    try:
        test_run_type = args[0]
        test_run = args[1]
    except:
        print("\ncan't get args, try:\n    pdk check_expected --help\n")
        return 1

    # normalize the test run, so they can say stuff like "daily_latest"
    test_run = common.find_test_run(test_run)

    print("TYPE %s" % test_run_type)
    print("test_run %s" % test_run)

    if test_run.endswith('latest'):
        print("this test run name is probably a mistake")
        return 1

    # construct the query for the set of tests that we are expecting

    select_args = [('test_run_type', test_run_type)]

    if '-h' in opt:
        select_args.append(('host', opt['-h']))
    if '-p' in opt:
        select_args.append(('project', opt['-p']))
    if '-c' in opt:
        select_args.append(('context', opt['-c']))

    where_text, where_dict = pdk_db.where_dict(select_args)

    s = "SELECT project, host, test_name, context FROM expected %s " % where_text

    if verbose > 1:
        print(s)
        print(where_dict)

    # perform the query

    c = pdk_db.execute(s, where_dict)

    if verbose > 1:
        print("query done")

    # check each test reported in the query result

    detected = 0

    for (project, host, test_name, context) in c:
        if verbose > 2:
            print("CHECK %s %s %s" % (project, host, test_name))

        c1 = pdk_db.execute("""SELECT status FROM result_scalar
                WHERE test_run = :1 AND project = :2 AND host = :3 AND
                test_name = :4 AND context = :5 """,
                            (test_run, project, host, test_name, context)
                            )

        if c1.fetchone() is None:
            # it wasn't there
            if verbose:
                print("        MISSING: %s %s %s" % (project, host, test_name))
            pdk_db.execute(
                """INSERT INTO result_scalar
                ( test_run, project, host, context, test_name, status, attn )
                VALUES ( :1, :2, :3, :4, :5, :6, :7 )""",
                (test_run,
                 project,
                 host,
                 context,
                 test_name,
                 'M',
                 'Y'))
            detected = detected + 1

            # do some commits from time to time to avoid lock timeouts
            if detected % 10000 == 0:
                pdk_db.commit()

    # must commit after db updates

    pdk_db.commit()

    print("detected %d" % detected)
Ejemplo n.º 3
0
def run(args):

    spec = {
        '-v': '',
        '-h': '=+',
        '-p': '=+',
        '-c': '=+',
        '--help': '',
        '--host': '-h',
        '--project': '-p',
        '--context': '-c',
        '--verbose': '-v',  # arg is an alias for some other arg
        '-help': '--help',
    }

    opt, args = easyargs.get(spec, args)

    if opt['--help']:
        print __doc__
        return

    verbose = opt['-v']

    try:
        test_run_type = args[0]
        test_run = args[1]
    except:
        print "\ncan't get args, try:\n    pdk check_expected --help\n"
        return 1

    # normalize the test run, so they can say stuff like "daily_latest"
    test_run = common.find_test_run(test_run)

    print "TYPE ", test_run_type
    print "test_run", test_run

    if test_run.endswith('latest'):
        print "this test run name is probably a mistake"
        return 1

    # construct the query for the set of tests that we are expecting

    select_args = [('test_run_type', test_run_type)]

    if '-h' in opt:
        select_args.append(('host', opt['-h']))
    if '-p' in opt:
        select_args.append(('project', opt['-p']))
    if '-c' in opt:
        select_args.append(('context', opt['-c']))

    where_text, where_dict = pdk_db.where_dict(select_args)

    s = "SELECT project, host, test_name, context FROM expected %s " % where_text

    if verbose > 1:
        print s
        print where_dict

    # perform the query

    c = pdk_db.execute(s, where_dict)

    if verbose > 1:
        print "query done"

    # check each test reported in the query result

    detected = 0

    for (project, host, test_name, context) in c:
        if verbose > 2:
            print "CHECK", project, host, test_name

        c1 = pdk_db.execute(
            """SELECT status FROM result_scalar 
                WHERE test_run = :1 AND project = :2 AND host = :3 AND 
                test_name = :4 AND context = :5 """,
            (test_run, project, host, test_name, context))

        if c1.fetchone() is None:
            # it wasn't there
            if verbose:
                print "        MISSING:", project, host, test_name
            pdk_db.execute(
                """INSERT INTO result_scalar 
                ( test_run, project, host, context, test_name, status, attn ) 
                VALUES ( :1, :2, :3, :4, :5, :6, :7 )""",
                (test_run, project, host, context, test_name, 'M', 'Y'))
            detected = detected + 1

            # do some commits from time to time to avoid lock timeouts
            if detected % 10000 == 0:
                pdk_db.commit()

    # must commit after db updates

    pdk_db.commit()

    print "detected ", detected
Ejemplo n.º 4
0
def gen_daily_table(test_run,
                    projects,
                    query_context,
                    query_host,
                    valuable=0,
                    chronic=False):

    # chronic is true if we should do the chronic column, false otherwise

    # convert special names, e.g. daily_latest to the name of the latest daily_*
    test_run = common.find_test_run(test_run)

    #
    show_delete = not valuable
    if show_delete:
        my_run_prefix = 'user_' + common.current_user()
        if test_run.startswith(my_run_prefix):
            del_text = '(del)'
        else:
            if common.current_user() in common.cfg.admin_user_list:
                del_text = '<font color=gray>(del)</font>'
            else:
                show_delete = False

    # this is the skeleton of the cgi queries for various links
    query = {"test_run": test_run}

    # This is a single table for all projects, because we want the
    # pass/fail/error columns to be aligned from one to the next
    #
    table = text_table.text_table()

    # The texttable object doesn't understand colspans, but we hack a
    # colspan into it anyway.  Thee result is ugly if you have borders.

    table.set_html_table_attributes("cellpadding=2 ")

    status_types = common.cfg.statuses

    row = 0
    table.define_column("host")
    table.define_column("context")
    table.define_column("os")
    table.define_column("total")
    for x in status_types:
        table.define_column(x)
    if chronic:
        table.define_column("chronic")
    table.define_column("del")
    table.define_column("note")

    n_cols = 3 + len(status_types) + 2

    #   #   #   #   #   #   #   #   #   #
    # loop across hosts
    prev_project = None

    all_sum = {'total': 0, 'chronic': 0}
    for status in status_types:
        all_sum[status] = 0

    hc_where, hc_where_dict = pdk_db.where_dict([('test_run', test_run),
                                                 ('project', projects),
                                                 ('context', query_context),
                                                 ('host', query_host)])
    c = pdk_db.execute(
        "SELECT DISTINCT project, host, context FROM result_scalar %s ORDER BY project, host, context "
        % hc_where, hc_where_dict)

    if chronic:
        chronic_str = "AND ( chronic = '0' or chronic IS NULL )"
    else:
        chronic_str = ""

    # now we forget the list of projects that came in and construct a
    # list of projects that we actually saw.
    projects = []
    for project, host, context in c:

        ## make a new project section of the table
        if project != prev_project:

            projects.append(project)

            table.set_value(row, 0, "")

            prev_project = project

            # values common to all the links we will write in this pass through the loop
            query["project"] = project
            query["host"] = "%"

            # this link text is common to all the links for this project
            link = common.selflink(query_dict=query, linkmode="treewalk")

            # the heading for a project subsection of the table
            project_text = cgi.escape(project)
            project_text = '<hr><big><strong><b><a name="%s" href="%s">%s</a></b></strong></big>' % (
                project_text, link, project_text)
            table.set_value(row, 0, text=project, html=project_text)
            table.set_html_cell_attributes(row, 0, "colspan=%d" % n_cols)
            row += 1

            # the column headings for this project's part of the table
            insert_col_headings(table, row, link, chronic)
            row += 1

            # This will be the sum of all the tests in a particular project.
            # It comes just under the headers for the project, but we don't
            # know the values until the end.
            project_sum = {'total': 0, 'chronic': 0}
            for status in status_types:
                project_sum[status] = 0

            project_sum_row = row

            # delete entire project from the test run
            if show_delete:
                table.set_value(row,
                                'del',
                                html=del_text,
                                link=delete_link(
                                    {
                                        'test_run': test_run,
                                        'project': project
                                    }, show_delete))

            row += 1

            prev_host = None

        # a new host/contest line
        query["host"] = host

        link = common.selflink(query_dict=query, linkmode="treewalk")

        if host != prev_host:
            table.set_value(row, 0, text=host, link=link)
            prev_host = host

        query['context'] = context
        link = common.selflink(query_dict=query, linkmode="treewalk")
        del query['context']
        table.set_value(row, 1, text=context, link=link)

        # delete entire project from the test run
        if show_delete:
            table.set_value(row,
                            'del',
                            html=del_text,
                            link=delete_link(
                                {
                                    'test_run': test_run,
                                    'project': project,
                                    'host': host,
                                    'context': context
                                }, show_delete))

        # show the host info
        hinfo = pandokia.common.hostinfo(host)
        table.set_value(row,
                        2,
                        text=hinfo[1],
                        link=common.selflink(query_dict={'host': host},
                                             linkmode='hostinfo'))

        total_results = 0
        missing_count = 0
        for status in status_types:
            # use "or chronic is null" until we update the database for the new schema.
            c1 = pdk_db.execute(
                "SELECT COUNT(*) FROM result_scalar WHERE  test_run = :1 AND project = :2 AND host = :3 AND status = :4 AND context = :5 %s"
                % (chronic_str, ), (test_run, project, host, status, context))
            (x, ) = c1.fetchone()
            total_results += x
            project_sum[status] += x
            all_sum[status] += x
            if x == 0:
                table.set_value(row, status, text='0')
            else:
                table.set_value(row,
                                status,
                                text=str(x),
                                link=link + "&status=" + status)
            table.set_html_cell_attributes(row, status, 'align="right"')

            if status == 'M':
                missing_count = x

        if chronic:
            c1 = pdk_db.execute(
                "SELECT COUNT(*) FROM result_scalar WHERE  test_run = :1 AND project = :2 AND host = :3 AND context = :5 AND chronic = '1'",
                (test_run, project, host, status, context))
            (x, ) = c1.fetchone()
            total_results += x
            project_sum['chronic'] += x
            all_sum['chronic'] += x
            table.set_value(row,
                            'chronic',
                            text=str(x),
                            link=link + "&chronic=1")
            table.set_html_cell_attributes(row, 'chronic', 'align="right"')

        project_sum['total'] += total_results
        all_sum['total'] += total_results

        if 0 and 'M' in status_types:
            # not sure how to deal with this in the presence of chronic problem tests

            if missing_count != 0:
                if missing_count == total_results:
                    # if it equals the total, then everything is missing; we make a note of that
                    table.set_value(row, 'note', 'all missing')
                else:
                    # only some of them are missing
                    table.set_value(row, 'note', 'some missing')

        table.set_value(row, 'total', text=str(total_results), link=link)
        table.set_html_cell_attributes(row, 'total', 'align="right"')

        row = row + 1

        for status in status_types:
            table.set_value(project_sum_row, status, project_sum[status])
            table.set_html_cell_attributes(
                project_sum_row, status,
                'align="right" style="font-weight:bold"')

        table.set_value(project_sum_row, 'total', project_sum['total'])
        table.set_html_cell_attributes(
            project_sum_row, 'total', 'align="right" style="font-weight:bold"')

        # insert this blank line between projects - keeps the headings away from the previous row
        table.set_value(row, 0, "")

    # insert a total for everything
    table.set_value(row, 0, html='<hr>')
    table.set_html_cell_attributes(row, 0, "colspan=%d" % n_cols)

    row = row + 1
    insert_col_headings(table, row, None, chronic)

    row = row + 1
    total_row = row

    query['host'] = '*'
    query['project'] = projects
    query['host'] = query_host
    query['context'] = query_context

    table.set_value(total_row,
                    'total',
                    text=str(all_sum['total']),
                    link=common.selflink(query_dict=query,
                                         linkmode="treewalk"))
    table.set_html_cell_attributes(row, 'total', 'align="right"')

    for status in status_types:
        query['status'] = status
        table.set_value(total_row,
                        status,
                        all_sum[status],
                        link=common.selflink(query_dict=query,
                                             linkmode="treewalk"))
        table.set_html_cell_attributes(total_row, status, 'align="right"')

    return (table, projects)
Ejemplo n.º 5
0
def rpt2():

    form = pandokia.pcgi.form

    if form.has_key("test_run"):
        test_run = form["test_run"].value
    else:
        # no parameter?  I think somebody is messing with us...
        # no matter - just give them a the list of all the test_runs
        rpt1()
        return

    #
    test_run = common.find_test_run(test_run)

    # create list of projects
    projects = None
    host = None
    context = None
    chronic = '0'

    if form.has_key("project"):
        projects = form.getlist("project")

    if form.has_key("host"):
        host = form.getlist("host")

    if form.has_key("context"):
        context = form.getlist("context")

    if form.has_key("chronic"):
        chronic = form.getlist("chronic")[0]

    c = pdk_db.execute(
        "SELECT note, valuable FROM distinct_test_run WHERE test_run = :1",
        (test_run, ))
    x = c.fetchone()
    if x is None:
        sys.stdout.write(common.cgi_header_html)
        sys.stdout.write(common.page_header())
        sys.stdout.write('No such test run')
        return

    test_run_note, test_run_valuable = x
    if test_run_note is None:
        test_run_note = ''
    if test_run_valuable is None:
        test_run_valuable = 0
    else:
        test_run_valuable = int(test_run_valuable)

    # create the actual table
    (table, projects) = gen_daily_table(test_run,
                                        projects,
                                        context,
                                        host,
                                        valuable=test_run_valuable,
                                        chronic=chronic == '1')

    # # # # # # # # # #
    if pandokia.pcgi.output_format == 'html':

        header = "<big><big><b>" + cgi.escape(test_run) + "</b></big></big>\n"

        if 1:
            # if it looks like there is a date in it, try to show the day of the week
            # dates must look like 2011-01-01 and do not occur at the beginning of the name
            t = common.looks_like_a_date(test_run)
            try:
                import datetime
                t = t.group(1).split('-')
                (year, month, day) = (int(t[0]), int(t[1]), int(t[2]))
                t = datetime.date(year, month, day)
                t = t.strftime("%A")
                header = header + "<big>(" + str(t) + ")</big>"
            except:
                pass

        header = header + "<p>"

        recurring_prefix = common.recurring_test_run(test_run)
        if recurring_prefix:
            #
            # If we have a recurring run, create a special header.

            # Include links to the previous / next in the sequence

            l = []
            prev = common.run_previous(recurring_prefix, test_run)
            if prev:
                l.append(
                    common.self_href(query_dict={'test_run': prev},
                                     linkmode='day_report.2',
                                     text=prev))

            next = common.run_next(recurring_prefix, test_run)
            if next:
                l.append(
                    common.self_href(query_dict={'test_run': next},
                                     linkmode='day_report.2',
                                     text=next))

            latest = common.run_latest(recurring_prefix)
            if latest and (latest != next) and (latest != test_run):
                l.append(
                    common.self_href(query_dict={'test_run': latest},
                                     linkmode='day_report.2',
                                     text=latest))

            header = header + '( %s )' % (' / '.join(l))

        if 1:
            if test_run_note.startswith('*'):
                header = header + '<p>\nNote: %s</p>' % (
                    cgi.escape(test_run_note))
            else:
                header = header + '<p><form action=%s>\nNote: <input type=text name=note value="%s" size=%d>\n<input type=hidden name=test_run value="%s">\n<input type=hidden name=query value=action></form></p>' % (
                    common.get_cgi_name(), cgi.escape(test_run_note),
                    len(test_run_note) + 20, test_run)

            if test_run_valuable:
                header = header + '<p>valuable '
            else:
                header = header + '<p>not valuable '
            header = header + '(<a href=%s>change</a>)' % (common.selflink(
                {
                    'test_run': test_run,
                    'valuable_run': int(not test_run_valuable)
                },
                linkmode='action'))

        sys.stdout.write(common.cgi_header_html)
        sys.stdout.write(common.page_header())
        sys.stdout.write(header)

        # write links to the top of each project
        sys.stdout.write('<p>\n')
        for p in projects:
            p = cgi.escape(p)
            sys.stdout.write('<a href="#%s">%s</a>&nbsp;&nbsp; ' % (p, p))
        sys.stdout.write('</p>\n')

        # write the report table
        sys.stdout.write(table.get_html(headings=0))

    elif pandokia.pcgi.output_format == 'csv':
        sys.stdout.write(common.cgi_header_csv)
        sys.stdout.write(table.get_csv())
Ejemplo n.º 6
0
def run():

    sys.stdout.write(common.cgi_header_html)
    sys.stdout.write(common.page_header())

    form = pandokia.pcgi.form

    if "test_name" in form:
        test_name = form.getvalue("test_name")
    else:
        test_name = ""

    if "context" in form:
        context = form.getvalue("context")
    else:
        context = "*"

    if "custom" in form:
        custom = form.getvalue("custom")
    else:
        custom = "*"

    if "host" in form:
        host = form.getvalue("host")
    else:
        host = "*"

    if "test_run" in form:
        test_run = form.getvalue("test_run")
    else:
        test_run = "*"

    if "project" in form:
        project = form.getvalue("project")
    else:
        project = "*"

    if "status" in form:
        status = form.getvalue("status")
    else:
        status = "*"

    if "test_name" in form:
        cmp_run = form.getvalue("test_name")
        if cmp_run == '':
            cmp_run = common.run_previous(None, test_run)
            if cmp_run is not None:
                cmp_run = common.find_test_run(cmp_run)
            else:
                cmp_run = ''
        else:
            cmp_run = common.find_test_run(cmp_run)
    else:
        cmp_run = ""

    if "key_id" in form:
        key_id = form.getvalue("key_id")
    else:
        key_id = ""

    if "qid" in form:
        qid = form.getvalue("qid")
    else:
        qid = ""

    #
    # main heading
    #

    sys.stdout.write("<h1>Test detail</h1>\n")

    #
    # this query finds all the test results that are an interesting part of this request
    #

    if key_id != "":
        n = do_result(key_id)
    elif qid != "":
        c1 = pdk_db.execute("SELECT key_id FROM query WHERE qid = :1 ",
                            (qid, ))
        l = []
        for x in c1:
            l.append(x[0])
        del c1
        n = 0
        for key_id in l:
            n = n + do_result(key_id)
    else:
        c1 = pdk_db.execute(
            "SELECT key_id FROM result_scalar WHERE test_run = :1 AND project = :2 AND host = :3 AND test_name = :4 AND context = :5 AND custom = :6 ",
            (test_run, project, host, test_name, context, custom))
        n = 0
        for x in c1:
            (key_id, ) = x
            n = n + do_result(key_id)

    if n == 0:
        sys.stdout.write("no tests match\n")
        d_in = {
            'project': project,
            'host': host,
            'context': context,
            'custom': custom,
            'test_run': test_run,
            'test_name': test_name
        }
        t = next_prev(d_in, test_run)
        if t != '':
            sys.stdout.write(t)
Ejemplo n.º 7
0
def run():

    sys.stdout.write(common.cgi_header_html)
    sys.stdout.write(common.page_header())

    form = pandokia.pcgi.form

    if "test_name" in form:
        test_name = form.getvalue("test_name")
    else:
        test_name = ""

    if "context" in form:
        context = form.getvalue("context")
    else:
        context = "*"

    if "host" in form:
        host = form.getvalue("host")
    else:
        host = "*"

    if "test_run" in form:
        test_run = form.getvalue("test_run")
    else:
        test_run = "*"

    if "project" in form:
        project = form.getvalue("project")
    else:
        project = "*"

    if "status" in form:
        status = form.getvalue("status")
    else:
        status = "*"

    if "test_name" in form:
        cmp_run = form.getvalue("test_name")
        if cmp_run == '':
            cmp_run = common.run_previous(None, test_run)
            if cmp_run is not None:
                cmp_run = common.find_test_run(cmp_run)
            else:
                cmp_run = ''
        else:
            cmp_run = common.find_test_run(cmp_run)
    else:
        cmp_run = ""

    if "key_id" in form:
        key_id = form.getvalue("key_id")
    else:
        key_id = ""

    if "qid" in form:
        qid = form.getvalue("qid")
    else:
        qid = ""

    #
    # main heading
    #

    sys.stdout.write("<h1>Test detail</h1>\n")

    #
    # this query finds all the test results that are an interesting part of this request
    #

    if key_id != "":
        n = do_result(key_id)
    elif qid != "":
        c1 = pdk_db.execute("SELECT key_id FROM query WHERE qid = :1 ", (qid,))
        l = []
        for x in c1:
            l.append(x[0])
        del c1
        n = 0
        for key_id in l:
            n = n + do_result(key_id)
    else:
        c1 = pdk_db.execute(
            "SELECT key_id FROM result_scalar WHERE test_run = :1 AND project = :2 AND host = :3 AND test_name = :4 AND context = :5 ",
            (test_run,
             project,
             host,
             test_name,
             context))
        n = 0
        for x in c1:
            (key_id, ) = x
            n = n + do_result(key_id)

    if n == 0:
        sys.stdout.write("no tests match\n")
        d_in = {
            'project': project,
            'host': host,
            'context': context,
            'test_run': test_run,
            'test_name': test_name}
        t = next_prev(d_in, test_run)
        if t != '':
            sys.stdout.write(t)
Ejemplo n.º 8
0
def gen_daily_table(
        test_run,
        projects,
        query_context,
        query_host,
        valuable=0,
        chronic=False):

    # chronic is true if we should do the chronic column, false otherwise

    # convert special names, e.g. daily_latest to the name of the latest
    # daily_*
    test_run = common.find_test_run(test_run)

    #
    show_delete = not valuable
    if show_delete:
        my_run_prefix = 'user_' + common.current_user()
        if test_run.startswith(my_run_prefix):
            del_text = '(del)'
        else:
            if common.current_user() in common.cfg.admin_user_list:
                del_text = '<font color=gray>(del)</font>'
            else:
                show_delete = False

    # this is the skeleton of the cgi queries for various links
    query = {"test_run": test_run}

    # This is a single table for all projects, because we want the
    # pass/fail/error columns to be aligned from one to the next
    #
    table = text_table.text_table()

    # The texttable object doesn't understand colspans, but we hack a
    # colspan into it anyway.  Thee result is ugly if you have borders.

    table.set_html_table_attributes("cellpadding=2 ")

    status_types = common.cfg.statuses

    row = 0
    table.define_column("host")
    table.define_column("context")
    table.define_column("os")
    table.define_column("total")
    for x in status_types:
        table.define_column(x)
    if chronic:
        table.define_column("chronic")
    table.define_column("del")
    table.define_column("note")

    n_cols = 3 + len(status_types) + 2

#   #   #   #   #   #   #   #   #   #
    # loop across hosts
    prev_project = None

    all_sum = {'total': 0, 'chronic': 0}
    for status in status_types:
        all_sum[status] = 0

    hc_where, hc_where_dict = pdk_db.where_dict(
        [('test_run', test_run), ('project', projects), ('context', query_context), ('host', query_host)])
    c = pdk_db.execute(
        "SELECT DISTINCT project, host, context FROM result_scalar %s ORDER BY project, host, context " %
        hc_where, hc_where_dict)

    if chronic:
        chronic_str = "AND ( chronic = '0' or chronic IS NULL )"
    else:
        chronic_str = ""

    # now we forget the list of projects that came in and construct a
    # list of projects that we actually saw.
    projects = []
    for project, host, context in c:

        # make a new project section of the table
        if project != prev_project:

            projects.append(project)

            table.set_value(row, 0, "")

            prev_project = project

            # values common to all the links we will write in this pass through
            # the loop
            query["project"] = project
            query["host"] = "%"

            # this link text is common to all the links for this project
            link = common.selflink(query_dict=query, linkmode="treewalk")

            # the heading for a project subsection of the table
            project_text = cgi.escape(project)
            project_text = '<hr><big><strong><b><a name="%s" href="%s">%s</a></b></strong></big>' % (
                project_text, link, project_text)
            table.set_value(row, 0, text=project, html=project_text)
            table.set_html_cell_attributes(row, 0, "colspan=%d" % n_cols)
            row += 1

            # the column headings for this project's part of the table
            insert_col_headings(table, row, link, chronic)
            row += 1

            # This will be the sum of all the tests in a particular project.
            # It comes just under the headers for the project, but we don't
            # know the values until the end.
            project_sum = {'total': 0, 'chronic': 0}
            for status in status_types:
                project_sum[status] = 0

            project_sum_row = row

            # delete entire project from the test run
            if show_delete:
                table.set_value(row, 'del', html=del_text, link=delete_link(
                    {'test_run': test_run, 'project': project}, show_delete))

            row += 1

            prev_host = None

        # a new host/contest line
        query["host"] = host

        link = common.selflink(query_dict=query, linkmode="treewalk")

        if host != prev_host:
            table.set_value(row, 0, text=host, link=link)
            prev_host = host

        query['context'] = context
        link = common.selflink(query_dict=query, linkmode="treewalk")
        del query['context']
        table.set_value(row, 1, text=context, link=link)

        # delete entire project from the test run
        if show_delete:
            table.set_value(row,
                            'del',
                            html=del_text,
                            link=delete_link({'test_run': test_run,
                                              'project': project,
                                              'host': host,
                                              'context': context},
                                             show_delete))

        # show the host info
        hinfo = pandokia.common.hostinfo(host)
        table.set_value(
            row,
            2,
            text=hinfo[1],
            link=common.selflink(
                query_dict={
                    'host': host},
                linkmode='hostinfo'))

        total_results = 0
        missing_count = 0
        for status in status_types:
            # use "or chronic is null" until we update the database for the new
            # schema.
            c1 = pdk_db.execute(
                "SELECT COUNT(*) FROM result_scalar WHERE  test_run = :1 AND project = :2 AND host = :3 AND status = :4 AND context = :5 %s" %
                (chronic_str, ), (test_run, project, host, status, context))
            (x,) = c1.fetchone()
            total_results += x
            project_sum[status] += x
            all_sum[status] += x
            if x == 0:
                table.set_value(row, status, text='0')
            else:
                table.set_value(
                    row,
                    status,
                    text=str(x),
                    link=link +
                    "&status=" +
                    status)
            table.set_html_cell_attributes(row, status, 'align="right"')

            if status == 'M':
                missing_count = x

        if chronic:
            c1 = pdk_db.execute(
                "SELECT COUNT(*) FROM result_scalar WHERE  test_run = :1 AND project = :2 AND host = :3 AND context = :5 AND chronic = '1'",
                (test_run,
                 project,
                 host,
                 status,
                 context))
            (x,) = c1.fetchone()
            total_results += x
            project_sum['chronic'] += x
            all_sum['chronic'] += x
            table.set_value(
                row,
                'chronic',
                text=str(x),
                link=link +
                "&chronic=1")
            table.set_html_cell_attributes(row, 'chronic', 'align="right"')

        project_sum['total'] += total_results
        all_sum['total'] += total_results

        if 0 and 'M' in status_types:
            # not sure how to deal with this in the presence of chronic problem
            # tests

            if missing_count != 0:
                if missing_count == total_results:
                    # if it equals the total, then everything is missing; we
                    # make a note of that
                    table.set_value(row, 'note', 'all missing')
                else:
                    # only some of them are missing
                    table.set_value(row, 'note', 'some missing')

        table.set_value(row, 'total', text=str(total_results), link=link)
        table.set_html_cell_attributes(row, 'total', 'align="right"')

        row = row + 1

        for status in status_types:
            table.set_value(project_sum_row, status, project_sum[status])
            table.set_html_cell_attributes(
                project_sum_row, status, 'align="right" style="font-weight:bold"')

        table.set_value(project_sum_row, 'total', project_sum['total'])
        table.set_html_cell_attributes(
            project_sum_row,
            'total',
            'align="right" style="font-weight:bold"')

        # insert this blank line between projects - keeps the headings away
        # from the previous row
        table.set_value(row, 0, "")

    # insert a total for everything
    table.set_value(row, 0, html='<hr>')
    table.set_html_cell_attributes(row, 0, "colspan=%d" % n_cols)

    row = row + 1
    insert_col_headings(table, row, None, chronic)

    row = row + 1
    total_row = row

    query['host'] = '*'
    query['project'] = projects
    query['host'] = query_host
    query['context'] = query_context

    table.set_value(total_row, 'total', text=str(all_sum['total']),
                    link=common.selflink(query_dict=query, linkmode="treewalk")
                    )
    table.set_html_cell_attributes(row, 'total', 'align="right"')

    for status in status_types:
        query['status'] = status
        table.set_value(
            total_row,
            status,
            all_sum[status],
            link=common.selflink(
                query_dict=query,
                linkmode="treewalk"))
        table.set_html_cell_attributes(total_row, status, 'align="right"')

    return (table, projects)
Ejemplo n.º 9
0
def rpt2():

    form = pandokia.pcgi.form

    if "test_run" in form:
        test_run = form.getvalue("test_run")
    else:
        # no parameter?  I think somebody is messing with us...
        # no matter - just give them a the list of all the test_runs
        rpt1()
        return

    #
    test_run = common.find_test_run(test_run)

    # create list of projects
    projects = None
    host = None
    context = None
    chronic = '0'

    if "project" in form:
        projects = form.getlist("project")

    if "host" in form:
        host = form.getlist("host")

    if "context" in form:
        context = form.getlist("context")

    if "chronic" in form:
        chronic = form.getlist("chronic")[0]

    c = pdk_db.execute(
        "SELECT note, valuable FROM distinct_test_run WHERE test_run = :1", (test_run,))
    x = c.fetchone()
    if x is None:
        sys.stdout.write(common.cgi_header_html)
        sys.stdout.write(common.page_header())
        sys.stdout.write('No such test run')
        return

    test_run_note, test_run_valuable = x
    if test_run_note is None:
        test_run_note = ''
    if test_run_valuable is None:
        test_run_valuable = 0
    else:
        test_run_valuable = int(test_run_valuable)

    # create the actual table
    (table, projects) = gen_daily_table(test_run, projects, context,
                                        host, valuable=test_run_valuable, chronic=chronic == '1')

# # # # # # # # # #
    if pandokia.pcgi.output_format == 'html':

        header = "<big><big><b>" + cgi.escape(test_run) + "</b></big></big>\n"

        if 1:
            # if it looks like there is a date in it, try to show the day of the week
            # dates must look like 2011-01-01 and do not occur at the beginning
            # of the name
            t = common.looks_like_a_date(test_run)
            try:
                import datetime
                t = t.group(1).split('-')
                (year, month, day) = (int(t[0]), int(t[1]), int(t[2]))
                t = datetime.date(year, month, day)
                t = t.strftime("%A")
                header = header + "<big>(" + str(t) + ")</big>"
            except:
                pass

        header = header + "<p>"

        recurring_prefix = common.recurring_test_run(test_run)
        if recurring_prefix:
            #
            # If we have a recurring run, create a special header.

            # Include links to the previous / next in the sequence

            l = []
            prev = common.run_previous(recurring_prefix, test_run)
            if prev:
                l.append(
                    common.self_href(
                        query_dict={
                            'test_run': prev},
                        linkmode='day_report.2',
                        text=prev))

            next = common.run_next(recurring_prefix, test_run)
            if next:
                l.append(
                    common.self_href(
                        query_dict={
                            'test_run': next},
                        linkmode='day_report.2',
                        text=next))

            latest = common.run_latest(recurring_prefix)
            if latest and (latest != next) and (latest != test_run):
                l.append(
                    common.self_href(
                        query_dict={
                            'test_run': latest},
                        linkmode='day_report.2',
                        text=latest))

            header = header + '( %s )' % (' / '.join(l))

        if 1:
            if test_run_note.startswith('*'):
                header = header + \
                    '<p>\nNote: %s</p>' % (cgi.escape(test_run_note))
            else:
                header = header + '<p><form action=%s>\nNote: <input type=text name=note value="%s" size=%d>\n<input type=hidden name=test_run value="%s">\n<input type=hidden name=query value=action></form></p>' % (
                    common.get_cgi_name(), cgi.escape(test_run_note), len(test_run_note) + 20, test_run)

            if test_run_valuable:
                header = header + '<p>valuable '
            else:
                header = header + '<p>not valuable '
            header = header + '(<a href=%s>change</a>)' % (common.selflink(
                {'test_run': test_run, 'valuable_run': int(not test_run_valuable)}, linkmode='action'))

        sys.stdout.write(common.cgi_header_html)
        sys.stdout.write(common.page_header())
        sys.stdout.write(header)

        # write links to the top of each project
        sys.stdout.write('<p>\n')
        for p in projects:
            p = cgi.escape(p)
            sys.stdout.write('<a href="#%s">%s</a>&nbsp;&nbsp; ' % (p, p))
        sys.stdout.write('</p>\n')

        # write the report table
        sys.stdout.write(table.get_html(headings=0))

    elif pandokia.pcgi.output_format == 'csv':
        sys.stdout.write(common.cgi_header_csv)
        sys.stdout.write(table.get_csv())
Ejemplo n.º 10
0
def run(args):
    opts, args = easyargs.get(
        {
            '-c': 'list',
            '-p': 'list',
            '-h': 'list',
            '--context': '-c',
            '--project': '-p',
            '--host': '-h',
        }, args)

    try:
        test_run_type = args[0]
        test_run_pattern = args[1]
    except:
        print("can't get args")
        print("   pdk gen_expected test_run_type test_run_pattern")
        sys.exit(1)

    test_run_pattern = common.find_test_run(test_run_pattern)

    print("test_run_pattern = %s" % test_run_pattern)

    l = [('test_run', test_run_pattern)]

    if '-c' in opts:
        l = l + [('context', x) for x in opts['-c']]
    if '-p' in opts:
        l = l + [('project', x) for x in opts['-p']]
    if '-h' in opts:
        l = l + [('host', x) for x in opts['-h']]

    if debug:
        for x in l:
            print("	%s" % x)
        print("?")
        sys.stdin.readline()

    where_str, where_dict = pdk_db.where_dict(l)

    sql = "select distinct project, host, context, test_name from result_scalar %s " % where_str
    c = pdk_db.execute(sql, where_dict)

    for (project, host, context, test_name) in c:
        if test_name.endswith("nose.failure.Failure.runTest"):
            # Sometimes nose generates this test name.  I don't want it in the database at all, because
            # the name is not unique, and the record does not contain any useful information about the problem.
            # In any case, we never want to list this test as "expected", even
            # if it leaks into the database.
            continue

        if debug:
            print("expect %s %s %s %s %s" %
                  (test_run_type, project, host, context, test_name))
        # insert to the expected table; if the record is already there, it's
        # ok.
        try:
            pdk_db.execute(
                'insert into expected ( test_run_type, project, host, context, test_name ) values ( :1, :2, :3, :4, :5 )',
                (test_run_type, project, host, context, test_name))
        except pdk_db.IntegrityError as e:
            if debug:
                print("exception %s" % e)
            pass
    pdk_db.commit()
Ejemplo n.º 11
0
def run(args):
    opts, args = easyargs.get({
        '-c': 'list',
        '-p': 'list',
        '-h': 'list',
        '--context': '-c',
        '--project': '-p',
        '--host': '-h',
    }, args)

    try:
        test_run_type = args[0]
        test_run_pattern = args[1]
    except:
        print("can't get args")
        print("   pdk gen_expected test_run_type test_run_pattern")
        sys.exit(1)

    test_run_pattern = common.find_test_run(test_run_pattern)

    print("test_run_pattern = %s" % test_run_pattern)

    l = [('test_run', test_run_pattern)]

    if '-c' in opts:
        l = l + [('context', x) for x in opts['-c']]
    if '-p' in opts:
        l = l + [('project', x) for x in opts['-p']]
    if '-h' in opts:
        l = l + [('host', x) for x in opts['-h']]

    if debug:
        for x in l:
            print("	%s" % x)
        print("?")
        sys.stdin.readline()

    where_str, where_dict = pdk_db.where_dict(l)

    sql = "select distinct project, host, context, test_name from result_scalar %s " % where_str
    c = pdk_db.execute(sql, where_dict)

    for (project, host, context, test_name) in c:
        if test_name.endswith("nose.failure.Failure.runTest"):
            # Sometimes nose generates this test name.  I don't want it in the database at all, because
            # the name is not unique, and the record does not contain any useful information about the problem.
            # In any case, we never want to list this test as "expected", even
            # if it leaks into the database.
            continue

        if debug:
            print(
                "expect %s %s %s %s %s" %
                (test_run_type, project, host, context, test_name))
        # check if the row already exists before insert since the expected table does not have unique enforcement
        # on its columns
        a = pdk_db.execute('select * from expected where test_run_type = :1 and project = :2 and host = :3 and context = :4 and test_name = :5', (test_run_type, project, host, context, test_name))
        y = a.fetchone()
        if y is None:
            try:
                pdk_db.execute(
                    'insert into expected ( test_run_type, project, host, context, test_name ) values ( :1, :2, :3, :4, :5 )',
                    (test_run_type,
                    project,
                    host,
                    context,
                    test_name))
            except Exception as e:
                if debug:
                    print("exception %s" % e)
                pass
    pdk_db.commit()
Ejemplo n.º 12
0
def run(args):
    opts, args = easyargs.get(
        {
            '-c': 'list',
            '-p': 'list',
            '-h': 'list',
            '-m': 'list',
            '--context': '-c',
            '--project': '-p',
            '--host': '-h',
            '--custom': '-m',
        }, args)

    try:
        test_run_type = args[0]
        test_run_pattern = args[1]
    except:
        print("can't get args")
        print("   pdk gen_expected test_run_type test_run_pattern")
        sys.exit(1)

    test_run_pattern = common.find_test_run(test_run_pattern)

    print("test_run_pattern = ", test_run_pattern)

    l = [('test_run', test_run_pattern)]

    if '-c' in opts:
        l = l + [('context', x) for x in opts['-c']]
    if '-p' in opts:
        l = l + [('project', x) for x in opts['-p']]
    if '-h' in opts:
        l = l + [('host', x) for x in opts['-h']]
    if '-m' in opts:
        l = l + [('custom', x) for x in opts['-m']]

    if debug:
        for x in l:
            print("	", x)
        print("?")
        sys.stdin.readline()

    where_str, where_dict = pdk_db.where_dict(l)

    sql = "select distinct project, host, context, custom, test_name from result_scalar %s " % where_str
    c = pdk_db.execute(sql, where_dict)

    for (project, host, context, custom, test_name) in c:
        if test_name.endswith("nose.failure.Failure.runTest"):
            # Sometimes nose generates this test name.  I don't want it in the database at all, because
            # the name is not unique, and the record does not contain any useful information about the problem.
            # In any case, we never want to list this test as "expected", even if it leaks into the database.
            continue

        if debug:
            print("expect ", test_run_type, project, host, context, custom,
                  test_name)
        a = pdk_db.execute(
            'select * from expected where test_run_type = :1 and project = :2 and host = :3 and context = :4 and custom = :5 and test_name = :6',
            (test_run_type, project, host, context, custom, test_name))
        y = a.fetchone()
        if y is None:
            try:
                pdk_db.execute(
                    'insert into expected ( test_run_type, project, host, context, custom, test_name ) values ( :1, :2, :3, :4, :5, :6 )',
                    (test_run_type, project, host, context, custom, test_name))
            except Exception as e:
                if debug:
                    print("exception", e)
                pass
    pdk_db.commit()