[Pkg-libvirt-commits] [libguestfs] 252/266: p2v: Add a test of virt-p2v.

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:42:52 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag debian/1%1.27.35-1
in repository libguestfs.

commit 22a556099a41ca4cbbfb746b1e620348b41b5049
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Mon Sep 1 14:10:49 2014 +0100

    p2v: Add a test of virt-p2v.
---
 p2v/Makefile.am          | 15 ++++++-----
 p2v/conversion.c         | 27 ++++++++++++++++---
 p2v/test-virt-p2v-ssh.sh | 61 +++++++++++++++++++++++++++++++++++++++++
 p2v/test-virt-p2v.sh     | 70 ++++++++++++++++++++++++++++++++++++++++++++++++
 v2v/TODO                 |  1 -
 5 files changed, 163 insertions(+), 11 deletions(-)

diff --git a/p2v/Makefile.am b/p2v/Makefile.am
index 644b405..8d4b1fc 100644
--- a/p2v/Makefile.am
+++ b/p2v/Makefile.am
@@ -83,10 +83,11 @@ stamp-virt-p2v.pod: virt-p2v.pod
 
 TESTS_ENVIRONMENT = $(top_builddir)/run --test
 
-#if ENABLE_APPLIANCE
-#TESTS = \
-#	test-virt-p2v.sh
-#endif ENABLE_APPLIANCE
-#
-#check-valgrind:
-#	$(MAKE) VG="$(top_builddir)/run @VG@" check
+if ENABLE_APPLIANCE
+TESTS = \
+	test-virt-p2v.sh
+endif ENABLE_APPLIANCE
+
+EXTRA_DIST += \
+	$(TESTS) \
+	test-virt-p2v-ssh.sh
diff --git a/p2v/conversion.c b/p2v/conversion.c
index 69ebb5b..e422f2b 100644
--- a/p2v/conversion.c
+++ b/p2v/conversion.c
@@ -132,7 +132,15 @@ start_conversion (struct config *config,
       goto out;
     }
 
