diff --git a/README b/README index fc88eb97b..9962ae880 100644 --- a/README +++ b/README @@ -223,6 +223,9 @@ The full requirements are described below. +--------------+-------------+---+-----------------------------------------+ | Sys::Virt | | O | Perl bindings for libvirt. | +--------------+-------------+---+-----------------------------------------+ +| libvirt-python | O | For testing Python libvirt/libguestfs | +| | | | interactions. | ++--------------+-------------+---+-----------------------------------------+ | Win::Hivex | | O | Perl bindings for hivex. | +--------------+-------------+---+-----------------------------------------+ | Pod::Usage | | O | Perl module used by tests. | diff --git a/generator/python.ml b/generator/python.ml index 82afb2e53..e47195f52 100644 --- a/generator/python.ml +++ b/generator/python.ml @@ -294,8 +294,8 @@ put_table (char * const * const argv) | Int n -> pr " int %s;\n" n | Int64 n -> pr " long long %s;\n" n | Pointer (t, n) -> - pr " long long %s_int64;\n" n; - pr " void * /* %s */ %s;\n" t n + pr " void * /* %s */ %s;\n" t n; + pr " PyObject *%s_long;\n" n ) args; (* Fetch the optional arguments as objects, so we can detect @@ -324,11 +324,12 @@ put_table (char * const * const argv) | StringList _ | DeviceList _ -> pr "O" | Bool _ -> pr "i" (* XXX Python has booleans? *) | Int _ -> pr "i" - | Int64 _ | Pointer _ -> + | Int64 _ -> (* XXX Whoever thought it was a good idea to * emulate C's int/long/long long in Python? *) pr "L" + | Pointer _ -> pr "O" | BufferIn _ -> pr "s#" ) args; @@ -347,7 +348,7 @@ put_table (char * const * const argv) | Bool n -> pr ", &%s" n | Int n -> pr ", &%s" n | Int64 n -> pr ", &%s" n - | Pointer (_, n) -> pr ", &%s_int64" n + | Pointer (_, n) -> pr ", &%s_long" n | BufferIn n -> pr ", &%s, &%s_size" n n ) args; @@ -369,8 +370,8 @@ put_table (char * const * const argv) | StringList n | DeviceList n -> pr " %s = get_string_list (py_%s);\n" n n; pr " if (!%s) goto out;\n" n - | Pointer (t, n) -> - pr " %s = POINTER_NOT_IMPLEMENTED (\"%s\");\n" n t + | Pointer (_, n) -> + pr " %s = PyLong_AsVoidPtr (%s_long);\n" n n ) args; pr "\n"; @@ -798,9 +799,11 @@ class GuestFS(object): | Pathname _ | Device _ | Mountable _ | Dev_or_Path _ | Mountable_or_Path _ | String _ | Key _ | FileIn _ | FileOut _ | OptString _ | Bool _ | Int _ | Int64 _ - | BufferIn _ | Pointer _ | GUID _ -> () + | BufferIn _ | GUID _ -> () | StringList n | DeviceList n -> - pr " %s = list (%s)\n" n n + pr " %s = list (%s)\n" n n + | Pointer (_, n) -> + pr " %s = %s.c_pointer()\n" n n ) args; pr " self._check_not_closed ()\n"; pr " r = libguestfsmod.%s (self._o" f.name; diff --git a/python/run-python-tests b/python/run-python-tests index af849c7f2..285bb189c 100755 --- a/python/run-python-tests +++ b/python/run-python-tests @@ -18,6 +18,9 @@ errors=0 +guestsdir="$(cd ../tests/guests && pwd)" +export guestsdir + for f in $srcdir/t/*.py; do $PYTHON $f r=$? diff --git a/python/t/910-libvirt.py b/python/t/910-libvirt.py new file mode 100644 index 000000000..1f70f36e4 --- /dev/null +++ b/python/t/910-libvirt.py @@ -0,0 +1,48 @@ +# libguestfs Python bindings +# 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. + +# The Python bindings for add_libvirt_dom require the libvirt-python +# library to support a new method (.c_pointer()). Ensure this keeps +# working by testing it. See: +# https://bugzilla.redhat.com/show_bug.cgi?id=1075164 + +import os +import guestfs + +guestsdir = os.environ['guestsdir'] + +try: + import libvirt +except: + print "could not import python-libvirt" + exit (77) + +conn = libvirt.open ("test:///%s/guests.xml" % guestsdir) + +# Check we're using the version of libvirt-python that has c_pointer() methods. +if not "c_pointer" in dir (conn): + print "skipping test: libvirt-python doesn't support c_pointer()" + exit (77) + +dom = conn.lookupByName ("blank-disk") + +g = guestfs.GuestFS () + +r = g.add_libvirt_dom (dom, readonly=1) + +if r != 1: + raise "unexpected return value from add_libvirt_dom (%d)" % r