26ea10f9fe34e1e429d764f80b70dfb40be63469
[libguestfs.git] / regressions / test-inspect-fstab.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., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 # Test various aspects of core inspection of /etc/fstab.
20 # This also tests: https://bugzilla.redhat.com/668574
21
22 set -e
23 export LANG=C
24
25 guestfish=../fish/guestfish
26
27 rm -f test1.img test.fstab test.output
28
29 # Start with the regular (good) fedora image, modify /etc/fstab
30 # and then inspect it.
31 cp ../images/fedora.img test1.img
32
33 cat <<'EOF' > test.fstab
34 /dev/VG/Root / ext2 default 0 0
35
36 # Xen-style partition names.
37 /dev/xvda1 /boot ext2 default 0 0
38
39 # Non-existant device.
40 /dev/sdb3 /var ext2 default 0 0
41
42 # Non-existant mountpoint.
43 /dev/VG/LV1 /nosuchfile ext2 default 0 0
44 EOF
45
46 $guestfish -a test1.img <<'EOF'
47   run
48   mount-options "" /dev/VG/Root /
49   upload test.fstab /etc/fstab
50 EOF
51
52 # This will give a warning, but should not fail.
53 $guestfish -a test1.img -i <<'EOF' | sort > test.output
54   inspect-get-mountpoints /dev/VG/Root
55 EOF
56
57 if [ "$(cat test.output)" != "/: /dev/VG/Root
58 /boot: /dev/vda1
59 /nosuchfile: /dev/VG/LV1
60 /var: /dev/sdb3" ]; then
61     echo "$0: error: unexpected output from inspect-get-mountpoints command"
62     cat test.output
63     exit 1
64 fi
65
66 # Test device name hints
67
68 cat <<'EOF' > test.fstab
69 /dev/VG/Root / ext2 default 0 0
70
71 # Device name which requires a hint
72 /dev/xvdg1 /boot ext2 default 0 0
73 EOF
74
75 $guestfish -a test1.img <<'EOF'
76   run
77   mount-options "" /dev/VG/Root /
78   upload test.fstab /etc/fstab
79 EOF
80
81 $guestfish <<'EOF' > test.output
82   add-drive-opts test1.img readonly:true name:xvdg
83   run
84   inspect-os
85   inspect-get-mountpoints /dev/VG/Root
86 EOF
87
88 if [ "$(cat test.output)" != "/dev/VG/Root
89 /: /dev/VG/Root
90 /boot: /dev/vda1" ]; then
91     echo "$0: error: unexpected output from inspect-get-mountpoints command"
92     cat test.output
93     exit 1
94 fi
95
96 cat <<'EOF' > test.fstab
97 /dev/VG/Root / ext2 default 0 0
98
99 # cciss device which requires a hint
100 /dev/cciss/c1d3p1 /boot ext2 default 0 0
101
102 # cciss device, whole disk
103 /dev/cciss/c1d3 /var ext2 default 0 0
104 EOF
105
106 $guestfish -a test1.img <<'EOF'
107   run
108   mount-options "" /dev/VG/Root /
109   upload test.fstab /etc/fstab
110 EOF
111
112 $guestfish <<'EOF' > test.output
113   add-drive-opts test1.img readonly:true name:cciss/c1d3
114   run
115   inspect-os
116   inspect-get-mountpoints /dev/VG/Root
117 EOF
118
119 if [ "$(cat test.output)" != "/dev/VG/Root
120 /: /dev/VG/Root
121 /boot: /dev/vda1
122 /var: /dev/vda" ]; then
123     echo "$0: error: unexpected output from inspect-get-mountpoints command"
124     cat test.output
125     exit 1
126 fi
127
128 rm test.fstab
129 rm test1.img
130 rm test.output