7063304 Attempting to delete a slice before creating it in manifest results in error
authorDrew Fisher <drew.fisher@oracle.com>
Wed, 06 Jul 2011 10:15:33 -0600
changeset 1253 b971c046c5d4
parent 1252 131154a3dcbe
child 1254 7a85c487dd24
7063304 Attempting to delete a slice before creating it in manifest results in error
usr/src/lib/install_target/shadow/physical.py
usr/src/lib/install_target/test/test_shadow_list.py
--- a/usr/src/lib/install_target/shadow/physical.py	Wed Jul 06 09:53:33 2011 +0100
+++ b/usr/src/lib/install_target/shadow/physical.py	Wed Jul 06 10:15:33 2011 -0600
@@ -252,7 +252,8 @@
             self.set_error(self.TooManySlicesError())
 
         # check for duplicate slice.name values
-        if value.name in [slc.name for slc in self._shadow]:
+        if value.name in [slc.name for slc in self._shadow \
+                          if slc.action != "delete"]:
             self.set_error(self.DuplicateSliceNameError(value.name))
 
         # check for in_zpool overlap
@@ -472,7 +473,8 @@
             p_size = value.start_sector + value.size.sectors
 
         # check that the name of the partition is not already in the list
-        if value.name in [p.name for p in self._shadow]:
+        if value.name in [p.name for p in self._shadow \
+                          if p.action != "delete"]:
             self.set_error(self.DuplicatePartitionNameError(value.name))
 
         # if this is an extended partition, verify there are no other
--- a/usr/src/lib/install_target/test/test_shadow_list.py	Wed Jul 06 09:53:33 2011 +0100
+++ b/usr/src/lib/install_target/test/test_shadow_list.py	Wed Jul 06 10:15:33 2011 -0600
@@ -866,6 +866,16 @@
         self.assertTrue(isinstance(error.error_data[ES_DATA_EXCEPTION],
                                    ShadowPhysical.InvalidPartitionNameError))
 
+    def test_insertion_of_partition_over_deleted_partition_of_same_name(self):
+        # add a 1GB partition at start_sector CYLSIZE and set the action to
+        # delete
+        p = self.disk.add_partition(1, CYLSIZE, 1, Size.gb_units)
+        p.action = "delete"
+
+        # insert another partition with the same name
+        self.disk.add_partition(1, CYLSIZE, 2, Size.gb_units)
+        self.assertFalse(errsvc._ERRORS)
+
 
 class TestSliceInDisk(unittest.TestCase):
     def setUp(self):
@@ -1131,6 +1141,15 @@
         self.assertEqual(start_sector, s.start_sector)
         self.assertEqual(Size("5gb"), s.size)
 
+    def test_insertion_of_slice_over_deleted_slice_of_same_name(self):
+        # add a 1GB slice at start_sector CYLSIZE and set the action to delete
+        s = self.disk.add_slice(0, CYLSIZE, 1, Size.gb_units)
+        s.action = "delete"
+
+        # insert another slice with the same name
+        self.disk.add_slice(0, CYLSIZE, 2, Size.gb_units)
+        self.assertFalse(errsvc._ERRORS)
+
 
 class TestSliceInPartition(unittest.TestCase):
     def setUp(self):
@@ -1350,6 +1369,15 @@
         self.assertEqual(start_sector, s.start_sector)
         self.assertEqual(Size("5gb"), s.size)
 
+    def test_insertion_of_slice_over_deleted_slice_of_same_name(self):
+        # add a 1GB slice at start_sector CYLSIZE and set the action to delete
+        s = self.partition.add_slice(0, CYLSIZE, 1, Size.gb_units)
+        s.action = "delete"
+
+        # insert another slice with the same name
+        self.partition.add_slice(0, CYLSIZE, 2, Size.gb_units)
+        self.assertFalse(errsvc._ERRORS)
+
 
 class TestLogicalPartition(unittest.TestCase):