Skip to content

Commit a8a61c0

Browse files
committed
tests: Various improvements in DM tests
Faster pbkdf when creating LUKS device for testing, reducing number of test cases and adding some additional checks.
1 parent cc7f26b commit a8a61c0

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/plugins/dm.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,6 @@ gchar* bd_dm_get_subsystem_from_name (const gchar *device_name, GError **error)
243243
gchar *subsystem = NULL;
244244
gchar *hyphen_pos = NULL;
245245

246-
if (geteuid () != 0) {
247-
g_set_error (error, BD_DM_ERROR, BD_DM_ERROR_NOT_ROOT,
248-
"Not running as root, cannot query DM device");
249-
return NULL;
250-
}
251-
252246
task = dm_task_create (DM_DEVICE_INFO);
253247
if (!task) {
254248
g_set_error (error, BD_DM_ERROR, BD_DM_ERROR_TASK,

tests/dm_test.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ def setUpClass(cls):
2222
else:
2323
BlockDev.reinit(cls.requested_plugins, True, None)
2424

25-
class DevMapperPluginVersionCase(DevMapperTest):
26-
@tag_test(TestTags.NOSTORAGE)
27-
def test_plugin_version(self):
28-
self.assertEqual(BlockDev.get_plugin_soname(BlockDev.Plugin.DM), "libbd_dm.so.3")
2925

3026
class DevMapperTestCase(DevMapperTest):
3127

@@ -51,6 +47,7 @@ def _clean_up(self):
5147

5248
os.unlink(self.dev_file)
5349

50+
5451
class DevMapperGetSubsystemFromName(DevMapperTestCase):
5552
def _destroy_lvm(self):
5653
run("vgremove --yes libbd_dm_tests --config \"devices {use_devicesfile = 0}\" >/dev/null 2>&1")
@@ -71,11 +68,12 @@ def test_get_subsystem_from_name_lvm(self):
7168
def test_get_subsystem_from_name_crypt(self):
7269
"""Verify that it is possible to get luks device subsystem from its name"""
7370
self.addCleanup(self._destroy_crypt)
74-
run("echo \"supersecretkey\" | cryptsetup luksFormat %s -" %self.loop_dev)
71+
run("echo \"supersecretkey\" | cryptsetup luksFormat --pbkdf=pbkdf2 --pbkdf-force-iterations=1000 %s -" %self.loop_dev)
7572
run("echo \"supersecretkey\" | cryptsetup open %s libbd_dm_tests-subsystem_crypt --key-file=-" %self.loop_dev)
7673
subsystem = BlockDev.dm_get_subsystem_from_name("libbd_dm_tests-subsystem_crypt")
7774
self.assertEqual(subsystem, "CRYPT")
7875

76+
7977
def test_get_subsystem_from_name_linear(self):
8078
succ = BlockDev.dm_create_linear("testMap", self.loop_dev, 100, None)
8179
self.assertTrue(succ)
@@ -101,16 +99,20 @@ def test_get_subsystem_from_name_linear(self):
10199
with self.assertRaisesRegex(GLib.GError, "does not exist"):
102100
BlockDev.dm_get_subsystem_from_name("testMap")
103101

102+
104103
class DevMapperCreateRemoveLinear(DevMapperTestCase):
105104
@tag_test(TestTags.CORE)
106105
def test_create_remove_linear(self):
107106
"""Verify that it is possible to create new linear mapping and remove it"""
108107

109108
succ = BlockDev.dm_create_linear("testMap", self.loop_dev, 100, None)
110109
self.assertTrue(succ)
110+
self.assertTrue(os.path.exists("/dev/mapper/testMap"))
111111

112112
succ = BlockDev.dm_remove("testMap")
113113
self.assertTrue(succ)
114+
self.assertFalse(os.path.exists("/dev/mapper/testMap"))
115+
114116

115117
class DevMapperMapExists(DevMapperTestCase):
116118
def test_map_exists(self):
@@ -140,6 +142,7 @@ def test_map_exists(self):
140142
succ = BlockDev.dm_map_exists("testMap", False, False)
141143
self.assertFalse(succ)
142144

145+
143146
class DevMapperNameNodeBijection(DevMapperTestCase):
144147
def test_name_node_bijection(self):
145148
"""Verify that the map's node and map name points to each other"""
@@ -150,9 +153,11 @@ def test_name_node_bijection(self):
150153
self.assertEqual(BlockDev.dm_name_from_node(BlockDev.dm_node_from_name("testMap")),
151154
"testMap")
152155

153-
self.assertTrue(succ)
154156

155-
class DMDepsTest(DevMapperTest):
157+
class DMNoStorageTest(DevMapperTest):
158+
@tag_test(TestTags.NOSTORAGE)
159+
def test_plugin_version(self):
160+
self.assertEqual(BlockDev.get_plugin_soname(BlockDev.Plugin.DM), "libbd_dm.so.3")
156161

157162
@tag_test(TestTags.NOSTORAGE)
158163
def test_missing_dependencies(self):

0 commit comments

Comments
 (0)