Merge lp:~mabac/linaro-image-tools/scripts-hooks into lp:linaro-image-tools/11.11

Proposed by Mattias Backman
Status: Rejected
Rejected by: Данило Шеган
Proposed branch: lp:~mabac/linaro-image-tools/scripts-hooks
Merge into: lp:linaro-image-tools/11.11
Diff against target: 138 lines (+48/-20)
4 files modified
linaro-media-create (+2/-1)
linaro_image_tools/media_create/__init__.py (+6/-0)
linaro_image_tools/media_create/chroot_utils.py (+37/-16)
linaro_image_tools/media_create/tests/test_media_create.py (+3/-3)
To merge this branch: bzr merge lp:~mabac/linaro-image-tools/scripts-hooks
Reviewer Review Type Date Requested Status
Alexandros Frantzis Pending
Ricardo Salveti Pending
Alexander Sack Pending
linaro-image-tools maintainers Pending
Review via email: mp+89889@code.launchpad.net

Description of the change

Hi,

This branch adds two command line options to linaro-media-create to enable users to customize the behaviour of l-m-c.

  --preinstall-script PREINSTALL_SCRIPT, --preinstall_script PREINSTALL_SCRIPT
                        Script to execute in the chroot before installing
                        hwpacks.
  --postinstall-script POSTINSTALL_SCRIPT, --postinstall_script POSTINSTALL_SCRIPT
                        Script to execute in the chroot after installing
                        hwpacks.

The scripts will be executed in the chroot before and after installing hwpacks.

Thanks,

Mattias

To post a comment you must log in.
487. By Mattias Backman

Update call signature in tests.

Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Tested with 2 simple scripts and it worked well.

A few comments:
1. At the preinstall script there's no way to access the hwpack content, because it wasn't yet extracted. This may be useful for people that want to read from hwpack packages or even customize in some way.
2. Would be useful if we could also copy both scripts at the rootfs, as it might help debugging any issues in the future.
3. Would also be useful if we could stamp that the image was customized by a script, like by adding a message via /etc/update-motd.d, so it'd show that info to the user.

Revision history for this message
Fathi Boudra (fboudra) wrote :

Hi,

Do we need the extra command line options? I'm thinking about a hook dir where you drop your hooks, in the same way it's done on live-build [1] or pbuilder[2]. A prefix will determine at which stage the scripts will be used. Until the proper solution is implemented, you can hardcode the scripts name.

[1] /usr/share/live/build/examples/hooks
[2] /usr/share/doc/pbuilder/examples

> 2. Would be useful if we could also copy both scripts at the rootfs
> 3. Would also be useful if we could stamp that the image was customized by a script

for both, I'll leave these outside of l-m-c. It's up to the developer and could be done through the hooks.

Revision history for this message
Mattias Backman (mabac) wrote :

> Tested with 2 simple scripts and it worked well.
>
> A few comments:
> 1. At the preinstall script there's no way to access the hwpack content,
> because it wasn't yet extracted. This may be useful for people that want to
> read from hwpack packages or even customize in some way.

Would you like the pre-hooks to be run in linaro-hwpack-install instead? That way the script can be run for every hwpack after unpacking it, meaning the pre-hook is run once per hwpack. If you mean we should unpack all the hwpacks and then run the pre-hook once it will require some more work but it is possible of course.

> 2. Would be useful if we could also copy both scripts at the rootfs, as it
> might help debugging any issues in the future.
> 3. Would also be useful if we could stamp that the image was customized by a
> script, like by adding a message via /etc/update-motd.d, so it'd show that
> info to the user.

Revision history for this message
Mattias Backman (mabac) wrote :

> Hi,
>
> Do we need the extra command line options? I'm thinking about a hook dir where

It's all down to how you'd like this to behave, we can do that instead. I think the discussions on irc kept mentioning command line options which is why I did that. Any other opinions about cli options vs a hook dir?

> you drop your hooks, in the same way it's done on live-build [1] or
> pbuilder[2]. A prefix will determine at which stage the scripts will be used.
> Until the proper solution is implemented, you can hardcode the scripts name.
>
> [1] /usr/share/live/build/examples/hooks
> [2] /usr/share/doc/pbuilder/examples
>
> > 2. Would be useful if we could also copy both scripts at the rootfs
> > 3. Would also be useful if we could stamp that the image was customized by a
> script
>
> for both, I'll leave these outside of l-m-c. It's up to the developer and
> could be done through the hooks.

