Merge lp:~smoser/curtin/trunk.snap-curtin-helpers into lp:~curtin-dev/curtin/trunk

Proposed by Scott Moser
Status: Merged
Merged at revision: 551
Proposed branch: lp:~smoser/curtin/trunk.snap-curtin-helpers
Merge into: lp:~curtin-dev/curtin/trunk
Diff against target: 62 lines (+26/-8)
1 file modified
curtin/util.py (+26/-8)
To merge this branch: bzr merge lp:~smoser/curtin/trunk.snap-curtin-helpers
Reviewer Review Type Date Requested Status
Ryan Harper (community) Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+334852@code.launchpad.net

Commit message

pack: fix packing when curtin is installed inside a snap.

When curtin is installed as part of a MAAS snap, then it would fail
to find its helpers directory. That is because instead of helpers
living in usr/lib/curtin/helpers they will be in
 /snap/maas/<version>/usr/lib/curtin/helpers
But helpfully, SNAP will be set in the environment to point to
 /snap/maas/<version>/

The fix is to adjust pack to consider trust the environment variable
and pack up the installed files based on that prefix.

To post a comment you must log in.
Revision history for this message
Ryan Harper (raharper) wrote :

Looks reasonable, question on 'is None' vs if not foo.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
550. By Scott Moser

update per ryan feedback

551. By Scott Moser

merge with trunk

Revision history for this message
Scott Moser (smoser) wrote :

dropped the rpint, and re-ordered the variables.

i really think it makes sense to not change the check for None to false-ish.

its more epxlicit as None, and we're not aware of any uses that are failing.
at very least its not related to this change, so no reason to shove such a change in.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ryan Harper (raharper) wrote :

Hrm,

as with most of these places, it's unlikely that someone ever means to pass
in a '' value here.

These are paths;they're meant to be non-empty strings. At least raise an
exception if the
string value is empty, otherwise aren't we just letting it blow up in some
other way?

Usually it's best practice to fail as soon as we know it's going to break.

On Thu, Dec 7, 2017 at 10:16 AM, Server Team CI bot <
<email address hidden>> wrote:

> Review: Approve continuous-integration
>
> PASSED: Continuous integration, rev:551
> https://jenkins.ubuntu.com/server/job/curtin-ci/695/
> Executed test runs:
> SUCCESS: https://jenkins.ubuntu.com/server/job/curtin-ci/nodes=
> metal-amd64/695
> SUCCESS: https://jenkins.ubuntu.com/server/job/curtin-ci/nodes=
> metal-arm64/695
> SUCCESS: https://jenkins.ubuntu.com/server/job/curtin-ci/nodes=
> metal-ppc64el/695
> SUCCESS: https://jenkins.ubuntu.com/server/job/curtin-ci/nodes=
> metal-s390x/695
>
> Click here to trigger a rebuild:
> https://jenkins.ubuntu.com/server/job/curtin-ci/695/rebuild
>
> --
> https://code.launchpad.net/~smoser/curtin/trunk.snap-
> curtin-helpers/+merge/334852
> Your team curtin developers is requested to review the proposed merge of
> lp:~smoser/curtin/trunk.snap-curtin-helpers into lp:curtin.
>

Revision history for this message
Ryan Harper (raharper) wrote :

I do think we should fix those; I know our current path doesn't break; but if we're touching it I think it makes sense to raise exceptions when we know we have bad input.

review: Needs Fixing
Revision history for this message
Scott Moser (smoser) wrote :

I disagree on two points.
a.) the existing interface is fine and consistent.
If you pass a value for a parameter, then you change behavior for that.
These things do what you want:
 get_paths()
 get_paths(lib="my-lib")
 get_paths(lib=None)

If you pass non-default you get non-default behavior. that is quite common.

b.) I don't agree with changing unrelated behaviors when fixing bugs. You are welcome to suggest that in a merge proposal of your own, but behavior changes do not belong as "tag alongs".

I'm willing to just do this because I'm annoyed by arguing, though.

Revision history for this message
Ryan Harper (raharper) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'curtin/util.py'
2--- curtin/util.py 2017-11-29 15:58:25 +0000
3+++ curtin/util.py 2017-12-07 15:59:37 +0000
4@@ -54,8 +54,8 @@
5
6 from .log import LOG
7
8-_INSTALLED_HELPERS_PATH = '/usr/lib/curtin/helpers'
9-_INSTALLED_MAIN = '/usr/bin/curtin'
10+_INSTALLED_HELPERS_PATH = 'usr/lib/curtin/helpers'
11+_INSTALLED_MAIN = 'usr/bin/curtin'
12
13 _LSB_RELEASE = {}
14 _USES_SYSTEMD = None
15@@ -677,6 +677,24 @@
16 return None
17
18
19+def _installed_file_path(path, check_file=None):
20+ # check the install root for the file 'path'.
21+ # if 'check_file', then path is a directory that contains file.
22+ # return absolute path or None.
23+ inst_pre = "/"
24+ if os.environ.get('SNAP'):
25+ inst_pre = os.path.abspath(os.environ['SNAP'])
26+ inst_path = os.path.join(inst_pre, path)
27+ if check_file:
28+ check_path = os.path.sep.join((inst_path, check_file))
29+ else:
30+ check_path = inst_path
31+
32+ if os.path.isfile(check_path):
33+ return os.path.abspath(inst_path)
34+ return None
35+
36+
37 def get_paths(curtin_exe=None, lib=None, helpers=None):
38 # return a dictionary with paths for 'curtin_exe', 'helpers' and 'lib'
39 # that represent where 'curtin' executable lives, where the 'curtin' module
40@@ -698,17 +716,17 @@
41 if found:
42 curtin_exe = found
43
44- if (curtin_exe is None and os.path.exists(_INSTALLED_MAIN)):
45- curtin_exe = _INSTALLED_MAIN
46+ if curtin_exe is None:
47+ curtin_exe = _installed_file_path(_INSTALLED_MAIN)
48
49- cfile = "common" # a file in 'helpers'
50+ # "common" is a file in helpers
51+ cfile = "common"
52 if (helpers is None and
53 os.path.isfile(os.path.join(tld, "helpers", cfile))):
54 helpers = os.path.join(tld, "helpers")
55
56- if (helpers is None and
57- os.path.isfile(os.path.join(_INSTALLED_HELPERS_PATH, cfile))):
58- helpers = _INSTALLED_HELPERS_PATH
59+ if helpers is None:
60+ helpers = _installed_file_path(_INSTALLED_HELPERS_PATH, cfile)
61
62 return({'curtin_exe': curtin_exe, 'lib': mydir, 'helpers': helpers})
63

Subscribers

People subscribed via source and target branches