render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Daniel P. Berrange 803b3b
From 25ea8e47e74def560bf89cd94dd54b75ca5ff4d6 Mon Sep 17 00:00:00 2001
Daniel P. Berrange 803b3b
From: "Daniel P. Berrange" <berrange@redhat.com>
Daniel P. Berrange 803b3b
Date: Tue, 5 Feb 2013 12:55:09 +0000
Daniel P. Berrange 803b3b
Subject: [PATCH] Fix missing error constants in libvirt python module
Daniel P. Berrange 803b3b
Daniel P. Berrange 803b3b
The previous change to the generator, changed too much - only
Daniel P. Berrange 803b3b
the functions are in 'virerror.c', the constants remained in
Daniel P. Berrange 803b3b
'virerror.h' which could not be renamed for API compat reasons.
Daniel P. Berrange 803b3b
Daniel P. Berrange 803b3b
Add a test case to sanity check the generated python bindings
Daniel P. Berrange 803b3b
Daniel P. Berrange 803b3b
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Daniel P. Berrange 803b3b
---
Daniel P. Berrange 803b3b
 python/Makefile.am   |  5 +++++
Daniel P. Berrange 803b3b
 python/generator.py  |  4 +++-
Daniel P. Berrange 803b3b
 python/sanitytest.py | 31 +++++++++++++++++++++++++++++++
Daniel P. Berrange 803b3b
 3 files changed, 39 insertions(+), 1 deletion(-)
Daniel P. Berrange 803b3b
 create mode 100644 python/sanitytest.py
Daniel P. Berrange 803b3b
Daniel P. Berrange 803b3b
diff --git a/python/Makefile.am b/python/Makefile.am
Daniel P. Berrange 803b3b
index dd69600..ef3c3eb 100644
Daniel P. Berrange 803b3b
--- a/python/Makefile.am
Daniel P. Berrange 803b3b
+++ b/python/Makefile.am
Daniel P. Berrange 803b3b
@@ -119,6 +119,11 @@ $(libvirtmod_la_OBJECTS): $(GENERATED)
Daniel P. Berrange 803b3b
 $(libvirtmod_qemu_la_OBJECTS): $(QEMU_GENERATED)
Daniel P. Berrange 803b3b
 $(libvirtmod_lxc_la_OBJECTS): $(LXC_GENERATED)
Daniel P. Berrange 803b3b
 
Daniel P. Berrange 803b3b
+EXTRA_DIST += sanitytest.py
Daniel P. Berrange 803b3b
+
Daniel P. Berrange 803b3b
+check-local:
Daniel P. Berrange 803b3b
+	$(AM_V_GEN)PYTHONPATH=$(abs_topbuilddir):$(abs_topbuilddir)/.libs $(PYTHON) $(srcdir)/sanitytest.py
Daniel P. Berrange 803b3b
+
Daniel P. Berrange 803b3b
 install-data-local:
Daniel P. Berrange 803b3b
 	$(mkinstalldirs) $(DESTDIR)$(pyexecdir)
Daniel P. Berrange 803b3b
 	$(INSTALL) -m 0644 libvirt.py $(DESTDIR)$(pyexecdir)
Daniel P. Berrange 803b3b
diff --git a/python/generator.py b/python/generator.py
Daniel P. Berrange 803b3b
index 71ca883..ceade6b 100755
Daniel P. Berrange 803b3b
--- a/python/generator.py
Daniel P. Berrange 803b3b
+++ b/python/generator.py
Daniel P. Berrange 803b3b
@@ -122,8 +122,9 @@ class docParser(xml.sax.handler.ContentHandler):
Daniel P. Berrange 803b3b
                 if attrs.has_key('field'):
Daniel P. Berrange 803b3b
                     self.function_return_field = attrs['field']
Daniel P. Berrange 803b3b
         elif tag == 'enum':
