← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:testfix-archive-gpg-signing-key-fix-non-default into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:testfix-archive-gpg-signing-key-fix-non-default into launchpad:master.

Commit message:
Keep generateSigningKey(async_keyserver=False) synchronous

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

generateSigningKey(async_keyserver=False) is used in non-Twisted contexts and so must remain synchronous.  generateSigningKey(async_keyserver=True) is an asynchronous variant used in tests.

Fixes test failures caused by https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/391427.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:testfix-archive-gpg-signing-key-fix-non-default into launchpad:master.
diff --git a/lib/lp/archivepublisher/archivegpgsigningkey.py b/lib/lp/archivepublisher/archivegpgsigningkey.py
index bdb2d16..4c3688d 100644
--- a/lib/lp/archivepublisher/archivegpgsigningkey.py
+++ b/lib/lp/archivepublisher/archivegpgsigningkey.py
@@ -245,7 +245,6 @@ class ArchiveGPGSigningKey(SignableArchive):
         with open(export_path, 'wb') as export_file:
             export_file.write(key.export())
 
-    @defer.inlineCallbacks
     def generateSigningKey(self, log=None, async_keyserver=False):
         """See `IArchiveGPGSigningKey`."""
         assert self.archive.signing_key_fingerprint is None, (
@@ -256,14 +255,26 @@ class ArchiveGPGSigningKey(SignableArchive):
         # is then propagated to the context named-ppa.
         default_ppa = self.archive.owner.archive
         if self.archive != default_ppa:
+            def propagate_key(_):
+                self.archive.signing_key_owner = default_ppa.signing_key_owner
+                self.archive.signing_key_fingerprint = (
+                    default_ppa.signing_key_fingerprint)
+                del get_property_cache(self.archive).signing_key
+
             if default_ppa.signing_key_fingerprint is None:
-                yield IArchiveGPGSigningKey(default_ppa).generateSigningKey(
+                d = IArchiveGPGSigningKey(default_ppa).generateSigningKey(
                     log=log, async_keyserver=async_keyserver)
-            self.archive.signing_key_owner = default_ppa.signing_key_owner
-            self.archive.signing_key_fingerprint = (
-                default_ppa.signing_key_fingerprint)
-            del get_property_cache(self.archive).signing_key
-            defer.returnValue(None)
+            else:
+                d = defer.succeed(None)
+            # generateSigningKey is only asynchronous if async_keyserver is
+            # true; we need some contortions to keep it synchronous
+            # otherwise.
+            if async_keyserver:
+                d.addCallback(propagate_key)
+                return d
+            else:
+                propagate_key(None)
+                return
 
         key_displayname = (
             "Launchpad PPA for %s" % self.archive.owner.displayname)
@@ -281,7 +292,7 @@ class ArchiveGPGSigningKey(SignableArchive):
         else:
             signing_key = getUtility(IGPGHandler).generateKey(
                 key_displayname, logger=log)
-        yield self._setupSigningKey(
+        return self._setupSigningKey(
             signing_key, async_keyserver=async_keyserver)
 
     def setSigningKey(self, key_path, async_keyserver=False):