I think it can be settled by sorting out if this always will be needed or if there may be cases where the hook author would want no trace of the hooks on the target system. If we feel that we need this for helping people with messed up images we need to do it in l-m-c. If it's up to the developer, I'm happy to leave this bit out.

Revision history for this message
Ricardo Salveti (rsalveti) wrote :

On Wed, Jan 25, 2012 at 6:35 AM, Mattias Backman
<email address hidden> wrote:
>> Tested with 2 simple scripts and it worked well.
>>
>> A few comments:
>> 1. At the preinstall script there's no way to access the hwpack content,
>> because it wasn't yet extracted. This may be useful for people that want to
>> read from hwpack packages or even customize in some way.
>
> Would you like the pre-hooks to be run in linaro-hwpack-install instead? That way the script can be run for every hwpack after unpacking it, meaning the pre-hook is run once per hwpack. If you mean we should unpack all the hwpacks and then run the pre-hook once it will require some more work but it is possible of course.

Can you flash the image using more than one hwpack? I thought it'd use
just one hwpack :-)

Guess to simplify things having the pre-hook the way you implemented
should be fine for now.

Revision history for this message
Ricardo Salveti (rsalveti) wrote :

On Wed, Jan 25, 2012 at 6:42 AM, Mattias Backman
<email address hidden> wrote:
>> Hi,
>>
>> Do we need the extra command line options? I'm thinking about a hook dir where
>
> It's all down to how you'd like this to behave, we can do that instead. I think the discussions on irc kept mentioning command line options which is why I did that. Any other opinions about cli options vs a hook dir?

While I like the pbuilder/livebuild way of hooking the script, I think
having them as a parameter (for pre/post) is more than enough, besides
easier to implement. If the user really want to customize the image
this much, I'd prefer him to go and create his own image by running
live-build by hand.

>> > 2. Would be useful if we could also copy both scripts at the rootfs
>> > 3. Would also be useful if we could stamp that the image was customized by a
>> script
>>
>> for both, I'll leave these outside of l-m-c. It's up to the developer and
>> could be done through the hooks.
>
> I think it can be settled by sorting out if this always will be needed or if there may be cases where the hook author would want no trace of the hooks on the target system. If we feel that we need this for helping people with messed up images we need to do it in l-m-c. If it's up to the developer, I'm happy to leave this bit out.

Do we have the logs from the l-m-c available at the image already?
Guess that this would be enough already.

Revision history for this message
Fathi Boudra (fboudra) wrote :

> On Wed, Jan 25, 2012 at 6:42 AM, Mattias Backman
> <email address hidden> wrote:
> >> Hi,
> >>
> >> Do we need the extra command line options? I'm thinking about a hook dir
> where
> >
> > It's all down to how you'd like this to behave, we can do that instead. I
> think the discussions on irc kept mentioning command line options which is why
> I did that. Any other opinions about cli options vs a hook dir?
>
> While I like the pbuilder/livebuild way of hooking the script, I think
> having them as a parameter (for pre/post) is more than enough, besides
> easier to implement. If the user really want to customize the image
> this much, I'd prefer him to go and create his own image by running
> live-build by hand.

I see at least one argument to prefer linaro-media-create instead of live-build for the job: it will work on other distributions. afaik, live-build isn't available on something else than Debian/Ubuntu, more over we carry a modified version available in our PPA.

> >> > 2. Would be useful if we could also copy both scripts at the rootfs
> >> > 3. Would also be useful if we could stamp that the image was customized
> by a
> >> script
> >>
> >> for both, I'll leave these outside of l-m-c. It's up to the developer and
> >> could be done through the hooks.
> >
> > I think it can be settled by sorting out if this always will be needed or if
> there may be cases where the hook author would want no trace of the hooks on
> the target system. If we feel that we need this for helping people with messed
> up images we need to do it in l-m-c. If it's up to the developer, I'm happy to
> leave this bit out.

As a hook author, I don't want trace of the hooks as I want to keep it small :)

> Do we have the logs from the l-m-c available at the image already?
> Guess that this would be enough already.

