Skip to content

Commit 00c98d9

Browse files
Merge pull request #1183 from vojtechtrefny/master_test-fixes-3
Various test fixes
2 parents fbd0cee + b25943d commit 00c98d9

25 files changed

+81
-80
lines changed

tests/_lvm_cases.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ def test_thinpool_cache_get_stats(self):
13471347
self.assertEqual(stats.md_size, 8 * 1024**2)
13481348
self.assertEqual(stats.mode, BlockDev.LVMCacheMode.WRITETHROUGH)
13491349

1350-
def test_vgtags(self):
1350+
def test_lvtags(self):
13511351
"""Verify that it's possible to set and get info about LV tags"""
13521352

13531353
succ = BlockDev.lvm_pvcreate(self.loop_dev, 0, 0, None)
@@ -1618,7 +1618,7 @@ def test_lvs_all(self):
16181618

16191619
# there should be at least 3 LVs -- testPool, [testPool_tdata], [testPool_tmeta] (plus probably some spare LVs)
16201620
lvs = BlockDev.lvm_lvs("testVG")
1621-
self.assertGreater(len(lvs), 3)
1621+
self.assertGreaterEqual(len(lvs), 3)
16221622

16231623
@tag_test(TestTags.CORE)
16241624
def test_thpoolcreate(self):
@@ -1937,8 +1937,8 @@ def setUpClass(cls):
19371937
if "File exists" not in e.message:
19381938
raise unittest.SkipTest("cannot load VDO kernel module, skipping.")
19391939

1940-
if LVM_VERSION < Version("2.3.07"):
1941-
raise unittest.SkipTest("LVM version 2.3.07 or newer needed for LVM VDO.")
1940+
if LVM_VERSION < Version("2.03.07"):
1941+
raise unittest.SkipTest("LVM version 2.03.07 or newer needed for LVM VDO.")
19421942

19431943
if not shutil.which("vdoformat"):
19441944
raise unittest.SkipTest("vdoformat executable not found in $PATH, skipping.")

tests/btrfs_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def setUpClass(cls):
3333
raise unittest.SkipTest('Btrfs kernel module not available, skipping.')
3434

3535
if not shutil.which("btrfs"):
36-
raise unittest.SkipTest("btrfs executable not foundin $PATH, skipping.")
36+
raise unittest.SkipTest("btrfs executable not found in $PATH, skipping.")
3737

3838
if not BlockDev.is_initialized():
3939
BlockDev.init(cls.requested_plugins, None)

tests/crypto_test.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,15 @@ def _clean_up(self):
8080
except:
8181
pass
8282

83-
for i in range(self._num_devices):
83+
for dev in self.loop_devs:
8484
try:
85-
delete_lio_device(self.loop_devs[i])
85+
delete_lio_device(dev)
8686
except RuntimeError:
8787
# just move on, we can do no better here
8888
pass
89-
os.unlink(self.dev_files[i])
89+
90+
for dev_file in self.dev_files:
91+
os.unlink(dev_file)
9092

9193
os.unlink(self.keyfile)
9294

@@ -230,7 +232,7 @@ def test_luks2_format(self):
230232
succ = BlockDev.crypto_luks_format(self.loop_devs[0], "aes-xts-plain64", 0, pw_ctx, 0)
231233
self.assertTrue(succ)
232234

233-
# create with a keyfile
235+
# create with a passphrase context
234236
kf_ctx = BlockDev.CryptoKeyslotContext(passphrase=PASSWD)
235237
succ = BlockDev.crypto_luks_format(self.loop_devs[0], "aes-xts-plain64", 0, kf_ctx, 0)
236238
self.assertTrue(succ)
@@ -291,7 +293,6 @@ def test_luks1_format_pbkdf_options(self):
291293
with self.assertRaisesRegex(GLib.GError, "Invalid pbkdf specified"):
292294
BlockDev.crypto_luks_format(self.loop_devs[0], "aes-xts-plain64", 0, ctx, 0,
293295
BlockDev.CryptoLUKSVersion.LUKS1, extra)
294-
self.assertTrue(succ)
295296

