2015-03-31 04:53:30 +00:00
|
|
|
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)
|
2015-06-07 20:44:10 +00:00
|
|
|
base_dest=$(basename $dest_dir)
|
2015-03-31 04:53:30 +00:00
|
|
|
|
2015-07-22 10:57:09 +00:00
|
|
|
trap "rm -rf $dest_dir; docker rmi $base_dest/image" EXIT
|
2015-03-31 04:53:30 +00:00
|
|
|
|
|
|
|
ELEMENTS_PATH=$DIB_ELEMENTS:$TEST_ELEMENTS \
|
2015-06-07 20:44:10 +00:00
|
|
|
$DIB_CMD -x $type_arg --docker-target=$base_dest/image \
|
|
|
|
-o $dest_dir/image -n fake-os
|
2015-03-31 04:53:30 +00:00
|
|
|
|
|
|
|
format=$(echo $format | tr ',' ' ')
|
|
|
|
for format in $format; do
|
2015-06-07 20:44:10 +00:00
|
|
|
if [ $format != 'docker' ]; then
|
|
|
|
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
|
2015-03-31 04:53:30 +00:00
|
|
|
else
|
2015-06-07 20:44:10 +00:00
|
|
|
if ! docker image | grep $base_dest/image ; then
|
|
|
|
echo "Error: No docker image with name $base_dest/image found!"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "Found docker image $base_dest/image"
|
|
|
|
fi
|
2015-03-31 04:53:30 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
trap EXIT
|
|
|
|
rm -rf $dest_dir
|
2015-06-07 20:44:10 +00:00
|
|
|
docker rmi $base_dest/image
|
2015-03-31 04:53:30 +00:00
|
|
|
}
|
2015-04-17 02:36:46 +00:00
|
|
|
|
2015-09-22 12:22:27 +00:00
|
|
|
function run_disk_element_test() {
|
2015-04-17 02:36:46 +00:00
|
|
|
test_element=$1
|
|
|
|
element=$2
|
|
|
|
|
|
|
|
dest_dir=$(mktemp -d)
|
|
|
|
|
|
|
|
trap "rm -rf $dest_dir /tmp/dib-test-should-fail" EXIT
|
|
|
|
|
|
|
|
if break="after-error" break_outside_target=1 \
|
|
|
|
break_cmd="cp \$TMP_MOUNT_PATH/tmp/dib-test-should-fail /tmp/ || true" \
|
|
|
|
ELEMENTS_PATH=$DIB_ELEMENTS:$DIB_ELEMENTS/$element/test-elements \
|
|
|
|
$DIB_CMD -t tar -o $dest_dir/image -n $element $test_element; then
|
|
|
|
if ! [ -f "$dest_dir/image.tar" ]; then
|
|
|
|
echo "Error: Build failed for element: $element, test-element: $test_element."
|
|
|
|
echo "No image $dest_dir/image.tar found!"
|
|
|
|
exit 1
|
|
|
|
else
|
2015-05-27 17:58:24 +00:00
|
|
|
if tar -t $dest_dir/image.tar | grep -q /tmp/dib-test-should-fail; then
|
2015-04-17 02:36:46 +00:00
|
|
|
echo "Error: Element: $element, test-element $test_element should have failed, but passed."
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "PASS: Element $element, test-element: $test_element"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ -f "/tmp/dib-test-should-fail" ]; then
|
|
|
|
echo "PASS: Element $element, test-element: $test_element"
|
|
|
|
else
|
|
|
|
echo "Error: Build failed for element: $element, test-element: $test_element."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
trap EXIT
|
|
|
|
rm -rf $dest_dir /tmp/dib-test-should-fail
|
|
|
|
}
|
2015-09-22 12:22:27 +00:00
|
|
|
|
|
|
|
function run_ramdisk_element_test() {
|
|
|
|
test_element=$1
|
|
|
|
element=$2
|
|
|
|
|
|
|
|
dest_dir=$(mktemp -d)
|
|
|
|
|
|
|
|
if ELEMENTS_PATH=$DIB_ELEMENTS/$element/test-elements \
|
|
|
|
$DIB_CMD -o $dest_dir/image $element $test_element; then
|
|
|
|
# TODO(dtantsur): test also kernel presence once we sort out its naming
|
|
|
|
# problem (vmlinuz vs kernel)
|
|
|
|
if ! [ -f "$dest_dir/image.initramfs" ]; then
|
|
|
|
echo "Error: Build failed for element: $element, test-element: $test_element."
|
|
|
|
echo "No image $dest_dir/image.initramfs found!"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "PASS: Element $element, test-element: $test_element"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Error: Build failed for element: $element, test-element: $test_element."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|