[PATCH 2/3] Move common kickstart_test code out into its own functions.sh file.

Chris Lumens clumens at redhat.com
Fri May 29 17:58:03 UTC 2015


This is primarily motivated by the fact that you need to provide your own
disks now.  If you need to do something fancier than the default basic
stuff (which most tests shouldn't), you source functions.sh and then
provide your own definition.
---
 tests/kickstart_tests/basic-ftp.sh             | 29 +------------
 tests/kickstart_tests/basic-ostree.sh          |  9 ++---
 tests/kickstart_tests/bond.sh                  | 30 +-------------
 tests/kickstart_tests/escrow-cert.sh           | 29 +------------
 tests/kickstart_tests/functions.sh             | 56 ++++++++++++++++++++++++++
 tests/kickstart_tests/groups-and-envs-1.sh     | 30 +-------------
 tests/kickstart_tests/groups-and-envs-2.sh     | 30 +-------------
 tests/kickstart_tests/groups-and-envs-3.sh     | 30 +-------------
 tests/kickstart_tests/hostname.sh              | 30 +-------------
 tests/kickstart_tests/nfs-repo-and-addon.sh    | 20 +--------
 tests/kickstart_tests/packages-and-groups-1.sh | 30 +-------------
 tests/kickstart_tests/packages-default.sh      | 30 +-------------
 tests/kickstart_tests/packages-excludedocs.sh  | 30 +-------------
 tests/kickstart_tests/packages-multilib.sh     | 30 +-------------
 tests/kickstart_tests/proxy-cmdline.sh         | 27 +------------
 tests/kickstart_tests/proxy-kickstart.sh       | 22 +---------
 tests/kickstart_tests/run_one_ks.sh            |  2 +
 tests/kickstart_tests/tmpfs-fixed_size.sh      | 30 +-------------
 18 files changed, 78 insertions(+), 416 deletions(-)
 create mode 100644 tests/kickstart_tests/functions.sh

diff --git a/tests/kickstart_tests/basic-ftp.sh b/tests/kickstart_tests/basic-ftp.sh
index 8c4344e..1564a16 100755
--- a/tests/kickstart_tests/basic-ftp.sh
+++ b/tests/kickstart_tests/basic-ftp.sh
@@ -18,31 +18,4 @@
 #
 # Red Hat Author(s): David Shea <dshea at redhat.com>
 
-kernel_args() {
-    echo vnc
-}
-
-prepare() {
-    ks=$1
-    tmpdir=$2
-
-    echo ${ks}
-}
-
-validate() {
-    img=$1
-
-    # 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 ${img} -m /dev/fedora/root /root/RESULT)
-    if [[ $? != 0 ]]; then
-        status=1
-        echo '*** /root/RESULT does not exist in VM image.'
-    elif [[ "${result}" != "SUCCESS" ]]; then
-        status=1
-        echo "${result}"
-    fi
-
-    return ${status}
-}
+. ${KSTESTDIR}/functions.sh
diff --git a/tests/kickstart_tests/basic-ostree.sh b/tests/kickstart_tests/basic-ostree.sh
index e1ce4ba..73a83f8 100755
--- a/tests/kickstart_tests/basic-ostree.sh
+++ b/tests/kickstart_tests/basic-ostree.sh
@@ -18,9 +18,7 @@
 #
 # Red Hat Author(s): Chris Lumens <clumens at redhat.com>
 
-kernel_args() {
-    echo vnc
-}
+. ${KSTESTDIR}/functions.sh
 
 prepare() {
     ks=$1
@@ -36,7 +34,8 @@ prepare() {
 }
 
 validate() {
-    img=$1
+    disksdir=$1
+    args=$(for d in ${disksdir}/*img; do echo -a ${d}; done)
 
     # Now attempt to boot the resulting VM and see if the install
     # actually worked.  The VM will shut itself down so there's no
@@ -49,7 +48,7 @@ validate() {
     # 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 ${img} -m /dev/fedora/root /ostree/deploy/fedora-atomic/var/roothome/RESULT)
+    result=$(virt-cat ${args} -m /dev/fedora/root /ostree/deploy/fedora-atomic/var/roothome/RESULT)
     if [[ $? != 0 ]]; then
         status=1
         echo '*** /root/RESULT does not exist in VM image.'
diff --git a/tests/kickstart_tests/bond.sh b/tests/kickstart_tests/bond.sh
index 02d06c1..7b2f4f0 100755
--- a/tests/kickstart_tests/bond.sh
+++ b/tests/kickstart_tests/bond.sh
@@ -17,32 +17,4 @@
 #
 # Red Hat Author(s): Chris Lumens <clumens at redhat.com>
 
-kernel_args() {
-    echo vnc
-}
-
-prepare() {
-    ks=$1
-    tmpdir=$2
-
-    echo ${ks}
-}
-
-validate() {
-    img=$1
-
-    # 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 ${img} -m /dev/fedora/root /root/RESULT)
-    if [[ $? != 0 ]]; then
-        status=1
-        echo '*** /root/RESULT does not exist in VM image.'
-    elif [[ "${result}" != "SUCCESS" ]]; then
-        status=1
-        echo "${result}"
-    fi
-
-    return ${status}
-}
-
+. ${KSTESTDIR}/functions.sh
diff --git a/tests/kickstart_tests/escrow-cert.sh b/tests/kickstart_tests/escrow-cert.sh
index 8c4344e..1564a16 100755
--- a/tests/kickstart_tests/escrow-cert.sh
+++ b/tests/kickstart_tests/escrow-cert.sh
@@ -18,31 +18,4 @@
 #
 # Red Hat Author(s): David Shea <dshea at redhat.com>
 
-kernel_args() {
-    echo vnc
-}
-
-prepare() {
-    ks=$1
-    tmpdir=$2
-
-    echo ${ks}
-}
-
-validate() {
-    img=$1
-
-    # 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 ${img} -m /dev/fedora/root /root/RESULT)
-    if [[ $? != 0 ]]; then
-        status=1
-        echo '*** /root/RESULT does not exist in VM image.'
-    elif [[ "${result}" != "SUCCESS" ]]; then
-        status=1
-        echo "${result}"
-    fi
-
-    return ${status}
-}
+. ${KSTESTDIR}/functions.sh
diff --git a/tests/kickstart_tests/functions.sh b/tests/kickstart_tests/functions.sh
new file mode 100644
index 0000000..9ab4402
--- /dev/null
+++ b/tests/kickstart_tests/functions.sh
@@ -0,0 +1,56 @@
+#!/bin/bash
+#
+# Copyright (C) 2015  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>
+
+kernel_args() {
+    echo vnc
+}
+
+prepare() {
+    ks=$1
+    tmpdir=$2
+
+    echo ${ks}
+}
+
+prepare_disks() {
+    tmpdir=$1
+
+    qemu-img create -q -f qcow2 ${tmpdir}/disks/a.img 10G
+    echo ${tmpdir}/disks/a.img
+}
+
+validate() {
+    disksdir=$1
+    args=$(for d in ${disksdir}/*img; do echo -a ${d}; done)
+
+    # 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 ${args} -m /dev/fedora/root /root/RESULT)
+    if [[ $? != 0 ]]; then
+        status=1
+        echo '*** /root/RESULT does not exist in VM image.'
+    elif [[ "${result}" != "SUCCESS" ]]; then
+        status=1
+        echo "${result}"
+    fi
+
+    return ${status}
+}
diff --git a/tests/kickstart_tests/groups-and-envs-1.sh b/tests/kickstart_tests/groups-and-envs-1.sh
index d343712..8fb4c21 100755
--- a/tests/kickstart_tests/groups-and-envs-1.sh
+++ b/tests/kickstart_tests/groups-and-envs-1.sh
@@ -17,32 +17,4 @@
 #
 # Red Hat Author(s): Chris Lumens <clumens at redhat.com>
 
-kernel_args() {
-    echo vnc
-}
-
-prepare() {
-    ks=$1
-    tmpdir=$2
-
-    echo ${ks}
-}
-
-validate() {
-    img=$1
-
-    # 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 ${img} -m /dev/fedora/root sda2 /root/RESULT)
-    if [[ $? != 0 ]]; then
-        status=1
-        echo '*** /root/RESULT does not exist in VM image.'
-    elif [[ "${result}" != "SUCCESS" ]]; then
-        status=1
-        echo "${result}"
-    fi
-
-    return ${status}
-}
-
+. ${KSTESTDIR}/functions.sh
diff --git a/tests/kickstart_tests/groups-and-envs-2.sh b/tests/kickstart_tests/groups-and-envs-2.sh
index 02d06c1..7b2f4f0 100755
--- a/tests/kickstart_tests/groups-and-envs-2.sh
+++ b/tests/kickstart_tests/groups-and-envs-2.sh
@@ -17,32 +17,4 @@
 #
 # Red Hat Author(s): Chris Lumens <clumens at redhat.com>
 
-kernel_args() {
-    echo vnc
-}
-
-prepare() {
-    ks=$1
-    tmpdir=$2
-
-    echo ${ks}
-}
-
-validate() {
-    img=$1
-
-    # 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 ${img} -m /dev/fedora/root /root/RESULT)
-    if [[ $? != 0 ]]; then
-        status=1
-        echo '*** /root/RESULT does not exist in VM image.'
-    elif [[ "${result}" != "SUCCESS" ]]; then
-        status=1
-        echo "${result}"
-    fi
-
-    return ${status}
-}
-
+. ${KSTESTDIR}/functions.sh
diff --git a/tests/kickstart_tests/groups-and-envs-3.sh b/tests/kickstart_tests/groups-and-envs-3.sh
index 02d06c1..7b2f4f0 100755
--- a/tests/kickstart_tests/groups-and-envs-3.sh
+++ b/tests/kickstart_tests/groups-and-envs-3.sh
@@ -17,32 +17,4 @@
 #
 # Red Hat Author(s): Chris Lumens <clumens at redhat.com>
 
-kernel_args() {
-    echo vnc
-}
-
-prepare() {
-    ks=$1
-    tmpdir=$2
-
-    echo ${ks}
-}
-
-validate() {
-    img=$1
-
-    # 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 ${img} -m /dev/fedora/root /root/RESULT)
-    if [[ $? != 0 ]]; then
-        status=1
-        echo '*** /root/RESULT does not exist in VM image.'
-    elif [[ "${result}" != "SUCCESS" ]]; then
-        status=1
-        echo "${result}"
-    fi
-
-    return ${status}
-}
-
+. ${KSTESTDIR}/functions.sh
diff --git a/tests/kickstart_tests/hostname.sh b/tests/kickstart_tests/hostname.sh
index 02d06c1..7b2f4f0 100755
--- a/tests/kickstart_tests/hostname.sh
+++ b/tests/kickstart_tests/hostname.sh
@@ -17,32 +17,4 @@
 #
 # Red Hat Author(s): Chris Lumens <clumens at redhat.com>
 
-kernel_args() {
-    echo vnc
-}
-
-prepare() {
-    ks=$1
-    tmpdir=$2
-
-    echo ${ks}
-}
-
-validate() {
-    img=$1
-
-    # 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 ${img} -m /dev/fedora/root /root/RESULT)
-    if [[ $? != 0 ]]; then
-        status=1
-        echo '*** /root/RESULT does not exist in VM image.'
-    elif [[ "${result}" != "SUCCESS" ]]; then
-        status=1
-        echo "${result}"
-    fi
-
-    return ${status}
-}
-
+. ${KSTESTDIR}/functions.sh
diff --git a/tests/kickstart_tests/nfs-repo-and-addon.sh b/tests/kickstart_tests/nfs-repo-and-addon.sh
index 2804d87..a4c5c94 100755
--- a/tests/kickstart_tests/nfs-repo-and-addon.sh
+++ b/tests/kickstart_tests/nfs-repo-and-addon.sh
@@ -17,9 +17,7 @@
 #
 # Red Hat Author(s): David Shea <dshea at redhat.com>
 
-kernel_args() {
-    echo vnc
-}
+. ${KSTESTDIR}/functions.sh
 
 prepare() {
     ks=$1
@@ -51,19 +49,3 @@ prepare() {
         -e "/^repo/ s|HTTP-ADDON-REPO|${KSTEST_ADDON_HTTP_REPO}|" ${ks} > ${tmpdir}/kickstart.ks
     echo ${tmpdir}/kickstart.ks
 }
-
-validate() {
-    img=$1
-
-    # Check the /root/RESULT file for whether the test succeeded or not
-    result=$(virt-cat -a ${img} -m /dev/fedora/root /root/RESULT)
-    if [[ $? != 0 ]]; then
-        status=1
-        echo '*** /root/RESULT does not exist in VM image.'
-    elif [[ "${result}" != "SUCCESS" ]]; then
-        status=1
-        echo "${result}"
-    fi
-
-    return ${status}
-}
diff --git a/tests/kickstart_tests/packages-and-groups-1.sh b/tests/kickstart_tests/packages-and-groups-1.sh
index 02d06c1..7b2f4f0 100755
--- a/tests/kickstart_tests/packages-and-groups-1.sh
+++ b/tests/kickstart_tests/packages-and-groups-1.sh
@@ -17,32 +17,4 @@
 #
 # Red Hat Author(s): Chris Lumens <clumens at redhat.com>
 
-kernel_args() {
-    echo vnc
-}
-
-prepare() {
-    ks=$1
-    tmpdir=$2
-
-    echo ${ks}
-}
-
-validate() {
-    img=$1
-
-    # 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 ${img} -m /dev/fedora/root /root/RESULT)
-    if [[ $? != 0 ]]; then
-        status=1
-        echo '*** /root/RESULT does not exist in VM image.'
-    elif [[ "${result}" != "SUCCESS" ]]; then
-        status=1
-        echo "${result}"
-    fi
-
-    return ${status}
-}
-
+. ${KSTESTDIR}/functions.sh
diff --git a/tests/kickstart_tests/packages-default.sh b/tests/kickstart_tests/packages-default.sh
index 02d06c1..7b2f4f0 100755
--- a/tests/kickstart_tests/packages-default.sh
+++ b/tests/kickstart_tests/packages-default.sh
@@ -17,32 +17,4 @@
 #
 # Red Hat Author(s): Chris Lumens <clumens at redhat.com>
 
-kernel_args() {
-    echo vnc
-}
-
-prepare() {
-    ks=$1
-    tmpdir=$2
-
-    echo ${ks}
-}
-
-validate() {
-    img=$1
-
-    # 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 ${img} -m /dev/fedora/root /root/RESULT)
-    if [[ $? != 0 ]]; then
-        status=1
-        echo '*** /root/RESULT does not exist in VM image.'
-    elif [[ "${result}" != "SUCCESS" ]]; then
-        status=1
-        echo "${result}"
-    fi
-
-    return ${status}
-}
-
+. ${KSTESTDIR}/functions.sh
diff --git a/tests/kickstart_tests/packages-excludedocs.sh b/tests/kickstart_tests/packages-excludedocs.sh
index 02d06c1..7b2f4f0 100755
--- a/tests/kickstart_tests/packages-excludedocs.sh
+++ b/tests/kickstart_tests/packages-excludedocs.sh
@@ -17,32 +17,4 @@
 #
 # Red Hat Author(s): Chris Lumens <clumens at redhat.com>
 
-kernel_args() {
-    echo vnc
-}
-
-prepare() {
-    ks=$1
-    tmpdir=$2
-
-    echo ${ks}
-}
-
-validate() {
-    img=$1
-
-    # 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 ${img} -m /dev/fedora/root /root/RESULT)
-    if [[ $? != 0 ]]; then
-        status=1
-        echo '*** /root/RESULT does not exist in VM image.'
-    elif [[ "${result}" != "SUCCESS" ]]; then
-        status=1
-        echo "${result}"
-    fi
-
-    return ${status}
-}
-
+. ${KSTESTDIR}/functions.sh
diff --git a/tests/kickstart_tests/packages-multilib.sh b/tests/kickstart_tests/packages-multilib.sh
index 02d06c1..7b2f4f0 100755
--- a/tests/kickstart_tests/packages-multilib.sh
+++ b/tests/kickstart_tests/packages-multilib.sh
@@ -17,32 +17,4 @@
 #
 # Red Hat Author(s): Chris Lumens <clumens at redhat.com>
 
-kernel_args() {
-    echo vnc
-}
-
-prepare() {
-    ks=$1
-    tmpdir=$2
-
-    echo ${ks}
-}
-
-validate() {
-    img=$1
-
-    # 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 ${img} -m /dev/fedora/root /root/RESULT)
-    if [[ $? != 0 ]]; then
-        status=1
-        echo '*** /root/RESULT does not exist in VM image.'
-    elif [[ "${result}" != "SUCCESS" ]]; then
-        status=1
-        echo "${result}"
-    fi
-
-    return ${status}
-}
-
+. ${KSTESTDIR}/functions.sh
diff --git a/tests/kickstart_tests/proxy-cmdline.sh b/tests/kickstart_tests/proxy-cmdline.sh
index 9c2dc49..05f67f8 100755
--- a/tests/kickstart_tests/proxy-cmdline.sh
+++ b/tests/kickstart_tests/proxy-cmdline.sh
@@ -17,31 +17,8 @@
 #
 # Red Hat Author(s): David Shea <dshea at redhat.com>
 
+. ${KSTESTDIR}/functions.sh
+
 kernel_args() {
     echo vnc inst.proxy=http://127.0.0.1:8080
 }
-
-prepare() {
-    ks=$1
-    tmpdir=$2
-
-    echo ${ks}
-}
-
-validate() {
-    img=$1
-
-    # 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 ${img} -m /dev/fedora/root /root/RESULT)
-    if [[ $? != 0 ]]; then
-        status=1
-        echo '*** /root/RESULT does not exist in VM image.'
-    elif [[ "${result}" != "SUCCESS" ]]; then
-        status=1
-        echo "${result}"
-    fi
-
-    return ${status}
-}
diff --git a/tests/kickstart_tests/proxy-kickstart.sh b/tests/kickstart_tests/proxy-kickstart.sh
index 92c4437..df0f76b 100755
--- a/tests/kickstart_tests/proxy-kickstart.sh
+++ b/tests/kickstart_tests/proxy-kickstart.sh
@@ -17,9 +17,7 @@
 #
 # Red Hat Author(s): David Shea <dshea at redhat.com>
 
-kernel_args() {
-    echo vnc
-}
+. ${KSTESTDIR}/functions.sh
 
 prepare() {
     ks=$1
@@ -33,21 +31,3 @@ prepare() {
     sed -e "/^repo/ s|HTTP-ADDON-REPO|${KSTEST_ADDON_HTTP_REPO}|" ${ks} > ${tmpdir}/kickstart.ks
     echo ${tmpdir}/kickstart.ks
 }
-
-validate() {
-    img=$1
-
-    # 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 ${img} -m /dev/fedora/root /root/RESULT)
-    if [[ $? != 0 ]]; then
-        status=1
-        echo '*** /root/RESULT does not exist in VM image.'
-    elif [[ "${result}" != "SUCCESS" ]]; then
-        status=1
-        echo "${result}"
-    fi
-
-    return ${status}
-}
diff --git a/tests/kickstart_tests/run_one_ks.sh b/tests/kickstart_tests/run_one_ks.sh
index 168edf9..b535d99 100755
--- a/tests/kickstart_tests/run_one_ks.sh
+++ b/tests/kickstart_tests/run_one_ks.sh
@@ -51,6 +51,8 @@ cleanup() {
 runone() {
     t=$1
 
+    export KSTESTDIR=$(pwd)/kickstart_tests
+
     ks=${t/.sh/.ks}
     . $t
 
diff --git a/tests/kickstart_tests/tmpfs-fixed_size.sh b/tests/kickstart_tests/tmpfs-fixed_size.sh
index e3ed01a..8fb4c21 100755
--- a/tests/kickstart_tests/tmpfs-fixed_size.sh
+++ b/tests/kickstart_tests/tmpfs-fixed_size.sh
@@ -17,32 +17,4 @@
 #
 # Red Hat Author(s): Chris Lumens <clumens at redhat.com>
 
-kernel_args() {
-    echo vnc
-}
-
-prepare() {
-    ks=$1
-    tmpdir=$2
-
-    echo ${ks}
-}
-
-validate() {
-    img=$1
-
-    # 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 ${img} -m /dev/sda2 /root/RESULT)
-    if [[ $? != 0 ]]; then
-        status=1
-        echo '*** /root/RESULT does not exist in VM image.'
-    elif [[ "${result}" != "SUCCESS" ]]; then
-        status=1
-        echo "${result}"
-    fi
-
-    return ${status}
-}
-
+. ${KSTESTDIR}/functions.sh
-- 
2.2.2



More information about the anaconda-patches mailing list