← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:fix-copy-signingkeys-options into launchpad:master

 

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

Commit message:
Fix option processing in copy-signingkeys

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

LaunchpadScript.__init__ runs handle_options before the component architecture has been set up, so we need to process our options a bit later.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:fix-copy-signingkeys-options into launchpad:master.
diff --git a/lib/lp/archivepublisher/scripts/copy_signingkeys.py b/lib/lp/archivepublisher/scripts/copy_signingkeys.py
index 7d7be1d..e4a46bd 100644
--- a/lib/lp/archivepublisher/scripts/copy_signingkeys.py
+++ b/lib/lp/archivepublisher/scripts/copy_signingkeys.py
@@ -69,7 +69,7 @@ class CopySigningKeysScript(LaunchpadScript):
                 "Could not find series '%s' in %s." %
                 (series_name, self.from_archive.distribution.display_name))
 
-    def handle_options(self):
+    def processOptions(self):
         if len(self.args) != 2:
             self.parser.print_help()
             sys.exit(1)
@@ -103,6 +103,7 @@ class CopySigningKeysScript(LaunchpadScript):
             to_archive, series, from_archive_signing_key.signing_key)
 
     def main(self):
+        self.processOptions()
         for key_type in self.key_types:
             self.copy(
                 self.from_archive, self.to_archive, key_type,
diff --git a/lib/lp/archivepublisher/tests/test_copy_signingkeys.py b/lib/lp/archivepublisher/tests/test_copy_signingkeys.py
index bc179ed..049bf95 100644
--- a/lib/lp/archivepublisher/tests/test_copy_signingkeys.py
+++ b/lib/lp/archivepublisher/tests/test_copy_signingkeys.py
@@ -12,6 +12,7 @@ from testtools.matchers import (
     MatchesSetwise,
     MatchesStructure,
     )
+import transaction
 
 from lp.archivepublisher.scripts.copy_signingkeys import CopySigningKeysScript
 from lp.services.config import config
@@ -23,6 +24,7 @@ from lp.services.signing.model.signingkey import ArchiveSigningKey
 from lp.services.utils import CapturedOutput
 from lp.testing import TestCaseWithFactory
 from lp.testing.layers import ZopelessDatabaseLayer
+from lp.testing.script import run_script
 
 
 class TestCopySigningKeysScript(TestCaseWithFactory):
@@ -39,6 +41,7 @@ class TestCopySigningKeysScript(TestCaseWithFactory):
                 script = CopySigningKeysScript(
                     "copy-signingkeys", dbuser=config.archivepublisher.dbuser,
                     test_args=test_args)
+                script.processOptions()
         except SystemExit:
             exited = True
         else:
@@ -300,3 +303,41 @@ class TestCopySigningKeysScript(TestCaseWithFactory):
                     archive=archives[1], earliest_distro_series=None,
                     key_type=SigningKeyType.UEFI, signing_key=signing_keys[1]),
                 ))
+
+    def runScript(self, args=None):
+        transaction.commit()
+        ret, out, err = run_script("scripts/copy-signingkeys.py", args=args)
+        if out:
+            self.addDetail("stdout", text_content(out))
+        if err:
+            self.addDetail("stderr", text_content(err))
+        self.assertEqual(0, ret)
+        transaction.commit()
+
+    def test_script(self):
+        archives = [self.factory.makeArchive() for _ in range(2)]
+        signing_keys = [
+            self.factory.makeSigningKey(key_type=key_type)
+            for key_type in (SigningKeyType.UEFI, SigningKeyType.KMOD)]
+        for signing_key in signing_keys[:2]:
+            self.factory.makeArchiveSigningKey(
+                archive=archives[0], signing_key=signing_key)
+
+        self.runScript(args=[archive.reference for archive in archives])
+
+        self.assertThat(
+            self.findKeys(archives),
+            MatchesSetwise(
+                MatchesStructure.byEquality(
+                    archive=archives[0], earliest_distro_series=None,
+                    key_type=SigningKeyType.UEFI, signing_key=signing_keys[0]),
+                MatchesStructure.byEquality(
+                    archive=archives[0], earliest_distro_series=None,
+                    key_type=SigningKeyType.KMOD, signing_key=signing_keys[1]),
+                MatchesStructure.byEquality(
+                    archive=archives[1], earliest_distro_series=None,
+                    key_type=SigningKeyType.UEFI, signing_key=signing_keys[0]),
+                MatchesStructure.byEquality(
+                    archive=archives[1], earliest_distro_series=None,
+                    key_type=SigningKeyType.KMOD, signing_key=signing_keys[1]),
+                ))