-    if (asprintf (&device, "/dev/%s", config->disks[i]) == -1) {
+    if (config->disks[i][0] == '/') {
+      device = strdup (config->disks[i]);
+      if (!device) {
+        perror ("strdup");
+        cleanup_data_conns (data_conns, nr_disks);
+        exit (EXIT_FAILURE);
+      }
+    }
+    else if (asprintf (&device, "/dev/%s", config->disks[i]) == -1) {
       perror ("asprintf");
       cleanup_data_conns (data_conns, nr_disks);
       exit (EXIT_FAILURE);
@@ -412,7 +420,7 @@ generate_libvirt_xml (struct config *config, struct data_conn *data_conns)
 
   /* XXX quoting needs to be improved here XXX */
   fprintf (fp,
-           "<domain>\n"
+           "<domain type='physical'>\n"
            "  <name>%s</name>\n"
            "  <memory unit='KiB'>%" PRIu64 "</memory>\n"
            "  <currentMemory unit='KiB'>%" PRIu64 "</currentMemory>\n"
@@ -430,6 +438,19 @@ generate_libvirt_xml (struct config *config, struct data_conn *data_conns)
            config->flags & FLAG_PAE  ? "<pae/>" : "");
 
   for (i = 0; config->disks[i] != NULL; ++i) {
+    char target_dev[64];
+
+    if (config->disks[i][0] == '/') {
+    target_sd:
+      memcpy (target_dev, "sd", 2);
+      guestfs___drive_name (i, &target_dev[2]);
+    } else {
+      if (strlen (config->disks[i]) <= sizeof (target_dev) - 1)
+        strcpy (target_dev, config->disks[i]);
+      else
+        goto target_sd;
+    }
+
     fprintf (fp,
              "    <disk type='network' device='disk'>\n"
              "      <driver name='qemu' type='raw'/>\n"
@@ -438,7 +459,7 @@ generate_libvirt_xml (struct config *config, struct data_conn *data_conns)
              "      </source>\n"
              "      <target dev='%s'/>\n"
              "    </disk>\n",
-             data_conns[i].nbd_remote_port, config->disks[i]);
+             data_conns[i].nbd_remote_port, target_dev);
   }
 
   if (config->removable) {
diff --git a/p2v/test-virt-p2v-ssh.sh b/p2v/test-virt-p2v-ssh.sh
new file mode 100755
index 0000000..79dc883
--- /dev/null
+++ b/p2v/test-virt-p2v-ssh.sh
@@ -0,0 +1,61 @@
+#!/bin/bash -
+# Copyright (C) 2014 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.
+
+# This is an ssh substitute used by test-virt-p2v.sh.
+
+TEMP=`getopt \
+        -o 'l:No:p:R:' \
+        -- "$@"`
+if [ $? != 0 ]; then
+    echo "$0: problem parsing the command line arguments"
+    exit 1
+fi
+eval set -- "$TEMP"
+
+while true ; do
+    case "$1" in
+        # Regular arguments that we can just ignore.
+        -N)
+            shift
+            ;;
+        -l|-o|-p)
+            shift 2
+            ;;
+
+        # ssh -R 0:localhost:<port> (port forwarding).  Don't actually
+        # port forward, just return the original port number here so that
+        # the conversion process connects directly to qemu-nbd.
+        -R)
+            arg="$2"
+            port="$(echo $arg | awk -F: '{print $3}')"
+            echo "Allocated port" $port "for remote forward"
+            shift 2
+            ;;
+
+        --)
+            shift
+	    break
+            ;;
+        *)
+            echo "$0: internal error ($1)"
+            exit 1
+            ;;
+    esac
+done
+
+# Now run the interactive shell.
+exec bash
diff --git a/p2v/test-virt-p2v.sh b/p2v/test-virt-p2v.sh
new file mode 100755
index 0000000..a062525
--- /dev/null
+++ b/p2v/test-virt-p2v.sh
@@ -0,0 +1,70 @@
+#!/bin/bash -
+# libguestfs virt-p2v test script
+# Copyright (C) 2014 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.
+
+# Test virt-p2v in non-GUI mode.
+
+unset CDPATH
+export LANG=C
+set -e
+
+if [ -n "$SKIP_TEST_VIRT_P2V_SH" ]; then
+    echo "$0: test skipped because environment variable is set"
+    exit 77
+fi
+
+if [ "$(../fish/guestfish get-backend)" = "uml" ]; then
+    echo "$0: test skipped because UML backend does not support network"
+    exit 77
+fi
+
+f="$(cd ../tests/guests && pwd)/windows.img"
+if ! test -f $f || ! test -s $f; then
+    echo "$0: test skipped because phony Windows image was not created"
+    exit 77
+fi
+
+virt_tools_data_dir=${VIRT_TOOLS_DATA_DIR:-/usr/share/virt-tools}
+if ! test -r $virt_tools_data_dir/rhsrvany.exe; then
+    echo "$0: test skipped because rhsrvany.exe is not installed"
+    exit 77
+fi
+
+d=test-virt-p2v.d
+rm -rf $d
+mkdir $d
+
+# We don't want to program under test to actually ssh.  It's unlikely
+# to work.  Therefore create a dummy 'ssh' binary.
+pushd $d
+ln -sf ../test-virt-p2v-ssh.sh ssh
+popd
+export PATH=$d:$PATH
+
+# Note that the PATH already contains the local virt-v2v binary
+# under test (because of the ./run script).
+
+# The Linux kernel command line.
+cmdline="p2v.server=localhost p2v.name=windows p2v.debug p2v.disks=$f p2v.output=local p2v.output_storage=$d"
+
+./virt-p2v --cmdline="$cmdline"
+
+# Test the libvirt XML metadata and a disk was created.
+test -f $d/windows.xml
+test -f $d/windows-sda
+
+rm -r $d
diff --git a/v2v/TODO b/v2v/TODO
index 309b197..a4978fc 100644
--- a/v2v/TODO
+++ b/v2v/TODO
@@ -8,7 +8,6 @@ Proper progress bars when copying.
 
 p2v:
 
- - test mode
  - vmlinuz + initrd? - if not possible, remove from man page
  - PXE boot
  - short transfers?

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list