def test_malformed_data(self): """ Pick up a key error on malformed introspection data. The introspection data is malformed because one of the attributes of the element should be its name. """ with self.assertRaises(DbusClientGenerationError): managed_object_class("Fail", ET.Element("name", {})) with self.assertRaises(DbusClientGenerationError): mo_query_builder(ET.Element("name", {}))
def test_managed_object(self, spec): """ Test that the GMO object has the correct set of properties. """ interface_name = spec.attrib["name"] klass = managed_object_class(interface_name, spec) property_names = [p.attrib["name"] for p in spec.findall("./property")] self.assertTrue(all(hasattr(klass, name) for name in property_names)) with self.assertRaises(DbusClientMissingInterfaceError): obj = klass({}) obj = klass({interface_name: {}}) for name in property_names: with self.assertRaises(DbusClientMissingPropertyError): getattr(obj, name)() for name in property_names: obj = klass({interface_name: {name: True}}) self.assertTrue(getattr(obj, name)())
raise StratisCliEnvironmentError( "The timeout value provided exceeds the largest acceptable value, %s." % MAXIMUM_DBUS_TIMEOUT_MS) # Convert from milliseconds to seconds return timeout_int / 1000 try: timeout = _get_timeout( environ.get("STRATIS_DBUS_TIMEOUT", DBUS_TIMEOUT_SECONDS * 1000)) filesystem_spec = ET.fromstring(SPECS[FILESYSTEM_INTERFACE]) Filesystem = make_class("Filesystem", filesystem_spec, timeout) MOFilesystem = managed_object_class("MOFilesystem", filesystem_spec) filesystems = mo_query_builder(filesystem_spec) pool_spec = ET.fromstring(SPECS[POOL_INTERFACE]) Pool = make_class("Pool", pool_spec, timeout) MOPool = managed_object_class("MOPool", pool_spec) pools = mo_query_builder(pool_spec) blockdev_spec = ET.fromstring(SPECS[BLOCKDEV_INTERFACE]) MODev = managed_object_class("MODev", blockdev_spec) devs = mo_query_builder(blockdev_spec) Manager = make_class("Manager", ET.fromstring(SPECS[_MANAGER_INTERFACE]), timeout) ObjectManager = make_class(
# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """ Wrapper for GetManagedObjects() result. """ import xml.etree.ElementTree as ET from dbus_client_gen import managed_object_class from dbus_client_gen import mo_query_builder from ._data import SPECS pools = mo_query_builder(ET.fromstring(SPECS['org.storage.stratis1.pool'])) filesystems = mo_query_builder(ET.fromstring(SPECS['org.storage.stratis1.filesystem'])) blockdevs = mo_query_builder(ET.fromstring(SPECS['org.storage.stratis1.blockdev'])) MOPool = managed_object_class( "MOPool", ET.fromstring(SPECS['org.storage.stratis1.pool']) ) MOBlockDev = managed_object_class( "MOBlockDev", ET.fromstring(SPECS['org.storage.stratis1.blockdev']) )
from dbus_client_gen import managed_object_class from dbus_client_gen import mo_query_builder from dbus_python_client_gen import make_class from ._data import SPECS _POOL_SPEC = ET.fromstring(SPECS["org.storage.stratis2.pool"]) _FILESYSTEM_SPEC = ET.fromstring(SPECS["org.storage.stratis2.filesystem"]) _BLOCKDEV_SPEC = ET.fromstring(SPECS["org.storage.stratis2.blockdev"]) pools = mo_query_builder(_POOL_SPEC) filesystems = mo_query_builder(_FILESYSTEM_SPEC) blockdevs = mo_query_builder(_BLOCKDEV_SPEC) MOPool = managed_object_class("MOPool", _POOL_SPEC) MOBlockDev = managed_object_class("MOBlockDev", _BLOCKDEV_SPEC) TIME_OUT = 120 # In seconds ObjectManager = make_class( "ObjectManager", ET.fromstring(SPECS["org.freedesktop.DBus.ObjectManager"]), TIME_OUT, ) Manager = make_class( "Manager", ET.fromstring(SPECS["org.storage.stratis2.Manager"]), TIME_OUT ) FetchProperties = make_class( "FetchProperties", ET.fromstring(SPECS["org.storage.stratis2.FetchProperties"]),
"ObjectManager", ET.fromstring(SPECS['org.freedesktop.DBus.ObjectManager'])) Pool = make_class("Pool", ET.fromstring(SPECS['org.storage.stratis1.pool'])) except DPClientGenerationError as err: raise StratisCliGenerationError( "Failed to generate some class needed for invoking dbus-python methods" ) from err # FIXME: catch DbusClientGenerationError once exported # pylint: disable=fixme # Note that these managed_object_class method calls can never actually raise an # exception, because the managed_object_class method only raises an exception on # introspection data that does not match the expected schema, and if there is # such data, then the calls to make_class() above will already have caused an # exception to be raised, and this code will never be reached. MOFilesystem = managed_object_class( "MOFilesystem", ET.fromstring(SPECS['org.storage.stratis1.filesystem'])) MOPool = managed_object_class("MOPool", ET.fromstring( SPECS['org.storage.stratis1.pool'])) MODev = managed_object_class("MODev", ET.fromstring( SPECS['org.storage.stratis1.blockdev'])) def _unique_wrapper(interface, func): """ Wraps other methods, implementing an additional unique parameter. """ def the_func(managed_objects, props=None, unique=False): """