Merge ~hyask/autopkgtest-cloud:skia/ease_browse_dev into autopkgtest-cloud:master

Proposed by Skia
Status: Merged
Merged at revision: 0bcf32f066b6d0a64186ccc2da94ba32ba539756
Proposed branch: ~hyask/autopkgtest-cloud:skia/ease_browse_dev
Merge into: autopkgtest-cloud:master
Diff against target: 205 lines (+187/-0)
3 files modified
charms/focal/autopkgtest-web/webcontrol/README.md (+12/-0)
charms/focal/autopkgtest-web/webcontrol/browse-test.py (+27/-0)
charms/focal/autopkgtest-web/webcontrol/helpers/tests.py (+148/-0)
Reviewer Review Type Date Requested Status
Tim Andersson Approve
Review via email: mp+461027@code.launchpad.net

Description of the change

Allow easier local development.

To post a comment you must log in.
Revision history for this message
Tim Andersson (andersson123) wrote :

Skia to remove header/hyperlink (h2) from running macro, move into browse-running and browse-admin.

Revision history for this message
Tim Andersson (andersson123) wrote :

Skia to
- both commit messages more verbose

Revision history for this message
Tim Andersson (andersson123) wrote :

LGTM once CI passes :)

Revision history for this message
Tim Andersson (andersson123) :
review: Approve
Revision history for this message
Tim Andersson (andersson123) wrote :

Now that CI works, we actually have to wait until it passes to merge things :/ footgun

Revision history for this message
Brian Murray (brian-murray) wrote :

Should the notes about "Developing browse.cgi locally" also end up in /docs and on readthedocs?

Revision history for this message
Tim Andersson (andersson123) wrote :

