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

David Lehman dlehman at redhat.com
Tue May 6 19:52:49 UTC 2014


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

diff --git a/tests/partitioning_test.py b/tests/partitioning_test.py
index be7f415..df1cd7c 100644
--- a/tests/partitioning_test.py
+++ b/tests/partitioning_test.py
@@ -6,6 +6,12 @@ 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
+from blivet.flags import flags
 
 # disklabel-type-specific constants
 # keys: disklabel type string
@@ -118,5 +124,87 @@ 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)
+
+        # at this point there should be an extended partition
+        self.assertIsNotNone(self.blivet.disks[0].format.extendedPartition,
+                             "no extended partition was created")
+
+        # remove the last partition request and verify that the extended goes away as a result
+        self.blivet.destroyDevice(p4)
+        doPartitioning(self.blivet)
+        self.assertIsNone(self.blivet.disks[0].format.extendedPartition,
+                          "extended partition was not removed with last logical")
+
+        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.assertIsNotNone(self.blivet.disks[0].format.extendedPartition,
+                             "no extended partition was created")
+
+        self.blivet.doIt()
+
+    def testImplicitExtendedPartitionsInstallerMode(self):
+        flags.installer_mode = True
+        self.testImplicitExtendedPartitions()
+        flags.install_mode = False
+
+    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