File: test-virt-builder-repository.sh

package info (click to toggle)
guestfs-tools 1.52.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 69,236 kB
  • sloc: ansic: 15,698; ml: 15,621; sh: 7,396; xml: 5,478; makefile: 3,601; perl: 1,535; lex: 135; yacc: 128; python: 80
file content (100 lines) | stat: -rwxr-xr-x 2,640 bytes parent folder | download | duplicates (4)
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
#!/bin/bash -
# libguestfs
# Copyright (C) 2017 SUSE 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.

set -e

$TEST_FUNCTIONS
slow_test
skip_if_skipped "$script"

test_data=repository-testdata
rm -rf $test_data
mkdir $test_data

# Make a copy of the Fedora image
cp ../test-data/phony-guests/fedora.img $test_data

# Create minimal index file
cat > $test_data/index << EOF
[fedora]
file=fedora.img
EOF

# Run virt-builder-repository (no compression, interactive)
echo 'x86_64
Fedora Test Image
fedora14
/dev/sda1
/dev/VG/Root
' | virt-builder-repository -v -x --no-compression -i $test_data

assert_config () {
    item=$1
    regex=$2

    sed -n -e "/\[$item]/,/^$/p" $test_data/index | grep "$regex"
}

# Check the generated index file
assert_config 'fedora' 'revision=1'
assert_config 'fedora' 'arch=x86_64'
assert_config 'fedora' 'name=Fedora Test Image'
assert_config 'fedora' 'osinfo=fedora14'
assert_config 'fedora' 'checksum'
assert_config 'fedora' 'format=raw'
assert_config 'fedora' '^size='
assert_config 'fedora' 'compressed_size='
assert_config 'fedora' 'expand=/dev/'


# Copy the debian image and add the minimal piece to index
cp ../test-data/phony-guests/debian.img $test_data

cat >> $test_data/index << EOF

[debian]
file=debian.img
EOF

# Run virt-builder-repository again
echo 'x86_64
Debian Test Image
debian9

' | virt-builder-repository --no-compression -i $test_data

# Check that the new image is complete and the first one hasn't changed
assert_config 'fedora' 'revision=1'

assert_config 'debian' 'revision=1'
assert_config 'debian' 'checksum'

# Modify the fedora image
export EDITOR='echo newline >>'
virt-edit -a $test_data/fedora.img /etc/test3

# Rerun the tool (with compression)
virt-builder-repository -i $test_data

# Check that the revision, file and size have been updated
assert_config 'fedora' 'revision=2'
assert_config 'fedora' 'file=fedora.img.xz'
test -e $test_data/fedora.img.xz
! test -e $test_data/fedora.img

rm -rf $test_data