I don't think so. Our docs on readthedocs dont really cover development at all - it's mostly sysadmin things and architectural information. I personally think this README.md is good, but I really don't mind if it goes into readthedocs also

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/charms/focal/autopkgtest-web/webcontrol/README.md b/charms/focal/autopkgtest-web/webcontrol/README.md
0new file mode 1006440new file mode 100644
index 0000000..e489c2a
--- /dev/null
+++ b/charms/focal/autopkgtest-web/webcontrol/README.md
@@ -0,0 +1,12 @@
1# autopkgtest-cloud web frontend
2
3## Developing browse.cgi locally
4
5Install the dependencies:
6`sudo apt install python3-flask python3-distro-info libjs-jquery libjs-bootstrap`
7
8Then simply run `./browse-test-py`, it will launch the flask application locally
9with some mocked data.
10As the import of `browse.cgi` is done trough `importlib`, changes in that file
11will not be reloaded automatically, so you'll still need to restart the app
12manually.
diff --git a/charms/focal/autopkgtest-web/webcontrol/browse-test.py b/charms/focal/autopkgtest-web/webcontrol/browse-test.py
0new file mode 10075513new file mode 100755
index 0000000..a5c5b4e
--- /dev/null
+++ b/charms/focal/autopkgtest-web/webcontrol/browse-test.py
@@ -0,0 +1,27 @@
1#!/usr/bin/env python3
2"""Run browse app in local debug mode for testing."""
3
4import importlib
5from pathlib import Path
6
7from helpers import tests, utils
8
9# import browse.cgi
10browse_path = str(Path(__file__).parent / "browse.cgi")
11loader = importlib.machinery.SourceFileLoader("browse", browse_path)
12spec = importlib.util.spec_from_loader("browse", loader)
13browse = importlib.util.module_from_spec(spec)
14loader.exec_module(browse)
15
16
17if __name__ == "__main__":
18 browse.db_con = utils.init_db(":memory:", check_same_thread=False)
19 with browse.db_con:
20 tests.populate_dummy_db(browse.db_con)
21 browse.swift_container_url = "swift-%s"
22 browse.AMQP_QUEUE_CACHE = Path("/dev/shm/queue.json")
23 tests.populate_dummy_amqp_cache(browse.AMQP_QUEUE_CACHE)
24 browse.RUNNING_CACHE = Path("/dev/shm/running.json")
25 tests.populate_dummy_running_cache(browse.RUNNING_CACHE)
26
27 browse.app.run(host="0.0.0.0", debug=True)
diff --git a/charms/focal/autopkgtest-web/webcontrol/helpers/tests.py b/charms/focal/autopkgtest-web/webcontrol/helpers/tests.py
0new file mode 10064428new file mode 100644
index 0000000..52017c2
--- /dev/null
+++ b/charms/focal/autopkgtest-web/webcontrol/helpers/tests.py
@@ -0,0 +1,148 @@
1import json
2from datetime import datetime
3from uuid import uuid4
4
5from .utils import get_supported_releases
6
7
8def populate_dummy_db(db_con):
9 supported_releases = get_supported_releases()
10
11 c = db_con.cursor()
12 tests = [
13 (1, supported_releases[0], "amd64", "hello"),
14 (2, supported_releases[1], "amd64", "hello"),
15 (3, supported_releases[0], "ppc64el", "hello"),
16 (4, supported_releases[1], "ppc64el", "hello"),
17 (5, supported_releases[2], "amd64", "hello"),
18 ]
19 c.executemany("INSERT INTO test values(?, ?, ?, ?)", tests)
20 results = [
21 # fmt: off
22 # test_id | run_id | version | trigger | duration | exit_code | requester | env | uuid
23 (1, datetime.now(), "1.2.3", "hello/1.2.3", 42, 0, "hyask", "", str(uuid4())),
24 (1, datetime.now(), "1.2.3", "hello/1.2.3", 42, 0, "hyask", "all-proposed=1", str(uuid4())),
25 (2, datetime.now(), "1.2.3", "hello/1.2.3", 42, 0, "", "", str(uuid4())),
26 (3, datetime.now(), "1.2.3", "hello/1.2.3", 42, 20, "", "", str(uuid4())),
27 # fmt: on
28 ]
29 c.executemany(
30 "INSERT INTO result values(?, ?, ?, ?, ?, ?, ?, ?, ?)", results
31 )
32 db_con.commit()
33
34
35def populate_dummy_amqp_cache(path):
36 supported_releases = get_supported_releases()
37 with open(path, "w") as f:
38 # pylint: disable=line-too-long
39 json.dump(
40 {
41 "arches": ["amd64", "ppc64el"],
42 "queues": {
43 "ubuntu": {
44 supported_releases[0]: {
45 "amd64": {
46 "size": 1,
47 "requests": [
48 'hello\n{"triggers": ["hello/1.2.3ubuntu1"], "submit-time": "2024-02-22 01:55:03"}',
49 ],
50 }
51 }
52 },
53 "huge": {
54 supported_releases[1]: {
55 "amd64": {
56 "size": 1,
57 "requests": [
58 'hello\n{"triggers": ["migration-reference/0"], "submit-time": "2024-02-22 01:55:03"}',
59 ],
60 }
61 }
62 },
63 "ppa": {
64 supported_releases[2]: {
65 "amd64": {
66 "size": 2,
67 "requests": [
68 'hello\n{"triggers": ["hello/1.2.4~ppa1"], "submit-time": "2024-02-22 01:55:03"}',
69 'hello2\n{"triggers": ["hello2/2.0.0~ppa1"], "submit-time": "2024-02-22 01:55:03"}',
70 ],
71 }
72 }
73 },
74 "upstream": {
75 supported_releases[3]: {
76 "amd64": {
77 "size": 1,
78 "requests": [
79 'hello\n{"triggers": ["hello/1.2.4~ppa1"], "submit-time": "2024-02-22 01:55:03"}',
80 ],
81 }
82 }
83 },
84 },
85 },
86 f,
87 )
88
89
90def populate_dummy_running_cache(path):
91 supported_releases = get_supported_releases()
92 with open(path, "w") as f:
93 json.dump(
94 {
95 "hello": {
96 "hash1": {
97 supported_releases[0]: {
98 "amd64": [
99 {
100 "requester": "hyask",
101 "submit-time": "2024-02-21 11:00:51",
102 "triggers": [
103 "hello/1.2.3",
104 ],
105 "uuid": "84669a9c-ac08-46a3-a5fd-6247d0d2021c",
106 },
107 3504,
108 """
1093071s hello/test_XYZ.hello . [ 54%]
1103153s hello/test_XYZ.hello ...... [ 64%]
1113271s hello/test_XYZ.hello .......... [ 74%]
1123292s hello/test_XYZ.hello .................. [ 84%]
1133493s hello/test_XYZ.hello ............................ [ 94%]
1143494s hello/test_XYZ.hello .................................... [ 98%]
115""",
116 ]
117 }
118 }
119 },
120 "hello2": {
121 "hash1": {
122 supported_releases[4]: {
123 "amd64": [
124 {
125 "all-proposed": "1",
126 "requester": "hyask",
127 "submit-time": "2024-02-21 11:01:21",
128 "triggers": [
129 "hello2/1.2.3-0ubuntu1",
130 ],
131 "uuid": "42369a9c-ac08-46a3-a5fd-6247d0d2021c",
132 },
133 3504,
134 """
1353071s hello2/test_XYZ.hello [ 54%]
1363153s hello2/test_XYZ.hello [ 64%]
1373271s hello2/test_XYZ.hello [ 74%]
1383292s hello2/test_XYZ.hello [ 84%]
1393493s hello2/test_XYZ.hello [ 94%]
1403494s hello2/test_XYZ.hello [ 98%]
141""",
142 ]
143 }
144 }
145 },
146 },
147 f,
148 )

Subscribers

People subscribed via source and target branches