示例#1
0
    def test_not_implemented(self):
        """Verify that unloaded/unimplemented functions report errors"""

        # should be loaded and working
        self.assertTrue(BlockDev.lvm_get_max_lv_size() > 0)

        ps = BlockDev.PluginSpec()
        ps.name = BlockDev.Plugin.BTRFS
        ps.so_name = ""
        self.assertTrue(BlockDev.reinit([ps], True, None))
        self.assertEqual(BlockDev.get_available_plugin_names(), ["btrfs"])

        # no longer loaded
        with self.assertRaises(GLib.GError):
            BlockDev.lvm_get_max_lv_size()

        self.assertTrue(BlockDev.reinit(None, True, None))

        # loaded again
        self.assertTrue(BlockDev.lvm_get_max_lv_size() > 0)
示例#2
0
    def storage(self):
        if not self._storage:
            import blivet
            import blivet.arch

            import gi
            gi.require_version("BlockDev", "1.0")

            from gi.repository import BlockDev as blockdev
            self._storage = blivet.Blivet(ksdata=self.ksdata)

            if self.instClass.defaultFS:
                self._storage.setDefaultFSType(self.instClass.defaultFS)

            if blivet.arch.isS390():
                # want to make sure s390 plugin is loaded
                if "s390" not in blockdev.get_available_plugin_names():
                    plugin = blockdev.PluginSpec()
                    plugin.name = blockdev.Plugin.S390
                    plugin.so_name = None
                    blockdev.reinit([plugin], reload=False)

        return self._storage
示例#3
0
gi.require_version("GLib", "2.0")
gi.require_version("BlockDev", "2.0")

# initialize the libblockdev library
from gi.repository import GLib
from gi.repository import BlockDev as blockdev
if arch.is_s390():
    _REQUESTED_PLUGIN_NAMES = set(("btrfs", "swap", "crypto", "loop", "mdraid",
                                   "mpath", "dm", "s390", "nvdimm"))
else:
    _REQUESTED_PLUGIN_NAMES = set(
        ("btrfs", "swap", "crypto", "loop", "mdraid", "mpath", "dm", "nvdimm"))

_requested_plugins = blockdev.plugin_specs_from_names(_REQUESTED_PLUGIN_NAMES)
# XXX force non-dbus LVM plugin
lvm_plugin = blockdev.PluginSpec()
lvm_plugin.name = blockdev.Plugin.LVM
lvm_plugin.so_name = "libbd_lvm.so.2"
_requested_plugins.append(lvm_plugin)
try:
    # do not check for dependencies during libblockdev initializtion, do runtime
    # checks instead
    blockdev.switch_init_checks(False)
    succ_, avail_plugs = blockdev.try_reinit(
        require_plugins=_requested_plugins,
        reload=False,
        log_func=log_bd_message)
except GLib.GError as err:
    raise RuntimeError("Failed to intialize the libblockdev library: %s" % err)
else:
    avail_plugs = set(avail_plugs)