neil / rpms / udisks2

Forked from rpms/udisks2 a year ago
Clone

Blame SOURCES/udisks-2.10.0-lvm2_teardown_tests.patch

68b050
From dd6ef8393a8f27fefad66cce136e52f13350f0df Mon Sep 17 00:00:00 2001
68b050
From: Tomas Bzatek <tbzatek@redhat.com>
68b050
Date: Fri, 1 Oct 2021 18:23:10 +0200
68b050
Subject: [PATCH] tests: Add LVM2 teardown object existence checks
68b050
68b050
This adds a check for the created stack objects presence after the teardown.
68b050
68b050
Due to the nature of the global lvm2 module update some objects may still
68b050
hang around after the org.freedesktop.UDisks2.VolumeGroup.Delete(options='tear-down')
68b050
method call has returned. Until this is properly fixed an explicit timeout
68b050
had to be added.
68b050
---
68b050
 src/tests/dbus-tests/test_20_LVM.py | 80 +++++++++++++++++------------
68b050
 1 file changed, 46 insertions(+), 34 deletions(-)
68b050
68b050
diff --git a/src/tests/dbus-tests/test_20_LVM.py b/src/tests/dbus-tests/test_20_LVM.py
68b050
index 56915e580..7fbff0434 100644
68b050
--- a/src/tests/dbus-tests/test_20_LVM.py
68b050
+++ b/src/tests/dbus-tests/test_20_LVM.py
68b050
@@ -3,6 +3,7 @@
68b050
 import re
68b050
 import time
68b050
 import unittest
68b050
+import six
68b050
 
68b050
 from distutils.version import LooseVersion
68b050
 
68b050
@@ -637,7 +638,8 @@ def _remove_luks(self, device, name, close=True):
68b050
                 device.Lock(self.no_options, dbus_interface=self.iface_prefix + '.Encrypted')
68b050
             except dbus.exceptions.DBusException as e:
68b050
                 # ignore when luks is actually already locked
68b050
-                if not str(e).endswith('is not unlocked') and not 'No such interface' in str(e):
68b050
+                if not str(e).endswith('is not unlocked') and not 'No such interface' in str(e) and \
68b050
+                   not 'Object does not exist at path' in str(e):
68b050
                     raise e
68b050
 
68b050
         try:
68b050
@@ -645,7 +647,7 @@ def _remove_luks(self, device, name, close=True):
68b050
             d['erase'] = True
68b050
             device.Format('empty', d, dbus_interface=self.iface_prefix + '.Block')
68b050
         except dbus.exceptions.DBusException as e:
68b050
-            if not 'No such interface' in str(e):
68b050
+            if not 'No such interface' in str(e) and not 'Object does not exist at path' in str(e):
68b050
                 raise e
68b050
 
68b050
     def _init_stack(self, name):
68b050
@@ -663,18 +665,19 @@ def _init_stack(self, name):
68b050
         self.assertIsNotNone(self.pv)
68b050
 
68b050
         self.vg = self._create_vg(vgname, dbus.Array([self.pv]))
68b050
+        self.vg_path = self.vg.object_path
68b050
         self.addCleanup(self._remove_vg, self.vg, tear_down=True, ignore_removed=True)
68b050
 
68b050
         # create an LV on it
68b050
-        lv_path = self.vg.CreatePlainVolume(lvname, dbus.UInt64(200 * 1024**2), self.no_options,
68b050
-                                            dbus_interface=self.iface_prefix + '.VolumeGroup')
68b050
-        self.lv = self.bus.get_object(self.iface_prefix, lv_path)
68b050
+        self.lv_path = self.vg.CreatePlainVolume(lvname, dbus.UInt64(200 * 1024**2), self.no_options,
68b050
+                                                 dbus_interface=self.iface_prefix + '.VolumeGroup')
68b050
+        self.lv = self.bus.get_object(self.iface_prefix, self.lv_path)
68b050
         self.assertIsNotNone(self.lv)
