[PATCH 3/3] Add some tests for extended partition management.

David Lehman dlehman at redhat.com
Mon May 5 17:57:50 UTC 2014


---
 tests/partitioning_test.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/tests/partitioning_test.py b/tests/partitioning_test.py
index be7f415..44c9099 100644
--- a/tests/partitioning_test.py
+++ b/tests/partitioning_test.py
@@ -6,6 +6,11 @@ from mock import Mock
 import parted
 
 from blivet.partitioning import getNextPartitionType
+from blivet.partitioning import doPartitioning
+
+from tests.imagebackedtestcase import ImageBackedTestCase
+from blivet.formats import getFormat
+from blivet.size import Size
 
 # disklabel-type-specific constants
 # keys: disklabel type string
@@ -118,5 +123,69 @@ class PartitioningTestCase(unittest.TestCase):
         disk = self.getDisk(disk_type="mac")
         self.assertEqual(getNextPartitionType(disk, no_primary=True), None)
 
+class ExtendedPartitionTestCase(ImageBackedTestCase):
+
+    disks = {"disk1": Size(spec="2 GiB")}
+    initialize_disks = False
+
+    def _set_up_storage(self):
+        # Don't rely on the default being an msdos disklabel since the test
+        # could be running on an EFI system.
+        for name in self.disks:
+            disk = self.blivet.devicetree.getDeviceByName(name)
+            fmt = getFormat("disklabel", labelType="msdos", device=disk.path)
+            self.blivet.formatDevice(disk, fmt)
+
+    def testImplicitExtendedPartitions(self):
+        """ Verify management of implicitly requested extended partition. """
+        # By running partition allocation multiple times with enough partitions
+        # to require an extended partition, we exercise the code that manages
+        # the implicit extended partition.
+        p1 = self.blivet.newPartition(size=Size(spec="100 MiB"))
+        self.blivet.createDevice(p1)
+
+        p2 = self.blivet.newPartition(size=Size(spec="200 MiB"))
+        self.blivet.createDevice(p2)
+
+        p3 = self.blivet.newPartition(size=Size(spec="300 MiB"))
+        self.blivet.createDevice(p3)
+
+        p4 = self.blivet.newPartition(size=Size(spec="400 MiB"))
+        self.blivet.createDevice(p4)
+
+        doPartitioning(self.blivet)
+
+        p5 = self.blivet.newPartition(size=Size(spec="500 MiB"))
+        self.blivet.createDevice(p5)
+
+        doPartitioning(self.blivet)
+
+        p6 = self.blivet.newPartition(size=Size(spec="450 MiB"))
+        self.blivet.createDevice(p6)
+
+        doPartitioning(self.blivet)
+
+        self.blivet.doIt()
+
+    def testExplicitExtendedPartitions(self):
+        """ Verify that explicitly requested extended partitions work. """
+        disk = self.blivet.disks[0]
+        p1 = self.blivet.newPartition(size=Size(spec="500 MiB"),
+                                      partType=parted.PARTITION_EXTENDED)
+        self.blivet.createDevice(p1)
+        doPartitioning(self.blivet)
+
+        self.assertEqual(p1.partedPartition.type, parted.PARTITION_EXTENDED)
+        self.assertEqual(p1.partedPartition, disk.format.extendedPartition)
+
+        p2 = self.blivet.newPartition(size=Size(spec="1 GiB"))
+        self.blivet.createDevice(p2)
+        doPartitioning(self.blivet)
+
+        self.assertEqual(p1.partedPartition, disk.format.extendedPartition,
+                         "user-specified extended partition was removed")
+
+        self.blivet.doIt()
+
 if __name__ == "__main__":
     unittest.main()
-- 
1.9.0



More information about the anaconda-patches mailing list