File: test-block-driver.sh

package info (click to toggle)
virt-v2v 2.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,256 kB
  • sloc: ml: 19,861; sh: 8,454; ansic: 6,880; makefile: 2,797; python: 1,114; perl: 854; xml: 117
file content (143 lines) | stat: -rwxr-xr-x 4,276 bytes parent folder | download | duplicates (5)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash -
# libguestfs virt-v2v test script
# Copyright (C) 2023 Virtuozzo International GmbH
#
# 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.

# Test --block-driver option.

set -e

source ./functions.sh
set -e
set -x

skip_if_skipped
img_base="$abs_top_builddir/test-data/phony-guests/windows.img"
requires test -s $img_base

export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools"
export VIRTIO_WIN="$srcdir/../test-data/fake-virtio-win/drivers"

d=$PWD/test-block-driver.d
rm -rf $d
cleanup_fn rm -rf $d
mkdir $d

viostor_img="$d/viostor.qcow2"
vioscsi_img="$d/vioscsi.qcow2"
qemu-img create -f qcow2 -b $img_base -o compat=1.1,backing_fmt=raw $viostor_img
qemu-img create -f qcow2 -b $img_base -o compat=1.1,backing_fmt=raw $vioscsi_img
base_md5="$(do_md5 $img_base)"

viostor_xml="$d/windows-viostor.xml"
viostor_name=windows-viostor
cat > $viostor_xml <<EOF
<node>
  <domain type='test'>
    <name>$viostor_name</name>
    <memory>1048576</memory>
    <os>
      <type>hvm</type>
      <boot dev='hd'/>
    </os>
    <devices>
      <disk type='file' device='disk'>
        <driver name='qemu' type='qcow2'/>
        <source file='$viostor_img'/>
        <target dev='vda' bus='virtio'/>
      </disk>
    </devices>
  </domain>
</node>
EOF

vioscsi_xml="$d/windows-vioscsi.xml"
vioscsi_name=windows-vioscsi
cat > $vioscsi_xml <<EOF
<node>
  <domain type='test'>
    <name>$vioscsi_name</name>
    <memory>1048576</memory>
    <os>
      <type>hvm</type>
      <boot dev='hd'/>
    </os>
    <devices>
      <disk type='file' device='disk'>
        <driver name='qemu' type='qcow2'/>
        <source file='$vioscsi_img'/>
        <target dev='sda' bus='scsi'/>
      </disk>
      <controller type='scsi' index='0' model='virtio-scsi'>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
      </controller>
    </devices>
  </domain>
</node>
EOF

response="$d/response"
expected="$d/expected"

echo -e "true\ntrue\ntrue\ntrue" >$expected

check_driver_presence ()
{
    local img="$1" drv="$2"

    local virtio_dir="/Windows/Drivers/VirtIO"

    guestfish --ro -a "$img" -i >$response <<-EOM
        is-dir $virtio_dir
        is-file $virtio_dir/$drv.cat
        is-file $virtio_dir/$drv.inf
        is-file $virtio_dir/$drv.sys
EOM

    diff -u $expected $response
}

# Test that --block-driver option doesn't break basic "-i disk" conversion
$VG virt-v2v --debug-gc --block-driver virtio-scsi \
    -i disk $img_base -o local -os $d

# Check that libvirt XML metadata and a disk was created.
test -f $d/windows.xml
test -f $d/windows-sda

# Test in-place conversion with --block-driver specified
#
# Note that v2v actually copies all the drivers present in $VIRTIO_WIN, no
# matter which block driver we specify.  The real difference comes from the
# PCI ID values written into the registry.  Since we can't really test those
# values, we're doing the best we can here, i.e. testing that conversion
# doesn't break and drivers are still present with --block-driver option
# being set explicitly.

# Check that in-place conversion works with --block-driver virtio-blk
$VG virt-v2v-in-place --debug-gc --block-driver virtio-blk \
    -i libvirt -ic "test://$viostor_xml" $viostor_name

check_driver_presence $viostor_img "viostor"

# Check that in-place conversion works with --block-driver virtio-scsi
$VG virt-v2v-in-place --debug-gc --block-driver virtio-scsi \
    -i libvirt -ic "test://$vioscsi_xml" $vioscsi_name

check_driver_presence $vioscsi_img "vioscsi"

# Finally check that the base image remained untouched
test "$base_md5" = "$(do_md5 $img_base)"