2015-06-18 09:24:13 +00:00
|
|
|
.. _developing-elements:
|
|
|
|
|
2015-02-12 07:07:47 +00:00
|
|
|
Developing Elements
|
|
|
|
===================
|
|
|
|
|
|
|
|
Conform to the following conventions:
|
|
|
|
|
|
|
|
* Use the environment for overridable defaults, prefixing environment variable
|
2015-09-16 13:44:49 +00:00
|
|
|
names with ``DIB_``. For example:
|
|
|
|
|
|
|
|
.. sourcecode:: sh
|
|
|
|
|
|
|
|
DIB_MYDEFAULT=${DIB_MYDEFAULT:-default}
|
|
|
|
|
|
|
|
If you do not use the ``DIB`` prefix you may find that your overrides are
|
2015-02-12 07:07:47 +00:00
|
|
|
discarded as the build environment is sanitised.
|
|
|
|
|
|
|
|
* Consider that your element co-exists with many others and try to guard
|
|
|
|
against undefined behaviours. Some examples:
|
|
|
|
|
|
|
|
* Two elements use the source-repositories element, but use the same filename
|
|
|
|
for the source-repositories config file. Files such as these (and indeed the
|
2015-09-16 13:44:49 +00:00
|
|
|
scripts in the various .d directories :ref:`listed below
|
|
|
|
<phase-subdirectories>`) should be named such that they are unique. If they
|
|
|
|
are not unique, when the combined tree is created by disk-image-builder for
|
|
|
|
injecting into the build environment, one of the files will be overwritten.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
* Two elements copy different scripts into ``/usr/local/bin`` with the same
|
|
|
|
name. If they both use ``set -e`` and ``cp -n`` then the conflict will be
|
|
|
|
caught and cause the build to fail.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
* If your element mounts anything into the image build tree (``$TMP_BUILD_DIR``)
|
|
|
|
then it will be automatically unmounted when the build tree is unmounted - and
|
|
|
|
not remounted into the filesystem image - if the mount point is needed again,
|
|
|
|
your element will need to remount it at that point.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-06-18 09:24:13 +00:00
|
|
|
* If caching is required, elements should use a location under
|
2015-09-16 13:44:49 +00:00
|
|
|
``$DIB_IMAGE_CACHE``.
|
2015-06-18 09:24:13 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
* Elements should allow for remote data to be cached. When ``$DIB_OFFLINE`` is
|
|
|
|
set, this cached data should be used if possible.
|
|
|
|
See the :ref:`dev-global-image-build-variables` section of this document for
|
|
|
|
more information.
|
|
|
|
|
2016-04-20 03:57:06 +00:00
|
|
|
* Elements in the upstream diskimage-builder elements should not create
|
|
|
|
executables which run before 10- or after 90- in any of the phases if
|
|
|
|
possible. This is to give downstream elements the ability to easily make
|
|
|
|
executables which run after our upstream ones.
|
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
.. _phase-subdirectories:
|
2015-06-18 09:24:13 +00:00
|
|
|
|
2015-02-12 07:07:47 +00:00
|
|
|
Phase Subdirectories
|
|
|
|
^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
Make as many of the following subdirectories as you need, depending on what
|
|
|
|
part of the process you need to customise. The subdirectories are executed in
|
|
|
|
the order given here. Scripts within the subdirectories should be named with a
|
2015-09-16 13:44:49 +00:00
|
|
|
two-digit numeric prefix, and are executed in numeric order.
|
|
|
|
|
|
|
|
Only files which are marked executable (+x) will be run, so other files can be
|
|
|
|
stored in these directories if needed. As a convention, we try to only store
|
|
|
|
executable scripts in the phase subdirectories and store data files elsewhere in
|
|
|
|
the element.
|
|
|
|
|
|
|
|
The phases are:
|
|
|
|
|
|
|
|
#. ``root.d``
|
|
|
|
#. ``extra-data.d``
|
|
|
|
#. ``pre-install.d``
|
|
|
|
#. ``install.d``
|
|
|
|
#. ``post-install.d``
|
|
|
|
#. ``block-device.d``
|
|
|
|
#. ``finalise.d``
|
|
|
|
#. ``cleanup.d``
|
|
|
|
|
|
|
|
``root.d``
|
|
|
|
Create or adapt the initial root filesystem content. This is where
|
2015-02-12 07:07:47 +00:00
|
|
|
alternative distribution support is added, or customisations such as
|
|
|
|
building on an existing image.
|
|
|
|
|
|
|
|
Only one element can use this at a time unless particular care is taken not
|
|
|
|
to blindly overwrite but instead to adapt the context extracted by other
|
|
|
|
elements.
|
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
* runs: **outside chroot**
|
|
|
|
* inputs:
|
|
|
|
|
|
|
|
* ``$ARCH=i386|amd64|armhf``
|
|
|
|
* ``$TARGET_ROOT=/path/to/target/workarea``
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
``extra-data.d``
|
|
|
|
Pull in extra data from the host environment that hooks may
|
2015-02-12 07:07:47 +00:00
|
|
|
need during image creation. This should copy any data (such as SSH keys,
|
2015-09-16 13:44:49 +00:00
|
|
|
http proxy settings and the like) somewhere under ``$TMP_HOOKS_PATH``.
|
|
|
|
|
|
|
|
* runs: **outside chroot**
|
|
|
|
* inputs: ``$TMP_HOOKS_PATH``
|
|
|
|
* outputs: None
|
|
|
|
|
|
|
|
``pre-install.d``
|
|
|
|
Run code in the chroot before customisation or packages are installed. A good
|
|
|
|
place to add apt repositories.
|
|
|
|
|
|
|
|
* runs: **in chroot**
|
|
|
|
|
|
|
|
``install.d``
|
|
|
|
Runs after ``pre-install.d`` in the chroot. This is a good place to
|
|
|
|
install packages, chain into configuration management tools or do other image
|
|
|
|
specific operations.
|
|
|
|
|
|
|
|
* runs: **in chroot**
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
``post-install.d``
|
|
|
|
Run code in the chroot. This is a good place to perform tasks you want to
|
|
|
|
handle after the OS/application install but before the first boot of the
|
|
|
|
image. Some examples of use would be:
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
Run ``chkconfig`` to disable unneeded services
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
Clean the cache left by the package manager to reduce the size of the image.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
* runs: **in chroot**
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
``block-device.d``
|
|
|
|
Customise the block device that the image will be made on (for example to
|
|
|
|
make partitions). Runs after the target tree has been fully populated but
|
|
|
|
before the ``cleanup.d`` phase runs.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
* runs: **outside chroot**
|
|
|
|
* inputs:
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
* ``$IMAGE_BLOCK_DEVICE={path}``
|
|
|
|
* ``$TARGET_ROOT={path}``
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
* outputs: ``$IMAGE_BLOCK_DEVICE={path}``
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
``finalise.d``
|
|
|
|
Perform final tuning of the root filesystem. Runs in a chroot after the root
|
|
|
|
filesystem content has been copied into the mounted filesystem: this is an
|
|
|
|
appropriate place to reset SELinux metadata, install grub bootloaders and so
|
|
|
|
on.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
Because this happens inside the final image, it is important to limit
|
|
|
|
operations here to only those necessary to affect the filesystem metadata and
|
|
|
|
image itself. For most operations, ``post-install.d`` is preferred.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
Refactor: block-device handling (local loop)
Block device handling can be somewhat complex - especially
when taking things like md, lvm or encryption into account.
This patch factors out the creation and deletion of the local
loop image device handling into a python library.
The main propose of this patch is to implement the needed
infrastructure. Based on this, more advanced functions can be added.
Example: (advanced) partitioning, LVM, handling different boot
scenarios (BIOS, UEFI, ...), possibility of handling multiple images
(local loop image, iSCSI, physical hard disk, ...), handling of
different filesystems for different partitions / LVs.
Change-Id: Ib626b36a00f8a5dc3dbde8df3e2619a2438eaaf1
Signed-off-by: Andreas Florath <andreas@florath.net>
2016-05-21 19:32:35 +00:00
|
|
|
* runs: **in chroot**
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
``cleanup.d``
|
|
|
|
Perform cleanup of the root filesystem content. For instance, temporary
|
|
|
|
settings to use the image build environment HTTP proxy are removed here in
|
|
|
|
the dpkg element.
|
|
|
|
|
|
|
|
* runs: outside chroot
|
|
|
|
* inputs:
|
|
|
|
|
|
|
|
* ``$ARCH=i386|amd64|armhf``
|
|
|
|
* ``$TARGET_ROOT=/path/to/target/workarea``
|
2015-02-12 07:07:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
Other Subdirectories
|
|
|
|
^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
Elements may have other subdirectories that are processed by specific elements
|
|
|
|
rather than the diskimage-builder tools themselves.
|
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
One example of this is the ``bin`` directory. The `rpm-distro`,
|
|
|
|
:doc:`../elements/dpkg/README` and :doc:`../elements/opensuse/README` elements
|
|
|
|
install all files found in the ``bin`` directory into ``/usr/local/bin`` within
|
|
|
|
the image as executable files.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
|
|
|
Environment Variables
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
2016-10-20 02:51:16 +00:00
|
|
|
To set environment variables for other hooks, add a file to your
|
|
|
|
element ``environment.d``. This directory contains bash script
|
|
|
|
snippets that are sourced before running scripts in each phase. Note
|
|
|
|
that because environment includes are sourced together, they should
|
|
|
|
not set global flags like ``set -x`` because they will affect all
|
|
|
|
preceeding imports.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
Dependencies
|
|
|
|
^^^^^^^^^^^^
|
|
|
|
|
|
|
|
Each element can use the following files to define or affect dependencies:
|
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
``element-deps``
|
|
|
|
A plain text, newline separated list of elements which will be added to the
|
|
|
|
list of elements built into the image at image creation time.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
``element-provides``
|
|
|
|
A plain text, newline separated list of elements which are provided by this
|
|
|
|
element. These elements will be excluded from elements built into the image
|
|
|
|
at image creation time.
|
|
|
|
|
|
|
|
For example if element A depends on element B and element C includes element B
|
|
|
|
in its ``element-provides`` file and A and C are included when building an
|
|
|
|
image, then B is not used.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-05-15 17:12:41 +00:00
|
|
|
Operating system elements
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-05-15 17:12:41 +00:00
|
|
|
Some elements define the base structure for an operating system -- for example,
|
|
|
|
the ``opensuse`` element builds a base openSUSE system. Such elements have
|
|
|
|
more requirements than the other elements:
|
|
|
|
|
|
|
|
* they must have ``operating-system`` in their element-provides, so this
|
|
|
|
indicates they are an "operating system".
|
|
|
|
|
|
|
|
* they must export the ``DISTRO_NAME`` environment variable with the name
|
|
|
|
of the distribution built, using an environment.d script. For example,
|
|
|
|
the ``opensuse`` element exports ``DISTRO_NAME=opensuse``.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
|
|
|
Ramdisk Elements
|
|
|
|
^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
Ramdisk elements support the following files in their element directories:
|
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
``binary-deps.d``
|
|
|
|
Text files listing executables required to be fed into the ramdisk. These
|
|
|
|
need to be present in ``$PATH`` in the build chroot (i.e. need to be installed
|
|
|
|
by your elements as described above).
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
``init.d``
|
|
|
|
POSIX shell script fragments that will be appended to the default script
|
|
|
|
executed as the ramdisk is booted (``/init``).
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
``ramdisk-install.d``
|
|
|
|
Called to copy files into the ramdisk. The variable ``$TMP_MOUNT_PATH`` points
|
|
|
|
to the root of the tree that will be packed into the ramdisk.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
``udev.d``
|
|
|
|
``udev`` rules files that will be copied into the ramdisk.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
|
|
|
Element coding standard
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
- lines should not include trailing whitespace.
|
|
|
|
- there should be no hard tabs in the file.
|
|
|
|
- indents are 4 spaces, and all indentation should be some multiple of
|
|
|
|
them.
|
|
|
|
- `do` and `then` keywords should be on the same line as the if, while or
|
|
|
|
for conditions.
|
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
.. _dev-global-image-build-variables:
|
|
|
|
|
2015-02-12 07:07:47 +00:00
|
|
|
Global image-build variables
|
|
|
|
----------------------------
|
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
``DIB_OFFLINE``
|
|
|
|
This is always set. When not empty, any operations that perform remote data
|
|
|
|
access should avoid it if possible. If not possible the operation should still
|
|
|
|
be attempted as the user may have an external cache able to keep the operation
|
|
|
|
functional.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
``DIB_IMAGE_ROOT_FS_UUID``
|
|
|
|
This contains the UUID of the root filesystem, when diskimage-builder is
|
|
|
|
building a disk image. This works only for ext filesystems.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
``DIB_IMAGE_CACHE``
|
|
|
|
Path to where cached inputs to the build process are stored. Defaults to
|
|
|
|
``~/.cache/image_create``.
|
2015-06-18 09:24:13 +00:00
|
|
|
|
2015-02-12 07:07:47 +00:00
|
|
|
Structure of an element
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
The above-mentioned global content can be further broken down in a way that
|
|
|
|
encourages composition of elements and reusability of their components. One
|
|
|
|
possible approach to this would be to label elements as either a "driver",
|
|
|
|
"service", or "config" element. Below are some examples.
|
|
|
|
|
|
|
|
- Driver-specific elements should only contain the necessary bits for that
|
2015-04-27 14:50:37 +00:00
|
|
|
driver::
|
2015-02-12 07:07:47 +00:00
|
|
|
|
|
|
|
elements/
|
|
|
|
driver-mellanox/
|
|
|
|
init - modprobe line
|
|
|
|
install.d/
|
|
|
|
10-mlx - package installation
|
|
|
|
|
|
|
|
- An element that installs and configures Nova might be a bit more complex,
|
2015-04-27 14:50:37 +00:00
|
|
|
containing several scripts across several phases::
|
2015-02-12 07:07:47 +00:00
|
|
|
|
|
|
|
elements/
|
|
|
|
service-nova/
|
|
|
|
source-repository-nova - register a source repository
|
|
|
|
pre-install.d/
|
|
|
|
50-my-ppa - add a PPA
|
|
|
|
install.d/
|
|
|
|
10-user - common Nova user accts
|
|
|
|
50-my-pack - install packages from my PPA
|
|
|
|
60-nova - install nova and some dependencies
|
|
|
|
|
|
|
|
- In the general case, configuration should probably be handled either by the
|
|
|
|
meta-data service (eg, o-r-c) or via normal CM tools
|
|
|
|
(eg, salt). That being said, it may occasionally be desirable to create a
|
|
|
|
set of elements which express a distinct configuration of the same software
|
|
|
|
components.
|
|
|
|
|
|
|
|
In this way, depending on the hardware and in which availability zone it is
|
|
|
|
to be deployed, an image would be composed of:
|
|
|
|
|
|
|
|
* zero or more driver-elements
|
|
|
|
* one or more service-elements
|
|
|
|
* zero or more config-elements
|
|
|
|
|
|
|
|
It should be noted that this is merely a naming convention to assist in
|
|
|
|
managing elements. Diskimage-builder is not, and should not be, functionally
|
|
|
|
dependent upon specific element names.
|
|
|
|
|
|
|
|
diskimage-builder has the ability to retrieve source code for an element and
|
|
|
|
place it into a directory on the target image during the extra-data phase. The
|
|
|
|
default location/branch can then be overridden by the process running
|
|
|
|
diskimage-builder, making it possible to use the same element to track more
|
|
|
|
then one branch of a git repository or to get source for a local cache. See
|
2015-09-16 13:44:49 +00:00
|
|
|
:doc:`../elements/source-repositories/README` for more information.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2016-06-28 05:57:55 +00:00
|
|
|
Finding other elements
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
DIB exposes an internal ``$IMAGE_ELEMENT_YAML`` variable which
|
|
|
|
provides elements access to the full set of included elements and
|
|
|
|
their paths. This can be used to process local in-element files
|
|
|
|
across all the elements (``pkg-map`` for example).
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
import os
|
|
|
|
import yaml
|
|
|
|
|
|
|
|
elements = yaml.load(os.getenv('IMAGE_ELEMENT_YAML'))
|
|
|
|
for element, path in elements:
|
|
|
|
...
|
|
|
|
|
|
|
|
For elements written in Bash, there is a function
|
|
|
|
``get_image_element_array`` that can be used to instantiate an
|
|
|
|
associative-array of elements and paths (note arrays can not be
|
|
|
|
exported in bash).
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
# note eval to expand the result of the get function
|
|
|
|
eval declare -A image_elements=($(get_image_element_array))
|
|
|
|
for i in ${!image_elements[$i]}; do
|
|
|
|
element=$i
|
|
|
|
path=${image_elements[$i]}
|
|
|
|
done
|
|
|
|
|
2015-02-12 07:07:47 +00:00
|
|
|
Debugging elements
|
|
|
|
------------------
|
|
|
|
|
|
|
|
The build-time environment and command line arguments are captured by the
|
2015-09-16 13:44:49 +00:00
|
|
|
:doc:`../elements/base/README` element and written to ``/etc/dib_environment``
|
|
|
|
and ``/etc/dib_arguments`` inside the image.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
Export ``break`` to drop to a shell during the image build. Break points can be
|
2015-02-12 07:07:47 +00:00
|
|
|
set either before or after any of the hook points by exporting
|
|
|
|
"break=[before|after]-hook-name". Multiple break points can be specified as a
|
|
|
|
comma-delimited string. Some examples:
|
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
* ``break=before-block-device-size`` will break before the block device size
|
|
|
|
hooks are called.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
* ``break=before-pre-install`` will break before the pre-install hooks.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
* ``break=after-error`` will break after an error during an in target hookpoint.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
|
|
|
Images are built such that the Linux kernel is instructed not to switch into
|
|
|
|
graphical consoles (i.e. it will not activate KMS). This maximises
|
|
|
|
compatibility with remote console interception hardware, such as HP's iLO.
|
2015-07-22 08:27:50 +00:00
|
|
|
However, you will typically only see kernel messages on the console - init
|
2015-02-12 07:07:47 +00:00
|
|
|
daemons (e.g. upstart) will usually be instructed to output to a serial
|
|
|
|
console so nova's console-log command can function. There is an element in the
|
|
|
|
tripleo-image-elements repository called "remove-serial-console" which will
|
|
|
|
force all boot messages to appear on the main console.
|
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
Ramdisk images can be debugged at run-time by passing ``troubleshoot`` as a
|
2015-02-12 07:07:47 +00:00
|
|
|
kernel command line argument, or by pressing "t" when an error is reached. This
|
|
|
|
will spawn a shell on the console (this can be extremely useful when network
|
|
|
|
interfaces or disks are not detected correctly).
|
|
|
|
|
|
|
|
Testing Elements
|
|
|
|
----------------
|
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
An element can have functional tests encapsulated inside the element itself. The
|
|
|
|
tests can be written either as shell or python unit tests.
|
2015-04-17 02:36:46 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
shell
|
|
|
|
"""""
|
|
|
|
|
|
|
|
In order to create a test case, follow these steps:
|
|
|
|
|
|
|
|
* Create a directory called ``test-elements`` inside your element.
|
2015-04-17 02:36:46 +00:00
|
|
|
|
|
|
|
* Inside the test-elements directory, create a directory with the name of your
|
|
|
|
test case. The test case directory should have the same structure as an
|
2015-09-16 13:44:49 +00:00
|
|
|
element. For example::
|
|
|
|
|
|
|
|
elements/apt-sources/test-elements/test-case-1
|
2015-04-17 02:36:46 +00:00
|
|
|
|
|
|
|
* Assert state during each of the element build phases you would like to test.
|
|
|
|
You can exit 1 to indicate a failure.
|
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
* To exit early and indicate a success, touch a file
|
|
|
|
``/tmp/dib-test-should-fail`` in the image chroot, then exit 1.
|
|
|
|
|
Rework functional test runner
This simplifies and enhances the functional-test runner script for
much better interactive behaviour and to give us the ability to better
choose what is running in CI.
Firstly, I have split the image-output testing into a separate script.
This is not actually part of the functional testing of elements and is
both logically and functionally different. It currently does not run
in upstream CI because we don't have docker in the images. I have
nothing against it, but it can be it's own thing.
run_functests.sh is overhauled to have a useful interactive interface,
e.g.
---
$ ./run_functests.sh -h
run_functests.sh [-h] [-l] <test> <test> ...
-h : show this help
-l : list available tests
<test> : functional test to run
Special test 'all' will run all tests
$ ./run_functests.sh -l
The available functional tests are:
apt-sources/test-sources
debian/build-succeeds
fedora/build-succeeds
fedora/build-succeeds-f21
ironic-agent/build-succeeds-fedora
---
As described there, you can run a single test, a number of tests, the
default tests (as CI will do) or all tests. Running all tests is too
much for regular CI, but currently the only way to stop a low priority
test running, or temporarily pause is to remove it completely --
clearly sub-optimal (see I93c2990472e88ab3e5ff14db56b4ff1b4dd965ef).
There is nothing complicated about this, and to further simplify I
have merged the runner functions back into run_functests.sh which
remains a very modest ~150 lines, with most of that being argument
sanity. With that and the image-format cleanup, we can remove the
indirection of the 3 small library files.
For consistency, I have renamed the "dib_functions_test" (that tests
things from the dib functions library) with a run_* prefix.
Because the default list is the same as the current functional tests
run, this does not modify the status-quo. I plan to modify this,
however, to run fedora-minimal & centos-minimal tests in a future
change, as these are required to be stable for openstack ci.
Documentation is updated, and a README.rst is added in the tests
directory for discoverability.
Change-Id: I86d208bd34ff09a29fdb916a4e7ef740c7f65af8
2016-02-05 03:54:50 +00:00
|
|
|
Tests are run with ``tools/run_functests.sh``. Running
|
|
|
|
``run_functests.sh -l`` will show available tests (the example above
|
|
|
|
would be called ``apt-sources/test-case-1``, for example). Specify
|
|
|
|
your test (or a series of tests as separate arguments) on the command
|
|
|
|
line to run it. If it should not be run as part of the default CI
|
|
|
|
run, you can submit a change with it added to ``DEFAULT_SKIP_TESTS``
|
|
|
|
in that file.
|
|
|
|
|
2016-07-20 21:34:50 +00:00
|
|
|
Running the functional tests is time consuming. Multiple parallel
|
|
|
|
jobs can be started by specifying ``-j <job count>``. Each of the
|
|
|
|
jobs uses a lot resources (CPU, disk space, RAM) - therefore the job
|
|
|
|
count must carefully be chosen.
|
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
python
|
|
|
|
""""""
|
2015-04-17 02:36:46 +00:00
|
|
|
|
2015-09-30 09:55:40 +00:00
|
|
|
To run functional tests locally, install and start docker, then use
|
|
|
|
the following tox command::
|
|
|
|
|
|
|
|
tox -efunc
|
|
|
|
|
|
|
|
Note that running functional tests requires *sudo* rights, thus you may be
|
|
|
|
asked for your password.
|
|
|
|
|
|
|
|
To run functional tests for one element, append its name to the command::
|
|
|
|
|
|
|
|
tox -efunc ironic-agent
|
|
|
|
|
2015-04-17 02:36:46 +00:00
|
|
|
Additionally, elements can be tested using python unittests. To create a
|
|
|
|
a python test:
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
* Create a directory called ``tests`` in the element directory.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
* Create an empty file called ``__init__.py`` to make it into a python
|
2015-02-12 07:07:47 +00:00
|
|
|
package.
|
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
* Create your test files as ``test\whatever.py``, using regular python test
|
2015-02-12 07:07:47 +00:00
|
|
|
code.
|
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
To run all the tests use testr - ``testr run``. To run just some tests provide
|
2015-02-12 07:07:47 +00:00
|
|
|
one or more regex filters - tests matching any of them are run -
|
2015-09-16 13:44:49 +00:00
|
|
|
``testr run apt-proxy``.
|
2015-02-12 07:07:47 +00:00
|
|
|
|
|
|
|
Third party elements
|
|
|
|
--------------------
|
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
Additional elements can be incorporated by setting ``ELEMENTS_PATH``, for
|
|
|
|
example if one were building tripleo-images, the variable would be set like:
|
|
|
|
|
|
|
|
.. sourcecode:: sh
|
2015-02-12 07:07:47 +00:00
|
|
|
|
2015-09-16 13:44:49 +00:00
|
|
|
export ELEMENTS_PATH=tripleo-image-elements/elements
|
|
|
|
disk-image-create rhel7 cinder-api
|
2016-04-08 05:46:21 +00:00
|
|
|
|
|
|
|
Linting
|
|
|
|
-------
|
|
|
|
|
|
|
|
You should always run ``bin/dib-lint`` over your elements. It will
|
|
|
|
warn you of common issues.
|
|
|
|
|
|
|
|
sudo
|
|
|
|
""""
|
|
|
|
|
|
|
|
Using ``sudo`` outside the chroot environment can cause breakout
|
|
|
|
issues where you accidentally modify parts of the host
|
|
|
|
system. ``dib-lint`` will warn if it sees ``sudo`` calls that do not
|
|
|
|
use the path arguments given to elements running outside the chroot.
|
|
|
|
|
|
|
|
To disable the error for a call you know is safe, add
|
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
# dib-lint: safe_sudo
|
|
|
|
|
|
|
|
to the end of the ``sudo`` command line. To disable the check for an
|
|
|
|
entire file, add
|
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
# dib-lint: disable=safe_sudo
|