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", {}))
Example #2
0
    def test_managed_object_query(self, specs):
        """
        Test that the query returns appropriate values for its query input.
        """
        for spec in specs:
            interface_name = spec.attrib["name"]

            query_builder = mo_query_builder(spec)

            properties = [p.attrib["name"] for p in spec.findall("./property")]

            with self.assertRaises(DbusClientUniqueResultError):
                query_builder({}).require_unique_match().search({})

            with self.assertRaises(DbusClientUnknownSearchPropertiesError):
                query_builder({"".join(properties) + "_": True})

            query = query_builder(dict((p, True) for p in properties))
            if properties == []:
                self.assertEqual(
                    list(query.search({"op": {interface_name: {}}})),
                    [("op", {interface_name: {}})],
                )
                self.assertEqual(list(query.search({"op": {}})), [])

            else:
                with self.assertRaises(DbusClientMissingSearchPropertiesError):
                    list(query.search({"op": {interface_name: {}}}))
Example #3
0
            "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(
        "ObjectManager",
Example #4
0
#
# 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'])
)
Example #5
0
"""

import xml.etree.ElementTree as ET

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
Example #6
0
        :param dict managed_objects: result of calling GetManagedObjects()
        :param dict props: props to narrow search on, empty if None
        :param bool unique: whether the result is required to be unique

        :returns: the result of calling the_func, or a unique element
        :rtype: generator of str * dict OR a single pair of str * dict
        :raises StratisCliDbusLookupError: if unique == True and none found
        """
        result = func(managed_objects, props=props)
        if unique is True:
            result = [x for x in result]
            if len(result) != 1:
                raise StratisCliDbusLookupError(interface, props)
            return result[0]
        return result

    return the_func


_FILESYSTEM_INTERFACE = 'org.storage.stratis1.filesystem'
_filesystems = mo_query_builder(ET.fromstring(SPECS[_FILESYSTEM_INTERFACE]))
filesystems = _unique_wrapper(_FILESYSTEM_INTERFACE, _filesystems)

_POOL_INTERFACE = 'org.storage.stratis1.pool'
_pools = mo_query_builder(ET.fromstring(SPECS[_POOL_INTERFACE]))
pools = _unique_wrapper(_POOL_INTERFACE, _pools)

_BLOCKDEV_INTERFACE = 'org.storage.stratis1.blockdev'
_devs = mo_query_builder(ET.fromstring(SPECS[_BLOCKDEV_INTERFACE]))
devs = _unique_wrapper(_BLOCKDEV_INTERFACE, _devs)