[master] Fix the GRUB raid1 tests

David Shea dshea at redhat.com
Wed Oct 22 14:41:38 UTC 2014


The stage2 is the RAID device now instead of the partition device. Also
add checks using a btrfs raid1 /boot.
---
 tests/pyanaconda_tests/grub_raid_test.py | 50 +++++++++++++++++++++++++++++---
 1 file changed, 46 insertions(+), 4 deletions(-)

diff --git a/tests/pyanaconda_tests/grub_raid_test.py b/tests/pyanaconda_tests/grub_raid_test.py
index 6690073..0e4188e 100644
--- a/tests/pyanaconda_tests/grub_raid_test.py
+++ b/tests/pyanaconda_tests/grub_raid_test.py
@@ -20,6 +20,8 @@
 # These tests do not write anything to the disk and do not require root
 
 from blivet.devices import DiskDevice, PartitionDevice, MDRaidArrayDevice
+from blivet.devices import BTRFSVolumeDevice, BTRFSSubVolumeDevice
+from blivet.devicelibs.raid import RAID1
 from blivet.formats import getFormat
 from blivet.size import Size
 
@@ -46,29 +48,40 @@ class GRUBRaidSimpleTest(unittest.TestCase):
         self.sdb = DiskDevice(name="sdb", size=Size("100 GiB"))
         self.sdb.format = getFormat("disklabel")
 
-        # Set up biosboot partitions and an array for /boot on sda + sdb.
+        # Set up biosboot partitions, an mdarray for /boot, and a btrfs array on sda + sdb.
         # Start with the partitions
         self.sda1 = PartitionDevice(name="sda1", parents=[self.sda], size=Size("1 MiB"))
         self.sda1.format = getFormat("biosboot")
         self.sda2 = PartitionDevice(name="sda2", parents=[self.sda], size=Size("500 MiB"))
         self.sda2.format = getFormat("mdmember")
+        self.sda4 = PartitionDevice(name="sda4", parents=[self.sda], size=Size("500 MiB"))
+        self.sda4.format = getFormat("btrfs")
 
         self.sdb1 = PartitionDevice(name="sdb1", parents=[self.sdb], size=Size("1 MiB"))
         self.sdb1.format = getFormat("biosboot")
         self.sdb2 = PartitionDevice(name="sdb2", parents=[self.sdb], size=Size("500 MiB"))
         self.sdb2.format = getFormat("mdmember")
+        self.sdb4 = PartitionDevice(name="sdb4", parents=[self.sdb], size=Size("4 GiB"))
+        self.sdb4.format = getFormat("btrfs")
 
         # Add an extra partition for /boot on not-RAID
         self.sda3 = PartitionDevice(name="sda3", parents=[self.sda], size=Size("500 MiB"))
         self.sda3.format = getFormat("ext4", mountpoint="/boot")
 
         # Pretend that the partitions are real with real parent disks
-        for part in (self.sda1, self.sda2, self.sdb1, self.sdb2):
+        for part in (self.sda1, self.sda2, self.sda3, self.sda4, self.sdb1, self.sdb2, self.sdb4):
             part.parents = part.req_disks
 
         self.boot_md = MDRaidArrayDevice(name="md1", parents=[self.sda2, self.sdb2], level=1)
         self.boot_md.format = getFormat("ext4", mountpoint="/boot")
 
+        # Set up the btrfs raid1 volume with a subvolume for /boot
+        self.btrfs_volume = BTRFSVolumeDevice(parents=[self.sda4, self.sdb4], dataLevel=RAID1)
+        self.btrfs_volume.format = getFormat("btrfs")
+
+        self.boot_btrfs = BTRFSSubVolumeDevice(parents=[self.btrfs_volume])
+        self.boot_btrfs.format = getFormat("btrfs", mountpoint="/boot")
+
         self.grub = GRUB()
 
     def grub_mbr_partition_test(self):
@@ -103,12 +116,12 @@ class GRUBRaidSimpleTest(unittest.TestCase):
 
         # Test stage1 on sda (MBR), stage2 on /boot RAID
         # install_targets should return two grub installs, one for each disk
-        # in the raid. stage1 will be the disk, stage2 will be the partition.
+        # in the raid. stage1 will be the disk, stage2 will be the raid device.
         self.grub.stage1_device = self.sda
         self.grub.stage2_device = self.boot_md
 
         install_targets = set(self.grub.install_targets)
-        expected_targets = set([(self.sda, self.sda2), (self.sdb, self.sdb2)])
+        expected_targets = set([(self.sda, self.boot_md), (self.sdb, self.boot_md)])
 
         self.assertEquals(install_targets, expected_targets)
 
@@ -125,3 +138,32 @@ class GRUBRaidSimpleTest(unittest.TestCase):
         expected_targets = set([(self.sda1, self.boot_md)])
 
         self.assertEquals(install_targets, expected_targets)
+
+    def grub_btrfs_test(self):
+        """Test installing GRUB to a MBR stage1 and btrfs RAID stage2"""
+
+        # Test stage1 on sda (MBR), stage2 on btrfs /boot RAID
+        # install_targets should return two grub installs, one for each disk
+        # in the btrfs volume. stage1 will be the disk, stage2 will be the
+        # btrfs subvolume.
+        self.grub.stage1_device = self.sda
+        self.grub.stage2_device = self.boot_btrfs
+
+        install_targets = set(self.grub.install_targets)
+        expected_targets = set([(self.sda, self.boot_btrfs), (self.sdb, self.boot_btrfs)])
+
+        self.assertEquals(install_targets, expected_targets)
+
+    def grub_partition_btrfs_test(self):
+        """Test installing GRUB to a partition stage1 and MBR stage2"""
+
+        # Test stage1 on sda1 (biosboot), stage2 on btrfs /boot RAID
+        # since stage1 is a non-raid partition, install_targets should return
+        # the original (stage1, stage2) and not add any targets
+        self.grub.stage1_device = self.sda1
+        self.grub.stage2_device = self.boot_btrfs
+
+        install_targets = set(self.grub.install_targets)
+        expected_targets = set([(self.sda1, self.boot_btrfs)])
+
+        self.assertEquals(install_targets, expected_targets)
-- 
2.1.0



More information about the anaconda-patches mailing list