Merge lp:~cjwatson/launchpad-buildd/better-snap-channel-handling into lp:launchpad-buildd

Proposed by Colin Watson
Status: Merged
Merged at revision: 363
Proposed branch: lp:~cjwatson/launchpad-buildd/better-snap-channel-handling
Merge into: lp:launchpad-buildd
Diff against target: 138 lines (+43/-16)
4 files modified
debian/changelog (+2/-0)
lpbuildd/snap.py (+2/-1)
lpbuildd/target/build_snap.py (+36/-14)
lpbuildd/target/tests/test_build_snap.py (+3/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad-buildd/better-snap-channel-handling
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+362859@code.launchpad.net

Commit message

Generalise snap channel handling slightly, allowing channel selection for core16 and core18.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2019-02-07 11:50:26 +0000
3+++ debian/changelog 2019-02-07 11:53:24 +0000
4@@ -2,6 +2,8 @@
5
6 * Allow the LXD backend to accept a LXD image instead of a chroot tarball,
7 skipping the conversion step (LP: #1811677).
8+ * Generalise snap channel handling slightly, allowing channel selection
9+ for core16 and core18.
10
11 -- Colin Watson <cjwatson@ubuntu.com> Thu, 07 Feb 2019 11:50:07 +0000
12
13
14=== modified file 'lpbuildd/snap.py'
15--- lpbuildd/snap.py 2018-10-19 06:41:14 +0000
16+++ lpbuildd/snap.py 2019-02-07 11:53:24 +0000
17@@ -328,7 +328,8 @@
18 known_snaps = ("core", "snapcraft")
19 for snap in known_snaps:
20 if snap in self.channels:
21- args.extend(["--channel-%s" % snap, self.channels[snap]])
22+ args.extend(
23+ ["--channel", "%s=%s" % (snap, self.channels[snap])])
24 unknown_snaps = set(self.channels) - set(known_snaps)
25 if unknown_snaps:
26 print(
27
28=== modified file 'lpbuildd/target/build_snap.py'
29--- lpbuildd/target/build_snap.py 2018-10-11 08:59:22 +0000
30+++ lpbuildd/target/build_snap.py 2019-02-07 11:53:24 +0000
31@@ -5,6 +5,7 @@
32
33 __metaclass__ = type
34
35+import argparse
36 from collections import OrderedDict
37 import json
38 import logging
39@@ -28,21 +29,39 @@
40 logger = logging.getLogger(__name__)
41
42
43+class SnapChannelsAction(argparse.Action):
44+
45+ def __init__(self, option_strings, dest, nargs=None, **kwargs):
46+ if nargs is not None:
47+ raise ValueError("nargs not allowed")
48+ super(SnapChannelsAction, self).__init__(
49+ option_strings, dest, **kwargs)
50+
51+ def __call__(self, parser, namespace, values, option_string=None):
52+ if "=" not in values:
53+ raise argparse.ArgumentError(
54+ self, "'{}' is not of the form 'snap=channel'".format(values))
55+ snap, channel = values.split("=", 1)
56+ if getattr(namespace, self.dest, None) is None:
57+ setattr(namespace, self.dest, {})
58+ getattr(namespace, self.dest)[snap] = channel
59+
60+
61 class BuildSnap(VCSOperationMixin, Operation):
62
63 description = "Build a snap."
64
65+ core_snap_names = ["core", "core16", "core18"]
66+
67 @classmethod
68 def add_arguments(cls, parser):
69 super(BuildSnap, cls).add_arguments(parser)
70 parser.add_argument(
71- "--channel-core", metavar="CHANNEL",
72- help="install core snap from CHANNEL")
73- parser.add_argument(
74- "--channel-snapcraft", metavar="CHANNEL",
75- help=(
76- "install snapcraft as a snap from CHANNEL rather than as a "
77- ".deb"))
78+ "--channel", action=SnapChannelsAction, metavar="SNAP=CHANNEL",
79+ dest="channels", default={}, help=(
80+ "install SNAP from CHANNEL "
81+ "(supported snaps: {}, snapcraft)".format(
82+ ", ".join(cls.core_snap_names))))
83 parser.add_argument(
84 "--build-url", help="URL of this build on Launchpad")
85 parser.add_argument("--proxy-url", help="builder proxy url")
86@@ -119,21 +138,24 @@
87 deps.extend(self.vcs_deps)
88 if self.args.proxy_url:
89 deps.extend(["python3", "socat"])
90- if self.args.channel_snapcraft:
91+ if "snapcraft" in self.args.channels:
92 # snapcraft requires sudo in lots of places, but can't depend on
93 # it when installed as a snap.
94 deps.append("sudo")
95 else:
96 deps.append("snapcraft")
97 self.backend.run(["apt-get", "-y", "install"] + deps)
98- if self.args.channel_core:
99- self.backend.run(
100- ["snap", "install",
101- "--channel=%s" % self.args.channel_core, "core"])
102- if self.args.channel_snapcraft:
103+ for snap_name in self.core_snap_names:
104+ if snap_name in self.args.channels:
105+ self.backend.run(
106+ ["snap", "install",
107+ "--channel=%s" % self.args.channels[snap_name],
108+ snap_name])
109+ if "snapcraft" in self.args.channels:
110 self.backend.run(
111 ["snap", "install", "--classic",
112- "--channel=%s" % self.args.channel_snapcraft, "snapcraft"])
113+ "--channel=%s" % self.args.channels["snapcraft"],
114+ "snapcraft"])
115 if self.args.proxy_url:
116 self.backend.copy_in(
117 os.path.join(self.slavebin, "snap-git-proxy"),
118
119=== modified file 'lpbuildd/target/tests/test_build_snap.py'
120--- lpbuildd/target/tests/test_build_snap.py 2018-10-11 08:59:22 +0000
121+++ lpbuildd/target/tests/test_build_snap.py 2019-02-07 11:53:24 +0000
122@@ -166,7 +166,8 @@
123 args = [
124 "buildsnap",
125 "--backend=fake", "--series=xenial", "--arch=amd64", "1",
126- "--channel-core=candidate", "--channel-snapcraft=edge",
127+ "--channel=core=candidate", "--channel=core18=beta",
128+ "--channel=snapcraft=edge",
129 "--branch", "lp:foo", "test-snap",
130 ]
131 build_snap = parse_args(args=args).operation
132@@ -174,6 +175,7 @@
133 self.assertThat(build_snap.backend.run.calls, MatchesListwise([
134 RanAptGet("install", "bzr", "sudo"),
135 RanSnap("install", "--channel=candidate", "core"),
136+ RanSnap("install", "--channel=beta", "core18"),
137 RanSnap("install", "--classic", "--channel=edge", "snapcraft"),
138 ]))
139

Subscribers

People subscribed via source and target branches

to all changes: