Commit Graph

25 Commits

Author SHA1 Message Date
Antoine Musso
33cd0fb40f dib-run-parts: make cp to target root more robust
The dib-run-parts/root.d/90-base-dib-run-parts script would mysteriously
fail whenever the dib-run-parts is not in the path.  The install
commands complaining with:

install: missing destination file operand after
'/tmp/image.ILFTBYVy/mnt/usr/local/bin/dib-run-parts'

The reason is chaining a command in exec bypasses set -e. For example:

 exec /bin/ls $(which doesnotexist)

Will works and continue.

Handle the which lookup in a variable to have the script abort
immediately whenever dib-run-parts is not found.

Left an inline comment to make sure the fix is kept around in the
future.

Signed-off-by: Dan Duvall <dduvall@wikimedia.org>
Change-Id: Ibb5d7342b0d06483b84f9dd567e1cc0bf90f194e
2016-04-05 16:29:57 +02:00
Ian Wienand
36b59c001c Standarise tracing for scripts
There is a wide variety of tracing options through the various shell
scripts.  Some use "set -eux", others explicity set xtrace and others
do nothing.  There is a "-x" option to bin/disk-image-create but it
doesn't flow down to the many scripts it calls.

This adds a global integer variable set by disk-image-create
DIB_DEBUG_TRACE.  All scripts have a stanza added to detect this and
turn on tracing.  Any other tracing methods are rolled into this.  So
the standard header is

---
if [ "${DIB_DEBUG_TRACE:-0}" -gt 0 ]; then
    set -x
fi
set -eu
set -o pipefail
---

Multiple -x options can be specified to dib-create-image, which
increases the value of DIB_DEBUG_TRACE.  If script authors feel their
script should only trace at higher levels, they should modify the
"-gt" value.  If they feel it should trace by default, they can modify
the default value also.

Changes to pachset 16 : scripts which currently trace themselves by
default have retained this behaviour with DIB_DEBUG_TRACE defaulting
to "1".  This was done by running [1] on patch set 15.  See the thread
beginning at [2]

dib-lint is also updated to look for the variable being matched.

[1] https://gist.github.com/ianw/71bbda9e6acc74ccd0fd
[2] http://lists.openstack.org/pipermail/openstack-dev/2014-November/051575.html

Change-Id: I6c5a962260741dcf6f89da9a33b96372a719b7b0
2015-02-12 10:41:32 +11:00
Ben Nemec
644598941c Use dib-run-parts from dib-utils
Now that dib-run-parts has been moved to the dib-utils project, we
need to update diskimage-builder to use it instead of the version
directly in diskimage-builder.

This change removes the old copy of the dib-run-parts script in
the element, adds dib-utils as a dependency of diskimage-builder,
and updates the uses of dib-run-parts to correctly handle the fact
that it is now external to the project.

Requires I0be1f876d0e4a7d38e0d5c6010a552a8ebb158a4

Change-Id: Ia0a0df7784a14c49b5c47ac0b03e6c2602c84b3b
2014-08-26 16:44:18 -05:00
Alexis Lee
2f6fdb4142 Fix sourcing of environment files
Includes "Don't match editor backup files in environment" and "Order
execution of environment.d scripts". These had to be squashed because
the first change alone changes the order env.d scripts are sourced in.

The current glob match for environment files can source editor backup
files (foo.bash~) which will override the real changes you have made.
Other parts use the regex to avoid matching such files, so do
the same for environment file matching.  Note this has to match "."
unlike the other regex, as most env files are "foo.bash"

Also sort the files before sourcing them to ensure a reliable order.
This change should be in line with current expectations, given the
convention is to numerically prefix scripts in this directory.

Update of: I934486b3ff5884063d29c6d9b66fd9b11140464c
Subsumes: Icc509f695d7a15a8026d8c7e463f06acf65499d7
Change-Id: Ibfb562c5970b40598fc95da1e8d4beb9d51d7612
2014-07-23 17:18:28 +01:00
Dan Prince
bbf62fc5b9 Revert "Don't match editor backup files in env...
This reverts commit 32eda4b92f.

I noticed today that environment.d files no longer seem to get sourced
by DIB. Reverting this commit fixes it.

Change-Id: I08a8feab541901c8fd0a803628f5aeb6c0eec598
Closes-bug: #1339116
2014-07-08 11:13:11 -04:00
Jenkins
92d4ed73db Merge "Don't match editor backup files in environment" 2014-07-07 11:51:08 +00:00
Ian Wienand
32eda4b92f Don't match editor backup files in environment
The current glob match for environment files can source editor backup
files (foo.bash~) which will override the real changes you have made.

Other parts matche use the regex to avoid matching such files, so do
the same for environment file matching.  Note this has to match "."
unlike the other regex, as most env files are "foo.bash"

Change-Id: I934486b3ff5884063d29c6d9b66fd9b11140464c
2014-07-03 13:54:18 +10:00
Yolanda Robla
8ed645f046 Set LC_ALL=C into dib-run-parts env
Force LC_ALL to C to allow printf to work independently
from the locale. Gives invalid number error if run in non-english
locale.

Change-Id: Ia68853505485fefbf0890313456e7edb6097666b
Closes-Bug: #1335932
2014-07-01 11:49:48 +02:00
Giulio Fidente
3262e76248 Ensure dib-run-parts profiling works with py3 and py2
This change adjusts the "inline" python function used to profile
run-parts duration to make it run successfully on both py2 and py3

Change-Id: Ib5287a56b8e2b3e882dca489192f01d9f01cd8ba
2014-06-06 18:37:39 +02:00
Gonéri Le Bouder
ea3f4dd459 4 spaces indent
ensure 4 spaces indentation is used everywhere.

Change-Id: Ieb48faacb4c96b7b358771d70c17f2f22d0354f4
2014-05-10 11:17:29 +02:00
Ben Nemec
16be6d7ce0 set -u and -o pipefail everywhere
As with the previous similar changes, this is intended to catch
problems as they happen instead of ignoring them and continuing on
to potentially fail later.  Setting this on all existing scripts
will allow us to enforce use via Jenkins.

Change-Id: Iad2d490c86dceab148ea9ab08f457c49a5d5352e
2014-05-06 15:51:07 -05:00
Jenkins
301dc5cc0e Merge "set -e all the things" 2014-04-29 11:29:43 +00:00
Ben Nemec
f6ba2aeaf4 set -e all the things
Using set -e in all of our scripts will prevent some subtle bugs
from slipping in, and will allow us to enforce use of set -e with
tooling.

This change also adds -u and set -o pipefail in the less complex
scripts where it is unlikely to cause problems.  A follow-up change
will enable those options in the complex scripts so that if it
breaks something it can be reverted easily.

Change-Id: I0ad358ccb98da7277a0ee2e9ce8fda98438675eb
2014-04-25 17:38:51 -05:00
Monty Taylor
1c07d4ba1a Remove All Rights Reserved
The phrase is no longer needed as of August 23, 2000 with Nicaragua's
joining of the Berne Convention.

Additionally, in at least one instance,
elements/cache-url/bin/cache-url, its existence in the file between
Copyright lines is just weird and feels misleading, even though it is
not.

Remove all of the lines, because sanity.

Change-Id: I24fd76c2b4f66b8036010b5079db39ead729abee
2014-04-25 11:25:10 -07:00
Ben Nemec
381ff6ab1d Fix set -eu and pipefail failures
Fixes problems found by set -eu and pipefail, including:
-Many unset variables
-Commands that can fail under normal circumstances, which breaks
with set -e.  This change swallows those expected errors to allow
our existing error code to handle them.
-The dkms element was not finding Fedora kernel versions correctly.
This may be an issue for other distros too, but since Fedora was
working fine without this functionality I only changed it to print
a warning message rather than failing the build when it happens.
-The ramdisk init script will not be set -eu because if it fails
the result is a kernel panic, which can be tricky to debug.
However, in testing with set -e a few failing commands were found
and have been fixed in this patch.

Change-Id: I44cf98dfc80cfcaec54b88cc83be80a3dbf2cec3
2014-04-15 20:53:15 -05:00
James Slagle
f760f11050 Don't hardcode environment.d
Don't assume environment.d is always under /tmp/in_target.d. This makes
dib-run-parts more flexible, and less specific to diskimage-builder. For
instance, dib-run-parts is already used by os-refresh-config, but
/tmp/in_target.d/environment.d is never going to exist when it's called
by os-refresh-config.

