Debian Codegraph @

test/install-export-import

raw
1 #!/bin/bash
2
3 set -eu
4
5 if [ $(id -u) != 0 ]; then
6 echo "Testing requires root due to losetup/kpartx usage" 2>&1
7 exit 77
8 fi
9
10 TEMPDIR=$(mktemp -d)
11 trap 'rm -rf "$TEMPDIR"' EXIT
12
13 DISK0="$TEMPDIR/disk0"
14 dd if=/dev/zero of="$DISK0" bs=1024k count=512
15
16 DUMP="$TEMPDIR/dump"
17
18 # check that we can actually run losetup, otherwise we might be under
19 # fakeroot, for example; include sbin* dirs in PATH to ensure we don't
20 # fail due to command not found.
21 PATH=$PATH:/sbin:/usr/sbin
22 LOOP=$(losetup --show -f "$DISK0") || \
23 { echo "losetup doesn't work, skipping test" 2>&1 ;
24 exit 77;
25 }
26 losetup -d "$LOOP"
27
28 echo "Installing instance..."
29 GENERATE_CACHE=no \
30 CLEAN_CACHE="" \
31 OS_API_VERSION=10 \
32 INSTANCE_NAME=foo.example.com \
33 HYPERVISOR=dont-care \
34 DISK_COUNT=1 \
35 DISK_0_PATH="$DISK0" \
36 $srcdir/create
37
38 echo "Exporting instance..."
39
40 OS_API_VERSION=10 \
41 INSTANCE_NAME=foo.example.com \
42 HYPERVISOR=dont-care \
43 DISK_COUNT=1 \
44 DISK_0_PATH="$DISK0" \
45 EXPORT_DISK_PATH="$DISK0" \
46 EXPORT_DEVICE="$DISK0" \
47 EXPORT_INDEX=0 \
48 $srcdir/export > "$DUMP"
49
50 echo "Importing instance..."
51
52 # first wipe the disk.
53 dd if=/dev/zero of="$DISK0" bs=1024k count=512
54
55 OS_API_VERSION=10 \
56 INSTANCE_NAME=foo.example.com \
57 HYPERVISOR=dont-care \
58 DISK_COUNT=1 \
59 DISK_0_PATH="$DISK0" \
60 IMPORT_DISK_PATH="$DISK0" \
61 IMPORT_DEVICE="$DISK0" \
62 IMPORT_INDEX=0 \
63 $srcdir/import < "$DUMP"
64
65 # Do a listing of the directory (to see the size of the dump, a proxy
66 # for the needed install space).
67 ls -l -h "$TEMPDIR"