The current add_cdrom way basically appends a new raw "-cdrom /path"
parameter to the qemu invocation (even when using libvirt as backend),
hence such images are seen as "CD-ROM drives" inside the appliance.
However, there is no need for such particular behaviour, as they need to
be handled as normal (read-only) drives.
Adding CD-ROM disk images as drives also changes the device names used
for them inside the appliance from /dev/srN to the usual e.g. /dev/sdX.
These changes fix different issues:
- it is possible to start guestfish without adding disks with -a, then
just add-cdrom and run
- list-devices does not cause guestfishd to crash when sorting the list
of devices (exposed by the test case in RHBZ#563450)
- the result of list-devices now reflects the order images were added
(RHBZ#563450)
Add two small regression tests for the fixes described above.
---
src/drives.c | 7 +-----
tests/regressions/Makefile.am | 2 ++
tests/regressions/rhbz563450.sh | 54 ++++++++++++++++++++++++++++++++++++++++
tests/regressions/rhbz563450b.sh | 43 ++++++++++++++++++++++++++++++++
4 files changed, 100 insertions(+), 6 deletions(-)
create mode 100755 tests/regressions/rhbz563450.sh
create mode 100755 tests/regressions/rhbz563450b.sh
diff --git a/src/drives.c b/src/drives.c
index 16798a3..4b65dda 100644
--- a/src/drives.c
+++ b/src/drives.c
@@ -1087,12 +1087,7 @@ guestfs__add_cdrom (guestfs_h *g, const char *filename)
return -1;
}
- if (access (filename, F_OK) == -1) {
- perrorf (g, "%s", filename);
- return -1;
- }
-
- return guestfs_config (g, "-cdrom", filename);
+ return guestfs__add_drive_ro (g, filename);
}
/* Depending on whether we are hotplugging or not, this function
diff --git a/tests/regressions/Makefile.am b/tests/regressions/Makefile.am
index 5b0d1c3..741f45f 100644
--- a/tests/regressions/Makefile.am
+++ b/tests/regressions/Makefile.am
@@ -21,6 +21,8 @@ TESTS = \
rhbz501893 \
rhbz503169c13.sh \
rhbz557655.sh \
+ rhbz563450.sh \
+ rhbz563450b.sh \
rhbz576879.sh \
rhbz578407.sh \
rhbz580246.sh \
diff --git a/tests/regressions/rhbz563450.sh b/tests/regressions/rhbz563450.sh
new file mode 100755
index 0000000..6fa6f2b
--- /dev/null
+++ b/tests/regressions/rhbz563450.sh
@@ -0,0 +1,54 @@
+#!/bin/bash -
+# libguestfs
+# Copyright (C) 2013 Red Hat Inc.
+#
+# 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.
+
+#
https://bugzilla.redhat.com/show_bug.cgi?id=563450
+# Test the order of added images
+
+set -e
+export LANG=C
+
+rm -f test.out
+
+../../fish/guestfish --ro > test.out <<EOF
+add-drive-ro ../guests/fedora.img
+add-cdrom ../data/test.iso
+add-drive-ro ../guests/debian.img
+
+run
+
+list-devices
+echo ----
+list-partitions
+
+ping-daemon
+EOF
+
+if [ "$(cat test.out)" != "/dev/sda
+/dev/sdb
+/dev/sdc
+----
+/dev/sda1
+/dev/sda2
+/dev/sdc1
+/dev/sdc2" ]; then
+ echo "$0: unexpected output:"
+ cat test.out
+ exit 1
+fi
+
+rm -f test.out
diff --git a/tests/regressions/rhbz563450b.sh b/tests/regressions/rhbz563450b.sh
new file mode 100755
index 0000000..bae641a
--- /dev/null
+++ b/tests/regressions/rhbz563450b.sh
@@ -0,0 +1,43 @@
+#!/bin/bash -
+# libguestfs
+# Copyright (C) 2013 Red Hat Inc.
+#
+# 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.
+
+#
https://bugzilla.redhat.com/show_bug.cgi?id=563450
+# Test only CD-ROM disk images can be added
+
+set -e
+export LANG=C
+
+rm -f test.out
+
+../../fish/guestfish --ro > test.out <<EOF
+add-cdrom ../data/test.iso
+
+run
+
+list-devices
+
+ping-daemon
+EOF
+
+if [ "$(cat test.out)" != "/dev/sda" ]; then
+ echo "$0: unexpected output:"
+ cat test.out
+ exit 1
+fi
+
+rm -f test.out
--
1.8.3.1