diff --git a/tests/_lvm_cases.py b/tests/_lvm_cases.py index 770d37ff8..b8ebc86c6 100644 --- a/tests/_lvm_cases.py +++ b/tests/_lvm_cases.py @@ -1347,7 +1347,7 @@ def test_thinpool_cache_get_stats(self): self.assertEqual(stats.md_size, 8 * 1024**2) self.assertEqual(stats.mode, BlockDev.LVMCacheMode.WRITETHROUGH) - def test_vgtags(self): + def test_lvtags(self): """Verify that it's possible to set and get info about LV tags""" succ = BlockDev.lvm_pvcreate(self.loop_dev, 0, 0, None) @@ -1618,7 +1618,7 @@ def test_lvs_all(self): # there should be at least 3 LVs -- testPool, [testPool_tdata], [testPool_tmeta] (plus probably some spare LVs) lvs = BlockDev.lvm_lvs("testVG") - self.assertGreater(len(lvs), 3) + self.assertGreaterEqual(len(lvs), 3) @tag_test(TestTags.CORE) def test_thpoolcreate(self): @@ -1937,8 +1937,8 @@ def setUpClass(cls): if "File exists" not in e.message: raise unittest.SkipTest("cannot load VDO kernel module, skipping.") - if LVM_VERSION < Version("2.3.07"): - raise unittest.SkipTest("LVM version 2.3.07 or newer needed for LVM VDO.") + if LVM_VERSION < Version("2.03.07"): + raise unittest.SkipTest("LVM version 2.03.07 or newer needed for LVM VDO.") if not shutil.which("vdoformat"): raise unittest.SkipTest("vdoformat executable not found in $PATH, skipping.") diff --git a/tests/btrfs_test.py b/tests/btrfs_test.py index 9fc3e6d15..da3d1f39a 100644 --- a/tests/btrfs_test.py +++ b/tests/btrfs_test.py @@ -33,7 +33,7 @@ def setUpClass(cls): raise unittest.SkipTest('Btrfs kernel module not available, skipping.') if not shutil.which("btrfs"): - raise unittest.SkipTest("btrfs executable not foundin $PATH, skipping.") + raise unittest.SkipTest("btrfs executable not found in $PATH, skipping.") if not BlockDev.is_initialized(): BlockDev.init(cls.requested_plugins, None) diff --git a/tests/crypto_test.py b/tests/crypto_test.py index 0c9eba765..32ba07e04 100644 --- a/tests/crypto_test.py +++ b/tests/crypto_test.py @@ -80,13 +80,15 @@ def _clean_up(self): except: pass - for i in range(self._num_devices): + for dev in self.loop_devs: try: - delete_lio_device(self.loop_devs[i]) + delete_lio_device(dev) except RuntimeError: # just move on, we can do no better here pass - os.unlink(self.dev_files[i]) + + for dev_file in self.dev_files: + os.unlink(dev_file) os.unlink(self.keyfile) @@ -230,7 +232,7 @@ def test_luks2_format(self): succ = BlockDev.crypto_luks_format(self.loop_devs[0], "aes-xts-plain64", 0, pw_ctx, 0) self.assertTrue(succ) - # create with a keyfile + # create with a passphrase context kf_ctx = BlockDev.CryptoKeyslotContext(passphrase=PASSWD) succ = BlockDev.crypto_luks_format(self.loop_devs[0], "aes-xts-plain64", 0, kf_ctx, 0) self.assertTrue(succ) @@ -291,7 +293,6 @@ def test_luks1_format_pbkdf_options(self): with self.assertRaisesRegex(GLib.GError, "Invalid pbkdf specified"): BlockDev.crypto_luks_format(self.loop_devs[0], "aes-xts-plain64", 0, ctx, 0, BlockDev.CryptoLUKSVersion.LUKS1, extra) - self.assertTrue(succ) @tag_test(TestTags.SLOW, TestTags.CORE) def test_luks2_format_pbkdf_options(self): @@ -622,7 +623,7 @@ class CryptoTestErrorLocale(CryptoTestCase): def setUp(self): self._orig_loc = None CryptoTestCase.setUp(self) - self._orig_loc = ".".join(locale.getdefaultlocale()) + self._orig_loc = locale.setlocale(locale.LC_ALL) def _clean_up(self): CryptoTestCase._clean_up(self) @@ -1472,7 +1473,7 @@ def _verify_token_info (self, info): self.assertEqual(info[0].keyslot, 0) @tag_test(TestTags.SLOW) - def test_luks2_integrity(self): + def test_luks2_token_info(self): """Verify that we can get information about LUKS2 tokens""" # the simple case with password diff --git a/tests/fs_tests/btrfs_test.py b/tests/fs_tests/btrfs_test.py index d98b1404c..2f621279e 100644 --- a/tests/fs_tests/btrfs_test.py +++ b/tests/fs_tests/btrfs_test.py @@ -37,7 +37,7 @@ def test_btrfs_features(self): self.assertIsNotNone(features) self.assertTrue(features.resize & BlockDev.FSResizeFlags.ONLINE_GROW) - self.assertTrue(features.resize & BlockDev.FSResizeFlags.ONLINE_GROW) + self.assertTrue(features.resize & BlockDev.FSResizeFlags.ONLINE_SHRINK) self.assertTrue(features.mkfs & BlockDev.FSMkfsOptionsFlags.LABEL) self.assertTrue(features.mkfs & BlockDev.FSMkfsOptionsFlags.UUID) diff --git a/tests/fs_tests/exfat_test.py b/tests/fs_tests/exfat_test.py index cc8f5c6ac..48a9db481 100644 --- a/tests/fs_tests/exfat_test.py +++ b/tests/fs_tests/exfat_test.py @@ -4,7 +4,6 @@ import overrides_hack import utils -from utils import TestTags, tag_test from gi.repository import BlockDev, GLib @@ -19,11 +18,11 @@ def setUp(self): class ExfatTestCase(FSTestCase): def setUp(self): - super(ExfatTestCase, self).setUp() - if not self.exfat_avail: self.skipTest("skipping exFAT: not available") + super(ExfatTestCase, self).setUp() + self.mount_dir = tempfile.mkdtemp(prefix="libblockdev.", suffix="exfat_test") diff --git a/tests/fs_tests/ext_test.py b/tests/fs_tests/ext_test.py index b0195ece2..a6d981aeb 100644 --- a/tests/fs_tests/ext_test.py +++ b/tests/fs_tests/ext_test.py @@ -248,10 +248,10 @@ def _test_ext_get_info(self, mkfs_function, info_function): self.assertEqual(fi.label, "") # should be an non-empty string self.assertTrue(fi.uuid) - self.assertTrue(fi.state, "clean") + self.assertTrue(fi.state) with mounted(self.loop_devs[0], self.mount_dir): - fi = BlockDev.fs_ext4_get_info(self.loop_devs[0]) + fi = info_function(self.loop_devs[0]) self.assertEqual(fi.block_size, 1024) self.assertEqual(fi.block_count, self.loop_size / 1024) # at least 50 % should be available, so it should be reported @@ -259,7 +259,7 @@ def _test_ext_get_info(self, mkfs_function, info_function): self.assertEqual(fi.label, "") # should be an non-empty string self.assertTrue(fi.uuid) - self.assertTrue(fi.state, "clean") + self.assertTrue(fi.state) @tag_test(TestTags.CORE) def test_ext2_get_info(self): @@ -409,33 +409,33 @@ class ExtSetUUID(ExtTestCase): test_uuid = "4d7086c4-a4d3-432f-819e-73da03870df9" - def _test_ext_set_uuid(self, mkfs_function, info_function, label_function, check_function): + def _test_ext_set_uuid(self, mkfs_function, info_function, uuid_function, check_function): succ = mkfs_function(self.loop_devs[0], None) self.assertTrue(succ) fi = info_function(self.loop_devs[0]) self.assertTrue(fi) - succ = label_function(self.loop_devs[0], self.test_uuid) + succ = uuid_function(self.loop_devs[0], self.test_uuid) self.assertTrue(succ) fi = info_function(self.loop_devs[0]) self.assertTrue(fi) self.assertEqual(fi.uuid, self.test_uuid) - succ = label_function(self.loop_devs[0], "clear") + succ = uuid_function(self.loop_devs[0], "clear") self.assertTrue(succ) fi = info_function(self.loop_devs[0]) self.assertTrue(fi) self.assertEqual(fi.uuid, "") - succ = label_function(self.loop_devs[0], "random") + succ = uuid_function(self.loop_devs[0], "random") self.assertTrue(succ) fi = info_function(self.loop_devs[0]) self.assertTrue(fi) self.assertNotEqual(fi.uuid, "") random_uuid = fi.uuid - succ = label_function(self.loop_devs[0], "time") + succ = uuid_function(self.loop_devs[0], "time") self.assertTrue(succ) fi = info_function(self.loop_devs[0]) self.assertTrue(fi) @@ -444,7 +444,7 @@ def _test_ext_set_uuid(self, mkfs_function, info_function, label_function, check time_uuid = fi.uuid # no UUID -> random - succ = label_function(self.loop_devs[0], None) + succ = uuid_function(self.loop_devs[0], None) self.assertTrue(succ) fi = info_function(self.loop_devs[0]) self.assertTrue(fi) @@ -461,19 +461,19 @@ def test_ext2_set_uuid(self): """Verify that it is possible to set UUID of an ext2 file system""" self._test_ext_set_uuid(mkfs_function=BlockDev.fs_ext2_mkfs, info_function=BlockDev.fs_ext2_get_info, - label_function=BlockDev.fs_ext2_set_uuid, + uuid_function=BlockDev.fs_ext2_set_uuid, check_function=BlockDev.fs_ext2_check_uuid) def test_ext3_set_uuid(self): """Verify that it is possible to set UUID of an ext3 file system""" self._test_ext_set_uuid(mkfs_function=BlockDev.fs_ext3_mkfs, info_function=BlockDev.fs_ext3_get_info, - label_function=BlockDev.fs_ext3_set_uuid, + uuid_function=BlockDev.fs_ext3_set_uuid, check_function=BlockDev.fs_ext3_check_uuid) def test_ext4_set_uuid(self): """Verify that it is possible to set UUID of an ext4 file system""" self._test_ext_set_uuid(mkfs_function=BlockDev.fs_ext4_mkfs, info_function=BlockDev.fs_ext4_get_info, - label_function=BlockDev.fs_ext4_set_uuid, + uuid_function=BlockDev.fs_ext4_set_uuid, check_function=BlockDev.fs_ext4_check_uuid) diff --git a/tests/fs_tests/f2fs_test.py b/tests/fs_tests/f2fs_test.py index b09eceeb3..2d6f328bb 100644 --- a/tests/fs_tests/f2fs_test.py +++ b/tests/fs_tests/f2fs_test.py @@ -238,15 +238,15 @@ def test_f2fs_resize(self): # shrink without the safe option -- should fail with self.assertRaises(GLib.GError): - BlockDev.fs_f2fs_resize(self.loop_devs[0], 100 * 1024**2 / 512, False) + BlockDev.fs_f2fs_resize(self.loop_devs[0], 100 * 1024**2 // 512, False) # if we can't shrink we'll just check it returns some sane error if not _can_resize_f2fs(): with self.assertRaisesRegex(GLib.GError, "Too low version of resize.f2fs. At least 1.12.0 required."): - BlockDev.fs_f2fs_resize(self.loop_devs[0], 100 * 1024**2 / 512, True) + BlockDev.fs_f2fs_resize(self.loop_devs[0], 100 * 1024**2 // 512, True) return - succ = BlockDev.fs_f2fs_resize(self.loop_devs[0], 100 * 1024**2 / 512, True) + succ = BlockDev.fs_f2fs_resize(self.loop_devs[0], 100 * 1024**2 // 512, True) self.assertTrue(succ) fi = BlockDev.fs_f2fs_get_info(self.loop_devs[0]) @@ -258,14 +258,14 @@ def test_f2fs_resize(self): self.assertEqual(fi.sector_count * fi.sector_size, 100 * 1024**2) # grow - succ = BlockDev.fs_f2fs_resize(self.loop_devs[0], 120 * 1024**2 / 512, True) + succ = BlockDev.fs_f2fs_resize(self.loop_devs[0], 120 * 1024**2 // 512, True) self.assertTrue(succ) fi = BlockDev.fs_f2fs_get_info(self.loop_devs[0]) self.assertEqual(fi.sector_count * fi.sector_size, 120 * 1024**2) # shrink again - succ = BlockDev.fs_f2fs_resize(self.loop_devs[0], 100 * 1024**2 / 512, True) + succ = BlockDev.fs_f2fs_resize(self.loop_devs[0], 100 * 1024**2 // 512, True) self.assertTrue(succ) fi = BlockDev.fs_f2fs_get_info(self.loop_devs[0]) diff --git a/tests/fs_tests/fs_test.py b/tests/fs_tests/fs_test.py index 2a8b8b5d6..e49873f0c 100644 --- a/tests/fs_tests/fs_test.py +++ b/tests/fs_tests/fs_test.py @@ -116,7 +116,7 @@ def setUp(self): self.addCleanup(self._clean_up) for i in range(self.num_devices): - dev_file = utils.create_sparse_tempfile("crypto_test", self.loop_size) + dev_file = utils.create_sparse_tempfile("fs_test", self.loop_size) self.dev_files.append(dev_file) try: @@ -131,13 +131,15 @@ def _clean_up(self): except: pass - for i in range(self.num_devices): + for dev in self.loop_devs: try: - utils.delete_lio_device(self.loop_devs[i]) + utils.delete_lio_device(dev) except RuntimeError: # just move on, we can do no better here pass - os.unlink(self.dev_files[i]) + + for dev_file in self.dev_files: + os.unlink(dev_file) self.dev_files.clear() self.loop_devs.clear() @@ -175,7 +177,6 @@ def _setup_lvm(self, vgname, lvname, lvsize="50M"): ret, _out, err = utils.run_command("lvcreate -n %s -L%s %s --config \"devices {use_devicesfile = 0}\"" % (lvname, lvsize, vgname)) if ret != 0: - import pdb; pdb.set_trace() raise RuntimeError("Failed to create LV for fs tests: %s" % err) return "/dev/%s/%s" % (vgname, lvname) diff --git a/tests/fs_tests/generic_test.py b/tests/fs_tests/generic_test.py index c08d03caa..f4ea37608 100644 --- a/tests/fs_tests/generic_test.py +++ b/tests/fs_tests/generic_test.py @@ -673,7 +673,7 @@ def test_ext4_progress_check(self): succ = BlockDev.utils_init_prog_reporting(None) def test_xfs_generic_check(self): - """Test generic check function with an ext4 file system""" + """Test generic check function with an xfs file system""" self._test_generic_check(mkfs_function=BlockDev.fs_xfs_mkfs, fstype="xfs") def test_ntfs_generic_check(self): @@ -1097,7 +1097,7 @@ def _test_xfs_generic_resize(self, mount): succ = BlockDev.fs_resize(lv, 40 * 1024**2) self._lvresize("libbd_fs_tests", "generic_test", "380M") - # should grow to 375 MiB (full size of the LV) + # should grow to 380 MiB (full size of the LV) if mount: with mounted(lv, self.mount_dir): succ = BlockDev.fs_resize(lv, 0) @@ -1304,25 +1304,25 @@ def _test_get_free_space(self, mkfs_function, fstype, size_delta=0): self.assertLessEqual(free, size) def test_ext2_get_free_space(self): - """Test generic resize function with an ext2 file system""" + """Test generic get_free_space function with an ext2 file system""" self._test_get_free_space(mkfs_function=BlockDev.fs_ext2_mkfs, fstype="ext2") def test_ext3_check_get_free_space(self): - """Test generic resize function with an ext3 file system""" + """Test generic get_free_space function with an ext3 file system""" self._test_get_free_space(mkfs_function=BlockDev.fs_ext3_mkfs, fstype="ext3") def test_ext4_get_free_space(self): - """Test generic resize function with an ext4 file system""" + """Test generic get_free_space function with an ext4 file system""" self._test_get_free_space(mkfs_function=BlockDev.fs_ext4_mkfs, fstype="ext4") def test_ntfs_get_free_space(self): - """Test generic resize function with an ntfs file system""" + """Test generic get_free_space function with an ntfs file system""" if not self.ntfs_avail: self.skipTest("skipping NTFS: not available") self._test_get_free_space(mkfs_function=BlockDev.fs_ntfs_mkfs, fstype="ntfs") def test_vfat_get_free_space(self): - """Test generic resize function with a vfat file system""" + """Test generic get_free_space function with a vfat file system""" def mkfs_vfat(device, options=None): if self._vfat_version >= Version("4.2"): if options: @@ -1335,19 +1335,19 @@ def mkfs_vfat(device, options=None): self._test_get_free_space(mkfs_function=mkfs_vfat, fstype="vfat") def test_nilfs2_get_free_space(self): - """Test generic resize function with an nilfs2 file system""" + """Test generic get_free_space function with an nilfs2 file system""" if not self.nilfs2_avail: self.skipTest("skipping NILFS2: not available") self._test_get_free_space(mkfs_function=BlockDev.fs_nilfs2_mkfs, fstype="nilfs2") def test_btrfs_get_free_space(self): - """Test generic resize function with an btrfs file system""" + """Test generic get_free_space function with a btrfs file system""" if not self.btrfs_avail: self.skipTest("skipping Btrfs: not available") self._test_get_free_space(mkfs_function=BlockDev.fs_btrfs_mkfs, fstype="btrfs") def test_udf_get_free_space(self): - """Test generic resize function with an udf file system""" + """Test generic get_free_space function with a udf file system""" if not self.udf_avail: self.skipTest("skipping UDF: not available") diff --git a/tests/fs_tests/mount_test.py b/tests/fs_tests/mount_test.py index a72f7148d..478b83469 100644 --- a/tests/fs_tests/mount_test.py +++ b/tests/fs_tests/mount_test.py @@ -120,7 +120,7 @@ def test_mount_ro_device(self): loop_dev = "/dev/" + dev # without any options, the mount should fall back to RO self.assertTrue(BlockDev.fs_mount(loop_dev, tmp_dir, None, None, None)) - self.addCleanup(utils.umount, dev) + self.addCleanup(utils.umount, loop_dev) self.assertTrue(os.path.ismount(tmp_dir)) succ = BlockDev.fs_unmount(tmp_dir, False, False, None) diff --git a/tests/fs_tests/nilfs_test.py b/tests/fs_tests/nilfs_test.py index eaac6a300..d73f5e238 100644 --- a/tests/fs_tests/nilfs_test.py +++ b/tests/fs_tests/nilfs_test.py @@ -4,7 +4,6 @@ import overrides_hack import utils -from utils import TestTags, tag_test from gi.repository import BlockDev, GLib @@ -68,7 +67,7 @@ def test_nilfs2_available(self): class NILFS2TestFeatures(NILFS2NoDevTestCase): - def test_vfat_features(self): + def test_nilfs2_features(self): features = BlockDev.fs_features("nilfs2") self.assertIsNotNone(features) diff --git a/tests/fs_tests/ntfs_test.py b/tests/fs_tests/ntfs_test.py index 55234bff2..fd3b74f85 100644 --- a/tests/fs_tests/ntfs_test.py +++ b/tests/fs_tests/ntfs_test.py @@ -4,7 +4,6 @@ from .fs_test import FSTestCase, FSNoDevTestCase, mounted import utils -from utils import TestTags, tag_test from gi.repository import BlockDev, GLib diff --git a/tests/fs_tests/udf_test.py b/tests/fs_tests/udf_test.py index 0a2109f7e..f449ec173 100644 --- a/tests/fs_tests/udf_test.py +++ b/tests/fs_tests/udf_test.py @@ -4,7 +4,6 @@ import overrides_hack import utils -from utils import TestTags, tag_test from gi.repository import BlockDev, GLib diff --git a/tests/fs_tests/vfat_test.py b/tests/fs_tests/vfat_test.py index 744c12d68..ea093b94f 100644 --- a/tests/fs_tests/vfat_test.py +++ b/tests/fs_tests/vfat_test.py @@ -7,7 +7,6 @@ import overrides_hack import utils -from utils import TestTags, tag_test from gi.repository import BlockDev, GLib diff --git a/tests/fs_tests/xfs_test.py b/tests/fs_tests/xfs_test.py index 7a8e97c95..13a4a8f28 100644 --- a/tests/fs_tests/xfs_test.py +++ b/tests/fs_tests/xfs_test.py @@ -252,7 +252,7 @@ def test_xfs_resize(self): if xfs_version < Version("5.12"): with mounted(lv, self.mount_dir): with self.assertRaises(GLib.GError): - succ = BlockDev.fs_xfs_resize(self.mount_dir, 40 * 1024**2 / fi.block_size, None) + succ = BlockDev.fs_xfs_resize(self.mount_dir, 40 * 1024**2 // fi.block_size, None) self._lvresize("libbd_fs_tests", "xfs_test", "400M") # should grow to 400 MiB (full size of the LV) @@ -267,7 +267,7 @@ def test_xfs_resize(self): self._lvresize("libbd_fs_tests", "xfs_test", "450M") # grow just to 430 MiB with mounted(lv, self.mount_dir): - succ = BlockDev.fs_xfs_resize(self.mount_dir, 430 * 1024**2 / fi.block_size, None) + succ = BlockDev.fs_xfs_resize(self.mount_dir, 430 * 1024**2 // fi.block_size, None) self.assertTrue(succ) with mounted(lv, self.mount_dir): fi = BlockDev.fs_xfs_get_info(lv) diff --git a/tests/library_test.py b/tests/library_test.py index c12967985..6fd68035c 100644 --- a/tests/library_test.py +++ b/tests/library_test.py @@ -2,7 +2,7 @@ import unittest import re import overrides_hack -from utils import fake_path, TestTags, tag_test, required_plugins +from utils import TestTags, tag_test, required_plugins import gi gi.require_version('GLib', '2.0') @@ -169,7 +169,7 @@ def test_non_en_init(self): """Verify that the library initializes with lang different from en_US""" orig_lang = os.environ.get("LANG") - os.environ["LANG"] = "cs.CZ_UTF-8" + os.environ["LANG"] = "cs_CZ.UTF-8" self.assertTrue(BlockDev.reinit(self.requested_plugins, True, None)) if orig_lang: os.environ["LANG"] = orig_lang diff --git a/tests/lvm_dbus_tests.py b/tests/lvm_dbus_tests.py index 1cf98ec90..4c43c9cf1 100644 --- a/tests/lvm_dbus_tests.py +++ b/tests/lvm_dbus_tests.py @@ -129,10 +129,10 @@ def setUpClass(cls): LvmDBusTestCase.setUpClass() -class LvmDBusTestLVcreateType(_lvm_cases.LvmPVVGLVTestCase, LvmDBusTestCase): +class LvmDBusTestLVcreateType(_lvm_cases.LvmTestLVcreateType, LvmDBusTestCase): @classmethod def setUpClass(cls): - _lvm_cases.LvmPVVGLVTestCase.setUpClass() + _lvm_cases.LvmTestLVcreateType.setUpClass() LvmDBusTestCase.setUpClass() diff --git a/tests/lvm_test.py b/tests/lvm_test.py index bce1ffd5f..f59fa4f70 100644 --- a/tests/lvm_test.py +++ b/tests/lvm_test.py @@ -104,10 +104,10 @@ def setUpClass(cls): LvmTestCase.setUpClass() -class LvmCLITestLVcreateType(_lvm_cases.LvmPVVGLVTestCase, LvmTestCase): +class LvmCLITestLVcreateType(_lvm_cases.LvmTestLVcreateType, LvmTestCase): @classmethod def setUpClass(cls): - _lvm_cases.LvmPVVGLVTestCase.setUpClass() + _lvm_cases.LvmTestLVcreateType.setUpClass() LvmTestCase.setUpClass() diff --git a/tests/mdraid_test.py b/tests/mdraid_test.py index ca5794ac2..a00ebccd9 100644 --- a/tests/mdraid_test.py +++ b/tests/mdraid_test.py @@ -121,9 +121,9 @@ def _clean_up(self): except: pass - for i in range(self._num_devices): + for dev in self.loop_devs: try: - BlockDev.md_destroy(self.loop_devs[i]) + BlockDev.md_destroy(dev) except: pass @@ -136,13 +136,15 @@ def _clean_up(self): except: pass - for i in range(self._num_devices): + for dev in self.loop_devs: try: - delete_lio_device(self.loop_devs[i]) + delete_lio_device(dev) except RuntimeError: # just move on, we can do no better here pass - os.unlink(self.dev_files[i]) + + for dev_file in self.dev_files: + os.unlink(dev_file) self.dev_files.clear() self.loop_devs.clear() diff --git a/tests/mpath_test.py b/tests/mpath_test.py index b9db34b4c..91147f7d8 100644 --- a/tests/mpath_test.py +++ b/tests/mpath_test.py @@ -46,7 +46,7 @@ def test_is_mpath_member(self): # just test that some non-mpath is not reported as a multipath member # device and no error is reported - self.assertFalse(BlockDev.mpath_is_mpath_member("/dev/loop0")) + self.assertFalse(BlockDev.mpath_is_mpath_member(self.loop_dev)) def test_flush_mpaths(self): """ Verify that mpath_flush_mpaths can be called """ diff --git a/tests/nvdimm_test.py b/tests/nvdimm_test.py index 281ca8336..93f4ce879 100644 --- a/tests/nvdimm_test.py +++ b/tests/nvdimm_test.py @@ -63,7 +63,7 @@ def setUp(self): # get the dict for the first nvdimm device self.sys_info = self.sys_info[0] - # skip the tests if the nvdimm is a 'fake' one + # skip the tests if the nvdimm is not a 'fake' one cmdline = read_file("/proc/cmdline") if "memmap=" not in cmdline: self.skipTest("NVDIMM device found, but not created by the 'memmap' kernel command-line option.") diff --git a/tests/part_test.py b/tests/part_test.py index 8f3ad5eae..ef99a13fa 100644 --- a/tests/part_test.py +++ b/tests/part_test.py @@ -55,13 +55,15 @@ def setUp(self): raise RuntimeError("Failed to setup loop device for testing: %s" % e) def _clean_up(self): - for i in range(self._num_devices): + for dev in self.loop_devs: try: - delete_lio_device(self.loop_devs[i]) + delete_lio_device(dev) except RuntimeError: # just move on, we can do no better here pass - os.unlink(self.dev_files[i]) + + for dev_file in self.dev_files: + os.unlink(dev_file) self.dev_files.clear() self.loop_devs.clear() @@ -687,7 +689,7 @@ def test_create_part_next_gpt(self): self.assertEqual(ps5.size, 10 * 1024**2) # we should get just next primary partition (GPT) - ps6 = BlockDev.part_create_part (self.loop_devs[0], BlockDev.PartTypeReq.NEXT, ps5.start + ps4.size + 1, + ps6 = BlockDev.part_create_part (self.loop_devs[0], BlockDev.PartTypeReq.NEXT, ps5.start + ps5.size + 1, 10 * 1024**2, BlockDev.PartAlign.OPTIMAL) self.assertTrue(ps6) self.assertEqual(ps6.path, self.loop_devs[0] + "6") @@ -760,7 +762,7 @@ def test_get_disk_free_regions(self): self.assertGreaterEqual(fi.start, 80 * 1024**2) self.assertGreaterEqual(fi.size, 19 * 1024**2) - # now something simple with GPT + # now something simple with MSDOS succ = BlockDev.part_create_table (self.loop_devs[0], BlockDev.PartTableType.MSDOS, True) self.assertTrue(succ) diff --git a/tests/run_tests.py b/tests/run_tests.py index 3694c8033..782cfda5d 100644 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -203,7 +203,7 @@ def _split_test_id(test_id): def _print_skip_message(test, skip_tags, missing): test_id = test.id() - test_module, test_name = _split_test_id(test_id) + test_name, test_module = _split_test_id(test_id) if missing: reason = 'skipping test because it is not tagged as one of: ' + ', '.join((t.value for t in skip_tags)) diff --git a/tests/swap_test.py b/tests/swap_test.py index c59f64bb1..c10faf1c1 100644 --- a/tests/swap_test.py +++ b/tests/swap_test.py @@ -149,7 +149,7 @@ def test_swapon_wrong_size(self): """Verify that activating swap with a wrong size fails with expected exception""" # create swap bigger than the device (twice as big in 1024 sectors) - ret, out, err = run_command("mkswap -f %s %d" % (self.loop_dev, (self.dev_size * 2) / 1024)) + ret, out, err = run_command("mkswap -f %s %d" % (self.loop_dev, (self.dev_size * 2) // 1024)) if ret != 0: self.fail("Failed to prepare swap for wrong size test: %s %s" % (out, err)) diff --git a/tests/utils.py b/tests/utils.py index 3cdd0c6d5..847415fca 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -151,7 +151,7 @@ def _get_lio_dev_path(store_wwn, tgt_wwn, store_name, retry=True): if retry: time.sleep(3) os.system("udevadm settle") - return _get_lio_dev_path(store_wwn, tgt_wwn, store_wwn, False) + return _get_lio_dev_path(store_wwn, tgt_wwn, store_name, False) else: _delete_target(tgt_wwn, store_name) raise RuntimeError("Failed to identify the resulting device for '%s'" % store_name) @@ -200,7 +200,7 @@ def create_lio_device(fpath, block_size=0): # create a new loopback device out = subprocess.check_output(["targetcli", "/loopback create"]) out = out.decode("utf-8") - match = re.match(r'Created target (.*).', out) + match = re.match(r'Created target (.*)\.', out) if match: tgt_wwn = match.groups()[0] else: @@ -453,7 +453,7 @@ def setup_nvme_target(dev_paths, subnqn): }} """.format(nguid=uuid.uuid4(), path=dev_path, nsid=i) for i, dev_path in enumerate(dev_paths, start=1)]) - json = """ + json_str = """ { "ports": [ { @@ -484,7 +484,7 @@ def setup_nvme_target(dev_paths, subnqn): ] } """ - tmp.write(json % (subnqn, namespaces, subnqn)) + tmp.write(json_str % (subnqn, namespaces, subnqn)) # export the loop device on the target ret, out, err = run_command("nvmetcli restore %s" % tcli_json_file)