68b050
 
68b050
-        lv_block_path = self.lv.Activate(self.no_options, dbus_interface=self.iface_prefix + '.LogicalVolume')
68b050
-        self.assertIsNotNone(lv_block_path)
68b050
+        self.lv_block_path = self.lv.Activate(self.no_options, dbus_interface=self.iface_prefix + '.LogicalVolume')
68b050
+        self.assertIsNotNone(self.lv_block_path)
68b050
 
68b050
-        self.lv_block = self.get_object(lv_block_path)
68b050
+        self.lv_block = self.get_object(self.lv_block_path)
68b050
         self.assertIsNotNone(self.lv_block)
68b050
 
68b050
         # create LUKS on the LV
68b050
@@ -702,10 +705,10 @@ def _init_stack(self, name):
68b050
         self.addCleanup(self._remove_luks, self.lv_block, vgname)
68b050
         self.luks_uuid = self.get_property_raw(self.lv_block, '.Block', 'IdUUID')
68b050
 
68b050
-        luks_block_path = self.get_property(self.lv_block, '.Encrypted', 'CleartextDevice')
68b050
-        self.luks_block = self.get_object(luks_block_path.value)
68b050
-        self.assertIsNotNone(self.luks_block)
68b050
-        self.fs_uuid = self.get_property_raw(self.luks_block, '.Block', 'IdUUID')
68b050
+        self.luks_block_path = self.get_property_raw(self.lv_block, '.Encrypted', 'CleartextDevice')
68b050
+        luks_block = self.get_object(self.luks_block_path)
68b050
+        self.assertIsNotNone(luks_block)
68b050
+        self.fs_uuid = self.get_property_raw(luks_block, '.Block', 'IdUUID')
68b050
 
68b050
         # check for present crypttab configuration item
68b050
         conf = self.get_property(self.lv_block, '.Block', 'Configuration')
68b050
@@ -713,7 +716,7 @@ def _init_stack(self, name):
68b050
         self.assertEqual(conf.value[0][0], 'crypttab')
68b050
 
68b050
         # check for present fstab configuration item on a cleartext block device
68b050
-        conf = self.get_property(self.luks_block, '.Block', 'Configuration')
68b050
+        conf = self.get_property(luks_block, '.Block', 'Configuration')
68b050
         conf.assertTrue()
68b050
         self.assertEqual(conf.value[0][0], 'fstab')
68b050
 
68b050
@@ -730,6 +733,32 @@ def _init_stack(self, name):
68b050
         self.assertIn(vgname, fstab)
68b050
         self.assertIn(self.fs_uuid, fstab)
68b050
 
68b050
+    def _check_torn_down_stack(self, name):
68b050
+        # check that all created objects don't exist anymore
68b050
+        msg = r'Object does not exist at path|No such interface'
68b050
+        with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg):
68b050
+            luks_block = self.get_object(self.luks_block_path)
68b050
+            self.get_property_raw(luks_block, '.Block', 'DeviceNumber')
68b050
+        with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg):
68b050
+            lv_block = self.get_object(self.lv_block_path)
68b050
+            self.get_property_raw(lv_block, '.Block', 'DeviceNumber')
68b050
+        with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg):
68b050
+            # the lvm2 udisks module is not fully synchronous, see https://github.com/storaged-project/udisks/pull/814
68b050
+            time.sleep(2)
68b050
+            lv = self.get_object(self.lv_path)
68b050
+            self.get_property_raw(lv, '.LogicalVolume', 'Name')
68b050
+        with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg):
68b050
+            vg = self.get_object(self.vg_path)
68b050
+            self.get_property_raw(vg, '.VolumeGroup', 'Name')
68b050
+
68b050
+        # check that fstab and crypttab records have been removed
68b050
+        crypttab = self.read_file('/etc/crypttab')
68b050
+        self.assertNotIn(name, crypttab)
68b050
+        self.assertNotIn(self.luks_uuid, crypttab)
68b050
+        fstab = self.read_file('/etc/fstab')
68b050
+        self.assertNotIn(name, fstab)
68b050
+        self.assertNotIn(self.fs_uuid, fstab)
68b050
+
68b050
 
