Merge ~xnox/launchpad-buildd:image-targets-fix into launchpad-buildd:master

Proposed by Dimitri John Ledkov
Status: Rejected
Rejected by: Colin Watson
Proposed branch: ~xnox/launchpad-buildd:image-targets-fix
Merge into: launchpad-buildd:master
Diff against target: 35 lines (+21/-3)
1 file modified
lpbuildd/target/chroot.py (+21/-3)
Reviewer Review Type Date Requested Status
Colin Watson (community) Disapprove
Review via email: mp+386328@code.launchpad.net

Commit message

target/chroot: fix passing space separate env variable values

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

You've misunderstood what lpbuildd/target/lxd.py is doing here. It has to quote arguments in the case where cwd is not None because it's explicitly constructing a shell command line. The rule is that there must be exactly one layer of quoting per layer of parsing, so because the shell invocation adds another layer of parsing, it has to add another layer of quoting to match. The lxd backend is correct.

The problem here is that the call to shell_escape in the lines you're modifying is flat-out wrong (which seems to have been my fault). There is no parsing involved here: args is being constructed as an argument list rather than something that's passed to a shell, and adding extra quoting to those is incorrect. The correct fix would be simply to remove the call to shell_escape on line 65. Could you please do that instead? It doesn't need a comment - it just needs to have the incorrect function call removed.

It would also be helpful to add a test for this, which could go alongside the other test_run* methods in lpbuildd/target/tests/test_chroot.py.

review: Needs Fixing
Revision history for this message
Colin Watson (cjwatson) wrote :
review: Disapprove

Unmerged commits

6ea1902... by Dimitri John Ledkov

target/chroot: fix passing space separate env variable values

image_targets list is encoded as space separated environment variable,
which is encoded in pylxd backend correctly, but not in the chroot
one.

Maybe lists should be encoded as comma separated, at lease
livecd-rootfs supports that.

LP: https://bugs.launchpad.net/launchpad-buildd/+bug/1884936

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lpbuildd/target/chroot.py b/lpbuildd/target/chroot.py
2index 203142c..cbed3c7 100644
3--- a/lpbuildd/target/chroot.py
4+++ b/lpbuildd/target/chroot.py
5@@ -61,9 +61,27 @@ class Chroot(Backend):
6 echo=False, **kwargs):
7 """See `Backend`."""
8 if env:
9- args = ["env"] + [
10- "%s=%s" % (key, shell_escape(value))
11- for key, value in env.items()] + args
12+ # Currently pylxd backend does not quote the k=v pairs
13+ # when passing them to the lxc executor, but it does quote
14+ # every arg if cwd is changed. Match that behaviour in
15+ # chroot executor too, and do not quote the value, of the
16+ # key, if shell_escape will happen later when cwd is set.
17+ # Otherwise instead of the expected 'IMAGE_TARGETS=tarball
18+ # squashfs' arg, it becomes \'IMAGE_TARGET\'"\'"\'tarball
19+ # squashfs\'"\'"\'\', and when decoded by make-config
20+ # python script in livecd-rootfs it ends up getting parsed
21+ # as ["'tarball", "squashfs'"], as in first value prefixed
22+ # and last value suffixed with ' Alternatively,
23+ # make-config script in livecd-rootfs can add a workaround
24+ # to parse such bad values.
25+ if cwd:
26+ args = ["env"] + [
27+ "%s=%s" % (key, value)
28+ for key, value in env.items()] + args
29+ else:
30+ args = ["env"] + [
31+ "%s=%s" % (key, shell_escape(value))
32+ for key, value in env.items()] + args
33 if self.arch is not None:
34 args = set_personality(args, self.arch, series=self.series)
35 if cwd is not None:

Subscribers

People subscribed via source and target branches