Skip to content

Commit

Permalink
tests: Wait for array resync in MD tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtechtrefny committed Dec 6, 2023
1 parent 851b5bb commit 87520a1
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions tests/storage_tests/devices_test/md_test.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 87520a1

Please sign in to comment.