Merge ~nacc/git-ubuntu:lp1741949-unset-snap-in-lxc-env into git-ubuntu:master

Proposed by Nish Aravamudan
Status: Merged
Approved by: Robie Basak
Approved revision: 467d0f591f7fcd79b7fb7a99ca6be12585ffc3ef
Merged at revision: 699b0185f4ed61eceb754e95568de12417ad3ad5
Proposed branch: ~nacc/git-ubuntu:lp1741949-unset-snap-in-lxc-env
Merge into: git-ubuntu:master
Diff against target: 217 lines (+75/-46)
2 files modified
gitubuntu/build.py (+36/-46)
gitubuntu/run.py (+39/-0)
Reviewer Review Type Date Requested Status
Robie Basak Approve
Andreas Hasenack Approve
Server Team CI bot continuous-integration Approve
Nish Aravamudan Pending
Review via email: mp+336391@code.launchpad.net

This proposal supersedes a proposal from 2018-01-18.

Commit message

Make Jenkins happy.

Description of the change

Make Jenkins happy.

To post a comment you must log in.
Revision history for this message
Robie Basak (racb) wrote : Posted in a previous version of this proposal

Why are we unsetting SNAP for some calls to lxc, but not all of them? Is there some criteria we have to use to decide this? Or are you just working around the calls that happen to break for now?

As long as we have to work around some other project's bug, I'd like to have a bug reference in a comment in our code which shows us why the workaround is present and what its status is for us to get rid of it. So when I asked for a bug against this, I meant I wanted an open bug task against the project which we are working around (whether that is snapd or lxd I'm not sure).

review: Needs Information
Revision history for this message
Server Team CI bot (server-team-bot) wrote : Posted in a previous version of this proposal

FAILED: Continuous integration, rev:c21e653eddde8b9ad7d4d89ee56ede9a4d504dc1
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~racb/usd-importer/+git/usd-importer/+merge/336297/+edit-commit-message

https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/246/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Style Check
    SUCCESS: Unit Tests
    SUCCESS: Integration Tests
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/246/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote : Posted in a previous version of this proposal

FAILED: Continuous integration, rev:d16589b9f2835f9cf1cae6daf228447b343e7330
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~racb/usd-importer/+git/usd-importer/+merge/336297/+edit-commit-message

https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/250/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Style Check
    SUCCESS: Unit Tests
    SUCCESS: Integration Tests
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/250/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:3e1087eb7c21e31b2f07bf3c44591102914ab0f1
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/254/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Style Check
    SUCCESS: Unit Tests
    FAILED: Integration Tests

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/254/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Nish Aravamudan (nacc) wrote :

There is a typo in my last run.py line, I'll try and fix it to pass CI this
weekend.

On Jan 19, 2018 17:52, "Server Team CI bot" <
<email address hidden>> wrote:

> Review: Needs Fixing continuous-integration
>
> FAILED: Continuous integration, rev:3e1087eb7c21e31b2f07bf3c445911
> 02914ab0f1
> https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/254/
> Executed test runs:
> SUCCESS: Checkout
> SUCCESS: Style Check
> SUCCESS: Unit Tests
> FAILED: Integration Tests
>
> Click here to trigger a rebuild:
> https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/254/rebuild
>
> --
> https://code.launchpad.net/~nacc/usd-importer/+git/usd-
> importer/+merge/336391
> You are the owner of ~nacc/usd-importer:lp1741949-unset-snap-in-lxc-env.
>

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:467d0f591f7fcd79b7fb7a99ca6be12585ffc3ef
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/255/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Style Check
    SUCCESS: Unit Tests
    SUCCESS: Integration Tests
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/255/rebuild

review: Approve (continuous-integration)
Revision history for this message
Andreas Hasenack (ahasenack) wrote :

Nice to see it applied to all lxc commands, and even nicer to see a green CI run :)

+1

