Merge "Check env-vars is a dictionary"

This commit is contained in:
Jenkins 2015-02-14 00:33:42 +00:00 committed by Gerrit Code Review
commit a0edab1d36
5 changed files with 61 additions and 21 deletions

View File

@ -173,21 +173,18 @@ will be built using the provider snapshot approach::
qemu-img-options: compat=0.10 qemu-img-options: compat=0.10
env-vars: env-vars:
DIB_DISTRIBUTION_MIRROR: http://archive.ubuntu.com DIB_DISTRIBUTION_MIRROR: http://archive.ubuntu.com
DIB_EXTRA_VARIABLE: foobar
For diskimages, the `name` is required. The `elements` section For diskimages, the `name` is required. The `elements` section
enumerates all the elements that will be included when building enumerates all the elements that will be included when building the
the image, and will point to the `elements-dir` path referenced image, and will point to the `elements-dir` path referenced in the
in the same config file. `release` specifies the distro to be same config file. `release` specifies the distro to be used as a base
used as a base image to build the image using diskimage-builder. image to build the image using diskimage-builder. `qemu-img-options`
`qemu-img-options` allows to specify custom settings that qemu allows to specify custom settings that qemu will be using to build the
will be using to build the final image. Settings there have to final image. Settings there have to be separated by commas, and must
be separated by commas, and must follow qemu syntax. follow qemu syntax. `env-vars` is an optional dictionary of arbitrary
environment variables that will be available in the spawned
The `env-vars` key is optional. It allows to specify a list of diskimage-builder child process.
environment variables that will be appended to the variables
that are send by default to diskimage-builder. Using that approach
it is possible to send the DIB_*environment variables neeeded by
diskimage-builder elements per image type.
providers providers
--------- ---------

View File

@ -766,11 +766,13 @@ class DiskImageBuilder(threading.Thread):
image.qemu_img_options) image.qemu_img_options)
img_elements = image.elements img_elements = image.elements
cmd = ('disk-image-create -x --no-tmpfs %s -o %s %s' %
(extra_options, out_file_path, img_elements))
if 'fake-' in filename: if 'fake-' in filename:
cmd = 'echo ' + cmd dib_cmd = 'nodepool/tests/fake-image-create'
else:
dib_cmd = 'disk-image-create'
cmd = ('%s -x --no-tmpfs %s -o %s %s' %
(dib_cmd, extra_options, out_file_path, img_elements))
log = logging.getLogger("nodepool.image.build.%s" % log = logging.getLogger("nodepool.image.build.%s" %
(image_name,)) (image_name,))
@ -1251,9 +1253,10 @@ class NodePool(threading.Thread):
d.elements = '' d.elements = ''
d.release = diskimage.get('release', '') d.release = diskimage.get('release', '')
d.qemu_img_options = diskimage.get('qemu-img-options', '') d.qemu_img_options = diskimage.get('qemu-img-options', '')
if 'env-vars' in diskimage: d.env_vars = diskimage.get('env-vars', {})
d.env_vars = diskimage['env-vars'] if not isinstance(d.env_vars, dict):
else: self.log.error("%s: ignoring env-vars; "
"should be a dict" % d.name)
d.env_vars = {} d.env_vars = {}
for provider in config['providers']: for provider in config['providers']:

View File

@ -0,0 +1,31 @@
#!/bin/bash
echo "*** fake-image-create: start"
echo "arguments:"
echo "----"
echo $*
echo "----"
# test passing of real-life env-vars
if [[ "${TMPDIR}" != "/opt/dib_tmp" ]]; then
echo "TMPDIR not set"
exit 1
fi
if [[ "${DIB_IMAGE_CACHE}" != "/opt/dib_cache" ]]; then
echo "DIB_IMAGE_CACHE not set"
exit 1
fi
if [[ "${DIB_CLOUD_IMAGES}" != "http://download.fedoraproject.org/pub/fedora/linux/releases/test/21-Beta/Cloud/Images/x86_64/" ]]; then
echo "DIB_CLOUD_IMAGES not set"
exit 1
fi
if [[ "${BASE_IMAGE_FILE}" != "Fedora-Cloud-Base-20141029-21_Beta.x86_64.qcow2" ]]; then
echo "BASE_IMAGE_FILE not set"
exit 1
fi
echo "*** fake-image-create: done"

View File

@ -53,4 +53,8 @@ diskimages:
- ubuntu - ubuntu
- vm - vm
release: precise release: precise
env-vars:
TMPDIR: /opt/dib_tmp
DIB_IMAGE_CACHE: /opt/dib_cache
DIB_CLOUD_IMAGES: http://download.fedoraproject.org/pub/fedora/linux/releases/test/21-Beta/Cloud/Images/x86_64/
BASE_IMAGE_FILE: Fedora-Cloud-Base-20141029-21_Beta.x86_64.qcow2

View File

@ -70,4 +70,9 @@ diskimages:
- ubuntu - ubuntu
- vm - vm
release: precise release: precise
env-vars:
TMPDIR: /opt/dib_tmp
DIB_IMAGE_CACHE: /opt/dib_cache
DIB_CLOUD_IMAGES: http://download.fedoraproject.org/pub/fedora/linux/releases/test/21-Beta/Cloud/Images/x86_64/
BASE_IMAGE_FILE: Fedora-Cloud-Base-20141029-21_Beta.x86_64.qcow2