1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
#!/bin/bash -
# libguestfs virt-builder test script
# Copyright (C) 2013 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
abs_builddir=$(pwd)
export XDG_CONFIG_HOME=
export XDG_CONFIG_DIRS="$abs_builddir/test-config"
if [ -n "$SKIP_TEST_VIRT_BUILDER_SH" ]; then
echo "$0: skipping test because environment variable is set."
exit 77
fi
if [ ! -f fedora.xz ]; then
echo "$0: test skipped because there is no fedora.xz in the build directory"
exit 77
fi
output=phony-fedora.img
format=qcow2
if [ "$(guestfish get-backend)" = "uml" ]; then
format=raw
# XXX We specifically want virt-builder to work with the UML
# backend. However currently it fails with:
# error: uml backend does not support networking
# We should be able to make uml have a network backend, but in
# the meantime add this:
no_network=--no-network
fi
rm -f $output
# Test as many options as we can!
#
# Note we cannot test --install, --run since the phony Fedora doesn't
# have a real OS inside just some configuration files. Just about
# every other option is fair game.
$VG virt-builder phony-fedora \
-v --no-cache --no-check-signature $no_network \
-o $output --size 2G --format $format \
--arch x86_64 \
--hostname test.example.com \
--timezone Europe/London \
--root-password password:123456 \
--mkdir /etc/foo/bar/baz \
--write '/etc/foo/bar/baz/foo:Hello World' \
--upload Makefile:/Makefile \
--edit '/Makefile: s{^#.*}{}' \
--upload Makefile:/etc/foo/bar/baz \
--delete /Makefile \
--link /etc/foo/bar/baz/foo:/foo \
--link /etc/foo/bar/baz/foo:/foo1:/foo2:/foo3 \
--firstboot Makefile --firstboot-command 'echo "hello"' \
--firstboot-install "minicom,inkscape"
# Check that some modifications were made.
$VG guestfish --ro -i -a $output > test.out <<EOF
# Uploaded files
is-file /etc/foo/bar/baz/Makefile
cat /etc/foo/bar/baz/foo
is-symlink /foo
is-symlink /foo1
is-symlink /foo2
is-symlink /foo3
echo -----
# Hostname
cat /etc/sysconfig/network | grep HOSTNAME=
echo -----
# Timezone
is-file /usr/share/zoneinfo/Europe/London
is-symlink /etc/localtime
readlink /etc/localtime
echo -----
# Password
is-file /etc/shadow
cat /etc/shadow | sed -r '/^root:/!d;s,^(root:\\\$6\\\$).*,\\1,g'
EOF
if [ "$(cat test.out)" != "true
Hello World
true
true
true
true
-----
HOSTNAME=test.example.com
-----
true
true
/usr/share/zoneinfo/Europe/London
-----
true
root:\$6\$" ]; then
echo "$0: unexpected output:"
cat test.out
exit 1
fi
rm $output
rm test.out
|