def test_try_reinit(self): """Verify that try_reinit() works as expected""" # try reinitializing with only some utilities being available and thus # only some plugins able to load with fake_path("tests/fake_utils/lib_missing_utils", keep_utils=["swapon", "swapoff", "mkswap", "swaplabel"]): succ, loaded = BlockDev.try_reinit(self.requested_plugins, True, None) self.assertFalse(succ) for plug_name in ("swap", "crypto"): self.assertIn(plug_name, loaded) # reset back to all plugins self.assertTrue(BlockDev.reinit(self.requested_plugins, True, None)) # now the same with a subset of plugins requested plugins = BlockDev.plugin_specs_from_names(["swap", "crypto"]) with fake_path("tests/fake_utils/lib_missing_utils", keep_utils=["swapon", "swapoff", "mkswap", "swaplabel"]): succ, loaded = BlockDev.try_reinit(plugins, True, None) self.assertTrue(succ) self.assertEqual(set(loaded), set(["swap", "crypto"]))
def test_check_no_mkswap(self): """Verify that checking mkswap and swaplabel tools availability works as expected """ # unload all plugins first self.assertTrue(BlockDev.reinit([], True, None)) with fake_path(all_but="mkswap"): # no mkswap available, the swap plugin should fail to load with self.assertRaises(GLib.GError): BlockDev.reinit(self.requested_plugins, True, None) self.assertNotIn("swap", BlockDev.get_available_plugin_names()) with fake_path(all_but="swaplabel"): # no swaplabel available, the swap plugin should fail to load with self.assertRaises(GLib.GError): BlockDev.reinit(self.requested_plugins, True, None) self.assertNotIn("swap", BlockDev.get_available_plugin_names()) # load the plugins back self.assertTrue(BlockDev.reinit(self.requested_plugins, True, None)) self.assertIn("swap", BlockDev.get_available_plugin_names())
def test_resiserfs_available(self): """Verify that it is possible to check resiserfs tech availability""" available = BlockDev.fs_is_tech_avail( BlockDev.FSTech.REISERFS, BlockDev.FSTechMode.MKFS | BlockDev.FSTechMode.QUERY | BlockDev.FSTechMode.REPAIR | BlockDev.FSTechMode.CHECK | BlockDev.FSTechMode.SET_LABEL | BlockDev.FSTechMode.RESIZE | BlockDev.FSTechMode.SET_UUID) self.assertTrue(available) BlockDev.switch_init_checks(False) BlockDev.reinit(self.requested_plugins, True, None) # now try without mkreiserfs with utils.fake_path(all_but="mkreiserfs"): with self.assertRaisesRegex( GLib.GError, "The 'mkreiserfs' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.REISERFS, BlockDev.FSTechMode.MKFS) # now try without reiserfsck with utils.fake_path(all_but="reiserfsck"): with self.assertRaisesRegex( GLib.GError, "The 'reiserfsck' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.REISERFS, BlockDev.FSTechMode.CHECK) with self.assertRaisesRegex( GLib.GError, "The 'reiserfsck' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.REISERFS, BlockDev.FSTechMode.REPAIR) # now try without debugreiserfs with utils.fake_path(all_but="debugreiserfs"): with self.assertRaisesRegex( GLib.GError, "The 'debugreiserfs' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.REISERFS, BlockDev.FSTechMode.QUERY) # now try without resize_reiserfs with utils.fake_path(all_but="resize_reiserfs"): with self.assertRaisesRegex( GLib.GError, "The 'resize_reiserfs' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.REISERFS, BlockDev.FSTechMode.RESIZE) # now try without reiserfstune with utils.fake_path(all_but="reiserfstune"): with self.assertRaisesRegex( GLib.GError, "The 'reiserfstune' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.REISERFS, BlockDev.FSTechMode.SET_LABEL) with self.assertRaisesRegex( GLib.GError, "The 'reiserfstune' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.REISERFS, BlockDev.FSTechMode.SET_UUID)
def test_check_no_mkswap(self): """Verify that checking mkswap and swaplabel tools availability works as expected """ # unload all plugins first self.assertTrue(BlockDev.reinit([], True, None)) with fake_path(all_but="mkswap"): # no mkswap available, the swap plugin should fail to load with self.assertRaises(GLib.GError): BlockDev.reinit(None, True, None) self.assertNotIn("swap", BlockDev.get_available_plugin_names()) with fake_path(all_but="swaplabel"): # no swaplabel available, the swap plugin should fail to load with self.assertRaises(GLib.GError): BlockDev.reinit(None, True, None) self.assertNotIn("swap", BlockDev.get_available_plugin_names()) # load the plugins back self.assertTrue(BlockDev.reinit(self.requested_plugins, True, None)) self.assertIn("swap", BlockDev.get_available_plugin_names())
def test_ntfs_available(self): """Verify that it is possible to check ntfs tech availability""" available = BlockDev.fs_is_tech_avail( BlockDev.FSTech.NTFS, BlockDev.FSTechMode.MKFS | BlockDev.FSTechMode.QUERY | BlockDev.FSTechMode.REPAIR | BlockDev.FSTechMode.CHECK | BlockDev.FSTechMode.SET_LABEL | BlockDev.FSTechMode.RESIZE | BlockDev.FSTechMode.SET_UUID) self.assertTrue(available) BlockDev.switch_init_checks(False) BlockDev.reinit(self.requested_plugins, True, None) # now try without mkntfs with utils.fake_path(all_but="mkntfs"): with self.assertRaisesRegex( GLib.GError, "The 'mkntfs' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.NTFS, BlockDev.FSTechMode.MKFS) # now try without ntfsfix with utils.fake_path(all_but="ntfsfix"): with self.assertRaisesRegex( GLib.GError, "The 'ntfsfix' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.NTFS, BlockDev.FSTechMode.CHECK) with self.assertRaisesRegex( GLib.GError, "The 'ntfsfix' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.NTFS, BlockDev.FSTechMode.REPAIR) # now try without ntfscluster with utils.fake_path(all_but="ntfscluster"): with self.assertRaisesRegex( GLib.GError, "The 'ntfscluster' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.NTFS, BlockDev.FSTechMode.QUERY) # now try without ntfsresize with utils.fake_path(all_but="ntfsresize"): with self.assertRaisesRegex( GLib.GError, "The 'ntfsresize' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.NTFS, BlockDev.FSTechMode.RESIZE) # now try without ntfslabel with utils.fake_path(all_but="ntfslabel"): with self.assertRaisesRegex( GLib.GError, "The 'ntfslabel' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.NTFS, BlockDev.FSTechMode.SET_LABEL) with self.assertRaisesRegex( GLib.GError, "The 'ntfslabel' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.NTFS, BlockDev.FSTechMode.SET_UUID)
def test_exfat_available(self): """Verify that it is possible to check exfat tech availability""" available = BlockDev.fs_is_tech_avail( BlockDev.FSTech.EXFAT, BlockDev.FSTechMode.MKFS | BlockDev.FSTechMode.REPAIR | BlockDev.FSTechMode.CHECK | BlockDev.FSTechMode.SET_LABEL) self.assertTrue(available) with six.assertRaisesRegex(self, GLib.GError, "doesn't support setting UUID"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.EXFAT, BlockDev.FSTechMode.SET_UUID) with six.assertRaisesRegex(self, GLib.GError, "doesn't support resizing"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.EXFAT, BlockDev.FSTechMode.RESIZE) BlockDev.switch_init_checks(False) BlockDev.reinit(self.requested_plugins, True, None) # now try without mkfs.exfat with utils.fake_path(all_but="mkfs.exfat"): with six.assertRaisesRegex( self, GLib.GError, "The 'mkfs.exfat' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.EXFAT, BlockDev.FSTechMode.MKFS) # now try without fsck.exfat with utils.fake_path(all_but="fsck.exfat"): with six.assertRaisesRegex( self, GLib.GError, "The 'fsck.exfat' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.EXFAT, BlockDev.FSTechMode.CHECK) with six.assertRaisesRegex( self, GLib.GError, "The 'fsck.exfat' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.EXFAT, BlockDev.FSTechMode.REPAIR) # now try without tune.exfat with utils.fake_path(all_but="tune.exfat"): with six.assertRaisesRegex( self, GLib.GError, "The 'tune.exfat' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.EXFAT, BlockDev.FSTechMode.QUERY) with six.assertRaisesRegex( self, GLib.GError, "The 'tune.exfat' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.EXFAT, BlockDev.FSTechMode.SET_LABEL)
def test_xfs_available(self): """Verify that it is possible to check xfs tech availability""" available = BlockDev.fs_is_tech_avail( BlockDev.FSTech.XFS, BlockDev.FSTechMode.MKFS | BlockDev.FSTechMode.QUERY | BlockDev.FSTechMode.REPAIR | BlockDev.FSTechMode.CHECK | BlockDev.FSTechMode.SET_LABEL | BlockDev.FSTechMode.RESIZE | BlockDev.FSTechMode.SET_UUID) self.assertTrue(available) BlockDev.switch_init_checks(False) BlockDev.reinit(self.requested_plugins, True, None) # now try without mkfs.xfs with utils.fake_path(all_but="mkfs.xfs"): with self.assertRaisesRegex( GLib.GError, "The 'mkfs.xfs' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.XFS, BlockDev.FSTechMode.MKFS) # now try without xfs_db with utils.fake_path(all_but="xfs_db"): with self.assertRaisesRegex( GLib.GError, "The 'xfs_db' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.XFS, BlockDev.FSTechMode.CHECK) # now try without xfs_repair with utils.fake_path(all_but="xfs_repair"): with self.assertRaisesRegex( GLib.GError, "The 'xfs_repair' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.XFS, BlockDev.FSTechMode.REPAIR) # now try without xfs_admin with utils.fake_path(all_but="xfs_admin"): with self.assertRaisesRegex( GLib.GError, "The 'xfs_admin' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.XFS, BlockDev.FSTechMode.QUERY) with self.assertRaisesRegex( GLib.GError, "The 'xfs_admin' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.XFS, BlockDev.FSTechMode.SET_LABEL) with self.assertRaisesRegex( GLib.GError, "The 'xfs_admin' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.XFS, BlockDev.FSTechMode.SET_UUID) # now try without xfs_growfs with utils.fake_path(all_but="xfs_growfs"): with self.assertRaisesRegex( GLib.GError, "The 'xfs_growfs' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.XFS, BlockDev.FSTechMode.RESIZE)
def _test_ext_available(self, tech): available = BlockDev.fs_is_tech_avail( tech, BlockDev.FSTechMode.MKFS | BlockDev.FSTechMode.QUERY | BlockDev.FSTechMode.REPAIR | BlockDev.FSTechMode.CHECK | BlockDev.FSTechMode.SET_LABEL | BlockDev.FSTechMode.RESIZE | BlockDev.FSTechMode.SET_UUID) self.assertTrue(available) BlockDev.switch_init_checks(False) BlockDev.reinit(self.requested_plugins, True, None) # now try without mke2fs with utils.fake_path(all_but="mke2fs"): with six.assertRaisesRegex( self, GLib.GError, "The 'mke2fs' utility is not available"): BlockDev.fs_is_tech_avail(tech, BlockDev.FSTechMode.MKFS) # now try without e2fsck with utils.fake_path(all_but="e2fsck"): with six.assertRaisesRegex( self, GLib.GError, "The 'e2fsck' utility is not available"): BlockDev.fs_is_tech_avail(tech, BlockDev.FSTechMode.CHECK) with six.assertRaisesRegex( self, GLib.GError, "The 'e2fsck' utility is not available"): BlockDev.fs_is_tech_avail(tech, BlockDev.FSTechMode.REPAIR) # now try without dumpe2fs with utils.fake_path(all_but="dumpe2fs"): with six.assertRaisesRegex( self, GLib.GError, "The 'dumpe2fs' utility is not available"): BlockDev.fs_is_tech_avail(tech, BlockDev.FSTechMode.QUERY) # now try without tune2fs with utils.fake_path(all_but="tune2fs"): with six.assertRaisesRegex( self, GLib.GError, "The 'tune2fs' utility is not available"): BlockDev.fs_is_tech_avail(tech, BlockDev.FSTechMode.SET_LABEL) with six.assertRaisesRegex( self, GLib.GError, "The 'tune2fs' utility is not available"): BlockDev.fs_is_tech_avail(tech, BlockDev.FSTechMode.SET_UUID) # now try without resize2fs with utils.fake_path(all_but="resize2fs"): with six.assertRaisesRegex( self, GLib.GError, "The 'resize2fs' utility is not available"): BlockDev.fs_is_tech_avail(tech, BlockDev.FSTechMode.RESIZE)
def test_vfat_available(self): """Verify that it is possible to check vfat tech availability""" available = BlockDev.fs_is_tech_avail( BlockDev.FSTech.VFAT, BlockDev.FSTechMode.MKFS | BlockDev.FSTechMode.QUERY | BlockDev.FSTechMode.REPAIR | BlockDev.FSTechMode.CHECK | BlockDev.FSTechMode.SET_LABEL | BlockDev.FSTechMode.RESIZE) self.assertTrue(available) with self.assertRaisesRegex(GLib.GError, "doesn't support setting UUID"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.VFAT, BlockDev.FSTechMode.SET_UUID) BlockDev.switch_init_checks(False) BlockDev.reinit(self.requested_plugins, True, None) # now try without mkfs.vfat with utils.fake_path(all_but="mkfs.vfat"): with self.assertRaisesRegex( GLib.GError, "The 'mkfs.vfat' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.VFAT, BlockDev.FSTechMode.MKFS) # now try without fsck.vfat with utils.fake_path(all_but="fsck.vfat"): with self.assertRaisesRegex( GLib.GError, "The 'fsck.vfat' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.VFAT, BlockDev.FSTechMode.CHECK) with self.assertRaisesRegex( GLib.GError, "The 'fsck.vfat' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.VFAT, BlockDev.FSTechMode.REPAIR) with self.assertRaisesRegex( GLib.GError, "The 'fsck.vfat' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.VFAT, BlockDev.FSTechMode.QUERY) # now try without fatlabel with utils.fake_path(all_but="fatlabel"): with self.assertRaisesRegex( GLib.GError, "The 'fatlabel' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.VFAT, BlockDev.FSTechMode.SET_LABEL) # now try without vfat-resize with utils.fake_path(all_but="vfat-resize"): with self.assertRaisesRegex( GLib.GError, "The 'vfat-resize' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.VFAT, BlockDev.FSTechMode.RESIZE)
def test_dep_checks_disabled(self): """Verify that disabling runtime dep checks works""" with fake_path(all_but="mkswap"): # should fail because of 'mkswap' missing with self.assertRaises(GLib.GError): BlockDev.reinit(self.requested_plugins, True, None) os.environ["LIBBLOCKDEV_SKIP_DEP_CHECKS"] = "" self.addCleanup(os.environ.pop, "LIBBLOCKDEV_SKIP_DEP_CHECKS") with fake_path(all_but="mkswap"): # should load just fine, skipping the runtime dep checks self.assertTrue(BlockDev.reinit(self.requested_plugins, True, None))
def test_f2fs_available(self): """Verify that it is possible to check f2fs tech availability""" available = BlockDev.fs_is_tech_avail(BlockDev.FSTech.F2FS, BlockDev.FSTechMode.MKFS | BlockDev.FSTechMode.QUERY) self.assertTrue(available) with six.assertRaisesRegex(self, GLib.GError, "doesn't support setting UUID"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.F2FS, BlockDev.FSTechMode.SET_UUID) with six.assertRaisesRegex(self, GLib.GError, "doesn't support setting label"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.F2FS, BlockDev.FSTechMode.SET_LABEL) if self._check_fsck_f2fs_version(): available = BlockDev.fs_is_tech_avail(BlockDev.FSTech.F2FS, BlockDev.FSTechMode.CHECK | BlockDev.FSTechMode.REPAIR) self.assertTrue(available) if self._can_resize_f2fs(): available = BlockDev.fs_is_tech_avail(BlockDev.FSTech.F2FS, BlockDev.FSTechMode.RESIZE) self.assertTrue(available) BlockDev.switch_init_checks(False) BlockDev.reinit(self.requested_plugins, True, None) # now try without mkfs.f2fs with utils.fake_path(all_but="mkfs.f2fs"): with six.assertRaisesRegex(self, GLib.GError, "The 'mkfs.f2fs' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.F2FS, BlockDev.FSTechMode.MKFS) # now try without fsck.f2fs with utils.fake_path(all_but="fsck.f2fs"): with six.assertRaisesRegex(self, GLib.GError, "The 'fsck.f2fs' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.F2FS, BlockDev.FSTechMode.CHECK) with six.assertRaisesRegex(self, GLib.GError, "The 'fsck.f2fs' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.F2FS, BlockDev.FSTechMode.REPAIR) # now try without dump.f2fs with utils.fake_path(all_but="dump.f2fs"): with six.assertRaisesRegex(self, GLib.GError, "The 'dump.f2fs' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.F2FS, BlockDev.FSTechMode.QUERY) # now try without resize.f2fs with utils.fake_path(all_but="resize.f2fs"): with six.assertRaisesRegex(self, GLib.GError, "The 'resize.f2fs' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.F2FS, BlockDev.FSTechMode.RESIZE)
def test_nilfs2_available(self): """Verify that it is possible to check nilfs2 tech availability""" available = BlockDev.fs_is_tech_avail( BlockDev.FSTech.NILFS2, BlockDev.FSTechMode.MKFS | BlockDev.FSTechMode.SET_LABEL | BlockDev.FSTechMode.QUERY | BlockDev.FSTechMode.RESIZE | BlockDev.FSTechMode.SET_UUID) self.assertTrue(available) with six.assertRaisesRegex(self, GLib.GError, "doesn't support filesystem check"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.NILFS2, BlockDev.FSTechMode.CHECK) with six.assertRaisesRegex(self, GLib.GError, "doesn't support filesystem repair"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.NILFS2, BlockDev.FSTechMode.REPAIR) BlockDev.switch_init_checks(False) BlockDev.reinit(self.requested_plugins, True, None) # now try without mkfs.nilfs2 with utils.fake_path(all_but="mkfs.nilfs2"): with six.assertRaisesRegex( self, GLib.GError, "The 'mkfs.nilfs2' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.NILFS2, BlockDev.FSTechMode.MKFS) # now try without nilfs-tune with utils.fake_path(all_but="nilfs-tune"): with six.assertRaisesRegex( self, GLib.GError, "The 'nilfs-tune' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.NILFS2, BlockDev.FSTechMode.QUERY) with six.assertRaisesRegex( self, GLib.GError, "The 'nilfs-tune' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.NILFS2, BlockDev.FSTechMode.SET_LABEL) # now try without nilfs-resize with utils.fake_path(all_but="nilfs-resize"): with six.assertRaisesRegex( self, GLib.GError, "The 'nilfs-resize' utility is not available"): BlockDev.fs_is_tech_avail(BlockDev.FSTech.NILFS2, BlockDev.FSTechMode.RESIZE)
def test_check_tech_available(self): """Verify that runtime checking mkswap and swaplabel tools availability works as expected """ with fake_path(all_but="mkswap"): BlockDev.switch_init_checks(False) BlockDev.reinit(self.requested_plugins, True, None) with self.assertRaises(GLib.GError): # we have swaplabel but not mkswap, so this should fail BlockDev.swap_is_tech_avail( BlockDev.SwapTech.SWAP_TECH_SWAP, BlockDev.SwapTechMode.CREATE | BlockDev.SwapTechMode.SET_LABEL) with self.assertRaises(GLib.GError): # we have swaplabel but not mkswap, so this should fail BlockDev.swap_is_tech_avail(BlockDev.SwapTech.SWAP_TECH_SWAP, BlockDev.SwapTechMode.CREATE) # only label checked -- should pass succ = BlockDev.swap_is_tech_avail( BlockDev.SwapTech.SWAP_TECH_SWAP, BlockDev.SwapTechMode.SET_LABEL) self.assertTrue(succ) with fake_path(all_but="swaplabel"): BlockDev.switch_init_checks(False) BlockDev.reinit(self.requested_plugins, True, None) with self.assertRaises(GLib.GError): # we have mkswap but not swaplabel, so this should fail BlockDev.swap_is_tech_avail( BlockDev.SwapTech.SWAP_TECH_SWAP, BlockDev.SwapTechMode.CREATE | BlockDev.SwapTechMode.SET_LABEL) with self.assertRaises(GLib.GError): # we have mkswap but not swaplabel, so this should fail BlockDev.swap_is_tech_avail(BlockDev.SwapTech.SWAP_TECH_SWAP, BlockDev.SwapTechMode.SET_LABEL) # only label checked -- should pass succ = BlockDev.swap_is_tech_avail( BlockDev.SwapTech.SWAP_TECH_SWAP, BlockDev.SwapTechMode.CREATE) self.assertTrue(succ)
def test_check_tech_available(self): """Verify that runtime checking mkswap and swaplabel tools availability works as expected """ with fake_path(all_but="mkswap"): BlockDev.switch_init_checks(False) BlockDev.reinit(self.requested_plugins, True, None) with self.assertRaises(GLib.GError): # we have swaplabel but not mkswap, so this should fail BlockDev.swap_is_tech_avail(BlockDev.SwapTech.SWAP_TECH_SWAP, BlockDev.SwapTechMode.CREATE | BlockDev.SwapTechMode.SET_LABEL) with self.assertRaises(GLib.GError): # we have swaplabel but not mkswap, so this should fail BlockDev.swap_is_tech_avail(BlockDev.SwapTech.SWAP_TECH_SWAP, BlockDev.SwapTechMode.CREATE) # only label checked -- should pass succ = BlockDev.swap_is_tech_avail(BlockDev.SwapTech.SWAP_TECH_SWAP, BlockDev.SwapTechMode.SET_LABEL) self.assertTrue(succ) with fake_path(all_but="swaplabel"): BlockDev.switch_init_checks(False) BlockDev.reinit(self.requested_plugins, True, None) with self.assertRaises(GLib.GError): # we have mkswap but not swaplabel, so this should fail BlockDev.swap_is_tech_avail(BlockDev.SwapTech.SWAP_TECH_SWAP, BlockDev.SwapTechMode.CREATE | BlockDev.SwapTechMode.SET_LABEL) with self.assertRaises(GLib.GError): # we have mkswap but not swaplabel, so this should fail BlockDev.swap_is_tech_avail(BlockDev.SwapTech.SWAP_TECH_SWAP, BlockDev.SwapTechMode.SET_LABEL) # only label checked -- should pass succ = BlockDev.swap_is_tech_avail(BlockDev.SwapTech.SWAP_TECH_SWAP, BlockDev.SwapTechMode.CREATE) self.assertTrue(succ)
def test_try_reinit(self): """Verify that try_reinit() works as expected""" # try reinitializing with only some utilities being available and thus # only some plugins able to load with fake_path("tests/lib_missing_utils", keep_utils=["swapon", "swapoff", "mkswap", "lvm", "btrfs"]): succ, loaded = BlockDev.try_reinit(None, True, None) self.assertFalse(succ) for plug_name in ("swap", "lvm", "btrfs"): self.assertIn(plug_name, loaded) # reset back to all plugins self.assertTrue(BlockDev.reinit(None, True, None)) # now the same with a subset of plugins requested plugins = BlockDev.plugin_specs_from_names(["btrfs", "lvm", "swap"]) with fake_path("tests/lib_missing_utils", keep_utils=["swapon", "swapoff", "mkswap", "lvm", "btrfs"]): succ, loaded = BlockDev.try_reinit(plugins, True, None) self.assertTrue(succ) self.assertEqual(set(loaded), set(["swap", "lvm", "btrfs"]))
def test_check_no_dasdfmt(self): """Verify that checking dasdfmt tool availability works as expected""" # unload all plugins first self.assertTrue(BlockDev.reinit([], True, None)) with fake_path(): # dasdfmt is not available, so the s390 plugin should fail to load with self.assertRaises(GLib.GError): BlockDev.reinit(None, True, None) self.assertNotIn("s390", BlockDev.get_available_plugin_names())
def test_check_no_bcache_progs(self): """Verify that checking the availability of make-bcache works as expected""" # unload all plugins first self.assertTrue(BlockDev.reinit([], True, None)) with fake_path(all_but="make-bcache"): with self.assertRaises(GLib.GError): BlockDev.reinit(self.requested_plugins, True, None) self.assertNotIn("kbd", BlockDev.get_available_plugin_names()) # load the plugins back self.assertTrue(BlockDev.reinit(self.requested_plugins, True, None)) self.assertIn("kbd", BlockDev.get_available_plugin_names())
def test_check_no_bcache_progs(self): """Verify that checking the availability of make-bcache works as expected""" # unload all plugins first self.assertTrue(BlockDev.reinit([], True, None)) with fake_path(): with self.assertRaises(GLib.GError): BlockDev.reinit(None, True, None) self.assertNotIn("kbd", BlockDev.get_available_plugin_names()) # load the plugins back self.assertTrue(BlockDev.reinit(None, True, None)) self.assertIn("kbd", BlockDev.get_available_plugin_names())
def test_check_no_dm(self): """Verify that checking dmsetup tool availability works as expected""" # unload all plugins first self.assertTrue(BlockDev.reinit([], True, None)) with fake_path(): # no dmsetup available, the DM plugin should fail to load with self.assertRaises(GLib.GError): BlockDev.reinit(None, True, None) self.assertNotIn("dm", BlockDev.get_available_plugin_names()) # load the plugins back self.assertTrue(BlockDev.reinit(None, True, None)) self.assertIn("dm", BlockDev.get_available_plugin_names())
def test_check_no_mpathconf(self): """Verify that checking mpathconf tool availability works as expected""" # unload all plugins first self.assertTrue(BlockDev.reinit([], True, None)) with fake_path("tests/mpath_no_mpathconf", keep_utils=["cat"]): # no mpathconf available, the mpath plugin should fail to load with self.assertRaises(GLib.GError): BlockDev.reinit(None, True, None) self.assertNotIn("mpath", BlockDev.get_available_plugin_names()) # load the plugins back self.assertTrue(BlockDev.reinit(None, True, None)) self.assertIn("mpath", BlockDev.get_available_plugin_names())
def test_check_no_ndctl(self): """Verify that checking ndctl tool availability works as expected""" # unload all plugins first self.assertTrue(BlockDev.reinit([], True, None)) with fake_path(all_but="ndctl"): # no ndctl tool available, the NVDIMM plugin should fail to load with self.assertRaises(GLib.GError): BlockDev.reinit(self.requested_plugins, True, None) self.assertNotIn("nvdimm", BlockDev.get_available_plugin_names()) # load the plugins back self.assertTrue(BlockDev.reinit(self.requested_plugins, True, None)) self.assertIn("nvdimm", BlockDev.get_available_plugin_names())
def test_check_no_dm(self): """Verify that checking dmsetup tool availability works as expected""" # unload all plugins first self.assertTrue(BlockDev.reinit([], True, None)) with fake_path(all_but="dmsetup"): # no dmsetup available, the DM plugin should fail to load with self.assertRaises(GLib.GError): BlockDev.reinit(self.requested_plugins, True, None) self.assertNotIn("dm", BlockDev.get_available_plugin_names()) # load the plugins back self.assertTrue(BlockDev.reinit(self.requested_plugins, True, None)) self.assertIn("dm", BlockDev.get_available_plugin_names())
def test_check_no_swapoff(self): """Verify that checking swapoff tool availability works as expected""" # unload all plugins first self.assertTrue(BlockDev.reinit([], True, None)) with fake_path("tests/swap_no_swapoff", keep_utils=["cat"]): # no mkswap available, the swap plugin should fail to load with self.assertRaises(GLib.GError): BlockDev.reinit(None, True, None) self.assertNotIn("swap", BlockDev.get_available_plugin_names()) # load the plugins back self.assertTrue(BlockDev.reinit(None, True, None)) self.assertIn("swap", BlockDev.get_available_plugin_names())
def test_check_no_btrfs(self): """Verify that checking btrfs tool availability works as expected""" # unload all plugins first self.assertTrue(BlockDev.reinit([], True, None)) with fake_path(): # no btrfs tool available, the BTRFS plugin should fail to load with self.assertRaises(GLib.GError): BlockDev.reinit(None, True, None) self.assertNotIn("btrfs", BlockDev.get_available_plugin_names()) # load the plugins back self.assertTrue(BlockDev.reinit(None, True, None)) self.assertIn("btrfs", BlockDev.get_available_plugin_names())
def test_check_no_md(self): """Verify that checking mdsetup tool availability works as expected""" # unload all plugins first self.assertTrue(BlockDev.reinit([], True, None)) with fake_path(all_but="mdadm"): # no mdadm available, the MD plugin should fail to load with self.assertRaises(GLib.GError): BlockDev.reinit(self.requested_plugins, True, None) self.assertNotIn("mdraid", BlockDev.get_available_plugin_names()) # load the plugins back self.assertTrue(BlockDev.reinit(self.requested_plugins, True, None)) self.assertIn("mdraid", BlockDev.get_available_plugin_names())
def test_check_no_mkswap_runtime(self): """Verify that runtime checking mkswap tool availability works as expected""" # unload all plugins first self.assertTrue(BlockDev.reinit([], True, None)) # make sure the initial checks during plugin loading are skipped BlockDev.switch_init_checks(False) self.addCleanup(BlockDev.switch_init_checks, True) with fake_path(all_but="mkswap"): # no mkswap available, but checks disabled, the swap plugin should load just fine self.assertTrue(BlockDev.reinit(self.requested_plugins, True, None)) self.assertIn("swap", BlockDev.get_available_plugin_names()) with self.assertRaisesRegexp(GLib.GError, "The 'mkswap' utility is not available"): # the device shouldn't matter, the function should return an # error before any other checks or actions BlockDev.swap_mkswap("/dev/device", "LABEL", None)