Various poorly documented changes to tko frontend. Sorry
From: Vladimir Samarskiy <vsamarsk@google.com>
Signed-off-by: Martin Bligh <mbligh@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@1437 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/tko/compose_query.cgi b/tko/compose_query.cgi
index 6002323..8e42928 100755
--- a/tko/compose_query.cgi
+++ b/tko/compose_query.cgi
@@ -105,7 +105,7 @@
force_column = split_forced_fields(force_column_field)
cgitb.enable()
-db = db.db()
+db_obj = db.db()
def construct_link(x, y):
@@ -203,7 +203,7 @@
def map_kernel_init():
fields = ['base', 'k.kernel_idx', 'name', 'url']
map = {}
- for (base, idx, name, url) in db.select(','.join(fields),
+ for (base, idx, name, url) in db_obj.select(','.join(fields),
'kernels k,patches p', 'k.kernel_idx=p.kernel_idx'):
match = re.match(r'.*(-mm[0-9]+|-git[0-9]+)\.(bz2|gz)$', url)
if match:
@@ -244,7 +244,10 @@
msg = "Unspecified error when parsing condition"
return [[display.box(msg)]]
- test_data = frontend.get_matrix_data(db, column, row, where)
+ try:
+ test_data = frontend.get_matrix_data(db_obj, column, row, where)
+ except db.MySQLTooManyRows, error:
+ return [[display.box(str(error))]]
for f_row in force_row:
if not f_row in test_data.y_values:
@@ -304,7 +307,7 @@
else:
link = construct_link(x, y)
- cur_row.append(display.status_precounted_box(db,
+ cur_row.append(display.status_precounted_box(db_obj,
box_data,
link))
matrix.append(cur_row)
diff --git a/tko/db.py b/tko/db.py
index 3adbdfa..14e7c1b 100644
--- a/tko/db.py
+++ b/tko/db.py
@@ -1,6 +1,9 @@
import re, os, sys, types
from common import global_config
+class MySQLTooManyRows(Exception):
+ pass
+
class db_sql:
def __init__(self, debug = False, autocommit=True, host = None,
@@ -59,8 +62,8 @@
return self.cur.fetchall()[0][0]
- def select(self, fields, table, where, wherein={}, distinct = False,
- group_by = None):
+ def select(self, fields, table, where, wherein={},
+ distinct = False, group_by = None, max_rows = None):
"""\
This selects all the fields requested from a
specific table with a particular where clause.
@@ -109,7 +112,10 @@
cmd.append(' GROUP BY ' + group_by)
self.dprint('%s %s' % (' '.join(cmd), values))
- self.cur.execute(' '.join(cmd), values)
+ numRec = self.cur.execute(' '.join(cmd), values)
+ if max_rows != None and numRec > max_rows:
+ msg = 'Exceeded allowed number of records'
+ raise MySQLTooManyRows(msg)
return self.cur.fetchall()
diff --git a/tko/frontend.py b/tko/frontend.py
index 9fbceea..046d8ff 100755
--- a/tko/frontend.py
+++ b/tko/frontend.py
@@ -1,5 +1,7 @@
#!/usr/bin/python
import os, re, db, sys, datetime
+MAX_RECORDS = 10000
+MAX_CELLS = 100000
tko = os.path.dirname(os.path.realpath(os.path.abspath(__file__)))
client_bin = os.path.abspath(os.path.join(tko, '../client/bin'))
@@ -53,6 +55,10 @@
self.x_values = smart_sort(data.keys(), x_field)
# List of rows columns (y-values)
self.y_values = smart_sort(list(y_values), y_field)
+ if len(self.y_values)*len(self.x_values) > MAX_CELLS:
+ msg = 'Exceeded allowed number of cells in a table'
+ raise db.MySQLTooManyRows(msg)
+
def truncateTimeFieldsInAllRecords(rows, pos):
## reduces hours:min:sec to 00:00:00 in time stamps
@@ -70,7 +76,7 @@
return tuple(altRow)
return map(truncateTimeFieldInOneRecord, rows)
-def get_matrix_data(db, x_axis, y_axis, where = None):
+def get_matrix_data(db_obj, x_axis, y_axis, where = None):
# Searches on the test_view table - x_axis and y_axis must both be
# column names in that table.
x_field = test_view_field_dict[x_axis]
@@ -79,7 +85,8 @@
'LEFT(GROUP_CONCAT(job_tag), 100)' # limit what's returned
) % (x_field, y_field)
group_by = '%s, %s, status' % (x_field, y_field)
- rows = db.select(fields, 'test_view', where=where, group_by=group_by)
+ rows = db_obj.select(fields, 'test_view',
+ where=where, group_by=group_by, max_rows = MAX_RECORDS)
if x_field.endswith("time"):
rows = truncateTimeFieldsInAllRecords(rows, 0)
if y_field.endswith("time"):