← Back to team overview

canonical-ubuntu-qa team mailing list archive

[Merge] ~hyask/autopkgtest-cloud:skia/use_new_ppa_interface into autopkgtest-cloud:master

 

Skia has proposed merging ~hyask/autopkgtest-cloud:skia/use_new_ppa_interface 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/477502

Use the new interface of autopkgtest to add PPA sources.
-- 
Your team Canonical's Ubuntu QA is requested to review the proposed merge of ~hyask/autopkgtest-cloud:skia/use_new_ppa_interface into autopkgtest-cloud:master.
diff --git a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/worker/worker b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/worker/worker
index c281b0f..c5868d9 100755
--- a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/worker/worker
+++ b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/worker/worker
@@ -23,9 +23,7 @@ import subprocess
 import sys
 import tempfile
 import time
-import urllib.request
 import uuid
-from urllib.error import HTTPError
 
 import amqp
 import distro_info
@@ -988,88 +986,23 @@ def request(msg):
                     )
                     msg.channel.basic_reject(msg.delivery_tag, requeue=False)
                     return
-                if fingerprint:
-                    logging.debug(
-                        "Request states that PPA user %s, name %s has GPG fingerprint %s"
-                        % (ppauser, ppaname, fingerprint)
-                    )
-                else:
-                    # Private PPAs require the fingerprint passed through the
-                    # request as we can't use the LP API to fetch it.
-                    if ppacreds_user:
-                        logging.error(
-                            "Invalid PPA specification, GPG fingerprint required for private PPAs"
-                        )
-                        msg.channel.basic_reject(
-                            msg.delivery_tag, requeue=False
-                        )
-                        return
-                    for retry in range(5):
-                        try:
-                            f = urllib.request.urlopen(
-                                "https://api.launchpad.net/1.0/~%s/+archive/ubuntu/%s";
-                                % (ppauser, ppaname)
-                            )
-                            contents = f.read().decode("UTF-8")
-                            f.close()
-                            fingerprint = json.loads(contents)[
-                                "signing_key_fingerprint"
-                            ]
-                            logging.debug(
-                                "PPA user %s, name %s has GPG fingerprint %s"
-                                % (ppauser, ppaname, fingerprint)
-                            )
-                        except HTTPError as e:
-                            # It's quite common to get 503s from LP; retry a
-                            # few times.
-                            if e.code != 503:
-                                raise
-                            logging.warning("Got error 503 from launchpad API")
-                            time.sleep(10)
-                        except (IOError, ValueError, KeyError) as e:
-                            logging.error(
-                                'Cannot get PPA information: "%s". Consuming the request - it will be left dangling; retry once the problem is resolved.'
-                                % e
-                            )
-                            msg.channel.basic_reject(
-                                msg.delivery_tag, requeue=False
-                            )
-                            return
-                        else:
-                            break
-                    else:
-                        logging.error(
-                            "Cannot contact Launchpad to get PPA information. Consuming the request - it will be left dangling; retry once the problem is resolved."
-                        )
-                        msg.channel.basic_reject(
-                            msg.delivery_tag, requeue=False
-                        )
-                        return
+                logging.debug(
+                    "Request states that PPA user '%s', name '%s' has GPG fingerprint '%s'"
+                    % (ppauser, ppaname, fingerprint)
+                )
                 if ppacreds_user:
                     # Any run with at least one private PPA needs to be private.
                     private = True
-                    ppaprefix = "https://%s:%s@private-"; % (
+                    ppaprefix = "%s:%s@" % (
                         ppacreds_user,
                         ppacreds_pass,
                     )
                 else:
-                    ppaprefix = "http://";
-                # add GPG key
-                # we need to `gpg --dearmor` because at least trusty doesn't seem to support asc keys and
-                # OpenPGP HKS protocol doesn't specify a way to directly download unarmored keys
-                # both wget and gpg are thus required on the testbed, and both are present on the cloud images by default
-                argv += [
-                    "--setup-commands",
-                    f"wget -O- 'http://keyserver.ubuntu.com/pks/lookup?op=get&options=mr&v=1&search=0x{fingerprint}' | "
-                    f"gpg --dearmor > '/etc/apt/trusted.gpg.d/autopkgtest-{ppauser}-{ppaname}.gpg'",
-                ]
-                # add apt source
+                    ppaprefix = ""
+                if fingerprint:
+                    fingerprint = f":{fingerprint}"
                 argv += [
-                    "--setup-commands",
-                    "REL=$(lsb_release -cs); "
-                    'echo "deb %(prefix)sppa.launchpad.net/%(u)s/%(p)s/ubuntu $REL main" > /etc/apt/sources.list.d/autopkgtest-%(u)s-%(p)s.list; '
-                    'echo "deb-src %(prefix)sppa.launchpad.net/%(u)s/%(p)s/ubuntu $REL main" >> /etc/apt/sources.list.d/autopkgtest-%(u)s-%(p)s.list;'
-                    % {"prefix": ppaprefix, "u": ppauser, "p": ppaname},
+                    f"--add-apt-source=ppa:{ppaprefix}{ppauser}/{ppaname}{fingerprint}"
                 ]
 
             # put results into separate container, named by the last PPA