[PATCH 4/4] Add a basic test for ostree-based installs.
Chris Lumens
clumens at redhat.com
Fri Jul 11 15:18:27 UTC 2014
Right now it just tries an install from a repo you specify (a local one is
fast), and then reboots to verify everything worked.
This would also allow for testing further ostree-related things in the future,
should anything come up.
---
tests/Makefile.am | 4 +-
tests/ostree/basic.ks | 36 ++++++++++++
tests/ostree/run_ostree_tests.sh | 120 +++++++++++++++++++++++++++++++++++++++
3 files changed, 159 insertions(+), 1 deletion(-)
create mode 100644 tests/ostree/basic.ks
create mode 100755 tests/ostree/run_ostree_tests.sh
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 877bdb9..2803481 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -49,6 +49,7 @@ dist_check_SCRIPTS = $(srcdir)/glade/*/*.py \
gettext/gettext_warnings.sh \
gettext/gettext_potfiles.py \
storage/run_storage_tests.py \
+ ostree/run_ostree_tests.sh \
$(srcdir)/gui/*.ks \
$(srcdir)/gui/*.sh \
$(srcdir)/gui/inside/*.py \
@@ -63,7 +64,8 @@ TESTS = nosetests.sh \
gettext/gettext_potfiles.py \
storage/run_storage_tests.py \
gui/run_gui_tests.sh \
- glade/run_glade_tests.sh
+ glade/run_glade_tests.sh \
+ ostree/run_ostree_tests.sh
clean-local:
-rm -rf pylint/.pylint.d
diff --git a/tests/ostree/basic.ks b/tests/ostree/basic.ks
new file mode 100644
index 0000000..3767366
--- /dev/null
+++ b/tests/ostree/basic.ks
@@ -0,0 +1,36 @@
+# Substitute something in for REPO or this will all come crashing down.
+ostreesetup --nogpg --osname=fedora-atomic --remote=fedora-atomic --url=REPO --ref=fedora-atomic/rawhide/x86_64/base/core
+
+bootloader --timeout=1 --extlinux
+zerombr
+clearpart --all
+part --fstype=ext4 --size=4400 /
+part --fstype=ext4 --size=500 /boot
+part --fstype=swap --size=500 swap
+
+keyboard us
+timezone America/New_York
+rootpw qweqwe
+shutdown
+
+%post
+cat <<EOF > /etc/systemd/system/default.target.wants/run-test.service
+[Unit]
+Description=Run a test to see if anaconda+ostree worked
+After=basic.target
+
+[Service]
+Type=oneshot
+ExecStart=/usr/bin/run-test.sh
+EOF
+
+cat <<EOF > /usr/bin/run-test.sh
+#!/bin/bash
+
+# For now, just the fact that we rebooted is good enough.
+echo SUCCESS > /root/RESULT
+shutdown -h now
+EOF
+
+chmod +x /usr/bin/run-test.sh
+%end
diff --git a/tests/ostree/run_ostree_tests.sh b/tests/ostree/run_ostree_tests.sh
new file mode 100755
index 0000000..b2d57eb
--- /dev/null
+++ b/tests/ostree/run_ostree_tests.sh
@@ -0,0 +1,120 @@
+#!/bin/bash
+#
+# Copyright (C) 2014 Red Hat, Inc.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions of
+# the GNU General Public License v.2, or (at your option) any later version.
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY expressed or implied, including the implied warranties of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details. You should have received a copy of the
+# GNU General Public License along with this program; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
+# source code or documentation are not subject to the GNU General Public
+# License and may only be used or replicated with the express permission of
+# Red Hat, Inc.
+#
+# Red Hat Author(s): Chris Lumens <clumens at redhat.com>
+
+# Have to be root to run this test, as it requires creating disk iamges.
+if [ ${EUID} != 0 ]; then
+ exit 77
+fi
+
+# The boot.iso location can come from one of two different places:
+# (1) $TEST_BOOT_ISO, if this script is being called from "make check"
+# (2) The command line, if this script is being called directly.
+if [[ "${TEST_BOOT_ISO}" != "" ]]; then
+ IMAGE=${TEST_BOOT_ISO}
+elif [[ $# != 0 ]]; then
+ IMAGE=$1
+ shift
+fi
+
+# The same with the ostree repo.
+if [[ "${TEST_OSTREE_REPO}" != "" ]]; then
+ REPO=${TEST_OSTREE_REPO}
+elif [[ $# != 0 ]]; then
+ REPO=$1
+ shift
+else
+ echo "usage: $0 <boot.iso> <ostree repo>"
+ exit 1
+fi
+
+if [ ! -e "${IMAGE}" ]; then
+ echo "Required boot.iso does not exist."
+ exit 2
+fi
+
+logdir=$(mktemp -d)
+
+status=0
+for ks in ostree/*ks; do
+ # Substitute in the location of an ostree repo here. This could be one
+ # publically accessible, or a very local and private one that happens
+ # to be fast.
+ ksfile=$(mktemp)
+ sed -e "/ostreesetup/ s|REPO|${REPO}|" ${ks} > ${ksfile}
+
+ echo ${ks}
+ echo ====================
+
+ livemedia-creator --make-disk \
+ --iso "${IMAGE}" \
+ --ks ${ksfile} \
+ --tmp /var/tmp \
+ --logfile ${logdir}/livemedia.log \
+ --title Fedora \
+ --project Fedora \
+ --releasever 21 \
+ --ram 2048 \
+ --vcpus 2 \
+ --vnc vnc
+ if [ $? != 0 ]; then
+ status=1
+ echo $(grep CRIT ${logdir}/virt-install.log)
+ fi
+
+ rm ${ksfile}
+
+ if [ -f ostree/run_ostree_tests.log ]; then
+ img=$(grep disk_img ostree/run_ostree_tests.log | cut -d= -f2)
+ trimmed=${img## }
+
+ if [ ! -f ${trimmed} ]; then
+ status=1
+ echo Disk image ${trimmed} does not exist.
+ continue
+ fi
+
+ # Now attempt to boot the resulting VM and see if the install
+ # actually worked. The VM will shut itself down so there's no
+ # need to worry with that here.
+ /usr/bin/qemu-kvm -m 2048 \
+ -smp 2 \
+ -hda ${trimmed}
+
+ # There should be a /root/RESULT file with results in it. Check
+ # its contents and decide whether the test finally succeeded or
+ # not.
+ result=$(virt-cat -a ${trimmed} -m /dev/sda2 /ostree/deploy/fedora-atomic/var/roothome/RESULT)
+ if [ $? != 0 ]; then
+ status=1
+ echo /root/RESULT does not exist in VM image.
+ elif [ "${result}" != "SUCCESS" ]; then
+ status=1
+ echo ${result}
+ fi
+ fi
+
+ # Clean it up for the next go around.
+ if [ -f ${trimmed} ]; then
+ rm ${trimmed}
+ fi
+done
+
+rm -r ${logdir}
+exit $status
--
1.9.3
More information about the anaconda-patches
mailing list