Example #1
0
    def test_try_init(self):
        """Verify that try_init just returns when already initialized"""

        ps = BlockDev.PluginSpec()
        ps.name = BlockDev.Plugin.BTRFS
        ps.so_name = "nonexisting.so"
        avail_plugs = BlockDev.get_available_plugin_names()

        # try init should exit early enough to not hit the issue with
        # non-existing so file since the library is already initialized here, it
        # shouldn't report any error and it shouldn't affect the loaded plugins
        self.assertTrue(BlockDev.try_init([ps], None))
        self.assertEqual(avail_plugs, BlockDev.get_available_plugin_names())
Example #2
0
import logging
log = logging.getLogger("blivet")
program_log = logging.getLogger("program")

# XXX: respect the level? Need to translate between C and Python log levels.
log_bd_message = lambda level, msg: program_log.info(msg)

# initialize the libblockdev library
from gi.repository import GLib
from gi.repository import BlockDev as blockdev
_REQUESTED_PLUGIN_NAMES = set(("lvm", "btrfs", "swap", "crypto", "loop", "mdraid", "mpath", "dm"))
_requested_plugins = blockdev.plugin_specs_from_names(_REQUESTED_PLUGIN_NAMES)
if not blockdev.is_initialized():
    try:
        blockdev.try_init(require_plugins=_requested_plugins, log_func=log_bd_message)
    except GLib.GError:
        pass
else:
    avail_plugs = set(blockdev.get_available_plugin_names())
    if avail_plugs != _REQUESTED_PLUGIN_NAMES:
        try:
            blockdev.reinit(require_plugins=_requested_plugins, reload=False, log_func=log_bd_message)
        except GLib.GError:
            pass

avail_plugs = set(blockdev.get_available_plugin_names())
missing_plugs =  _REQUESTED_PLUGIN_NAMES - avail_plugs
for p in missing_plugs:
    log.info("Failed to load plugin %s", p)