Merge "Add functional smoke test for disk-image-create"
This commit is contained in:
commit
cb78c554ff
@ -45,6 +45,9 @@ What tools are there?
|
||||
|
||||
* element-info : Extract information about elements.
|
||||
|
||||
* tests/run_functests.sh
|
||||
This runs a set of functional tests for diskimage-builder.
|
||||
|
||||
Why?
|
||||
----
|
||||
|
||||
|
@ -205,6 +205,7 @@ fi
|
||||
mk_build_dir
|
||||
create_base
|
||||
# This variable needs to be propagated into the chroot
|
||||
mkdir -p $TMP_HOOKS_PATH/environment.d
|
||||
echo "export DIB_DEFAULT_INSTALLTYPE=\"${DIB_DEFAULT_INSTALLTYPE}\"" > $TMP_HOOKS_PATH/environment.d/11-dib-install-type.bash
|
||||
run_d extra-data
|
||||
# Run pre-install scripts. These do things that prepare the chroot for package installs
|
||||
|
6
tests/elements/fake-os/README.rst
Normal file
6
tests/elements/fake-os/README.rst
Normal file
@ -0,0 +1,6 @@
|
||||
fake-os
|
||||
=======
|
||||
|
||||
This is not the element you are looking for.
|
||||
|
||||
This element does not provide an operating system, it provides a fake for testing purposes only.
|
1
tests/elements/fake-os/element-provides
Normal file
1
tests/elements/fake-os/element-provides
Normal file
@ -0,0 +1 @@
|
||||
operating-system
|
16
tests/elements/fake-os/root.d/10-fake-os
Executable file
16
tests/elements/fake-os/root.d/10-fake-os
Executable file
@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eux
|
||||
set -o pipefail
|
||||
|
||||
sudo touch $TARGET_ROOT/fake-os
|
||||
|
||||
sudo mkdir -p $TARGET_ROOT/etc
|
||||
sudo mkdir -p $TARGET_ROOT/mnt
|
||||
sudo mkdir -p $TARGET_ROOT/proc
|
||||
sudo mkdir -p $TARGET_ROOT/dev
|
||||
sudo mkdir -p $TARGET_ROOT/sys
|
||||
|
||||
# We need some size so the mkfs does not fail when making an fs of size 0
|
||||
# We also need to account for the journal size on the FS
|
||||
dd if=/dev/zero of=$TARGET_ROOT/fake-data bs=1M count=42
|
21
tests/image_output_formats.bash
Executable file
21
tests/image_output_formats.bash
Executable file
@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eux
|
||||
set -o pipefail
|
||||
|
||||
source $(dirname $0)/test_functions.bash
|
||||
|
||||
test_formats="tar raw qcow2"
|
||||
if [ -z "$(which qemu-img)" ]; then
|
||||
echo "Warning: No qemu-img binary found, cowardly refusing to run tests."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
for format in '' $test_formats; do
|
||||
build_test_image $format
|
||||
echo "Test passed for output formats '$format'."
|
||||
done
|
||||
|
||||
combined_format=$(echo $test_formats | tr ' ' ',')
|
||||
build_test_image $combined_format
|
||||
echo "Test passed for output format '$combined_format'."
|
8
tests/run_functests.sh
Executable file
8
tests/run_functests.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eux
|
||||
set -o pipefail
|
||||
|
||||
$(dirname $0)/image_output_formats.bash
|
||||
|
||||
echo "Tests passed!"
|
34
tests/test_functions.bash
Normal file
34
tests/test_functions.bash
Normal file
@ -0,0 +1,34 @@
|
||||
export TEST_ELEMENTS=$(dirname $0)/elements
|
||||
export DIB_ELEMENTS=$(dirname $0)/../elements
|
||||
export DIB_CMD=$(dirname $0)/../bin/disk-image-create
|
||||
|
||||
function build_test_image() {
|
||||
format=${1:-}
|
||||
|
||||
if [ -n "$format" ]; then
|
||||
type_arg="-t $format"
|
||||
else
|
||||
type_arg=
|
||||
format="qcow2"
|
||||
fi
|
||||
dest_dir=$(mktemp -d)
|
||||
|
||||
trap "rm -rf $dest_dir" EXIT
|
||||
|
||||
ELEMENTS_PATH=$DIB_ELEMENTS:$TEST_ELEMENTS \
|
||||
$DIB_CMD $type_arg -o $dest_dir/image -n fake-os
|
||||
|
||||
format=$(echo $format | tr ',' ' ')
|
||||
for format in $format; do
|
||||
img_path="$dest_dir/image.$format"
|
||||
if ! [ -f "$img_path" ]; then
|
||||
echo "Error: No image with name $img_path found!"
|
||||
exit 1
|
||||
else
|
||||
echo "Found image $img_path."
|
||||
fi
|
||||
done
|
||||
|
||||
trap EXIT
|
||||
rm -rf $dest_dir
|
||||
}
|
Loading…
Reference in New Issue
Block a user