← Back to team overview

canonical-ubuntu-qa team mailing list archive

[Merge] ~andersson123/autopkgtest-cloud:autopkgtest-db-sha256-fix into autopkgtest-cloud:master

 

Tim Andersson has proposed merging ~andersson123/autopkgtest-cloud:autopkgtest-db-sha256-fix into autopkgtest-cloud:master.

Commit message:
fix: web: ensure that autopkgtest.db.sha256 is symlinked

The functionality to symlink /home/ubuntu/public/autopkgtest.db to the
static directory which the flask web app serves files from was
duplicated for autopkgtest.db.sha256 - however a flag wasn't added for
this new statically served file, and the flag for the db being symlinked
was already set, meaning the `symlink_public_db` function wasn't
executed in production and thus autopkgtest.db.sha256 was never
symlinked or served via the web app.

Additionally to this, symlinking the sha256 file was in the same
try/except block as the db itself, where the exception was a
FileExistsError. The db symlink already existed, meaning the exception
was thrown, and thus the sha256 file wouldn't have been symlinked even
with a separate flag as described above.

This commit amends the issue by adding a second flag for the sha256
file, and symlinking the db and the sha256 file in a loop, separately.
The functionality beforehand in which the public directory is created,
was moved to it's own try/except block also.

Requested reviews:
  Canonical's Ubuntu QA (canonical-ubuntu-qa)

For more details, see:
https://code.launchpad.net/~andersson123/autopkgtest-cloud/+git/autopkgtest-cloud/+merge/468232

Recently we updated britney to start using the checksum instead of the content-length when downloading autopkgtest.db to validate integrity of the downloaded file. However, the autopkgtest.db.sha256 file hadn't been symlinked by the charm and thus the file wasn't being served. This MP amends the issue.
-- 
Your team Canonical's Ubuntu QA is requested to review the proposed merge of ~andersson123/autopkgtest-cloud:autopkgtest-db-sha256-fix into autopkgtest-cloud:master.
diff --git a/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py b/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
index c36b9ff..ba091b7 100644
--- a/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
+++ b/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
@@ -16,6 +16,7 @@ from charms.reactive import (
     when_all,
     when_any,
     when_not,
+    when_not_all,
 )
 
 AUTOPKGTEST_CLOUD_CONF = os.path.expanduser("~ubuntu/autopkgtest-cloud.conf")
@@ -500,29 +501,35 @@ def symlink_running():
         pass
 
 
-@when_not("autopkgtest-web.public-db-symlinked")
+@when_not_all(
+    "autopkgtest-web.public-db-symlinked",
+    "autopkgtest-web.public-db-sha256-symlinked",
+)
 def symlink_public_db():
-    status.maintenance("Creating symlink for public database")
+    status.maintenance(
+        "Creating symlink for public database and sha256 checksum of public database"
+    )
     try:
         publicdir = os.path.expanduser("~ubuntu/public/")
         os.makedirs(publicdir)
         shutil.chown(publicdir, user="ubuntu", group="ubuntu")
-        os.symlink(
-            os.path.join(publicdir, "autopkgtest.db"),
-            os.path.join(
-                charm_dir(), "webcontrol", "static", "autopkgtest.db"
-            ),
-        )
-        os.symlink(
-            os.path.join(publicdir, "autopkgtest.db.sha256"),
-            os.path.join(
-                charm_dir(), "webcontrol", "static", "autopkgtest.db.sha256"
-            ),
-        )
-        status.maintenance("Done creating symlink for public database")
-        set_flag("autopkgtest-web.public-db-symlinked")
     except FileExistsError:
         pass
+    for symlink_file, symlink_flag in {
+        "autopkgtest.db": "autopkgtest-web.public-db-symlinked",
+        "autopkgtest.db.sha256": "autopkgtest-web-public-db-sha256-symlinked",
+    }.items():
+        try:
+            os.symlink(
+                os.path.join(publicdir, symlink_file),
+                os.path.join(
+                    charm_dir(), "webcontrol", "static", symlink_file
+                ),
+            )
+            set_flag(symlink_flag)
+            status.maintenance(f"Done creating symlink for {symlink_file}")
+        except FileExistsError:
+            pass
 
 
 @when("leadership.is_leader")