296297
@tag_test(TestTags.SLOW, TestTags.CORE)
297298
def test_luks2_format_pbkdf_options(self):
@@ -622,7 +623,7 @@ class CryptoTestErrorLocale(CryptoTestCase):
622623
def setUp(self):
623624
self._orig_loc = None
624625
CryptoTestCase.setUp(self)
625-
self._orig_loc = ".".join(locale.getdefaultlocale())
626+
self._orig_loc = locale.setlocale(locale.LC_ALL)
626627

627628
def _clean_up(self):
628629
CryptoTestCase._clean_up(self)
@@ -1472,7 +1473,7 @@ def _verify_token_info (self, info):
14721473
self.assertEqual(info[0].keyslot, 0)
14731474

14741475
@tag_test(TestTags.SLOW)
1475-
def test_luks2_integrity(self):
1476+
def test_luks2_token_info(self):
14761477
"""Verify that we can get information about LUKS2 tokens"""
14771478

14781479
# the simple case with password

tests/fs_tests/btrfs_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_btrfs_features(self):
3737
self.assertIsNotNone(features)
3838

3939
self.assertTrue(features.resize & BlockDev.FSResizeFlags.ONLINE_GROW)
40-
self.assertTrue(features.resize & BlockDev.FSResizeFlags.ONLINE_GROW)
40+
self.assertTrue(features.resize & BlockDev.FSResizeFlags.ONLINE_SHRINK)
4141

4242
self.assertTrue(features.mkfs & BlockDev.FSMkfsOptionsFlags.LABEL)
4343
self.assertTrue(features.mkfs & BlockDev.FSMkfsOptionsFlags.UUID)

tests/fs_tests/exfat_test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import overrides_hack
66
import utils
7-
from utils import TestTags, tag_test
87

98
from gi.repository import BlockDev, GLib
109

@@ -19,11 +18,11 @@ def setUp(self):
1918

2019
class ExfatTestCase(FSTestCase):
2120
def setUp(self):
22-
super(ExfatTestCase, self).setUp()
23-
2421
if not self.exfat_avail:
2522
self.skipTest("skipping exFAT: not available")
2623

24+
super(ExfatTestCase, self).setUp()
25+
2726
self.mount_dir = tempfile.mkdtemp(prefix="libblockdev.", suffix="exfat_test")
2827

2928

tests/fs_tests/ext_test.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,18 @@ def _test_ext_get_info(self, mkfs_function, info_function):
248248
self.assertEqual(fi.label, "")
249249
# should be an non-empty string
250250
self.assertTrue(fi.uuid)
251-
self.assertTrue(fi.state, "clean")
251+
self.assertTrue(fi.state)
252252

253253
with mounted(self.loop_devs[0], self.mount_dir):
254-
fi = BlockDev.fs_ext4_get_info(self.loop_devs[0])
254+
fi = info_function(self.loop_devs[0])
255255
self.assertEqual(fi.block_size, 1024)
256256
self.assertEqual(fi.block_count, self.loop_size / 1024)
257257
# at least 50 % should be available, so it should be reported
258258
self.assertGreater(fi.free_blocks, 0.50 * self.loop_size / 1024)
259259
self.assertEqual(fi.label, "")
260260
# should be an non-empty string
261261
self.assertTrue(fi.uuid)
262-
self.assertTrue(fi.state, "clean")
262+
self.assertTrue(fi.state)
263263

264264
@tag_test(TestTags.CORE)
265265
def test_ext2_get_info(self):
@@ -409,33 +409,33 @@ class ExtSetUUID(ExtTestCase):
409409

410410
test_uuid = "4d7086c4-a4d3-432f-819e-73da03870df9"
411411

412-
def _test_ext_set_uuid(self, mkfs_function, info_function, label_function, check_function):
412+
def _test_ext_set_uuid(self, mkfs_function, info_function, uuid_function, check_function):
413413
succ = mkfs_function(self.loop_devs[0], None)
414414
self.assertTrue(succ)
415415

