tests: Rename capitests -> tests/c-api.
[libguestfs.git] / tests / luks / test-luks-list.sh
1 #!/bin/bash -
2 # libguestfs
3 # Copyright (C) 2011 Red Hat Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19 # Test LUKS devices appear in the output of list-dm-devices.
20
21 set -e
22
23 [ -n "$SKIP_TEST_LUKS_SH" ] && {
24     echo "test-luks-list.sh skipped (environment variable set)"
25     exit 0
26 }
27
28 rm -f test1.img test.output
29
30 ../../fish/guestfish --keys-from-stdin > test.output <<'EOF'
31 sparse test1.img 1G
32 run
33 part-init /dev/sda mbr
34 part-add /dev/sda p 64 1048575
35 part-add /dev/sda p 1048576 -64
36
37 # Create LUKS device with key "key0" in slot 0.
38 luks-format /dev/sda1 0
39 key0
40
41 # Create some unrelated LVs.
42 pvcreate /dev/sda2
43 vgcreate VG /dev/sda2
44 lvcreate LV1 /dev/VG 100
45 lvcreate LV2 /dev/VG 200
46 lvcreate LV3 /dev/VG 100
47
48 # Open the device as 'lukstest'.
49 luks-open /dev/sda1 lukstest
50 key0
51
52 # List devices, '/dev/mapper/lukstest' should appear.
53 echo test 1
54 list-dm-devices
55
56 # Close the device.
57 luks-close /dev/mapper/lukstest
58
59 # List devices, '/dev/mapper/lukstest' should not appear.
60 echo test 2
61 list-dm-devices
62
63 # Open the device again.
64 luks-open /dev/sda1 lukstest
65 key0
66
67 # Check no LVs appear in list-dm-devices output.
68 echo test 3
69 list-dm-devices
70
71 # Check LUKS device doesn't appear in any of the other lists.
72 echo test 4
73 list-devices | sed 's,^/dev/[hv]d,/dev/sd,'
74 echo test 5
75 list-partitions | sed 's,^/dev/[hv]d,/dev/sd,'
76 echo test 6
77 lvs
78 echo test 7
79 vgs
80 echo test 8
81 pvs | sed 's,^/dev/[hv]d,/dev/sd,'
82
83 EOF
84
85 # Expected vs actual output.
86 if [ "$(cat test.output)" != "\
87 test 1
88 /dev/mapper/lukstest
89 test 2
90 test 3
91 /dev/mapper/lukstest
92 test 4
93 /dev/sda
94 test 5
95 /dev/sda1
96 /dev/sda2
97 test 6
98 /dev/VG/LV1
99 /dev/VG/LV2
100 /dev/VG/LV3
101 test 7
102 VG
103 test 8
104 /dev/sda2" ]; then
105     echo "test-luks-list.sh: Unexpected output from test:"
106     cat test.output
107     echo "[end of output]"
108     exit 1
109 fi
110
111 rm -f test1.img test.output