Mike Frysinger | d03e6b5 | 2019-08-03 12:49:01 -0400 | [diff] [blame] | 1 | #!/usr/bin/python2 |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 2 | """ |
| 3 | Selects all rows and columns that satisfy the condition specified |
| 4 | and prints the matrix. |
| 5 | """ |
showard | d9e341e | 2010-01-12 18:56:42 +0000 | [diff] [blame] | 6 | import optparse |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 7 | import common |
| 8 | from autotest_lib.cli import rpc |
mbligh | 789da1e | 2009-04-01 18:35:12 +0000 | [diff] [blame] | 9 | from autotest_lib.database import database_connection |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 10 | |
| 11 | |
| 12 | # First do all the options parsing |
| 13 | parser = optparse.OptionParser() |
showard | d9e341e | 2010-01-12 18:56:42 +0000 | [diff] [blame] | 14 | parser.add_option( |
| 15 | '-C', '--columns', action='store', dest='columns', |
| 16 | default='test_name,reason,test_started_time,test_finished_time,job_tag,' |
| 17 | 'job_name,hostname,platform,kernel,status', |
| 18 | help='Comma-separated list of column names to display') |
| 19 | parser.add_option('-w', '--where', action='store', dest='condition', |
mbligh | 8dd5c6c | 2008-09-04 16:46:34 +0000 | [diff] [blame] | 20 | help=("The WHERE condition for the query witten in the 'new style' " |
mbligh | 28afa73 | 2008-09-30 20:29:46 +0000 | [diff] [blame] | 21 | "condition syntax for new tko (see " |
showard | d9e341e | 2010-01-12 18:56:42 +0000 | [diff] [blame] | 22 | "http://autotest.kernel.org/wiki/TkoHowTo for more info)")) |
| 23 | parser.add_option( |
jamesren | 708f1c0 | 2010-03-31 21:43:57 +0000 | [diff] [blame] | 24 | '--test-attribute-field', action='append', default=[], |
showard | d9e341e | 2010-01-12 18:56:42 +0000 | [diff] [blame] | 25 | help='Specifies a test attribute to include as a field. The attribute ' |
| 26 | 'value will be available as a field named attribute_<attribute ' |
| 27 | 'name>. This option may be specified multiple times. Filtering ' |
| 28 | 'must be done slightly differently -- see ' |
| 29 | 'http://autotest.kernel.org/wiki/TkoHowTo#attribute_filtering ' |
| 30 | 'for more details.') |
jamesren | 708f1c0 | 2010-03-31 21:43:57 +0000 | [diff] [blame] | 31 | parser.add_option('--test-label-field', action='append', default=[], |
showard | d9e341e | 2010-01-12 18:56:42 +0000 | [diff] [blame] | 32 | help='Specifies a test label to include as a field. See ' |
| 33 | '--attribute-field for more details') |
jamesren | 708f1c0 | 2010-03-31 21:43:57 +0000 | [diff] [blame] | 34 | parser.add_option('--iteration-result-field', action='append', default=[], |
showard | d9e341e | 2010-01-12 18:56:42 +0000 | [diff] [blame] | 35 | help='Specifies an iteration result to include as a field. ' |
| 36 | 'See --attribute-field for more details. Note that ' |
| 37 | 'this causes the rows returned to represent iterations ' |
| 38 | 'rather than plain test results.') |
| 39 | parser.add_option('--machine-label-field', action='append', default=[], |
| 40 | help='Specifies a machine label to include as a field. See ' |
| 41 | '--attribute-field for more details') |
jamesren | 708f1c0 | 2010-03-31 21:43:57 +0000 | [diff] [blame] | 42 | parser.add_option('--job-keyval-field', action='append', default=[], |
| 43 | help='Specifies a job keyval to include as a field. See ' |
| 44 | '--attribute-field for more details') |
| 45 | parser.add_option('--iteration-attribute-field', action='append', default=[], |
| 46 | help='Specifies an iteration attribute to include as a ' |
| 47 | 'field. See --attribute-field for more details. Note ' |
| 48 | 'that this causes the rows returned to represent ' |
| 49 | 'iterations rather than plain test results.') |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 50 | parser.add_option('-s', '--separator', action='store', default = ' | ', |
| 51 | dest='separator', help = 'output separator') |
| 52 | parser.add_option('-n', '--nocount', action='store_true', default=False, |
| 53 | help='Do not display line counts before each line') |
| 54 | parser.add_option('-l', '--logpath', action='store_true', default=False, |
| 55 | help='Reformats the the tag column into a URL \ |
| 56 | like http://autotest/results/[tag]. \ |
| 57 | This will append the tag column if it isn\'t provided.') |
mbligh | 789da1e | 2009-04-01 18:35:12 +0000 | [diff] [blame] | 58 | parser.add_option('--host-label', action='store', dest='host_label', |
| 59 | help=('Return results only for machines currently ' |
| 60 | 'in the specified label')) |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 61 | |
| 62 | (options, args) = parser.parse_args() |
| 63 | |
showard | d9e341e | 2010-01-12 18:56:42 +0000 | [diff] [blame] | 64 | if not options.condition: |
| 65 | parser.error('You must specify a condition.') |
| 66 | |
| 67 | where = options.condition.replace('%', '%%') |
| 68 | tag = 'job_tag' |
mbligh | deb758e | 2008-08-11 19:56:23 +0000 | [diff] [blame] | 69 | |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 70 | columns = options.columns.split(',') |
| 71 | |
| 72 | url_prefix = rpc.get_autotest_server() + '/results/' |
| 73 | if options.logpath: |
mbligh | 8dd5c6c | 2008-09-04 16:46:34 +0000 | [diff] [blame] | 74 | if tag not in columns: |
| 75 | columns.append(tag) |
| 76 | tag_index=columns.index(tag) |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 77 | |
mbligh | 789da1e | 2009-04-01 18:35:12 +0000 | [diff] [blame] | 78 | if options.host_label: |
| 79 | database = database_connection.DatabaseConnection("AUTOTEST_WEB") |
| 80 | database.connect() |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 81 | sql = ("SELECT hostname FROM afe_labels JOIN afe_hosts_labels " |
| 82 | "ON afe_labels.id=afe_hosts_labels.label_id JOIN afe_hosts " |
| 83 | "ON afe_hosts_labels.host_id=afe_hosts.id WHERE name=%s") |
mbligh | 789da1e | 2009-04-01 18:35:12 +0000 | [diff] [blame] | 84 | results = database.execute(sql, options.host_label) |
| 85 | hosts = [row[0] for row in results] |
| 86 | where += " AND hostname IN ('" + "','".join(hosts) + "')" |
| 87 | |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 88 | # Grab the data |
showard | d9e341e | 2010-01-12 18:56:42 +0000 | [diff] [blame] | 89 | tko = rpc.tko_comm() |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 90 | count = 0 |
jamesren | 708f1c0 | 2010-03-31 21:43:57 +0000 | [diff] [blame] | 91 | test_views = tko.run( |
| 92 | 'get_test_views', extra_where=where, |
| 93 | test_attribute_fields=options.test_attribute_field, |
| 94 | test_label_fields=options.test_label_field, |
| 95 | iteration_result_fields=options.iteration_result_field, |
| 96 | machine_label_fields=options.machine_label_field, |
| 97 | job_keyval_fields=options.job_keyval_field, |
| 98 | iteration_attribute_fields=options.iteration_attribute_field) |
showard | d9e341e | 2010-01-12 18:56:42 +0000 | [diff] [blame] | 99 | for test_view in test_views: |
| 100 | values = [str(test_view[column]) for column in columns] |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 101 | if options.logpath: |
| 102 | values[tag_index] = url_prefix + values[tag_index] |
| 103 | if not options.nocount: |
| 104 | print '[%d] ' % count, |
| 105 | count += 1 |
| 106 | print options.separator.join(values) |