review: Approve
Revision history for this message
Robie Basak (racb) wrote :

Thanks! I'll merge this now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/gitubuntu/build.py b/gitubuntu/build.py
2index 072d3e7..22b95a9 100644
3--- a/gitubuntu/build.py
4+++ b/gitubuntu/build.py
5@@ -35,7 +35,13 @@ from gitubuntu.cache import CACHE_PATH
6 from gitubuntu.dsc import GitUbuntuDsc
7 import gitubuntu.lint
8 import gitubuntu.git_repository
9-from gitubuntu.run import decode_binary, run, runq
10+from gitubuntu.run import (
11+ decode_binary,
12+ get_cmd_in_origpath,
13+ run,
14+ runq,
15+ run_lxc,
16+)
17 from gitubuntu.source_information import (
18 GitUbuntuSourceInformation,
19 NoPublicationHistoryException,
20@@ -889,15 +895,6 @@ def do_build_host_exitstack(
21
22 return built_pardir_contents
23
24-def get_cmd_in_origpath(cmd):
25- return shutil.which(
26- cmd,
27- path=os.getenv(
28- 'ORIG_PATH',
29- os.getenv('PATH', os.defpath),
30- ),
31- )
32-
33 @functools.lru_cache()
34 def _gpg_abspath():
35 orig_gpg = get_cmd_in_origpath('gpg')
36@@ -905,18 +902,11 @@ def _gpg_abspath():
37 return orig_gpg
38 raise RuntimeError("Unable to find a gpg binary, is it installed?")
39
40-@functools.lru_cache()
41-def _lxc_abspath():
42- orig_lxc = get_cmd_in_origpath('lxc')
43- if orig_lxc:
44- return orig_lxc
45- raise RuntimeError("Unable to find a lxc binary, is it installed?")
46-
47 def _cleanup_lxd(container_name):
48- run([_lxc_abspath(), 'stop', '--force', container_name])
49+ run_lxc(['stop', '--force', container_name])
50
51 def _run_in_lxd(container_name, args, user=None, **kwargs):
52- cmd = [_lxc_abspath(), 'exec', container_name, '--',]
53+ _args = ['exec', container_name, '--',]
54 # user == None means run as root
55 if user:
56 try:
57@@ -944,9 +934,9 @@ def _run_in_lxd(container_name, args, user=None, **kwargs):
58 )
59 else:
60 raise
61- cmd.extend(['sudo', '-s', '-H', '-u', user,])
62- cmd.extend(args)
63- return run(cmd, **kwargs)
64+ _args.extend(['sudo', '-s', '-H', '-u', user,])
65+ _args.extend(args)
66+ return run_lxc(_args, **kwargs)
67
68 def do_build_lxd_exitstack(
69 changelog,
70@@ -960,19 +950,18 @@ def do_build_lxd_exitstack(
71 retry_backoffs,
72 stack,
73 ):
74- lxc = _lxc_abspath()
75 try:
76- run([lxc, 'list'])
77+ run_lxc(['list'])
78 except Exception as e:
79 raise RuntimeError("LXD running?") from e
80
81 container_name = petname.Generate(2, '-')
82
83- cmd = [lxc, 'launch', '-e']
84+ args = ['launch', '-e']
85 if profile:
86- cmd.extend(['-p', profile])
87+ args.extend(['-p', profile])
88 if image:
89- cmd.extend([image,])
90+ args.extend([image,])
91 else:
92 try:
93 source = derive_source_from_changelog(changelog)
94@@ -985,12 +974,12 @@ def do_build_lxd_exitstack(
95 raise
96 if source == 'ubuntu':
97 # devel is properly handled for the daily remote
98- cmd.extend(['ubuntu-daily:%s' % series,])
99+ args.extend(['ubuntu-daily:%s' % series,])
100 else:
101- cmd.extend(['images:debian/%s' % series,])
102- cmd.extend([container_name,])
103+ args.extend(['images:debian/%s' % series,])
104+ args.extend([container_name,])
105 try:
106- run(cmd)
107+ run_lxc(args)
108 except Exception as e:
109 raise RuntimeError("Failed to launch ephemeral build container") from e
110
111@@ -1030,23 +1019,24 @@ def do_build_lxd_exitstack(
112 )
113
114 try:
115- run([
116- lxc,
117- 'file',
118- 'push',
119- archive_tarball_name,
120- '%s/tmp/' % container_name,
121- ])
122+ run_lxc(
123+ [
124+ 'file',
125+ 'push',
126+ archive_tarball_name,
127+ '%s/tmp/' % container_name,
128+ ],
129+ )
130 except Exception as e:
131 raise RuntimeError(
132 "Failed to push archive tarball to ephemeral build container"
133 ) from e
134
135- cmd = [lxc, 'file', 'push']
136- cmd.extend(tarballs)
137- cmd.extend(['%s/tmp/' % container_name,])
138+ args = ['file', 'push']
139+ args.extend(tarballs)
140+ args.extend(['%s/tmp/' % container_name,])
141 try:
142- run(cmd)
143+ run_lxc(args)
144 except Exception as e:
145 raise RuntimeError("Failed to push orig tarballs to container") from e
146
147@@ -1142,14 +1132,14 @@ def do_build_lxd_exitstack(
148 )
149
150 built_temp_contents = new_temp_contents - orig_temp_contents
151- cmd = [lxc, 'file', 'pull']
152- cmd.extend([
153+ args = ['file', 'pull']
154+ args.extend([
155 '%s%s' % (container_name, os.path.join('/tmp', f))
156 for f in built_temp_contents
157 ]
158 )
159- cmd.extend([os.pardir,])
160- run(cmd)
161+ args.extend([os.pardir,])
162+ run_lxc(args)
163
164 return [os.path.join(os.pardir, f) for f in built_temp_contents]
165
166diff --git a/gitubuntu/run.py b/gitubuntu/run.py
167index 4b1a86c..8fb4d85 100644
168--- a/gitubuntu/run.py
169+++ b/gitubuntu/run.py
170@@ -1,4 +1,7 @@
171+import functools
172 import logging
173+import os
174+import shutil
175 import subprocess
176
177
178@@ -102,3 +105,39 @@ def decode_binary(binary, verbose=True):
179 logging.warning("Failed to decode blob: %s", e)
180 logging.warning("blob=%s", binary.decode(errors='replace'))
181 return binary.decode('utf-8', errors='replace')
182+
183+def get_cmd_in_origpath(cmd):
184+ return shutil.which(
185+ cmd,
186+ path=os.getenv(
187+ 'ORIG_PATH',
188+ os.getenv('PATH', os.defpath),
189+ ),
190+ )
191+
192+@functools.lru_cache()
193+def _lxc_abspath():
194+ orig_lxc = get_cmd_in_origpath('lxc')
195+ if orig_lxc:
196+ return orig_lxc
197+ raise RuntimeError("Unable to find a lxc binary, is it installed?")
198+
199+
200+def run_lxc(args, env=None, **kwargs):
201+ cmd = [_lxc_abspath()] + args
202+ # lxd assumes that if SNAP is set in the environment, that it is
203+ # running as a snap. That is not necessarily true when git-ubuntu is
204+ # the snapped application. So unset SNAP before we exec.
205+ # LP: #1741949
206+ # This can be dropped if https://github.com/lxc/lxd/issues/4183 is
207+ # resolved.
208+ if env:
209+ env_unset_SNAP = env.copy()
210+ else:
211+ env_unset_SNAP = os.environ.copy()
212+ try:
213+ del env_unset_SNAP['SNAP']
214+ except KeyError:
215+ pass
216+
217+ return run(cmd, env=env_unset_SNAP, **kwargs)

Subscribers

People subscribed via source and target branches