Daniel P. Berrange 803b3b
+            # enums come from header files, hence virterror.h
Daniel P. Berrange 803b3b
             if (attrs['file'] == "libvirt" or
Daniel P. Berrange 803b3b
-                attrs['file'] == "virerror"):
Daniel P. Berrange 803b3b
+                attrs['file'] == "virterror"):
Daniel P. Berrange 803b3b
                 enum(attrs['type'],attrs['name'],attrs['value'])
Daniel P. Berrange 803b3b
             elif attrs['file'] == "libvirt-lxc":
Daniel P. Berrange 803b3b
                 lxc_enum(attrs['type'],attrs['name'],attrs['value'])
Daniel P. Berrange 803b3b
@@ -134,6 +135,7 @@ class docParser(xml.sax.handler.ContentHandler):
Daniel P. Berrange 803b3b
         if debug:
Daniel P. Berrange 803b3b
             print "end %s" % tag
Daniel P. Berrange 803b3b
         if tag == 'function':
Daniel P. Berrange 803b3b
+            # fuctions come from source files, hence 'virerror.c'
Daniel P. Berrange 803b3b
             if self.function != None:
Daniel P. Berrange 803b3b
                 if (self.function_module == "libvirt" or
Daniel P. Berrange 803b3b
                     self.function_module == "virevent" or
Daniel P. Berrange 803b3b
diff --git a/python/sanitytest.py b/python/sanitytest.py
Daniel P. Berrange 803b3b
new file mode 100644
Daniel P. Berrange 803b3b
index 0000000..047450b
Daniel P. Berrange 803b3b
--- /dev/null
Daniel P. Berrange 803b3b
+++ b/python/sanitytest.py
Daniel P. Berrange 803b3b
@@ -0,0 +1,31 @@
Daniel P. Berrange 803b3b
+#!/usr/bin/python
Daniel P. Berrange 803b3b
+
Daniel P. Berrange 803b3b
+import libvirt
Daniel P. Berrange 803b3b
+
Daniel P. Berrange 803b3b
+globals = dir(libvirt)
Daniel P. Berrange 803b3b
+
Daniel P. Berrange 803b3b
+# Sanity test that the generator hasn't gone wrong
Daniel P. Berrange 803b3b
+
Daniel P. Berrange 803b3b
+# Look for core classes
Daniel P. Berrange 803b3b
+assert("virConnect" in globals)
Daniel P. Berrange 803b3b
+assert("virDomain" in globals)
Daniel P. Berrange 803b3b
+assert("virDomainSnapshot" in globals)
Daniel P. Berrange 803b3b
+assert("virInterface" in globals)
Daniel P. Berrange 803b3b
+assert("virNWFilter" in globals)
Daniel P. Berrange 803b3b
+assert("virNodeDevice" in globals)
Daniel P. Berrange 803b3b
+assert("virNetwork" in globals)
Daniel P. Berrange 803b3b
+assert("virSecret" in globals)
Daniel P. Berrange 803b3b
+assert("virStoragePool" in globals)
Daniel P. Berrange 803b3b
+assert("virStorageVol" in globals)
Daniel P. Berrange 803b3b
+assert("virStream" in globals)
Daniel P. Berrange 803b3b
+assert("VIR_CONNECT_RO" in globals)
Daniel P. Berrange 803b3b
+
Daniel P. Berrange 803b3b
+# Error related bits
Daniel P. Berrange 803b3b
+assert("libvirtError" in globals)
Daniel P. Berrange 803b3b
+assert("VIR_ERR_AUTH_FAILED" in globals)
Daniel P. Berrange 803b3b
+assert("virGetLastError" in globals)
Daniel P. Berrange 803b3b
+
Daniel P. Berrange 803b3b
+# Some misc methods
Daniel P. Berrange 803b3b
+assert("virInitialize" in globals)
Daniel P. Berrange 803b3b
+assert("virEventAddHandle" in globals)
Daniel P. Berrange 803b3b
+assert("virEventRegisterDefaultImpl" in globals)
Daniel P. Berrange 803b3b
-- 
Daniel P. Berrange 803b3b
1.7.11.7
Daniel P. Berrange 803b3b