PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/libguestfs-1.19.22/tests/md/test-inspect-fstab.sh

#
Shell | 139 lines | 83 code | 26 blank | 30 comment | 6 complexity | 9bc923a470026e8dd23e68928d68d20d MD5 | raw file
Possible License(s): LGPL-2.0, GPL-3.0, GPL-2.0
  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. # Test various aspects of core inspection of /etc/fstab.
  19. # This also tests: https://bugzilla.redhat.com/668574
  20. set -e
  21. export LANG=C
  22. guestfish=../../fish/guestfish
  23. canonical="sed s,/dev/vd,/dev/sd,g"
  24. rm -f test1.qcow2 test.fstab test.output
  25. # Start with the regular (good) fedora image, modify /etc/fstab
  26. # and then inspect it.
  27. qemu-img create -F raw -b ../guests/fedora.img -f qcow2 test1.qcow2
  28. cat <<'EOF' > test.fstab
  29. /dev/VG/Root / ext2 default 0 0
  30. # Xen-style partition names.
  31. /dev/xvda1 /boot ext2 default 0 0
  32. # Non-existent device.
  33. /dev/sdb3 /var ext2 default 0 0
  34. # Non-existent mountpoint.
  35. /dev/VG/LV1 /nosuchfile ext2 default 0 0
  36. # /dev/disk/by-id path (RHBZ#627675).
  37. /dev/disk/by-id/ata-QEMU_HARDDISK_QM00001 /id ext2 default 0 0
  38. /dev/disk/by-id/ata-QEMU_HARDDISK_QM00001-part1 /id1 ext2 default 0 0
  39. /dev/disk/by-id/ata-QEMU_HARDDISK_QM00001-part3 /id3 ext2 default 0 0
  40. EOF
  41. $guestfish -a test1.qcow2 <<'EOF'
  42. run
  43. mount-options "" /dev/VG/Root /
  44. upload test.fstab /etc/fstab
  45. EOF
  46. # This will give a warning, but should not fail.
  47. $guestfish -a test1.qcow2 -i <<'EOF' | sort | $canonical > test.output
  48. inspect-get-mountpoints /dev/VG/Root
  49. EOF
  50. if [ "$(cat test.output)" != "/: /dev/VG/Root
  51. /boot: /dev/sda1
  52. /id1: /dev/sda1
  53. /id3: /dev/disk/by-id/ata-QEMU_HARDDISK_QM00001-part3
  54. /id: /dev/disk/by-id/ata-QEMU_HARDDISK_QM00001
  55. /nosuchfile: /dev/VG/LV1
  56. /var: /dev/sdb3" ]; then
  57. echo "$0: error #1: unexpected output from inspect-get-mountpoints command"
  58. cat test.output
  59. exit 1
  60. fi
  61. # Test device name hints
  62. cat <<'EOF' > test.fstab
  63. /dev/VG/Root / ext2 default 0 0
  64. # Device name which requires a hint
  65. /dev/xvdg1 /boot ext2 default 0 0
  66. EOF
  67. $guestfish -a test1.qcow2 <<'EOF'
  68. run
  69. mount-options "" /dev/VG/Root /
  70. upload test.fstab /etc/fstab
  71. EOF
  72. $guestfish <<'EOF' | $canonical > test.output
  73. add test1.qcow2 readonly:true name:xvdg
  74. run
  75. inspect-os
  76. inspect-get-mountpoints /dev/VG/Root
  77. EOF
  78. if [ "$(cat test.output)" != "/dev/VG/Root
  79. /: /dev/VG/Root
  80. /boot: /dev/sda1" ]; then
  81. echo "$0: error #2: unexpected output from inspect-get-mountpoints command"
  82. cat test.output
  83. exit 1
  84. fi
  85. cat <<'EOF' > test.fstab
  86. /dev/VG/Root / ext2 default 0 0
  87. # cciss device which requires a hint
  88. /dev/cciss/c1d3p1 /boot ext2 default 0 0
  89. # cciss device, whole disk
  90. /dev/cciss/c1d3 /var ext2 default 0 0
  91. EOF
  92. $guestfish -a test1.qcow2 <<'EOF'
  93. run
  94. mount-options "" /dev/VG/Root /
  95. upload test.fstab /etc/fstab
  96. EOF
  97. $guestfish <<'EOF' | $canonical > test.output
  98. add test1.qcow2 readonly:true name:cciss/c1d3
  99. run
  100. inspect-os
  101. inspect-get-mountpoints /dev/VG/Root
  102. EOF
  103. if [ "$(cat test.output)" != "/dev/VG/Root
  104. /: /dev/VG/Root
  105. /boot: /dev/sda1
  106. /var: /dev/sda" ]; then
  107. echo "$0: error #3: unexpected output from inspect-get-mountpoints command"
  108. cat test.output
  109. exit 1
  110. fi
  111. rm test.fstab
  112. rm test1.qcow2
  113. rm test.output