mirror of
git://sourceware.org/git/lvm2.git
synced 2024-10-27 18:55:19 +03:00
lvmdbustest.py: Reduce test client introspection calls
The default dbus python library mode of operation is to leverage introspection. However, this introspection data isn't accessible for users of the library and they have to specifically retrieve the introspection data too. This resulted in many introspection calls being made. This change eliminates introspection calls if we are testing multiple concurrent test clients. If it's a single client we will leverage a reduced amount of introspection data to verify the introspection data is correct. Typically clients don't leverage introspection data nearly as much as this test client.
This commit is contained in:
parent
4f1171466f
commit
61f6be7d2b
File diff suppressed because it is too large
Load Diff
@ -29,10 +29,12 @@ LV_COMMON_INT = BASE_INTERFACE + ".LvCommon"
|
||||
JOB_INT = BASE_INTERFACE + ".Job"
|
||||
CACHE_POOL_INT = BASE_INTERFACE + ".CachePool"
|
||||
CACHE_LV_INT = BASE_INTERFACE + ".CachedLv"
|
||||
|
||||
THINPOOL_LV_PATH = '/' + THINPOOL_INT.replace('.', '/')
|
||||
|
||||
|
||||
validate_introspection = True
|
||||
|
||||
|
||||
def rs(length, suffix, character_set=string.ascii_lowercase):
|
||||
return ''.join(random.choice(character_set) for _ in range(length)) + suffix
|
||||
|
||||
@ -154,19 +156,16 @@ def verify_type(value, dbus_str_rep):
|
||||
(dbus_str_rep, actual_str_rep, str(type(value))))
|
||||
|
||||
|
||||
class RemoteObject(object):
|
||||
class RemoteInterface(object):
|
||||
def _set_props(self, props=None):
|
||||
# print 'Fetching properties'
|
||||
if not props:
|
||||
# prop_fetch = dbus.Interface(self.bus.get_object(
|
||||
# BUSNAME, self.object_path), 'org.freedesktop.DBus.Properties')
|
||||
|
||||
for i in range(0, 3):
|
||||
for _ in range(0, 3):
|
||||
try:
|
||||
prop_fetch = dbus.Interface(self.bus.get_object(
|
||||
BUS_NAME, self.object_path),
|
||||
prop_obj = self.bus.get_object(
|
||||
BUS_NAME, self.object_path, introspect=False)
|
||||
prop_interface = dbus.Interface(prop_obj,
|
||||
'org.freedesktop.DBus.Properties')
|
||||
props = prop_fetch.GetAll(self.interface)
|
||||
props = prop_interface.GetAll(self.interface)
|
||||
break
|
||||
except dbus.exceptions.DBusException as dbe:
|
||||
if "GetAll" not in str(dbe):
|
||||
@ -174,9 +173,9 @@ class RemoteObject(object):
|
||||
if props:
|
||||
for kl, vl in list(props.items()):
|
||||
# Verify type is correct!
|
||||
verify_type(
|
||||
vl,
|
||||
self.introspect[self.interface]['properties'][kl]['p_type'])
|
||||
if self.introspect:
|
||||
verify_type(vl, self.introspect[self.interface]
|
||||
['properties'][kl]['p_type'])
|
||||
setattr(self, kl, vl)
|
||||
|
||||
def __init__(
|
||||
@ -188,7 +187,7 @@ class RemoteObject(object):
|
||||
self.introspect = introspect
|
||||
|
||||
self.dbus_method = dbus.Interface(specified_bus.get_object(
|
||||
BUS_NAME, self.object_path), self.interface)
|
||||
BUS_NAME, self.object_path, introspect=False), self.interface)
|
||||
|
||||
self._set_props(properties)
|
||||
|
||||
@ -203,13 +202,14 @@ class RemoteObject(object):
|
||||
# print("DEBUG: %s.%s result %s" %
|
||||
# (self.interface, _method_name, str(type(result))))
|
||||
|
||||
if 'RETURN_VALUE' in self.introspect[
|
||||
self.interface]['methods'][_method_name]:
|
||||
r_type = self.introspect[
|
||||
self.interface]['methods'][
|
||||
_method_name]['RETURN_VALUE']['a_type']
|
||||
if self.introspect:
|
||||
if 'RETURN_VALUE' in self.introspect[
|
||||
self.interface]['methods'][_method_name]:
|
||||
r_type = self.introspect[
|
||||
self.interface]['methods'][
|
||||
_method_name]['RETURN_VALUE']['a_type']
|
||||
|
||||
verify_type(result, r_type)
|
||||
verify_type(result, r_type)
|
||||
|
||||
return result
|
||||
|
||||
@ -222,36 +222,49 @@ class ClientProxy(object):
|
||||
def _intf_short_name(nm):
|
||||
return nm.split('.')[-1:][0]
|
||||
|
||||
def __init__(self, specified_bus, object_path, interface=None, props=None):
|
||||
i = dbus.Interface(specified_bus.get_object(
|
||||
BUS_NAME, object_path), 'org.freedesktop.DBus.Introspectable')
|
||||
def get_introspect(self):
|
||||
i = dbus.Interface(self.bus.get_object(
|
||||
BUS_NAME, self.object_path, introspect=False),
|
||||
'org.freedesktop.DBus.Introspectable')
|
||||
|
||||
introspection_xml = i.Introspect()
|
||||
return DbusIntrospection.introspect(i.Introspect())
|
||||
|
||||
# import xml.dom.minidom
|
||||
#
|
||||
# xml = xml.dom.minidom.parseString(introspection_xml)
|
||||
# print(xml.toprettyxml())
|
||||
|
||||
self.intro_spect = DbusIntrospection.introspect(introspection_xml)
|
||||
|
||||
for k in self.intro_spect.keys():
|
||||
sn = ClientProxy._intf_short_name(k)
|
||||
# print('Client proxy has interface: %s %s' % (k, sn))
|
||||
|
||||
if interface and interface == k and props is not None:
|
||||
ro = RemoteObject(
|
||||
specified_bus, object_path, k, self.intro_spect, props)
|
||||
else:
|
||||
ro = RemoteObject(
|
||||
specified_bus, object_path, k, self.intro_spect)
|
||||
|
||||
setattr(self, sn, ro)
|
||||
def _common(self, interface, introspect, properties):
|
||||
short_name = ClientProxy._intf_short_name(interface)
|
||||
self.short_interface_names.append(short_name)
|
||||
ro = RemoteInterface(self.bus, self.object_path, interface, introspect,
|
||||
properties)
|
||||
setattr(self, short_name, ro)
|
||||
|
||||
def __init__(self, specified_bus, object_path, interface_prop_hash=None,
|
||||
interfaces=None):
|
||||
self.object_path = object_path
|
||||
self.short_interface_names = []
|
||||
self.bus = specified_bus
|
||||
|
||||
if interface_prop_hash:
|
||||
assert interfaces is None
|
||||
if interfaces:
|
||||
assert interface_prop_hash is None
|
||||
|
||||
if interface_prop_hash and not validate_introspection:
|
||||
# We have everything including the values of the properties
|
||||
for i, props in interface_prop_hash.items():
|
||||
self._common(i, None, props)
|
||||
elif interfaces and not validate_introspection:
|
||||
# We are retrieving the values of the properties
|
||||
for i in interfaces:
|
||||
self._common(i, None, None)
|
||||
else:
|
||||
# We need to query the interfaces and gather all the properties
|
||||
# for each interface, as we have the introspection data we
|
||||
# will also utilize it to verify what we get back verifies
|
||||
introspect = self.get_introspect()
|
||||
|
||||
for i in list(introspect.keys()):
|
||||
self._common(i, introspect, None)
|
||||
|
||||
def update(self):
|
||||
# Go through all interfaces and update them
|
||||
for int_f in self.intro_spect.keys():
|
||||
sn = ClientProxy._intf_short_name(int_f)
|
||||
for sn in self.short_interface_names:
|
||||
getattr(self, sn).update()
|
||||
|
Loading…
Reference in New Issue
Block a user