canonical-ubuntu-qa team mailing list archive
-
canonical-ubuntu-qa team
-
Mailing list archive
-
Message #06322
[Merge] ~adrien/autopkgtest-cloud:browse-recent-filters-and-json into autopkgtest-cloud:master
Adrien Nader has proposed merging ~adrien/autopkgtest-cloud:browse-recent-filters-and-json into autopkgtest-cloud:master.
Commit message:
Add filtering by arch and release for the recent page. Use a dict for test
result fields rather than an array of fourteen elements. Expose a JSON file for
recent test results.
The JSON file is accessible at /api/experimental/recent.json. I figured that if
we were first spending time designing an API, we would likely never get to
finishing it. I'm using the same fields as the ones on HTML page; it should be
the same as the page but as JSON.
Since there is a commit that refactors some code, it's possible that some
regressions are introduced in other pages but that should be pretty safe
nonetheless.
Requested reviews:
Canonical's Ubuntu QA (canonical-ubuntu-qa)
For more details, see:
https://code.launchpad.net/~adrien/autopkgtest-cloud/+git/autopkgtest-cloud/+merge/482540
--
Your team Canonical's Ubuntu QA is requested to review the proposed merge of ~adrien/autopkgtest-cloud:browse-recent-filters-and-json into autopkgtest-cloud:master.
diff --git a/charms/focal/autopkgtest-web/webcontrol/browse.cgi b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
index fe25701..c9ae1db 100755
--- a/charms/focal/autopkgtest-web/webcontrol/browse.cgi
+++ b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
@@ -211,7 +211,11 @@ def db_has_result_requester_idx(cursor: sqlite3.Cursor):
return False
-def get_results(limit: int, offset: int = 0, user: str = None) -> list:
+def get_results(limit: int, offset: int = 0, **kwargs) -> list:
+ requested_arch = kwargs.get("arch", None)
+ requested_release = kwargs.get("release", None)
+ requested_user = kwargs.get("user", None)
+
results = []
# We want to use sqlite3.Row here, so we need to create a cursor
# as to not affect the overall db_con object, which could interfere
@@ -222,11 +226,11 @@ def get_results(limit: int, offset: int = 0, user: str = None) -> list:
for row in cursor.execute(
"SELECT test_id, run_id, version, triggers, "
"duration, exitcode, requester, env, uuid FROM result "
- + ("WHERE requester=:user " if user else "")
+ + ("WHERE requester=:requested_user " if requested_user else "")
+ "ORDER BY run_id DESC "
"LIMIT :limit OFFSET :offset ",
{
- "user": user,
+ "user": requested_user,
"limit": limit,
"offset": offset,
},
@@ -240,6 +244,8 @@ def get_results(limit: int, offset: int = 0, user: str = None) -> list:
] # string of comma separated env variables e.g. all-proposed=1,test-name=mytest
code = human_exitcode(row["exitcode"])
package, release, arch = get_package_release_arch(test_id)
+ if (requested_release and release != requested_release) or (requested_arch and arch != requested_arch):
+ continue
url = os.path.join(
CONFIG["swift_container_url"] % release,
release,
@@ -254,21 +260,21 @@ def get_results(limit: int, offset: int = 0, user: str = None) -> list:
and "all-proposed=1" in additional_params
)
results.append(
- (
- version,
- triggers,
- additional_params,
- human_date(row["run_id"]),
- human_sec(int(row["duration"])),
- requester,
- code,
- url,
- show_retry,
- all_proposed,
- row["uuid"],
- package,
- release,
- arch,
+ dict(
+ version=version,
+ triggers=triggers,
+ additional_params=additional_params,
+ human_date=human_date(row["run_id"]),
+ human_sec=human_sec(int(row["duration"])),
+ requester=requester,
+ code=code,
+ url=url,
+ show_retry=show_retry,
+ all_proposed=all_proposed,
+ uuid=row["uuid"],
+ package=package,
+ release=release,
+ arch=arch,
)
)
else:
@@ -276,20 +282,21 @@ def get_results(limit: int, offset: int = 0, user: str = None) -> list:
# the user that the issue is the db index not
# being present
results.append(
- (
- "No results are being displayed as",
- "the db index required for this page",
- "is not present, please contact an admin." "",
- "",
- "",
- 1,
- "",
- False,
- False,
- "",
- "",
- "",
- "",
+ dict(
+ version="No results are being displayed as",
+ triggers="the db index required for this page",
+ additional_params="is not present, please contact an admin." "",
+ human_date="",
+ human_sec="",
+ requester=1,
+ code="",
+ url=False,
+ show_retry=False,
+ all_proposed="",
+ uuid="",
+ package="",
+ release="",
+ arch="",
)
)
return results
@@ -527,9 +534,9 @@ def user_overview(user):
# Get results for this user
if show_results:
- previous_test_results = get_results(limit, offset, user)
+ previous_test_results = get_results(limit, offset, user=user)
else:
- previous_test_results = []
+ previous_test_results = dict()
# add queued tests for this user
if show_queued:
@@ -578,7 +585,19 @@ def recent():
except (AssertionError, ValueError):
offset = 0
- recent_test_results = get_results(limit, offset)
+ arch = args.get("arch")
+ release = args.get("release")
+ user = args.get("user")
+
+ recent_test_results = get_results(limit, offset, arch=arch,
+ release=release, user=user)
+
+ all_arches = set()
+ all_releases = []
+ for release, arches in get_release_arches(db_con).items():
+ all_releases.append(release)
+ for a in arches:
+ all_arches.add(a)
return render(
"browse-recent.html",
@@ -587,9 +606,38 @@ def recent():
recent_test_results=recent_test_results,
limit=limit,
offset=offset,
+ releases=all_releases,
+ all_arches=all_arches,
)
+@app.route("/api/experimental/recent.json")
+def recent_json():
+ args = flask.request.args
+ try:
+ limit = int(args.get("limit", 100))
+ assert limit > 0
+ assert limit <= 10000
+ except (AssertionError, ValueError):
+ limit = 100
+
+ try:
+ offset = int(args.get("offset", 0))
+ assert offset > 0
+ assert isinstance(offset, int)
+ except (AssertionError, ValueError):
+ offset = 0
+
+ arch = args.get("arch")
+ release = args.get("release")
+ user = args.get("user")
+
+ recent_test_results = get_results(limit, offset, arch=arch,
+ release=release, user=user)
+
+ return flask.jsonify(recent_test_results)
+
+
@app.route("/user/<user>/ppa")
def list_user_ppas(user):
ppa_containers = load_ppa_cache()
@@ -771,42 +819,42 @@ def package_release_arch(package, release, arch, _=None):
item_info = json.loads(item.split("\n")[1])
results.insert(
0,
- (
- "N/A",
- item_info.get("triggers"),
- (
+ dict(
+ version="N/A",
+ triggers=item_info.get("triggers"),
+ additional_params=(
"all-proposed=1"
if "all-proposed" in item_info.keys()
else ""
),
- human_date(item_info.get("submit-time")),
- "N/A",
- "-",
- "queued",
- "",
- False,
- "",
- item_info.get("uuid", ""),
- ),
+ human_date=human_date(item_info.get("submit-time")),
+ human_sec="N/A",
+ requester="-",
+ code="queued",
+ url="",
+ show_retry=False,
+ all_proposed="",
+ uuid=item_info.get("uuid", ""),
+ )
)
except Exception:
# We never want to fail in that block, even is there are issues with cache-amqp
# Let's signal the error in the page, but still display other results
results.insert(
0,
- (
- "Unknown queued list",
- "There are errors in cache-amqp",
- "Please contact QA team",
- "",
- "",
- "",
- "",
- "",
- False,
- "",
- "",
- ),
+ dict(
+ version="Unknown queued list",
+ triggers="There are errors in cache-amqp",
+ additional_params="Please contact QA team",
+ human_date="",
+ human_sec="",
+ requester="",
+ code="",
+ url="",
+ show_retry=False,
+ all_proposed="",
+ uuid="",
+ )
)
return render(
diff --git a/charms/focal/autopkgtest-web/webcontrol/templates/browse-recent.html b/charms/focal/autopkgtest-web/webcontrol/templates/browse-recent.html
index 4c35c52..12163ec 100644
--- a/charms/focal/autopkgtest-web/webcontrol/templates/browse-recent.html
+++ b/charms/focal/autopkgtest-web/webcontrol/templates/browse-recent.html
@@ -17,13 +17,13 @@
</tr>
{% for row in results %}
<tr {% if row[6] in ["running", "queued"] %}class="unfinished"{% endif %}>
- {% set package = row[11] %}
- {% set release = row[12] %}
- {% set arch = row[13] %}
+ {% set package = row["package"] %}
+ {% set release = row["release"] %}
+ {% set arch = row["arch"] %}
<td>{{ package }}</td>
<td>{{ release }}</td>
<td>{{ arch }}</td>
- {{ macros.results_table_core(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], package, release, arch) }}
+ {{ macros.results_table_core(row["version"], row["triggers"], row["additional_params"], row["human_date"], row["human_sec"], row["requester"], row["code"], row["url"], row["show_retry"], row["all_proposed"], row["uuid"], package, release, arch) }}
</tr>
{% endfor %}
</table>
@@ -42,6 +42,20 @@
<option value="5000" {% if limit == 5000 %}selected="selected"{% endif %}>5000</option>
<option value="10000" {% if limit == 10000 %}selected="selected"{% endif %}>10000</option>
</select>
+ <label for="arch">Architecture:</label>
+ <select name="arch" id="arch">
+ {% for a in all_arches %}
+ <option value="{{ a }}" {% if arch == a %}selected="selected"{% endif %}>{{ a }}</option>
+ {% endfor %}
+ </select>
+ <label for="release">Release:</label>
+ <select name="release" id="release">
+ {% for r in releases %}
+ <option value="{{ r }}" {% if release == r %}selected="selected"{% endif %}>{{ r }}</option>
+ {% endfor %}
+ </select>
+ <label for="release">Release:</label>
+ <input type="text" name="release" id="release"></input>
<input type="submit" value="Show">
</form>
diff --git a/charms/focal/autopkgtest-web/webcontrol/templates/browse-results.html b/charms/focal/autopkgtest-web/webcontrol/templates/browse-results.html
index 9d15751..1256acd 100644
--- a/charms/focal/autopkgtest-web/webcontrol/templates/browse-results.html
+++ b/charms/focal/autopkgtest-web/webcontrol/templates/browse-results.html
@@ -15,8 +15,8 @@
<tr>{{ macros.set_up_results_table() }}</tr>
{% for row in package_results %}
- <tr {% if row[6] in ["running", "queued"] %}class="unfinished"{% endif %}>
- {{ macros.results_table_core(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], package, release, arch) }}
+ <tr {% if row["code"] in ["running", "queued"] %}class="unfinished"{% endif %}>
+ {{ macros.results_table_core(row["version"], row["triggers"], row["additional_params"], row["human_date"], row["human_sec"], row["requester"], row["code"], row["url"], row["show_retry"], row["all_proposed"], row["uuid"], package, release, arch) }}
</tr>
{% endfor %}
</table>
diff --git a/charms/focal/autopkgtest-web/webcontrol/templates/browse-user.html b/charms/focal/autopkgtest-web/webcontrol/templates/browse-user.html
index 388f23f..3e5e24d 100644
--- a/charms/focal/autopkgtest-web/webcontrol/templates/browse-user.html
+++ b/charms/focal/autopkgtest-web/webcontrol/templates/browse-user.html
@@ -16,14 +16,14 @@
{{ macros.set_up_results_table() }}
</tr>
{% for row in user_results %}
- <tr {% if row[6] in ["running", "queued"] %}class="unfinished"{% endif %}>
- {% set package = row[11] %}
- {% set release = row[12] %}
- {% set arch = row[13] %}
+ <tr {% if row["code"] in ["running", "queued"] %}class="unfinished"{% endif %}>
+ {% set package = row["package"] %}
+ {% set release = row["release"] %}
+ {% set arch = row["arch"] %}
<td>{{ package }}</td>
<td>{{ release }}</td>
<td>{{ arch }}</td>
- {{ macros.results_table_core(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], package, release, arch) }}
+ {{ macros.results_table_core(row["version"], row["triggers"], row["additional_params"], row["human_date"], row["human_sec"], row["requester"], row["code"], row["url"], row["show_retry"], row["all_proposed"], row["uuid"], package, release, arch) }}
</tr>
{% endfor %}
</table>
Follow ups