7043629 Target shadow list should not adjust boundaries on discovered partitions
authorDrew Fisher <drew.fisher@oracle.com>
Tue, 10 May 2011 16:45:24 -0600
changeset 1117 ae9a188dcfcc
parent 1116 29e34d65ceef
child 1118 c87a271a3921
7043629 Target shadow list should not adjust boundaries on discovered partitions
usr/src/lib/install_target/discovery.py
usr/src/lib/install_target/physical.py
usr/src/lib/install_target/shadow/physical.py
usr/src/lib/install_target/test/test_shadow_list.py
--- a/usr/src/lib/install_target/discovery.py	Tue May 10 11:01:28 2011 +0200
+++ b/usr/src/lib/install_target/discovery.py	Tue May 10 16:45:24 2011 -0600
@@ -111,8 +111,10 @@
 
         drive - which physical drive to parse
         """
-        # create a DOC object for this drive
-        new_disk = Disk("disk")
+        # create a DOC object for this drive.  Set adjust_boundaries to False
+        # so the shadow code doesn't adjust the start sector or size for any
+        # children discovered
+        new_disk = Disk("disk", adjust_boundaries=False)
 
         # extract drive attributes and media information
         drive_attributes = drive.attributes
@@ -292,7 +294,11 @@
 
         # partition name is ctdp path.  Split the string on "p"
         root_path, _none, index = partition.name.partition("p")
-        new_partition = Partition(index)
+
+        # create a DOC object for this partition.  Set adjust_boundaries to
+        # False so the shadow code doesn't adjust the start sector or size for
+        # any children discovered
+        new_partition = Partition(index, adjust_boundaries=False)
         new_partition.action = "preserve"
         new_partition.part_type = partition_attributes.id
 
--- a/usr/src/lib/install_target/physical.py	Tue May 10 11:01:28 2011 +0200
+++ b/usr/src/lib/install_target/physical.py	Tue May 10 16:45:24 2011 -0600
@@ -68,10 +68,11 @@
     # extended partition.
     EXTENDED_ID_LIST = [5, 12, 15]
 
-    def __init__(self, name):
+    def __init__(self, name, adjust_boundaries=True):
         super(Partition, self).__init__(name)
+        self.action = "create"
+        self.adjust_boundaries = adjust_boundaries
 
-        self.action = "create"
         # set the default partition type to Solaris2
         self.part_type = self.name_to_num("Solaris2")
         self.bootid = Partition.INACTIVE
@@ -521,10 +522,11 @@
     """class for modifying disk layout
     """
 
-    def __init__(self, name):
+    def __init__(self, name, adjust_boundaries=True):
         """ constructor for the class
         """
         super(Disk, self).__init__(name)
+        self.adjust_boundaries = adjust_boundaries
         self.disk_prop = None
         self.disk_keyword = None
 
--- a/usr/src/lib/install_target/shadow/physical.py	Tue May 10 11:01:28 2011 +0200
+++ b/usr/src/lib/install_target/shadow/physical.py	Tue May 10 16:45:24 2011 -0600
@@ -444,16 +444,23 @@
         ShadowList.insert(self, index, value)
 
     def insert(self, index, value):
-        # reset the errsvc for Physical errors
-        errsvc.clear_error_list_by_mod_id(self.mod_id)
+        # check the container object's adjust_boundaries attribute.  If False,
+        # simply insert the object into the shadow list
+        if hasattr(self.container, "adjust_boundaries") and \
+           not self.container.adjust_boundaries:
+            ShadowList.insert(self, index, value)
+        else:
+            # reset the errsvc for Physical errors
+            errsvc.clear_error_list_by_mod_id(self.mod_id)
 
-        # check the value to see what kind of DOC object we're trying to insert
-        if hasattr(value, "force"):
-            # this is a Slice object, so call insert_slice
-            self.insert_slice(index, value)
-        elif hasattr(value, "part_type"):
-            # this is a Partition object, so call insert_partition
-            self.insert_partition(index, value)
+            # check the value to see what kind of DOC object we're trying to
+            # insert.
+            if hasattr(value, "force"):
+                # this is a Slice object, so call insert_slice
+                self.insert_slice(index, value)
+            elif hasattr(value, "part_type"):
+                # this is a Partition object, so call insert_partition
+                self.insert_partition(index, value)
 
     def remove(self, value):
         # reset the errsvc for Physical errors
--- a/usr/src/lib/install_target/test/test_shadow_list.py	Tue May 10 11:01:28 2011 +0200
+++ b/usr/src/lib/install_target/test/test_shadow_list.py	Tue May 10 16:45:24 2011 -0600
@@ -817,6 +817,14 @@
         self.assertFalse(errsvc._ERRORS)
         self.assertTrue(logical_part.is_logical)
 
+    def test_no_adjust_boundaries(self):
+        self.disk.adjust_boundaries = False
+        start_sector = 12345
+        p = self.disk.add_partition(1, 12345, 5, Size.gb_units)
+        self.assertFalse(errsvc._ERRORS)
+        self.assertEqual(start_sector, p.start_sector)
+        self.assertEqual(Size("5gb"), p.size)
+
 
 class TestSliceInDisk(unittest.TestCase):
     def setUp(self):
@@ -1056,6 +1064,14 @@
         # verify the size of the slice, rounding for cylinder size
         self.assertEqual(disksize / CYLSIZE * CYLSIZE, s.size.sectors)
 
+    def test_no_adjust_boundaries(self):
+        self.disk.adjust_boundaries = False
+        start_sector = 12345
+        s = self.disk.add_slice(1, 12345, 5, Size.gb_units)
+        self.assertFalse(errsvc._ERRORS)
+        self.assertEqual(start_sector, s.start_sector)
+        self.assertEqual(Size("5gb"), s.size)
+
 
 class TestSliceInPartition(unittest.TestCase):
     def setUp(self):
@@ -1267,6 +1283,14 @@
         # verify the size of the slice
         self.assertEqual(self.partition.size.sectors, s.size.sectors)
 
+    def test_no_adjust_boundaries(self):
+        self.partition.adjust_boundaries = False
+        start_sector = 12345
+        s = self.partition.add_slice(1, 12345, 5, Size.gb_units)
+        self.assertFalse(errsvc._ERRORS)
+        self.assertEqual(start_sector, s.start_sector)
+        self.assertEqual(Size("5gb"), s.size)
+
 
 class TestLogicalPartition(unittest.TestCase):