[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[PATCH 12/15] Cleanup some preconditions in DeviceAction constructors.



- ActionCreateDevice should require a non-existent device.
- ActionResizeDevice should check that the device is resizable first.
- ActionResizeFormat should check that the format is resizable first.
- ActionResizeFormat should check new size against currentSize, not
  targetSize.
---
 pyanaconda/storage/deviceaction.py |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/pyanaconda/storage/deviceaction.py b/pyanaconda/storage/deviceaction.py
index 4396661..e020a57 100644
--- a/pyanaconda/storage/deviceaction.py
+++ b/pyanaconda/storage/deviceaction.py
@@ -228,6 +228,9 @@ class ActionCreateDevice(DeviceAction):
     obj = ACTION_OBJECT_DEVICE
 
     def __init__(self, device):
+        if device.exists:
+            raise ValueError("device already exists")
+
         # FIXME: assert device.fs is None
         DeviceAction.__init__(self, device)
 
@@ -333,15 +336,14 @@ class ActionResizeDevice(DeviceAction):
     obj = ACTION_OBJECT_DEVICE
 
     def __init__(self, device, newsize):
-        currentSize = long(math.floor(device.currentSize))
-        if currentSize == newsize:
-            raise ValueError("new size same as old size")
-
         if not device.resizable:
             raise ValueError("device is not resizable")
 
+        if long(math.floor(device.currentSize)) == newsize:
+            raise ValueError("new size same as old size")
+
         DeviceAction.__init__(self, device)
-        if newsize > currentSize:
+        if newsize > long(math.floor(device.currentSize)):
             self.dir = RESIZE_GROW
         else:
             self.dir = RESIZE_SHRINK
@@ -516,7 +518,10 @@ class ActionResizeFormat(DeviceAction):
     obj = ACTION_OBJECT_FORMAT
 
     def __init__(self, device, newsize):
-        if long(math.floor(device.format.targetSize)) == newsize:
+        if not device.format.resizable:
+            raise ValueError("format is not resizable")
+
+        if long(math.floor(device.format.currentSize)) == newsize:
             raise ValueError("new size same as old size")
 
         DeviceAction.__init__(self, device)
-- 
1.7.2.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]