From d0ba031e679d480855bea61060acea597d5ffbbd Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Wed, 15 Dec 2021 14:14:19 +0100 Subject: [PATCH 1/2] tests: Wait for raid and mirrored LVs to be synced before removing Resolves: rhbz#2030647 --- tests/lvm_dbus_tests.py | 31 +++++++++++++++++++++++++------ tests/lvm_test.py | 31 +++++++++++++++++++++++++------ 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/tests/lvm_dbus_tests.py b/tests/lvm_dbus_tests.py index 5516afe..5ce653e 100644 --- a/tests/lvm_dbus_tests.py +++ b/tests/lvm_dbus_tests.py @@ -7,6 +7,8 @@ import six import re import shutil import subprocess +import time +from contextlib import contextmanager from distutils.version import LooseVersion from itertools import chain @@ -18,6 +20,21 @@ sb = dbus.SystemBus() lvm_dbus_running = any("lvmdbus" in name for name in chain(sb.list_names(), sb.list_activatable_names())) +@contextmanager +def wait_for_sync(vg_name, lv_name): + try: + yield + finally: + time.sleep(2) + while True: + ret, out, _err = run_command("LC_ALL=C lvs -o copy_percent --noheadings %s/%s" % (vg_name, lv_name)) + if ret != 0: + break + if int(float(out)) == 100: + break + time.sleep(1) + + class LVMTestCase(unittest.TestCase): @classmethod def setUpClass(cls): @@ -801,9 +818,10 @@ class LvmTestLVcreateType(LvmPVVGLVTestCase): succ = BlockDev.lvm_lvremove("testVG", "testLV", True, None) self.assertTrue(succ) - # try to create a mirrored LV - succ = BlockDev.lvm_lvcreate("testVG", "testLV", 512 * 1024**2, "mirror", [self.loop_dev, self.loop_dev2], None) - self.assertTrue(succ) + with wait_for_sync("testVG", "testLV"): + # try to create a mirrored LV + succ = BlockDev.lvm_lvcreate("testVG", "testLV", 512 * 1024**2, "mirror", [self.loop_dev, self.loop_dev2], None) + self.assertTrue(succ) # verify that the LV has the requested segtype info = BlockDev.lvm_lvinfo("testVG", "testLV") @@ -812,9 +830,10 @@ class LvmTestLVcreateType(LvmPVVGLVTestCase): succ = BlockDev.lvm_lvremove("testVG", "testLV", True, None) self.assertTrue(succ) - # try to create a raid1 LV - succ = BlockDev.lvm_lvcreate("testVG", "testLV", 512 * 1024**2, "raid1", [self.loop_dev, self.loop_dev2], None) - self.assertTrue(succ) + with wait_for_sync("testVG", "testLV"): + # try to create a raid1 LV + succ = BlockDev.lvm_lvcreate("testVG", "testLV", 512 * 1024**2, "raid1", [self.loop_dev, self.loop_dev2], None) + self.assertTrue(succ) # verify that the LV has the requested segtype info = BlockDev.lvm_lvinfo("testVG", "testLV") diff --git a/tests/lvm_test.py b/tests/lvm_test.py index e349817..12b78ca 100644 --- a/tests/lvm_test.py +++ b/tests/lvm_test.py @@ -7,12 +7,29 @@ import six import re import shutil import subprocess +import time +from contextlib import contextmanager from distutils.version import LooseVersion from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, fake_utils, fake_path, TestTags, tag_test, run_command, read_file from gi.repository import BlockDev, GLib +@contextmanager +def wait_for_sync(vg_name, lv_name): + try: + yield + finally: + time.sleep(2) + while True: + info = BlockDev.lvm_lvinfo(vg_name, lv_name) + if not info: + break + if info.copy_percent == 100: + break + time.sleep(1) + + class LVMTestCase(unittest.TestCase): @classmethod @@ -737,9 +754,10 @@ class LvmTestLVcreateType(LvmPVVGLVTestCase): succ = BlockDev.lvm_lvremove("testVG", "testLV", True, None) self.assertTrue(succ) - # try to create a mirrored LV - succ = BlockDev.lvm_lvcreate("testVG", "testLV", 512 * 1024**2, "mirror", [self.loop_dev, self.loop_dev2], None) - self.assertTrue(succ) + with wait_for_sync("testVG", "testLV"): + # try to create a mirrored LV + succ = BlockDev.lvm_lvcreate("testVG", "testLV", 512 * 1024**2, "mirror", [self.loop_dev, self.loop_dev2], None) + self.assertTrue(succ) # verify that the LV has the requested segtype info = BlockDev.lvm_lvinfo("testVG", "testLV") @@ -748,9 +766,10 @@ class LvmTestLVcreateType(LvmPVVGLVTestCase): succ = BlockDev.lvm_lvremove("testVG", "testLV", True, None) self.assertTrue(succ) - # try to create a raid1 LV - succ = BlockDev.lvm_lvcreate("testVG", "testLV", 512 * 1024**2, "raid1", [self.loop_dev, self.loop_dev2], None) - self.assertTrue(succ) + with wait_for_sync("testVG", "testLV"): + # try to create a raid1 LV + succ = BlockDev.lvm_lvcreate("testVG", "testLV", 512 * 1024**2, "raid1", [self.loop_dev, self.loop_dev2], None) + self.assertTrue(succ) # verify that the LV has the requested segtype info = BlockDev.lvm_lvinfo("testVG", "testLV") -- 2.31.1 From 36dbac970bc4a052dbd97f51eb47379036d15b6e Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Thu, 16 Dec 2021 12:27:33 +0100 Subject: [PATCH 2/2] tests: Make smaller images for test_lvcreate_type We are now waiting for the initial resync for the RAID/mirror LVs which means we are trying to overwrite the entire 1 GB image which doesn't fit in /tmp on our CI machines. --- tests/lvm_dbus_tests.py | 16 +++++++++++----- tests/lvm_test.py | 15 ++++++++++----- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/tests/lvm_dbus_tests.py b/tests/lvm_dbus_tests.py index 5ce653e..723aabb 100644 --- a/tests/lvm_dbus_tests.py +++ b/tests/lvm_dbus_tests.py @@ -313,14 +313,17 @@ class LvmNoDevTestCase(LVMTestCase): @unittest.skipUnless(lvm_dbus_running, "LVM DBus not running") class LvmPVonlyTestCase(LVMTestCase): + + _sparse_size = 1024**3 + # :TODO: # * test pvmove (must create two PVs, a VG, a VG and some data in it # first) # * some complex test for pvs, vgs, lvs, pvinfo, vginfo and lvinfo def setUp(self): self.addCleanup(self._clean_up) - self.dev_file = create_sparse_tempfile("lvm_test", 1024**3) - self.dev_file2 = create_sparse_tempfile("lvm_test", 1024**3) + self.dev_file = create_sparse_tempfile("lvm_test", self._sparse_size) + self.dev_file2 = create_sparse_tempfile("lvm_test", self._sparse_size) try: self.loop_dev = create_lio_device(self.dev_file) except RuntimeError as e: @@ -795,6 +798,9 @@ class LvmTestLVcreateWithExtra(LvmPVVGLVTestCase): @unittest.skipUnless(lvm_dbus_running, "LVM DBus not running") class LvmTestLVcreateType(LvmPVVGLVTestCase): + + _sparse_size = 200 * 1024**2 + def test_lvcreate_type(self): """Verify it's possible to create LVs with various types""" @@ -808,7 +814,7 @@ class LvmTestLVcreateType(LvmPVVGLVTestCase): self.assertTrue(succ) # try to create a striped LV - succ = BlockDev.lvm_lvcreate("testVG", "testLV", 512 * 1024**2, "striped", [self.loop_dev, self.loop_dev2], None) + succ = BlockDev.lvm_lvcreate("testVG", "testLV", 100 * 1024**2, "striped", [self.loop_dev, self.loop_dev2], None) self.assertTrue(succ) # verify that the LV has the requested segtype @@ -820,7 +826,7 @@ class LvmTestLVcreateType(LvmPVVGLVTestCase): with wait_for_sync("testVG", "testLV"): # try to create a mirrored LV - succ = BlockDev.lvm_lvcreate("testVG", "testLV", 512 * 1024**2, "mirror", [self.loop_dev, self.loop_dev2], None) + succ = BlockDev.lvm_lvcreate("testVG", "testLV", 100 * 1024**2, "mirror", [self.loop_dev, self.loop_dev2], None) self.assertTrue(succ) # verify that the LV has the requested segtype @@ -832,7 +838,7 @@ class LvmTestLVcreateType(LvmPVVGLVTestCase): with wait_for_sync("testVG", "testLV"): # try to create a raid1 LV - succ = BlockDev.lvm_lvcreate("testVG", "testLV", 512 * 1024**2, "raid1", [self.loop_dev, self.loop_dev2], None) + succ = BlockDev.lvm_lvcreate("testVG", "testLV", 100 * 1024**2, "raid1", [self.loop_dev, self.loop_dev2], None) self.assertTrue(succ) # verify that the LV has the requested segtype diff --git a/tests/lvm_test.py b/tests/lvm_test.py index 12b78ca..97f6c69 100644 --- a/tests/lvm_test.py +++ b/tests/lvm_test.py @@ -302,14 +302,17 @@ class LvmNoDevTestCase(LVMTestCase): BlockDev.lvm_cache_get_mode_from_str("bla") class LvmPVonlyTestCase(LVMTestCase): + + _sparse_size = 1024**3 + # :TODO: # * test pvmove (must create two PVs, a VG, a VG and some data in it # first) # * some complex test for pvs, vgs, lvs, pvinfo, vginfo and lvinfo def setUp(self): self.addCleanup(self._clean_up) - self.dev_file = create_sparse_tempfile("lvm_test", 1024**3) - self.dev_file2 = create_sparse_tempfile("lvm_test", 1024**3) + self.dev_file = create_sparse_tempfile("lvm_test", self._sparse_size) + self.dev_file2 = create_sparse_tempfile("lvm_test", self._sparse_size) try: self.loop_dev = create_lio_device(self.dev_file) except RuntimeError as e: @@ -731,6 +734,8 @@ class LvmTestLVcreateWithExtra(LvmPVVGLVTestCase): self.assertTrue(succ) class LvmTestLVcreateType(LvmPVVGLVTestCase): + _sparse_size = 200 * 1024**2 + def test_lvcreate_type(self): """Verify it's possible to create LVs with various types""" @@ -744,7 +749,7 @@ class LvmTestLVcreateType(LvmPVVGLVTestCase): self.assertTrue(succ) # try to create a striped LV - succ = BlockDev.lvm_lvcreate("testVG", "testLV", 512 * 1024**2, "striped", [self.loop_dev, self.loop_dev2], None) + succ = BlockDev.lvm_lvcreate("testVG", "testLV", 100 * 1024**2, "striped", [self.loop_dev, self.loop_dev2], None) self.assertTrue(succ) # verify that the LV has the requested segtype @@ -756,7 +761,7 @@ class LvmTestLVcreateType(LvmPVVGLVTestCase): with wait_for_sync("testVG", "testLV"): # try to create a mirrored LV - succ = BlockDev.lvm_lvcreate("testVG", "testLV", 512 * 1024**2, "mirror", [self.loop_dev, self.loop_dev2], None) + succ = BlockDev.lvm_lvcreate("testVG", "testLV", 100 * 1024**2, "mirror", [self.loop_dev, self.loop_dev2], None) self.assertTrue(succ) # verify that the LV has the requested segtype @@ -768,7 +773,7 @@ class LvmTestLVcreateType(LvmPVVGLVTestCase): with wait_for_sync("testVG", "testLV"): # try to create a raid1 LV - succ = BlockDev.lvm_lvcreate("testVG", "testLV", 512 * 1024**2, "raid1", [self.loop_dev, self.loop_dev2], None) + succ = BlockDev.lvm_lvcreate("testVG", "testLV", 100 * 1024**2, "raid1", [self.loop_dev, self.loop_dev2], None) self.assertTrue(succ) # verify that the LV has the requested segtype -- 2.31.1