summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel P. Berrangé <berrange@redhat.com>2022-03-22 17:52:55 +0000
committerDaniel P. Berrangé <berrange@redhat.com>2022-04-21 15:00:29 +0000
commit4ae177d49c48fb941656fded4bb036f0754cf6fc (patch)
tree9c9063a53eb2e474f8568c990bdcb234f3ecd269
parentb29d0aaa26f5bdc25b88908cfdf5fad9e53dac62 (diff)
downloadlibvirt-python-4ae177d49c48fb941656fded4bb036f0754cf6fc.tar.gz
sanitytest: move class method mapping fixup into a helper method
This is a step towards turning the sanitytest.py file into a normal python unittest. Best viewed with the '-b' flag to diff. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
-rw-r--r--sanitytest.py236
1 files changed, 120 insertions, 116 deletions
diff --git a/sanitytest.py b/sanitytest.py
index 1ab4620..ba086e2 100644
--- a/sanitytest.py
+++ b/sanitytest.py
@@ -197,125 +197,128 @@ for cname in wantfunctions:
basicklassmap[name] = ("libvirt", name[3:], cname)
-# Phase 4: Deal with oh so many special cases in C -> python mapping
-finalklassmap = {} # type: Dict[str, Tuple[str, str, str]]
-
-for name, (klass, func, cname) in sorted(basicklassmap.items()):
- # The object lifecycle APIs are irrelevant since they're
- # used inside the object constructors/destructors.
- if func in ["Ref", "Free", "New", "GetConnect", "GetDomain", "GetNetwork"]:
- if klass == "virStream" and func == "New":
- klass = "virConnect"
- func = "NewStream"
- else:
- continue
+# Deal with oh so many special cases in C -> python mapping
+def fixup_class_method_mapping(basicklassmap):
+ finalklassmap = {} # type: Dict[str, Tuple[str, str, str]]
+
+ for name, (klass, func, cname) in sorted(basicklassmap.items()):
+ # The object lifecycle APIs are irrelevant since they're
+ # used inside the object constructors/destructors.
+ if func in ["Ref", "Free", "New", "GetConnect", "GetDomain", "GetNetwork"]:
+ if klass == "virStream" and func == "New":
+ klass = "virConnect"
+ func = "NewStream"
+ else:
+ continue
- # All the error handling methods need special handling
- if klass == "libvirt":
- if func in ["CopyLastError", "DefaultErrorFunc",
- "ErrorFunc", "FreeError",
- "SaveLastError", "ResetError"]:
- continue
- elif func in ["GetLastError", "GetLastErrorMessage",
- "GetLastErrorCode", "GetLastErrorDomain",
- "ResetLastError", "Initialize"]:
- func = "vir" + func
- elif func == "SetErrorFunc":
- func = "RegisterErrorHandler"
- elif klass == "virConnect":
- if func in ["CopyLastError", "SetErrorFunc"]:
- continue
- elif func in ["GetLastError", "ResetLastError"]:
- func = "virConn" + func
-
- # Remove 'Get' prefix from most APIs, except those in virConnect
- # and virDomainSnapshot namespaces which stupidly used a different
- # convention which we now can't fix without breaking API
- if func[0:3] == "Get" and klass not in ["virConnect", "virDomainCheckpoint", "virDomainSnapshot", "libvirt"]:
- if func not in ["GetCPUStats", "GetTime"]:
- func = func[3:]
-
- # The object creation and lookup APIs all have to get re-mapped
- # into the parent class
- if func in ["CreateXML", "CreateLinux", "CreateXMLWithFiles",
- "DefineXML", "CreateXMLFrom", "LookupByUUID",
- "LookupByUUIDString", "LookupByVolume" "LookupByName",
- "LookupByID", "LookupByName", "LookupByKey", "LookupByPath",
- "LookupByMACString", "LookupByUsage", "LookupByVolume",
- "LookupByTargetPath", "LookupSCSIHostByWWN", "LookupByPortDev",
- "Restore", "RestoreFlags",
- "SaveImageDefineXML", "SaveImageGetXMLDesc", "DefineXMLFlags",
- "CreateXMLFlags"]:
- if klass != "virDomain":
- func = klass[3:] + func
-
- if klass in ["virDomainCheckpoint", "virDomainSnapshot"]:
- klass = "virDomain"
- func = func[6:]
- elif klass == "virStorageVol" and func in ["StorageVolCreateXMLFrom", "StorageVolCreateXML"]:
- klass = "virStoragePool"
- func = func[10:]
- elif klass == "virNetworkPort":
- klass = "virNetwork"
- func = func[7:]
- elif func == "StoragePoolLookupByVolume":
- klass = "virStorageVol"
- elif func == "StorageVolLookupByName":
- klass = "virStoragePool"
- else:
+ # All the error handling methods need special handling
+ if klass == "libvirt":
+ if func in ["CopyLastError", "DefaultErrorFunc",
+ "ErrorFunc", "FreeError",
+ "SaveLastError", "ResetError"]:
+ continue
+ elif func in ["GetLastError", "GetLastErrorMessage",
+ "GetLastErrorCode", "GetLastErrorDomain",
+ "ResetLastError", "Initialize"]:
+ func = "vir" + func
+ elif func == "SetErrorFunc":
+ func = "RegisterErrorHandler"
+ elif klass == "virConnect":
+ if func in ["CopyLastError", "SetErrorFunc"]:
+ continue
+ elif func in ["GetLastError", "ResetLastError"]:
+ func = "virConn" + func
+
+ # Remove 'Get' prefix from most APIs, except those in virConnect
+ # and virDomainSnapshot namespaces which stupidly used a different
+ # convention which we now can't fix without breaking API
+ if func[0:3] == "Get" and klass not in ["virConnect", "virDomainCheckpoint", "virDomainSnapshot", "libvirt"]:
+ if func not in ["GetCPUStats", "GetTime"]:
+ func = func[3:]
+
+ # The object creation and lookup APIs all have to get re-mapped
+ # into the parent class
+ if func in ["CreateXML", "CreateLinux", "CreateXMLWithFiles",
+ "DefineXML", "CreateXMLFrom", "LookupByUUID",
+ "LookupByUUIDString", "LookupByVolume" "LookupByName",
+ "LookupByID", "LookupByName", "LookupByKey", "LookupByPath",
+ "LookupByMACString", "LookupByUsage", "LookupByVolume",
+ "LookupByTargetPath", "LookupSCSIHostByWWN", "LookupByPortDev",
+ "Restore", "RestoreFlags",
+ "SaveImageDefineXML", "SaveImageGetXMLDesc", "DefineXMLFlags",
+ "CreateXMLFlags"]:
+ if klass != "virDomain":
+ func = klass[3:] + func
+
+ if klass in ["virDomainCheckpoint", "virDomainSnapshot"]:
+ klass = "virDomain"
+ func = func[6:]
+ elif klass == "virStorageVol" and func in ["StorageVolCreateXMLFrom", "StorageVolCreateXML"]:
+ klass = "virStoragePool"
+ func = func[10:]
+ elif klass == "virNetworkPort":
+ klass = "virNetwork"
+ func = func[7:]
+ elif func == "StoragePoolLookupByVolume":
+ klass = "virStorageVol"
+ elif func == "StorageVolLookupByName":
+ klass = "virStoragePool"
+ else:
+ klass = "virConnect"
+
+ # The open methods get remapped to primary namespace
+ if klass == "virConnect" and func in ["Open", "OpenAuth", "OpenReadOnly"]:
+ klass = "libvirt"
+
+ # These are inexplicably renamed in the python API
+ if func == "ListDomains":
+ func = "ListDomainsID"
+ elif func == "ListAllNodeDevices":
+ func = "ListAllDevices"
+ elif func == "ListNodeDevices":
+ func = "ListDevices"
+
+ # The virInterfaceChangeXXXX APIs go into virConnect. Stupidly
+ # they have lost their 'interface' prefix in names, but we can't
+ # fix this name
+ if func[0:6] == "Change":
klass = "virConnect"
- # The open methods get remapped to primary namespace
- if klass == "virConnect" and func in ["Open", "OpenAuth", "OpenReadOnly"]:
- klass = "libvirt"
-
- # These are inexplicably renamed in the python API
- if func == "ListDomains":
- func = "ListDomainsID"
- elif func == "ListAllNodeDevices":
- func = "ListAllDevices"
- elif func == "ListNodeDevices":
- func = "ListDevices"
-
- # The virInterfaceChangeXXXX APIs go into virConnect. Stupidly
- # they have lost their 'interface' prefix in names, but we can't
- # fix this name
- if func[0:6] == "Change":
- klass = "virConnect"
-
- # Need to special case the checkpoint and snapshot APIs
- if klass == "virDomainSnapshot" and func in ["Current", "ListNames", "Num"]:
- klass = "virDomain"
- func = "snapshot" + func
-
- # Names should start with lowercase letter...
- func = func[0:1].lower() + func[1:]
- if func[0:8] == "nWFilter":
- func = "nwfilter" + func[8:]
- if func[0:8] == "fSFreeze" or func[0:6] == "fSThaw" or func[0:6] == "fSInfo":
- func = "fs" + func[2:]
- if func[0:12] == "iOThreadInfo":
- func = "ioThreadInfo"
-
- if klass == "virNetwork":
- func = func.replace("dHCP", "DHCP")
-
- # ...except when they don't. More stupid naming
- # decisions we can't fix
- if func == "iD":
- func = "ID"
- if func == "uUID":
- func = "UUID"
- if func == "uUIDString":
- func = "UUIDString"
- if func == "oSType":
- func = "OSType"
- if func == "xMLDesc":
- func = "XMLDesc"
- if func == "mACString":
- func = "MACString"
-
- finalklassmap[name] = (klass, func, cname)
+ # Need to special case the checkpoint and snapshot APIs
+ if klass == "virDomainSnapshot" and func in ["Current", "ListNames", "Num"]:
+ klass = "virDomain"
+ func = "snapshot" + func
+
+ # Names should start with lowercase letter...
+ func = func[0:1].lower() + func[1:]
+ if func[0:8] == "nWFilter":
+ func = "nwfilter" + func[8:]
+ if func[0:8] == "fSFreeze" or func[0:6] == "fSThaw" or func[0:6] == "fSInfo":
+ func = "fs" + func[2:]
+ if func[0:12] == "iOThreadInfo":
+ func = "ioThreadInfo"
+
+ if klass == "virNetwork":
+ func = func.replace("dHCP", "DHCP")
+
+ # ...except when they don't. More stupid naming
+ # decisions we can't fix
+ if func == "iD":
+ func = "ID"
+ if func == "uUID":
+ func = "UUID"
+ if func == "uUIDString":
+ func = "UUIDString"
+ if func == "oSType":
+ func = "OSType"
+ if func == "xMLDesc":
+ func = "XMLDesc"
+ if func == "mACString":
+ func = "MACString"
+
+ finalklassmap[name] = (klass, func, cname)
+
+ return finalklassmap
# Validate that every C API is mapped to a python API
@@ -373,6 +376,7 @@ def validate_c_api_bindings_present(finalklassmap):
try:
+ finalklassmap = fixup_class_method_mapping(basicklassmap)
usedfunctions = validate_c_to_python_api_mappings(finalklassmap, gotfunctions)
validate_python_to_c_api_mappings(gotfunctions, usedfunctions)
validate_c_api_bindings_present(finalklassmap)