68b050
     @udiskstestcase.tag_test(udiskstestcase.TestTags.UNSAFE)
68b050
     def test_teardown_active_vg_unlocked(self):
68b050
@@ -741,13 +770,7 @@ def test_teardown_active_vg_unlocked(self):
68b050
 
68b050
         self._remove_vg(self.vg, tear_down=True, ignore_removed=False)
68b050
 
68b050
-        # check that fstab and crypttab records have been removed
68b050
-        crypttab = self.read_file('/etc/crypttab')
68b050
-        self.assertNotIn(name, crypttab)
68b050
-        self.assertNotIn(self.luks_uuid, crypttab)
68b050
-        fstab = self.read_file('/etc/fstab')
68b050
-        self.assertNotIn(name, fstab)
68b050
-        self.assertNotIn(self.fs_uuid, fstab)
68b050
+        self._check_torn_down_stack(name)
68b050
 
68b050
     @udiskstestcase.tag_test(udiskstestcase.TestTags.UNSAFE)
68b050
     def test_teardown_active_vg_locked(self):
68b050
@@ -760,13 +783,7 @@ def test_teardown_active_vg_locked(self):
68b050
         self.lv_block.Lock(self.no_options, dbus_interface=self.iface_prefix + '.Encrypted')
68b050
         self._remove_vg(self.vg, tear_down=True, ignore_removed=False)
68b050
 
68b050
-        # check that fstab and crypttab records have been removed
68b050
-        crypttab = self.read_file('/etc/crypttab')
68b050
-        self.assertNotIn(name, crypttab)
68b050
-        self.assertNotIn(self.luks_uuid, crypttab)
68b050
-        fstab = self.read_file('/etc/fstab')
68b050
-        self.assertNotIn(name, fstab)
68b050
-        self.assertNotIn(self.fs_uuid, fstab)
68b050
+        self._check_torn_down_stack(name)
68b050
 
68b050
     @udiskstestcase.tag_test(udiskstestcase.TestTags.UNSAFE)
68b050
     def test_teardown_inactive_vg_locked(self):
68b050
@@ -780,13 +797,7 @@ def test_teardown_inactive_vg_locked(self):
68b050
         self.lv.Deactivate(self.no_options, dbus_interface=self.iface_prefix + '.LogicalVolume')
68b050
         self._remove_vg(self.vg, tear_down=True, ignore_removed=False)
68b050
 
68b050
-        # check that fstab and crypttab records have been removed
68b050
-        crypttab = self.read_file('/etc/crypttab')
68b050
-        self.assertNotIn(name, crypttab)
68b050
-        self.assertNotIn(self.luks_uuid, crypttab)
68b050
-        fstab = self.read_file('/etc/fstab')
68b050
-        self.assertNotIn(name, fstab)
68b050
-        self.assertNotIn(self.fs_uuid, fstab)
68b050
+        self._check_torn_down_stack(name)
68b050
 
68b050
     @udiskstestcase.tag_test(udiskstestcase.TestTags.UNSAFE)
68b050
     def test_reformat_inactive_vg_locked(self):
68b050
@@ -812,6 +823,7 @@ def test_reformat_inactive_vg_locked(self):
68b050
 
68b050
         # check that fstab and crypttab records have been removed
68b050
         # TODO: these checks are the opposite - record shouldn't be present, once this is fixed
68b050
+        # self._check_torn_down_stack(name)
68b050
         crypttab = self.read_file('/etc/crypttab')
68b050
         self.assertIn(name, crypttab)
68b050
         self.assertIn(self.luks_uuid, crypttab)