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

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