This is useful b/c elements can now install os-refresh-config scripts
under /opt/stack/os-config-refresh/environment.d to influence how
further scripts are run. Specifically, the OpenSuse packages prepend the
OpenStack user accounts with "openstack-". Instead of checking for which
users exists with an if/else in all the os-refresh-config scripts that
need to do user related things, we can just update the scripts to use
$NOVA_USER, etc. The OpenSuse element can then install a file under
/opt/stack/os-config-refresh/environment.d to set NOVA_USER to
openstack-nova. We could have files that declare defaults as well within
each specific element, or just set a default variable at the top of each
os-refresh-config script.

Change-Id: Iadbfad995da657e2965fd55fc4ba3a88138b4cfc
2014-02-11 08:33:45 -05:00
James Slagle
79f31d0476 dib-run-parts should dereference symlinks
dib-run-parts should dereference symlinks, and if they point to an
executable file, execute that file as a script. This can be accomplished
by using the xtype predicate in the find command instead of the type
predicate.

This change is needed so that we can dynamically symlink hook scripts
into hook directories such as install.d at runtime to support different
install types.

Change-Id: I933e7f4b4dcf16956841d8c14aa63b0f9a18fc5d
2014-01-15 14:57:08 -05:00
JUN JIE NAN
afc07e2b2d Enhance dib-run-parts usage message
and fix $1: unbound variable issue when run dib-run-parts --list.

Change-Id: Id18e21683f785f318bce11d401cb4f826bed1b01
2013-11-27 17:42:37 +08:00
Tomas Sedovic
d5afe2b1fa Set locale for the profiling printf command
When LC_NUMERIC is set to a format that doesn't use a decimal point,
`printf` will fail.

Change-Id: Ie6c4d075928f47b17cc413d537fc31c9d0734bdb
Signed-off-by: Tomas Sedovic <tsedovic@redhat.com>
2013-09-30 12:10:07 +02:00
Chris Jones
6311388892 Add --list support to dib-run-parts.
Our custom dib-run-parts now supports --list for better compatibility
with some OS-provided run-parts tools.

Change-Id: I2feb615b2094d9d6522bfe9b422362223bb8e652
Closes-Bug: #1190521
2013-09-04 09:44:48 +01:00
Tim Serong
ee5ae03d58 Enable running disk-image-create on SUSE Linux
- Ensures /sbin and friends are in $PATH when invoked (without this,
  various sudo invocations fail in exciting ways).
- Use dib-run-parts in lib/common-functions instead of run-parts
  (neither SLES nor openSUSE ship run-parts).
- Ensure dib-run-parts doesn't descend into subdirectories (same
  behaviour as run-parts).
- Move dib-run-parts from root.d to bin (cleaner, consistent with
  other elements with separate bin scripts).
- Tested by building Ubuntu image on openSUSE 12.3.
- Note: this doesn't add support for creating SUSE images, it just
  lets you run disk-image-create on SUSE-based distros.

Change-Id: I906c6bc3cf51cdf2c4415adeae1ca250faac25e1
2013-07-24 20:16:31 +10:00
Clint Byrum
3464064a87 Add environment.d hook to setup environment.
Before each phase dib-run-parts will pick these up to setup the
environment for the commands it runs.

Change-Id: I56697d7bc370918d4063eee67a1c35d4988a5359
2013-07-09 15:01:33 -07:00
Lucas Alvares Gomes
4e428c6844 dib-run-parts was failing with empty targets.
When the target directory is empty, the for loop printing our profile
data was failing because of a glob problem.

Change-Id: I34e612021c70d6b8f75423de0d8be969c52e58e2
2013-06-13 11:29:02 +01:00
Clint Byrum
92e420aaf0 Basic wall clock profiling per element script.
Change-Id: I43f90574ac716f2ef22949c0fe4fa2e7fc84348e
2013-05-20 11:14:52 -07:00
Clint Byrum
91c30f6ab2 Use dib-run-parts for running scripts in target
Also modified dib-run-parts to apply a more workable solution for
filtering out unwanted files such as editor backups and VCS.

The script is installed in its own element, depended on by the OS
specific ubuntu element. This is  because the ubuntu element (and
later other OS's) are responsible for populating the root filesystem.
If we try to install this in base, the root filesystem will look to
be populated already and we will skip automatically choosing ubuntu.

Change-Id: I017646748c1a8360299106289b57d976d45875a8
2013-02-14 10:48:10 -08:00