Do you mean a build log shipped inside the image? We don't have that.
We can add traces on l-m-c build log (though, it isn't shipped in the generated rootfs).

Revision history for this message
Ricardo Salveti (rsalveti) wrote :

On Wed, Jan 25, 2012 at 4:08 PM, Fathi Boudra <email address hidden> wrote:
>> On Wed, Jan 25, 2012 at 6:42 AM, Mattias Backman
>> <email address hidden> wrote:
>> >> Hi,
>> >>
>> >> Do we need the extra command line options? I'm thinking about a hook dir
>> where
>> >
>> > It's all down to how you'd like this to behave, we can do that instead. I
>> think the discussions on irc kept mentioning command line options which is why
>> I did that. Any other opinions about cli options vs a hook dir?
>>
>> While I like the pbuilder/livebuild way of hooking the script, I think
>> having them as a parameter (for pre/post) is more than enough, besides
>> easier to implement. If the user really want to customize the image
>> this much, I'd prefer him to go and create his own image by running
>> live-build by hand.
>
> I see at least one argument to prefer linaro-media-create instead of live-build for the job: it will work on other distributions. afaik, live-build isn't available on something else than Debian/Ubuntu, more over we carry a modified version available in our PPA.

Yeah, having linaro-media-create working on any other distro is
already a pain, requesting further customization with live-build is
even worse, +1 for fathi's solution then.

>> >> > 2. Would be useful if we could also copy both scripts at the rootfs
>> >> > 3. Would also be useful if we could stamp that the image was customized
>> by a
>> >> script
>> >>
>> >> for both, I'll leave these outside of l-m-c. It's up to the developer and
>> >> could be done through the hooks.
>> >
>> > I think it can be settled by sorting out if this always will be needed or if
>> there may be cases where the hook author would want no trace of the hooks on
>> the target system. If we feel that we need this for helping people with messed
>> up images we need to do it in l-m-c. If it's up to the developer, I'm happy to
>> leave this bit out.
>
> As a hook author, I don't want trace of the hooks as I want to keep it small :)

Fair enough.

>> Do we have the logs from the l-m-c available at the image already?
>> Guess that this would be enough already.
>
> Do you mean a build log shipped inside the image? We don't have that.
> We can add traces on l-m-c build log (though, it isn't shipped in the generated rootfs).

Yeah, I believe having the build logs is useful, and could be
available at /var/something. But guess this can be tracked by another
bug/merge request.

Revision history for this message
Mattias Backman (mabac) wrote :

On Wed, Jan 25, 2012 at 6:31 PM, Ricardo Salveti <email address hidden> wrote:
> On Wed, Jan 25, 2012 at 6:35 AM, Mattias Backman
> <email address hidden> wrote:
>>> Tested with 2 simple scripts and it worked well.
>>>
>>> A few comments:
>>> 1. At the preinstall script there's no way to access the hwpack content,
>>> because it wasn't yet extracted. This may be useful for people that want to
>>> read from hwpack packages or even customize in some way.
>>
>> Would you like the pre-hooks to be run in linaro-hwpack-install instead? That way the script can be run for every hwpack after unpacking it, meaning the pre-hook is run once per hwpack. If you mean we should unpack all the hwpacks and then run the pre-hook once it will require some more work but it is possible of course.
>
> Can you flash the image using more than one hwpack? I thought it'd use
> just one hwpack :-)

You can give as many hwpacks to l-m-c as you like, but most hwpacks
won't make any sense to combine of course. It's intended for having
base and addon hwpacks I think, but I'm not sure it's the most used
feature of l-m-c.

>
> Guess to simplify things having the pre-hook the way you implemented
> should be fine for now.
>
> --
> https://code.launchpad.net/~mabac/linaro-image-tools/scripts-hooks/+merge/89889
> You are the owner of lp:~mabac/linaro-image-tools/scripts-hooks.

Revision history for this message
Mattias Backman (mabac) wrote :

On Thu, Jan 26, 2012 at 3:40 AM, Ricardo Salveti <email address hidden> wrote:
> On Wed, Jan 25, 2012 at 4:08 PM, Fathi Boudra <email address hidden> wrote:
>>> On Wed, Jan 25, 2012 at 6:42 AM, Mattias Backman
>>> <email address hidden> wrote:
>>> >> Hi,
>>> >>
>>> >> Do we need the extra command line options? I'm thinking about a hook dir
>>> where
>>> >
>>> > It's all down to how you'd like this to behave, we can do that instead. I
>>> think the discussions on irc kept mentioning command line options which is why
>>> I did that. Any other opinions about cli options vs a hook dir?
>>>
>>> While I like the pbuilder/livebuild way of hooking the script, I think
>>> having them as a parameter (for pre/post) is more than enough, besides
>>> easier to implement. If the user really want to customize the image
>>> this much, I'd prefer him to go and create his own image by running
>>> live-build by hand.
>>
>> I see at least one argument to prefer linaro-media-create instead of live-build for the job: it will work on other distributions. afaik, live-build isn't available on something else than Debian/Ubuntu, more over we carry a modified version available in our PPA.
>
> Yeah, having linaro-media-create working on any other distro is
> already a pain, requesting further customization with live-build is
> even worse, +1 for fathi's solution then.

So we change this to the hooks drop-in folder then.

>
>>> >> > 2. Would be useful if we could also copy both scripts at the rootfs
>>> >> > 3. Would also be useful if we could stamp that the image was customized
>>> by a
>>> >> script
>>> >>
>>> >> for both, I'll leave these outside of l-m-c. It's up to the developer and
>>> >> could be done through the hooks.
>>> >
>>> > I think it can be settled by sorting out if this always will be needed or if
>>> there may be cases where the hook author would want no trace of the hooks on
>>> the target system. If we feel that we need this for helping people with messed
>>> up images we need to do it in l-m-c. If it's up to the developer, I'm happy to
>>> leave this bit out.
>>
>> As a hook author, I don't want trace of the hooks as I want to keep it small :)
>
> Fair enough.
>
>>> Do we have the logs from the l-m-c available at the image already?
>>> Guess that this would be enough already.
>>
>> Do you mean a build log shipped inside the image? We don't have that.
>> We can add traces on l-m-c build log (though, it isn't shipped in the generated rootfs).
>
> Yeah, I believe having the build logs is useful, and could be
> available at /var/something. But guess this can be tracked by another
> bug/merge request.

We brough this up as part of the image metadata discussion. It is a
separate feature but we can probably sneak it in while doing some
other work.

>
> --
> https://code.launchpad.net/~mabac/linaro-image-tools/scripts-hooks/+merge/89889
> You are the owner of lp:~mabac/linaro-image-tools/scripts-hooks.

Revision history for this message
Данило Шеган (danilo) wrote :

Unmerged revisions

487. By Mattias Backman

Update call signature in tests.

486. By Mattias Backman

Add pre and post hwpack install script hooks.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'linaro-media-create'
2--- linaro-media-create 2012-01-17 14:50:47 +0000
3+++ linaro-media-create 2012-01-24 14:06:24 +0000
4@@ -160,7 +160,8 @@
5 if lmc_dir == '':
6 lmc_dir = None
7 install_hwpacks(ROOTFS_DIR, TMP_DIR, lmc_dir, args.hwpack_force_yes,
8- verified_files, *hwpacks)
9+ verified_files, args.preinstall_script, args.postinstall_script,
10+ *hwpacks)
11
12 if args.rootfs == 'btrfs':
13 install_packages(ROOTFS_DIR, TMP_DIR, "btrfs-tools")
14
15=== modified file 'linaro_image_tools/media_create/__init__.py'
16--- linaro_image_tools/media_create/__init__.py 2012-01-19 06:31:50 +0000
17+++ linaro_image_tools/media_create/__init__.py 2012-01-24 14:06:24 +0000
18@@ -152,6 +152,12 @@
19 '--nocheck-mmc', dest='nocheck_mmc',
20 action='store_true',
21 help='Assume yes to the question "Are you 100%% sure, on selecting [mmc]"')
22+ parser.add_argument(
23+ '--preinstall-script', '--preinstall_script',
24+ help='Script to execute in the chroot before installing hwpacks.')
25+ parser.add_argument(
26+ '--postinstall-script', '--postinstall_script',
27+ help='Script to execute in the chroot after installing hwpacks.')
28
29 add_common_options(parser)
30 return parser
31
32=== modified file 'linaro_image_tools/media_create/chroot_utils.py'
33--- linaro_image_tools/media_create/chroot_utils.py 2011-11-16 21:09:18 +0000
34+++ linaro_image_tools/media_create/chroot_utils.py 2012-01-24 14:06:24 +0000
35@@ -19,6 +19,7 @@
36
37 import os
38 import sys
39+import logging
40
41 from linaro_image_tools import cmd_runner
42 from linaro_image_tools.utils import (
43@@ -42,8 +43,38 @@
44 copy_file('/usr/bin/qemu-arm-static',
45 os.path.join(chroot_dir, 'usr', 'bin'))
46
47+
48+def run_script_in_chroot(chroot_dir, script):
49+ logger = logging.getLogger("linaro_image_tools")
50+ logger.info(" -- Executing user script %s in %s. --" % (script, chroot_dir))
51+
52+ script_in_chroot = os.path.join('usr', 'bin', 'lmc-user-script')
53+ copy_file(script, os.path.join(chroot_dir, script_in_chroot))
54+
55+ cmd_runner.run([script_in_chroot], as_root=True, chroot=chroot_dir).wait()
56+ logger.info(" -- User script %s finished. --" % script)
57+
58+
59+def try_qemu_static(chroot_dir):
60+ try:
61+ # Sometimes the host will have qemu-user-static installed but
62+ # another package (i.e. scratchbox) will have mangled its config
63+ # and thus we won't be able to chroot and install the hwpack, so
64+ # we fail here and tell the user to ensure qemu-arm-static is
65+ # setup before trying again.
66+ cmd_runner.run(['true'], as_root=True, chroot=chroot_dir).wait()
67+ except:
68+ print ("Cannot proceed with hwpack installation because "
69+ "there doesn't seem to be a binfmt interpreter registered "
70+ "to execute armel binaries in the chroot. Please check "
71+ "that qemu-user-static is installed and properly "
72+ "configured before trying again.")
73+ raise
74+
75+
76 def install_hwpacks(
77- chroot_dir, tmp_dir, tools_dir, hwpack_force_yes, verified_files, *hwpack_files):
78+ chroot_dir, tmp_dir, tools_dir, hwpack_force_yes, verified_files,
79+ preinstall_script, postinstall_script, *hwpack_files):
80 """Install the given hwpacks onto the given chroot."""
81 prepare_chroot(chroot_dir, tmp_dir)
82
83@@ -57,26 +88,16 @@
84
85 try:
86 mount_chroot_proc(chroot_dir)
87- try:
88- # Sometimes the host will have qemu-user-static installed but
89- # another package (i.e. scratchbox) will have mangled its config
90- # and thus we won't be able to chroot and install the hwpack, so
91- # we fail here and tell the user to ensure qemu-arm-static is
92- # setup before trying again.
93- cmd_runner.run(['true'], as_root=True, chroot=chroot_dir).wait()
94- except:
95- print ("Cannot proceed with hwpack installation because "
96- "there doesn't seem to be a binfmt interpreter registered "
97- "to execute armel binaries in the chroot. Please check "
98- "that qemu-user-static is installed and properly "
99- "configured before trying again.")
100- raise
101-
102+ try_qemu_static(chroot_dir)
103+ if preinstall_script:
104+ run_script_in_chroot(chroot_dir, preinstall_script)
105 for hwpack_file in hwpack_files:
106 hwpack_verified = False
107 if os.path.basename(hwpack_file) in verified_files:
108 hwpack_verified = True
109 install_hwpack(chroot_dir, hwpack_file, hwpack_force_yes or hwpack_verified)
110+ if postinstall_script:
111+ run_script_in_chroot(chroot_dir, postinstall_script)
112 finally:
113 run_local_atexit_funcs()
114
115
116=== modified file 'linaro_image_tools/media_create/tests/test_media_create.py'
117--- linaro_image_tools/media_create/tests/test_media_create.py 2012-01-17 14:50:47 +0000
118+++ linaro_image_tools/media_create/tests/test_media_create.py 2012-01-24 14:06:24 +0000
119@@ -2956,8 +2956,8 @@
120 prefer_dir = preferred_tools_dir()
121
122 install_hwpacks(
123- chroot_dir, tmp_dir, prefer_dir, force_yes, [], 'hwpack1.tgz',
124- 'hwpack2.tgz')
125+ chroot_dir, tmp_dir, prefer_dir, force_yes, [], None, None,
126+ 'hwpack1.tgz', 'hwpack2.tgz')
127 linaro_hwpack_install = find_command(
128 'linaro-hwpack-install', prefer_dir=prefer_dir)
129 expected = [
130@@ -3072,7 +3072,7 @@
131 try:
132 install_hwpacks(
133 'chroot', '/tmp/dir', preferred_tools_dir(), force_yes, [],
134- 'hwp.tgz', 'hwp2.tgz')
135+ None, None, 'hwp.tgz', 'hwp2.tgz')
136 except:
137 exception_caught = True
138 self.assertTrue(self.run_local_atexit_functions_called)

Subscribers

People subscribed via source and target branches