canonical-ubuntu-qa team mailing list archive
-
canonical-ubuntu-qa team
-
Mailing list archive
-
Message #03212
[Merge] ~hyask/autopkgtest-cloud:skia/improve_debugging into autopkgtest-cloud:master
Skia has proposed merging ~hyask/autopkgtest-cloud:skia/improve_debugging into autopkgtest-cloud:master.
Requested reviews:
Canonical's Ubuntu QA (canonical-ubuntu-qa)
For more details, see:
https://code.launchpad.net/~hyask/autopkgtest-cloud/+git/autopkgtest-cloud/+merge/461711
--
Your team Canonical's Ubuntu QA is requested to review the proposed merge of ~hyask/autopkgtest-cloud:skia/improve_debugging into autopkgtest-cloud:master.
diff --git a/charms/focal/autopkgtest-web/webcontrol/README.md b/charms/focal/autopkgtest-web/webcontrol/README.md
index e489c2a..158b1f1 100644
--- a/charms/focal/autopkgtest-web/webcontrol/README.md
+++ b/charms/focal/autopkgtest-web/webcontrol/README.md
@@ -5,6 +5,10 @@
Install the dependencies:
`sudo apt install python3-flask python3-distro-info libjs-jquery libjs-bootstrap`
+*Optional*: `python3 -m pip install --user --break-system-packages flask-debugtoolbar`
+This will automatically activate the Falsk DebugToolbar that brings valuable
+information for developers.
+
Then simply run `./browse-test-py`, it will launch the flask application locally
with some mocked data.
As the import of `browse.cgi` is done trough `importlib`, changes in that file
diff --git a/charms/focal/autopkgtest-web/webcontrol/browse-test.py b/charms/focal/autopkgtest-web/webcontrol/browse-test.py
index a5c5b4e..30bbca2 100755
--- a/charms/focal/autopkgtest-web/webcontrol/browse-test.py
+++ b/charms/focal/autopkgtest-web/webcontrol/browse-test.py
@@ -1,9 +1,17 @@
#!/usr/bin/env python3
"""Run browse app in local debug mode for testing."""
+import argparse
import importlib
from pathlib import Path
+try:
+ from flask_debugtoolbar import DebugToolbarExtension
+
+ activate_debugtoolbar = True
+except ImportError:
+ activate_debugtoolbar = False
+
from helpers import tests, utils
# import browse.cgi
@@ -14,14 +22,58 @@ browse = importlib.util.module_from_spec(spec)
loader.exec_module(browse)
+def parse_args():
+ parser = argparse.ArgumentParser(description="Run a local browse.cgi")
+ parser.add_argument(
+ "--database",
+ dest="database",
+ type=str,
+ )
+ parser.add_argument(
+ "--running",
+ dest="running",
+ type=str,
+ )
+ parser.add_argument(
+ "--queue",
+ dest="queue",
+ type=str,
+ )
+
+ return parser.parse_args()
+
+
if __name__ == "__main__":
- browse.db_con = utils.init_db(":memory:", check_same_thread=False)
- with browse.db_con:
- tests.populate_dummy_db(browse.db_con)
+ args = parse_args()
+ if args.database:
+ browse.db_con = utils.init_db(
+ args.database,
+ check_same_thread=False,
+ )
+ else:
+ browse.db_con = utils.init_db(
+ ":memory:",
+ check_same_thread=False,
+ )
+ with browse.db_con:
+ tests.populate_dummy_db(browse.db_con)
+
+ if args.queue:
+ browse.AMQP_QUEUE_CACHE = Path(args.queue)
+ else:
+ browse.AMQP_QUEUE_CACHE = Path("/dev/shm/queue.json")
+ tests.populate_dummy_amqp_cache(browse.AMQP_QUEUE_CACHE)
+
+ if args.running:
+ browse.RUNNING_CACHE = Path(args.running)
+ else:
+ browse.RUNNING_CACHE = Path("/dev/shm/running.json")
+ tests.populate_dummy_running_cache(browse.RUNNING_CACHE)
+
browse.swift_container_url = "swift-%s"
- browse.AMQP_QUEUE_CACHE = Path("/dev/shm/queue.json")
- tests.populate_dummy_amqp_cache(browse.AMQP_QUEUE_CACHE)
- browse.RUNNING_CACHE = Path("/dev/shm/running.json")
- tests.populate_dummy_running_cache(browse.RUNNING_CACHE)
+ if activate_debugtoolbar:
+ browse.app.debug = True
+ browse.app.config["SECRET_KEY"] = "AutopkgtestCloudSecretK3y"
+ toolbar = DebugToolbarExtension(browse.app)
browse.app.run(host="0.0.0.0", debug=True)
Follow ups