[LNT] r299253 - Use suite and db specific keys for baseline selection
Chris Matthews via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 31 13:28:14 PDT 2017
Author: cmatthews
Date: Fri Mar 31 15:28:13 2017
New Revision: 299253
URL: http://llvm.org/viewvc/llvm-project?rev=299253&view=rev
Log:
Use suite and db specific keys for baseline selection
Baselines are stored at the test-suite and db level, but the session
key we used did not encode that. That would mean if selected a baseline
then moved to a different DB, a differnt baseline would be randomly
selected, or LNT would crash.
Now we encode the DB name and suite in the session key, so we know which
baseline is which.
Modified:
lnt/trunk/lnt/server/db/testsuitedb.py
lnt/trunk/lnt/server/ui/globals.py
lnt/trunk/lnt/server/ui/templates/layout.html
lnt/trunk/lnt/server/ui/util.py
lnt/trunk/lnt/server/ui/views.py
lnt/trunk/tests/server/ui/V4Pages.py
Modified: lnt/trunk/lnt/server/db/testsuitedb.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/testsuitedb.py?rev=299253&r1=299252&r2=299253&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/testsuitedb.py (original)
+++ lnt/trunk/lnt/server/db/testsuitedb.py Fri Mar 31 15:28:13 2017
@@ -15,6 +15,8 @@ from sqlalchemy import *
import testsuite
import lnt.testing.profile.profile as profile
+import lnt
+
def strip(obj):
"""Give back a dict without sqlalchemy stuff."""
@@ -641,7 +643,7 @@ class TestSuiteDB(object):
def get_users_baseline(self):
try:
- session_baseline = session.get('baseline')
+ session_baseline = session.get(lnt.server.ui.util.baseline_key(self.name))
except RuntimeError:
# Sometimes this is called from outside the app context.
# In that case, don't get the user's session baseline.
Modified: lnt/trunk/lnt/server/ui/globals.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/globals.py?rev=299253&r1=299252&r2=299253&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/globals.py (original)
+++ lnt/trunk/lnt/server/ui/globals.py Fri Mar 31 15:28:13 2017
@@ -4,12 +4,16 @@ Module for defining additional Jinja glo
import flask
+import lnt.server.ui.util
+
+
def db_url_for(*args, **kwargs):
"""
Like url_for, but handles automatically providing the db_name argument.
"""
return flask.url_for(*args, db_name=flask.g.db_name, **kwargs)
+
def v4_url_for(*args, **kwargs):
"""
Like url_for, but handles automatically providing the db_name and
@@ -18,6 +22,7 @@ def v4_url_for(*args, **kwargs):
return flask.url_for(*args, db_name=flask.g.db_name,
testsuite_name=flask.g.testsuite_name, **kwargs)
+
def v4_url_available(*args, **kwargs):
"""
Return True if v4_url_for can be used; if there is a testsuite_name
@@ -29,6 +34,7 @@ def v4_url_available(*args, **kwargs):
except:
return False
+
def register(env):
# Add some normal Python builtins which can be useful in templates.
env.globals.update(zip=zip)
@@ -37,4 +43,7 @@ def register(env):
env.globals.update(
db_url_for=db_url_for,
v4_url_for=v4_url_for,
- v4_url_available=v4_url_available)
+ v4_url_available=v4_url_available,
+ baseline_key=lnt.server.ui.util.baseline_key)
+
+
Modified: lnt/trunk/lnt/server/ui/templates/layout.html
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/templates/layout.html?rev=299253&r1=299252&r2=299253&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/templates/layout.html (original)
+++ lnt/trunk/lnt/server/ui/templates/layout.html Fri Mar 31 15:28:13 2017
@@ -194,7 +194,7 @@
<ul class="dropdown-menu">
<li class="nav-header">Select baseline:</li>
{% for b in ts.query(ts.Baseline).all() %}
- {% set is_bold = b.id == session.get('baseline') %}
+ {% set is_bold = b.id == session.get(baseline_key()) %}
<li><a href="{{ v4_url_for('v4_set_baseline', id=b.id) }}">
{% if is_bold %}
<b>{{ b.name }}</b>
Modified: lnt/trunk/lnt/server/ui/util.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/util.py?rev=299253&r1=299252&r2=299253&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/util.py (original)
+++ lnt/trunk/lnt/server/ui/util.py Fri Mar 31 15:28:13 2017
@@ -2,6 +2,8 @@ import colorsys
import math
import re
+from flask import g
+
def toColorString(col):
r, g, b = [clamp(int(v * 255), 0, 255)
@@ -348,3 +350,16 @@ def guess_test_short_name(test_name):
return split_name[-3]
else:
return last_path_name
+
+
+def baseline_key(ts_name=None):
+ """A unique name for baseline session keys per DB and suite.
+
+ Optionally, get the test-suite name from a parameter, when this is called during
+ submission the global context does not know which test-suite we are in until too late.
+ """
+ if ts_name:
+ name = ts_name
+ else:
+ name = g.db_name
+ return "baseline-{}-{}".format(name, g.db_name)
Modified: lnt/trunk/lnt/server/ui/views.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/views.py?rev=299253&r1=299252&r2=299253&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/views.py (original)
+++ lnt/trunk/lnt/server/ui/views.py Fri Mar 31 15:28:13 2017
@@ -47,6 +47,7 @@ from collections import namedtuple, defa
from lnt.util import async_ops
from urlparse import urlparse, urljoin
from flask import request, url_for
+from lnt.server.ui.util import baseline_key
integral_rex = re.compile(r"[\d]+")
@@ -526,7 +527,7 @@ def v4_set_baseline(id):
if not base:
return abort(404)
flash("Baseline set to " + base.name, FLASH_SUCCESS)
- session['baseline'] = id
+ session[baseline_key()] = id
return redirect(get_redirect_target())
@@ -1402,7 +1403,7 @@ def baseline():
or None if one is not defined.
"""
ts = request.get_testsuite()
- base_id = session.get('baseline')
+ base_id = session.get(baseline_key())
if not base_id:
return None
try:
Modified: lnt/trunk/tests/server/ui/V4Pages.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/server/ui/V4Pages.py?rev=299253&r1=299252&r2=299253&view=diff
==============================================================================
--- lnt/trunk/tests/server/ui/V4Pages.py (original)
+++ lnt/trunk/tests/server/ui/V4Pages.py Fri Mar 31 15:28:13 2017
@@ -267,7 +267,7 @@ def main():
check_code(client, '/v4/nts/set_baseline/1', expected_code=HTTP_REDIRECT)
with app.test_client() as c:
c.get('/v4/nts/set_baseline/1')
- session.get('baseline') == 1
+ session.get('baseline-default-nts') == 1
# Get a run result page (and associated views).
check_code(client, '/v4/nts/1')
More information about the llvm-commits
mailing list