416416
fi = info_function(self.loop_devs[0])
417417
self.assertTrue(fi)
418418

419-
succ = label_function(self.loop_devs[0], self.test_uuid)
419+
succ = uuid_function(self.loop_devs[0], self.test_uuid)
420420
self.assertTrue(succ)
421421
fi = info_function(self.loop_devs[0])
422422
self.assertTrue(fi)
423423
self.assertEqual(fi.uuid, self.test_uuid)
424424

425-
succ = label_function(self.loop_devs[0], "clear")
425+
succ = uuid_function(self.loop_devs[0], "clear")
426426
self.assertTrue(succ)
427427
fi = info_function(self.loop_devs[0])
428428
self.assertTrue(fi)
429429
self.assertEqual(fi.uuid, "")
430430

431-
succ = label_function(self.loop_devs[0], "random")
431+
succ = uuid_function(self.loop_devs[0], "random")
432432
self.assertTrue(succ)
433433
fi = info_function(self.loop_devs[0])
434434
self.assertTrue(fi)
435435
self.assertNotEqual(fi.uuid, "")
436436
random_uuid = fi.uuid
437437

438-
succ = label_function(self.loop_devs[0], "time")
438+
succ = uuid_function(self.loop_devs[0], "time")
439439
self.assertTrue(succ)
440440
fi = info_function(self.loop_devs[0])
441441
self.assertTrue(fi)
@@ -444,7 +444,7 @@ def _test_ext_set_uuid(self, mkfs_function, info_function, label_function, check
444444
time_uuid = fi.uuid
445445

446446
# no UUID -> random
447-
succ = label_function(self.loop_devs[0], None)
447+
succ = uuid_function(self.loop_devs[0], None)
448448
self.assertTrue(succ)
449449
fi = info_function(self.loop_devs[0])
450450
self.assertTrue(fi)
@@ -461,19 +461,19 @@ def test_ext2_set_uuid(self):
461461
"""Verify that it is possible to set UUID of an ext2 file system"""
462462
self._test_ext_set_uuid(mkfs_function=BlockDev.fs_ext2_mkfs,
463463
info_function=BlockDev.fs_ext2_get_info,
464-
label_function=BlockDev.fs_ext2_set_uuid,
464+
uuid_function=BlockDev.fs_ext2_set_uuid,
465465
check_function=BlockDev.fs_ext2_check_uuid)
466466

467467
def test_ext3_set_uuid(self):
468468
"""Verify that it is possible to set UUID of an ext3 file system"""
469469
self._test_ext_set_uuid(mkfs_function=BlockDev.fs_ext3_mkfs,
470470
info_function=BlockDev.fs_ext3_get_info,
471-
label_function=BlockDev.fs_ext3_set_uuid,
471+
uuid_function=BlockDev.fs_ext3_set_uuid,
472472
check_function=BlockDev.fs_ext3_check_uuid)
473473

474474
def test_ext4_set_uuid(self):
475475
"""Verify that it is possible to set UUID of an ext4 file system"""
476476
self._test_ext_set_uuid(mkfs_function=BlockDev.fs_ext4_mkfs,
477477
info_function=BlockDev.fs_ext4_get_info,
478-
label_function=BlockDev.fs_ext4_set_uuid,
478+
uuid_function=BlockDev.fs_ext4_set_uuid,
479479
check_function=BlockDev.fs_ext4_check_uuid)

tests/fs_tests/f2fs_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,15 @@ def test_f2fs_resize(self):
238238

239239
# shrink without the safe option -- should fail
240240
with self.assertRaises(GLib.GError):
241-
BlockDev.fs_f2fs_resize(self.loop_devs[0], 100 * 1024**2 / 512, False)
241+
BlockDev.fs_f2fs_resize(self.loop_devs[0], 100 * 1024**2 // 512, False)
242242

243243
# if we can't shrink we'll just check it returns some sane error
244244
if not _can_resize_f2fs():
245245
with self.assertRaisesRegex(GLib.GError, "Too low version of resize.f2fs. At least 1.12.0 required."):
246-
BlockDev.fs_f2fs_resize(self.loop_devs[0], 100 * 1024**2 / 512, True)
246+
BlockDev.fs_f2fs_resize(self.loop_devs[0], 100 * 1024**2 // 512, True)
247247
return
248248

249-
succ = BlockDev.fs_f2fs_resize(self.loop_devs[0], 100 * 1024**2 / 512, True)
249+
succ = BlockDev.fs_f2fs_resize(self.loop_devs[0], 100 * 1024**2 // 512, True)
250250
self.assertTrue(succ)
251251

252252
fi = BlockDev.fs_f2fs_get_info(self.loop_devs[0])
@@ -258,14 +258,14 @@ def test_f2fs_resize(self):
258258
self.assertEqual(fi.sector_count * fi.sector_size, 100 * 1024**2)
259259

260260
# grow
261-
succ = BlockDev.fs_f2fs_resize(self.loop_devs[0], 120 * 1024**2 / 512, True)
261+
succ = BlockDev.fs_f2fs_resize(self.loop_devs[0], 120 * 1024**2 // 512, True)
262262
self.assertTrue(succ)
263263

264264
fi = BlockDev.fs_f2fs_get_info(self.loop_devs[0])
265265
self.assertEqual(fi.sector_count * fi.sector_size, 120 * 1024**2)
266266

267267
# shrink again
268-
succ = BlockDev.fs_f2fs_resize(self.loop_devs[0], 100 * 1024**2 / 512, True)
268+
succ = BlockDev.fs_f2fs_resize(self.loop_devs[0], 100 * 1024**2 // 512, True)
269269
self.assertTrue(succ)
270270

271271
fi = BlockDev.fs_f2fs_get_info(self.loop_devs[0])

tests/fs_tests/fs_test.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def setUp(self):
116116
self.addCleanup(self._clean_up)
117117

118118
for i in range(self.num_devices):
119-
dev_file = utils.create_sparse_tempfile("crypto_test", self.loop_size)
119+
dev_file = utils.create_sparse_tempfile("fs_test", self.loop_size)
120120
self.dev_files.append(dev_file)
121121

122122
try:
@@ -131,13 +131,15 @@ def _clean_up(self):
131131
except:
132132
pass
133133

134-
for i in range(self.num_devices):
134+
for dev in self.loop_devs:
135135
try:
136-
utils.delete_lio_device(self.loop_devs[i])
136+
utils.delete_lio_device(dev)
137137
except RuntimeError:
138138
# just move on, we can do no better here
139139
pass
140-
os.unlink(self.dev_files[i])
140+
141+
for dev_file in self.dev_files:
142+
os.unlink(dev_file)
141143

142144
self.dev_files.clear()
143145
self.loop_devs.clear()
@@ -175,7 +177,6 @@ def _setup_lvm(self, vgname, lvname, lvsize="50M"):
175177

176178
ret, _out, err = utils.run_command("lvcreate -n %s -L%s %s --config \"devices {use_devicesfile = 0}\"" % (lvname, lvsize, vgname))
177179
if ret != 0:
178-
import pdb; pdb.set_trace()
179180
raise RuntimeError("Failed to create LV for fs tests: %s" % err)
180181

181182
return "/dev/%s/%s" % (vgname, lvname)

tests/fs_tests/generic_test.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ def test_ext4_progress_check(self):
673673
succ = BlockDev.utils_init_prog_reporting(None)
674674

675675
def test_xfs_generic_check(self):
676-
"""Test generic check function with an ext4 file system"""
676+
"""Test generic check function with an xfs file system"""
677677
self._test_generic_check(mkfs_function=BlockDev.fs_xfs_mkfs, fstype="xfs")
678678

679679
def test_ntfs_generic_check(self):
@@ -1097,7 +1097,7 @@ def _test_xfs_generic_resize(self, mount):
10971097
succ = BlockDev.fs_resize(lv, 40 * 1024**2)
10981098

10991099
self._lvresize("libbd_fs_tests", "generic_test", "380M")
1100-
# should grow to 375 MiB (full size of the LV)
1100+
# should grow to 380 MiB (full size of the LV)
11011101
if mount:
11021102
with mounted(lv, self.mount_dir):
11031103
succ = BlockDev.fs_resize(lv, 0)
@@ -1304,25 +1304,25 @@ def _test_get_free_space(self, mkfs_function, fstype, size_delta=0):
13041304
self.assertLessEqual(free, size)
13051305

13061306
def test_ext2_get_free_space(self):
1307-
"""Test generic resize function with an ext2 file system"""
1307+
"""Test generic get_free_space function with an ext2 file system"""
13081308
self._test_get_free_space(mkfs_function=BlockDev.fs_ext2_mkfs, fstype="ext2")
13091309

13101310
def test_ext3_check_get_free_space(self):
1311-
"""Test generic resize function with an ext3 file system"""
1311+
"""Test generic get_free_space function with an ext3 file system"""
13121312
self._test_get_free_space(mkfs_function=BlockDev.fs_ext3_mkfs, fstype="ext3")
13131313

13141314
def test_ext4_get_free_space(self):
1315-
"""Test generic resize function with an ext4 file system"""
1315+
"""Test generic get_free_space function with an ext4 file system"""
13161316
self._test_get_free_space(mkfs_function=BlockDev.fs_ext4_mkfs, fstype="ext4")
13171317

13181318
def test_ntfs_get_free_space(self):
1319-
"""Test generic resize function with an ntfs file system"""
1319+
"""Test generic get_free_space function with an ntfs file system"""
13201320
if not self.ntfs_avail:
13211321
self.skipTest("skipping NTFS: not available")
13221322
self._test_get_free_space(mkfs_function=BlockDev.fs_ntfs_mkfs, fstype="ntfs")
13231323

13241324
def test_vfat_get_free_space(self):
1325-
"""Test generic resize function with a vfat file system"""
1325+
"""Test generic get_free_space function with a vfat file system"""
13261326
def mkfs_vfat(device, options=None):
13271327
if self._vfat_version >= Version("4.2"):
13281328
if options:
@@ -1335,19 +1335,19 @@ def mkfs_vfat(device, options=None):
13351335
self._test_get_free_space(mkfs_function=mkfs_vfat, fstype="vfat")
13361336

13371337
def test_nilfs2_get_free_space(self):
1338-
"""Test generic resize function with an nilfs2 file system"""
1338+
"""Test generic get_free_space function with an nilfs2 file system"""
13391339
if not self.nilfs2_avail:
13401340
self.skipTest("skipping NILFS2: not available")
13411341
self._test_get_free_space(mkfs_function=BlockDev.fs_nilfs2_mkfs, fstype="nilfs2")
13421342

13431343
def test_btrfs_get_free_space(self):
1344-
"""Test generic resize function with an btrfs file system"""
1344+
"""Test generic get_free_space function with a btrfs file system"""
13451345
if not self.btrfs_avail:
13461346
self.skipTest("skipping Btrfs: not available")
13471347
self._test_get_free_space(mkfs_function=BlockDev.fs_btrfs_mkfs, fstype="btrfs")
13481348

13491349
def test_udf_get_free_space(self):
1350-
"""Test generic resize function with an udf file system"""
1350+
"""Test generic get_free_space function with a udf file system"""
13511351
if not self.udf_avail:
13521352
self.skipTest("skipping UDF: not available")
13531353

tests/fs_tests/mount_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def test_mount_ro_device(self):
120120
loop_dev = "/dev/" + dev
121121
# without any options, the mount should fall back to RO
122122
self.assertTrue(BlockDev.fs_mount(loop_dev, tmp_dir, None, None, None))
123-
self.addCleanup(utils.umount, dev)
123+
self.addCleanup(utils.umount, loop_dev)
124124
self.assertTrue(os.path.ismount(tmp_dir))
125125

126126
succ = BlockDev.fs_unmount(tmp_dir, False, False, None)

0 commit comments

Comments
 (0)