Blame SOURCES/0011-tests-Wait-for-raid-and-mirrored-LVs-to-be-synced-be.patch

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