From 46dcaaedfc7c483c0f837252aafd5e5203f5b330 Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Tue, 22 Sep 2015 14:22:27 +0200 Subject: [PATCH] Add functional test for ironic-agent on Fedora Added support for ramdisk-type elements in tests/test_functions.bash Elements are distinguished by element-type file in a test element. Note that ironic-agent ramdisk is built with disk-image-create. Change-Id: I4759859e7f3c004c2d00e7318729602e6c3c4d95 --- .../ironic-agent/test-elements/README.rst | 0 .../build-succeeds-fedora/element-deps | 1 + .../build-succeeds-fedora/element-type | 1 + .../environment.d/10-fedora-pin-mirror.bash | 2 ++ tests/test_elements.bash | 6 ++++- tests/test_functions.bash | 25 ++++++++++++++++++- 6 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 elements/ironic-agent/test-elements/README.rst create mode 100644 elements/ironic-agent/test-elements/build-succeeds-fedora/element-deps create mode 100644 elements/ironic-agent/test-elements/build-succeeds-fedora/element-type create mode 100644 elements/ironic-agent/test-elements/build-succeeds-fedora/environment.d/10-fedora-pin-mirror.bash diff --git a/elements/ironic-agent/test-elements/README.rst b/elements/ironic-agent/test-elements/README.rst new file mode 100644 index 000000000..e69de29bb diff --git a/elements/ironic-agent/test-elements/build-succeeds-fedora/element-deps b/elements/ironic-agent/test-elements/build-succeeds-fedora/element-deps new file mode 100644 index 000000000..35a143bac --- /dev/null +++ b/elements/ironic-agent/test-elements/build-succeeds-fedora/element-deps @@ -0,0 +1 @@ +fedora diff --git a/elements/ironic-agent/test-elements/build-succeeds-fedora/element-type b/elements/ironic-agent/test-elements/build-succeeds-fedora/element-type new file mode 100644 index 000000000..fb12a1ff8 --- /dev/null +++ b/elements/ironic-agent/test-elements/build-succeeds-fedora/element-type @@ -0,0 +1 @@ +ramdisk diff --git a/elements/ironic-agent/test-elements/build-succeeds-fedora/environment.d/10-fedora-pin-mirror.bash b/elements/ironic-agent/test-elements/build-succeeds-fedora/environment.d/10-fedora-pin-mirror.bash new file mode 100644 index 000000000..13224cfa2 --- /dev/null +++ b/elements/ironic-agent/test-elements/build-succeeds-fedora/environment.d/10-fedora-pin-mirror.bash @@ -0,0 +1,2 @@ +# Pin to this mirror because the roundrobin is fairly unreliable +export DIB_DISTRIBUTION_MIRROR=http://dl.fedoraproject.org/pub/fedora/linux diff --git a/tests/test_elements.bash b/tests/test_elements.bash index 804ce195e..068f0d197 100755 --- a/tests/test_elements.bash +++ b/tests/test_elements.bash @@ -10,6 +10,10 @@ for test_element in $basedir/../elements/*/test-elements/*; do if [ -d "$test_element" ]; then # our element name is two dirs up element_name=$(basename $(dirname $(dirname $test_element))) - run_element_test "$(basename $test_element)" "$element_name" + element_type=disk + if [ -f "$test_element/element-type" ]; then + element_type=$(cat "$test_element/element-type") + fi + run_${element_type}_element_test "$(basename $test_element)" "$element_name" fi done diff --git a/tests/test_functions.bash b/tests/test_functions.bash index b89a45979..921faf34c 100644 --- a/tests/test_functions.bash +++ b/tests/test_functions.bash @@ -45,7 +45,7 @@ function build_test_image() { docker rmi $base_dest/image } -function run_element_test() { +function run_disk_element_test() { test_element=$1 element=$2 @@ -81,3 +81,26 @@ function run_element_test() { trap EXIT rm -rf $dest_dir /tmp/dib-test-should-fail } + +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 +}