[libvirt] [libvirt-python PATCH] sanitytest: check for exported enums

We are already collecting list of enums exported and list of enums we want to have available. Event hough there was an issue with one enum fixed with 014d9bbaf368b33a881f1d6b2fd8a5dd285a4f71, there was no test for it and this commit tries to fix that. Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- sanitytest.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/sanitytest.py b/sanitytest.py index 3c1568b..8cb0154 100644 --- a/sanitytest.py +++ b/sanitytest.py @@ -16,7 +16,10 @@ f = open(xml, "r") tree = lxml.etree.parse(f) verbose = False +fail = False +enumvals = {} +second_pass = [] wantenums = [] wantfunctions = [] @@ -25,11 +28,51 @@ set = tree.xpath('/api/files/file/exports[@type="function"]/@symbol') for n in set: wantfunctions.append(n) +set = tree.xpath('/api/symbols/enum') +for n in set: + typ = n.attrib['type'] + name = n.attrib['name'] + val = n.attrib['value'] + + if typ not in enumvals: + enumvals[typ] = {} + + # If the value cannot be converted to int, it is reference to + # another enum and needs to be sorted out later on + try: + val = int(val) + except ValueError: + second_pass.append(n) + continue + + enumvals[typ][name] = int(val) + +for n in second_pass: + typ = n.attrib['type'] + name = n.attrib['name'] + val = n.attrib['value'] + + for v in enumvals.values(): + if val in v: + val = int(v[val]) + break + + if type(val) != int: + fail = True + print("Cannot get a value of enum %s (originally %s)" % (val, name)) + enumvals[typ][name] = val + set = tree.xpath('/api/files/file/exports[@type="enum"]/@symbol') for n in set: + for enumval in enumvals.values(): + if n in enumval: + enum = enumval + break + # Eliminate sentinels + if n.endswith('_LAST') and enum[n] == max(enum.values()): + continue wantenums.append(n) - # Phase 2: Identify all classes and methods in the 'libvirt' python module gotenums = [] gottypes = [] @@ -51,6 +94,13 @@ for name in dir(libvirt): else: pass +for enum in wantenums: + if enum not in gotenums: + fail = True + for typ, enumval in enumvals.items(): + if enum in enumval: + print("FAIL Missing exported enum %s of type %s" % (enum, typ)) + for klassname in gottypes: klassobj = getattr(libvirt, klassname) for name in dir(klassobj): @@ -241,7 +291,6 @@ for name in sorted(basicklassmap): # Phase 5: Validate sure that every C API is mapped to a python API -fail = False usedfunctions = {} for name in sorted(finalklassmap): klass = finalklassmap[name][0] -- 2.1.2

On 10/06/2014 04:32 AM, Martin Kletzander wrote:
We are already collecting list of enums exported and list of enums we want to have available. Event hough there was an issue with one enum
s/hough/though/
fixed with 014d9bbaf368b33a881f1d6b2fd8a5dd285a4f71, there was no test for it and this commit tries to fix that.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- sanitytest.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-)
for n in set: + for enumval in enumvals.values(): + if n in enumval: + enum = enumval + break + # Eliminate sentinels + if n.endswith('_LAST') and enum[n] == max(enum.values()):
We have one enum ending in _LAST that is not a sentinel: VIR_NETWORK_UPDATE_COMMAND_ADD_LAST. But it looks like you were careful (since that sentinel is not the maximum value, you are not skipping it). ACK. Also, I still think we should fix libvirt to export XML that recursively resolves all enum values down to ints, rather than making clients have to repeat the resolution; but as that would only impact new libvirt, we still need this code to deal with existing libvirt. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Mon, Oct 06, 2014 at 08:41:45AM -0600, Eric Blake wrote:
On 10/06/2014 04:32 AM, Martin Kletzander wrote:
We are already collecting list of enums exported and list of enums we want to have available. Event hough there was an issue with one enum
s/hough/though/
fixed with 014d9bbaf368b33a881f1d6b2fd8a5dd285a4f71, there was no test for it and this commit tries to fix that.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- sanitytest.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-)
for n in set: + for enumval in enumvals.values(): + if n in enumval: + enum = enumval + break + # Eliminate sentinels + if n.endswith('_LAST') and enum[n] == max(enum.values()):
We have one enum ending in _LAST that is not a sentinel: VIR_NETWORK_UPDATE_COMMAND_ADD_LAST. But it looks like you were careful (since that sentinel is not the maximum value, you are not skipping it).
I did it exactly because of that argument (see the referenced commit).
ACK.
Thanks, pushed. Martin
Also, I still think we should fix libvirt to export XML that recursively resolves all enum values down to ints, rather than making clients have to repeat the resolution; but as that would only impact new libvirt, we still need this code to deal with existing libvirt.
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
Martin Kletzander