summaryrefslogtreecommitdiffstats
path: root/sysprep
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-04-01 20:02:25 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-04-01 20:02:25 +0100
commit95123a9144edc1ddb3ad67d75276ca3af70eddb8 (patch)
tree92a60ee0b46cd082c43b79dd73cd3463cd3de80e /sysprep
parent6282d92b1bc4fe57a92f939258d7ccee815fa6ab (diff)
downloadlibguestfs-95123a9144edc1ddb3ad67d75276ca3af70eddb8.tar.gz
libguestfs-95123a9144edc1ddb3ad67d75276ca3af70eddb8.tar.xz
libguestfs-95123a9144edc1ddb3ad67d75276ca3af70eddb8.zip
sysprep: Add a test of the --script option.
Diffstat (limited to 'sysprep')
-rw-r--r--sysprep/Makefile.am7
-rwxr-xr-xsysprep/script1.sh21
-rwxr-xr-xsysprep/script2.sh23
-rwxr-xr-xsysprep/script3.sh21
-rwxr-xr-xsysprep/test-virt-sysprep-script.sh45
5 files changed, 116 insertions, 1 deletions
diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am
index d534629e..8730bc0c 100644
--- a/sysprep/Makefile.am
+++ b/sysprep/Makefile.am
@@ -20,6 +20,7 @@ include $(top_srcdir)/subdir-rules.mk
EXTRA_DIST = \
$(SOURCES) \
test-virt-sysprep.sh \
+ test-virt-sysprep-script.sh script1.sh script2.sh script3.sh \
virt-sysprep.pod
CLEANFILES = \
@@ -124,10 +125,14 @@ random_val := $(shell awk 'BEGIN{srand(); print 1+int(255*rand())}' < /dev/null)
TESTS_ENVIRONMENT = \
MALLOC_PERTURB_=$(random_val) \
+ abs_builddir=$(abs_builddir) \
+ abs_srcdir=$(abs_srcdir) \
$(top_builddir)/run
if ENABLE_APPLIANCE
-TESTS = test-virt-sysprep.sh
+TESTS = \
+ test-virt-sysprep.sh \
+ test-virt-sysprep-script.sh
endif ENABLE_APPLIANCE
# Dependencies.
diff --git a/sysprep/script1.sh b/sysprep/script1.sh
new file mode 100755
index 00000000..6ba274cc
--- /dev/null
+++ b/sysprep/script1.sh
@@ -0,0 +1,21 @@
+#!/bin/bash -
+# libguestfs virt-sysprep test --script option
+# Copyright (C) 2012 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty 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.
+
+# This is used by test-virt-sysprep-script.sh.
+
+pwd > $abs_builddir/stamp-script1.sh
diff --git a/sysprep/script2.sh b/sysprep/script2.sh
new file mode 100755
index 00000000..a8ca21fe
--- /dev/null
+++ b/sysprep/script2.sh
@@ -0,0 +1,23 @@
+#!/bin/bash -
+# libguestfs virt-sysprep test --script option
+# Copyright (C) 2012 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty 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.
+
+# This is used by test-virt-sysprep-script.sh.
+
+rm -f etc/resolv.conf
+
+pwd > $abs_builddir/stamp-script2.sh
diff --git a/sysprep/script3.sh b/sysprep/script3.sh
new file mode 100755
index 00000000..b4e7fcac
--- /dev/null
+++ b/sysprep/script3.sh
@@ -0,0 +1,21 @@
+#!/bin/bash -
+# libguestfs virt-sysprep test --script option
+# Copyright (C) 2012 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty 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.
+
+# This is used by test-virt-sysprep-script.sh.
+
+exit 1
diff --git a/sysprep/test-virt-sysprep-script.sh b/sysprep/test-virt-sysprep-script.sh
new file mode 100755
index 00000000..7d34a991
--- /dev/null
+++ b/sysprep/test-virt-sysprep-script.sh
@@ -0,0 +1,45 @@
+#!/bin/bash -
+# libguestfs virt-sysprep test --script option
+# Copyright (C) 2011-2012 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty 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.
+
+export LANG=C
+set -e
+#set -x
+
+if [ ! -w /dev/fuse ]; then
+ echo "$0: SKIPPING test, because there is no /dev/fuse."
+ exit 0
+fi
+
+# Check that multiple scripts can run.
+rm -f stamp-script1.sh stamp-script2.sh
+if ! ./virt-sysprep -n -a ../tests/guests/fedora.img --enable script \
+ --script $abs_srcdir/script1.sh --script $abs_srcdir/script2.sh; then
+ echo "$0: virt-sysprep wasn't expected to exit with error."
+ exit 1
+fi
+if [ ! -f stamp-script1.sh -o ! -f stamp-script2.sh ]; then
+ echo "$0: one of the two test scripts did not run."
+ exit 1
+fi
+
+# Check that if a script fails, virt-sysprep exits with an error.
+if ./virt-sysprep -n -a ../tests/guests/fedora.img --enable script \
+ --script $abs_srcdir/script3.sh; then
+ echo "$0: virt-sysprep didn't exit with an error."
+ exit 1
+fi