From ec6ed4d7c8f24cef96cb28a45b7f4baab02741fd Mon Sep 17 00:00:00 2001 From: Guannan Ren Date: Wed, 21 Aug 2013 16:07:20 +0800 Subject: python: fix bindings that don't raise an exception Resovles: https://bugzilla.redhat.com/show_bug.cgi?id=912170 (cherry picked from commit 4b143ab23173000d1afa258726be0ff38cf2b386) For example: >>> dom.memoryStats() libvir: QEMU Driver error : Requested operation is not valid:\ domain is not running There are six such python API functions like so. The root reason is that generator.py script checks the type of return value of a python stub function defined in libvirt-api.xml or libvirt-override-api.xml to see whether to add the raise clause or not in python wrapper code in libvirt.py. The type of return value is supposed to be C types. For those stub functions which return python non-integer data type like string, list, tuple, dictionary, the existing type in functions varies from each other which leads problem like this. Currently, in generator.py, it maintains a buggy whitelist for stub functions returning a list type. I think it is easy to forget adding new function name in the whitelist. This patch makes the value of type consistent with C type "char *" in libvirt-override-api.xml. For python, any of types could be printed as string, so I choose "char *" in this case. And the comment in xml could explain it when adding new function definition. ... - + ... Conflicts: python/libvirt-override-api.xml *no virDomainGetJobStats and virNodeGetCPUMap APIs in RHEL6.5 --- generator.py | 10 ++--- libvirt-override-api.xml | 113 +++++++++++++++++++++++++---------------------- 2 files changed, 65 insertions(+), 58 deletions(-) diff --git a/generator.py b/generator.py index 9096f9e..9bd64b7 100755 --- a/generator.py +++ b/generator.py @@ -925,11 +925,9 @@ functions_list_exception_test = { } functions_list_default_test = "%s is None" -def is_list_type (name): - whitelist = [ "virDomainBlockStats", - "virDomainInterfaceStats" ] +def is_python_noninteger_type (name): - return name[-1:] == "*" or name in whitelist + return name[-1:] == "*" def nameFixup(name, classe, type, file): # avoid a desastrous clash @@ -1304,7 +1302,7 @@ def buildWrappers(module): ("ret", name)) classes.write(" return ret\n") - elif is_list_type (ret[0]): + elif is_python_noninteger_type (ret[0]): if not functions_noexcept.has_key (name): if functions_list_exception_test.has_key (name): test = functions_list_exception_test[name] @@ -1574,7 +1572,7 @@ def buildWrappers(module): classes.write (" return ret\n") - elif is_list_type (ret[0]): + elif is_python_noninteger_type (ret[0]): if not functions_noexcept.has_key (name): if functions_list_exception_test.has_key (name): test = functions_list_exception_test[name] diff --git a/libvirt-override-api.xml b/libvirt-override-api.xml index b76fb4e..a057715 100644 --- a/libvirt-override-api.xml +++ b/libvirt-override-api.xml @@ -1,5 +1,14 @@ + Returns the running hypervisor version of the connection host @@ -14,34 +23,34 @@ Returns the list of the ID of the domains on the hypervisor - + list the defined domains, stores the pointers to the names in @names - + returns list of all defined domains - + list the networks, stores the pointers to the names in @names - + list the defined networks, stores the pointers to the names in @names - + returns list of all networks - + Try to lookup a domain on the given hypervisor based on its UUID. @@ -57,48 +66,48 @@ Extract information about a domain. Note that if the connection used to get the domain is limited only a partial set of the information can be extracted. - + Extract domain state. - + Extract details about current state of control interface to a domain. - + Extract information about a domain block device size - + Extract information about an active job being processed for a domain. - + Extract hardware information about the Node. - + Extract node's CPU statistics. - + Extract node's memory statistics. - + @@ -150,13 +159,13 @@ Extracts block device statistics for a domain - + Extracts block device statistics parameters of a running domain - + @@ -169,20 +178,20 @@ [{cpu_time:xxx}, {cpu_time:xxx}, ...] If it is True or 1, it returns total domain CPU statistics in the format of [{cpu_time:xxx, user_time:xxx, system_time:xxx}] - + Extracts interface device statistics for a domain - + Extracts memory statistics for a domain - + @@ -190,16 +199,16 @@ - + Get the scheduler parameters, the @params array will be filled with the values. - + Get the scheduler parameters - + @@ -230,7 +239,7 @@ Query the CPU affinity setting of all virtual CPUs of domain - + @@ -256,7 +265,7 @@ Get the blkio parameters - + @@ -269,7 +278,7 @@ Get the memory parameters - + @@ -282,7 +291,7 @@ Get the NUMA parameters - + @@ -299,44 +308,44 @@ - + list the storage pools, stores the pointers to the names in @names - + list the defined storage pool, stores the pointers to the names in @names - + returns list of all storage pools - + list the storage volumes, stores the pointers to the names in @names - + return list of storage volume objects - + Extract information about a storage pool. Note that if the connection used to get the domain is limited only a partial set of the information can be extracted. - + Extract information about a storage volume. Note that if the connection used to get the domain is limited only a partial set of the information can be extracted. - + @@ -344,18 +353,18 @@ - + returns list of all host node devices - + list the node device's capabilities - + Fetches the value associated with a secret. @@ -366,13 +375,13 @@ List the defined secret IDs - + returns list of all interfaces - + Associates a value with a secret. @@ -400,13 +409,13 @@ List the defined network filters - + returns list of all network fitlers - + Try to lookup a network filter on the given hypervisor based on its UUID. @@ -427,18 +436,18 @@ list the running interfaces, stores the pointers to the names in @names - + list the defined interfaces, stores the pointers to the names in @names - + returns list of all interfaces - + Computes the most feature-rich CPU which is compatible with all given host CPUs. @@ -451,25 +460,25 @@ collect the list of snapshot names for the given domain - + returns the list of snapshots for the given domain - + collect the list of child snapshot names for the given snapshot - + returns the list of child snapshots for the given snapshot - + revert the domain to the given snapshot @@ -483,7 +492,7 @@ - + Get currently configured maximum migration speed for a domain @@ -504,7 +513,7 @@ - + Read the contents of domain's disk device @@ -525,7 +534,7 @@ Extract errors on disk devices. - + @@ -538,7 +547,7 @@ Get the node memory parameters - + -- cgit