← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:sync-signingkeys-fix-paths into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:sync-signingkeys-fix-paths into launchpad:master.

Commit message:
Use absolute key paths in sync-signingkeys

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/383860

sync-signingkeys failed because it tried to open just the basename of the key file when preparing to inject it.  Rearrange things so that it opens the key files by absolute path instead.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:sync-signingkeys-fix-paths into launchpad:master.
diff --git a/lib/lp/archivepublisher/scripts/sync_signingkeys.py b/lib/lp/archivepublisher/scripts/sync_signingkeys.py
index f25d5c2..38444ce 100644
--- a/lib/lp/archivepublisher/scripts/sync_signingkeys.py
+++ b/lib/lp/archivepublisher/scripts/sync_signingkeys.py
@@ -64,12 +64,12 @@ class SyncSigningKeysScript(LaunchpadScript):
             SigningKeyType.SIPL: ("sipl.pem", "sipl.x509"),
             SigningKeyType.FIT: ("fit.key", "fit.crt"),
         }
+        found_keys_per_type = {}
         for key_type in SigningKeyType.items:
             files = [os.path.join(dir, f) for f in keys_per_type[key_type]]
-            if not all(os.path.exists(f) for f in files):
-                del keys_per_type[key_type]
-                continue
-        return keys_per_type
+            if all(os.path.exists(f) for f in files):
+                found_keys_per_type[key_type] = tuple(files)
+        return found_keys_per_type
 
     def getSeriesPaths(self, archive):
         """Returns the directory of each series containing signing keys.
diff --git a/lib/lp/archivepublisher/tests/test_sync_signingkeys.py b/lib/lp/archivepublisher/tests/test_sync_signingkeys.py
index 19d6138..a1d1796 100644
--- a/lib/lp/archivepublisher/tests/test_sync_signingkeys.py
+++ b/lib/lp/archivepublisher/tests/test_sync_signingkeys.py
@@ -103,7 +103,9 @@ class TestSyncSigningKeysScript(TestCaseWithFactory):
 
         script = self.makeScript([])
         self.assertThat(script.getKeysPerType(keys_dir), MatchesDict({
-            SigningKeyType.UEFI: Equals(("uefi.key", "uefi.crt"))
+            SigningKeyType.UEFI: Equals(
+                (os.path.join(keys_dir, "uefi.key"),
+                 os.path.join(keys_dir, "uefi.crt")))
         }))
 
     def test_get_series_paths(self):
@@ -150,12 +152,18 @@ class TestSyncSigningKeysScript(TestCaseWithFactory):
         script.main()
 
         self.assertItemsEqual([
-            mock.call(archive, SigningKeyType.KMOD, series1, "kmod.pem",
-                      "kmod.x509"),
-            mock.call(archive, SigningKeyType.OPAL, series1, "opal.pem",
-                      "opal.x509"),
-            mock.call(archive, SigningKeyType.UEFI, None, "uefi.key",
-                      "uefi.crt")],
+            mock.call(
+                archive, SigningKeyType.KMOD, series1,
+                os.path.join(key_dirs[series1], "kmod.pem"),
+                os.path.join(key_dirs[series1], "kmod.x509")),
+            mock.call(
+                archive, SigningKeyType.OPAL, series1,
+                os.path.join(key_dirs[series1], "opal.pem"),
+                os.path.join(key_dirs[series1], "opal.x509")),
+            mock.call(
+                archive, SigningKeyType.UEFI, None,
+                os.path.join(archive_root, "uefi.key"),
+                os.path.join(archive_root, "uefi.crt"))],
             script.inject.call_args_list)
 
         # Check the log messages.
@@ -166,13 +174,22 @@ class TestSyncSigningKeysScript(TestCaseWithFactory):
 
         tpl = "INFO Found key files %s / %s (type=%s, series=%s)."
         self.assertIn(
-            tpl % ("kmod.pem", "kmod.x509", SigningKeyType.KMOD, series1.name),
+            tpl % (
+                os.path.join(key_dirs[series1], "kmod.pem"),
+                os.path.join(key_dirs[series1], "kmod.x509"),
+                SigningKeyType.KMOD, series1.name),
             content)
         self.assertIn(
-            tpl % ("opal.pem", "opal.x509", SigningKeyType.OPAL, series1.name),
+            tpl % (
+                os.path.join(key_dirs[series1], "opal.pem"),
+                os.path.join(key_dirs[series1], "opal.x509"),
+                SigningKeyType.OPAL, series1.name),
             content)
         self.assertIn(
-            tpl % ("uefi.key", "uefi.crt", SigningKeyType.UEFI, None),
+            tpl % (
+                os.path.join(archive_root, "uefi.key"),
+                os.path.join(archive_root, "uefi.crt"),
+                SigningKeyType.UEFI, None),
             content)
 
     def test_inject(self):