From 87520a1a36e4131b72b8c2216470a57fff33716e Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Wed, 6 Dec 2023 14:19:17 +0100 Subject: [PATCH] tests: Wait for array resync in MD tests --- tests/storage_tests/devices_test/md_test.py | 38 +++++++++++++++++---- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/tests/storage_tests/devices_test/md_test.py b/tests/storage_tests/devices_test/md_test.py index 0fed916dc..9975d27aa 100644 --- a/tests/storage_tests/devices_test/md_test.py +++ b/tests/storage_tests/devices_test/md_test.py @@ -1,10 +1,28 @@ import os +import time + +from contextlib import contextmanager from ..storagetestcase import StorageTestCase import blivet +@contextmanager +def wait_for_resync(): + try: + yield + finally: + time.sleep(2) + action = True + while action: + with open("/proc/mdstat", "r") as f: + action = "resync" in f.read() + if action: + print("Sleeping") + time.sleep(1) + + class MDTestCase(StorageTestCase): raidname = "blivetTestRAID" @@ -57,7 +75,8 @@ def _test_mdraid(self, raid_level, members): member_devices=members) self.storage.create_device(array) - self.storage.do_it() + with wait_for_resync(): + self.storage.do_it() self.storage.reset() array = self.storage.devicetree.get_device_by_name(self.raidname) @@ -95,7 +114,8 @@ def test_mdraid_raid0_extra(self): metadata_version="1.2") self.storage.create_device(array) - self.storage.do_it() + with wait_for_resync(): + self.storage.do_it() self.storage.reset() array = self.storage.devicetree.get_device_by_name(self.raidname) @@ -111,7 +131,8 @@ def test_mdraid_raid1_spare(self): member_devices=2) self.storage.create_device(array) - self.storage.do_it() + with wait_for_resync(): + self.storage.do_it() self.storage.reset() array = self.storage.devicetree.get_device_by_name(self.raidname) @@ -133,7 +154,8 @@ def test_mdraid_members_add_remove(self): member_devices=2) self.storage.create_device(array) - self.storage.do_it() + with wait_for_resync(): + self.storage.do_it() self.storage.reset() array = self.storage.devicetree.get_device_by_name(self.raidname) @@ -158,7 +180,9 @@ def test_mdraid_members_add_remove(self): ac = blivet.deviceaction.ActionAddMember(array, part) self.storage.devicetree.actions.add(ac) - self.storage.do_it() + + with wait_for_resync(): + self.storage.do_it() array = self.storage.devicetree.get_device_by_name(self.raidname) self.assertIsNotNone(array) @@ -171,7 +195,9 @@ def test_mdraid_members_add_remove(self): # and now remove it from the array ac = blivet.deviceaction.ActionRemoveMember(array, part) self.storage.devicetree.actions.add(ac) - self.storage.do_it() + + with wait_for_resync(): + self.storage.do_it() array = self.storage.devicetree.get_device_by_name(self.raidname) self.assertIsNotNone(array)