----- Original Message -----
From: "David Lehman" <dlehman(a)redhat.com>
To: anaconda-patches(a)lists.fedorahosted.org
Sent: Friday, December 20, 2013 12:59:58 PM
Subject: [PATCH 5/6] Allow negative sizes.
There are times, especially when reconfiguring a stack via the device
factory, when a volume group might have a negative amount free space.
---
blivet/errors.py | 3 ---
blivet/size.py | 11 ++++-------
tests/size_test.py | 5 -----
3 files changed, 4 insertions(+), 15 deletions(-)
diff --git a/blivet/errors.py b/blivet/errors.py
index 78d8271..03c9d7b 100644
--- a/blivet/errors.py
+++ b/blivet/errors.py
@@ -182,9 +182,6 @@ class DasdFormatError(StorageError):
class SizeParamsError(StorageError):
pass
-class SizeNotPositiveError(StorageError):
- pass
-
class SizePlacesError(StorageError):
pass
diff --git a/blivet/size.py b/blivet/size.py
index a837a98..590f744 100644
--- a/blivet/size.py
+++ b/blivet/size.py
@@ -92,9 +92,6 @@ def _parseSpec(spec, xlate):
except InvalidOperation:
raise ValueError("invalid size specification", spec)
- if size < 0:
- raise SizeNotPositiveError("spec= param must be >=0")
-
specifier = m.groups()[1].lower()
if xlate:
bytes = [_(b) for b in _bytes]
@@ -154,11 +151,11 @@ class Size(Decimal):
raise SizeParamsError("only specify one parameter")
if bytes is not None:
- if type(bytes).__name__ in ["int", "long",
"float", 'Decimal']
and bytes >= 0:
+ if type(bytes).__name__ in ["int", "long",
"float", 'Decimal']:
# sorry, but no partial bytes
self = Decimal.__new__(cls, value=int(bytes))
else:
- raise SizeNotPositiveError("bytes= param must be >=0")
+ raise ValueError("invalid value for bytes param")
elif spec:
self = Decimal.__new__(cls, value=_parseSpec(spec, True))
elif en_spec:
@@ -256,14 +253,14 @@ class Size(Decimal):
check = self._trimEnd("%d" % self)
- if Decimal(check) < 1000:
+ if abs(Decimal(check)) < 1000:
return "%s %s" % (check, _("B"))
prefixes_xlated = [_(p) for p in _prefixes]
for factor, prefix, abbr in prefixes_xlated:
newcheck = super(Size, self).__div__(Decimal(factor))
- if newcheck < 1000:
+ if abs(newcheck) < 1000:
# nice value, use this factor, prefix and abbr
break
diff --git a/tests/size_test.py b/tests/size_test.py
index 2b1ef64..de13900 100644
--- a/tests/size_test.py
+++ b/tests/size_test.py
@@ -31,14 +31,9 @@ class SizeTestCase(unittest.TestCase):
self.assertRaises(SizeParamsError, Size)
self.assertRaises(SizeParamsError, Size, bytes=500, en_spec="45GB")
- self.assertRaises(SizeNotPositiveError, Size, bytes=-1)
-
zero = Size(bytes=0)
self.assertEqual(zero, 0.0)
- self.assertRaises(SizeNotPositiveError, Size, en_spec="-1 TB")
- self.assertRaises(SizeNotPositiveError, Size, en_spec="-47kb")
-
s = Size(bytes=500)
self.assertRaises(SizePlacesError, s.humanReadable, places=-1)
Ack, although it might be worthwhile having a test that reads a negative size and
succeeds.
--
1.8.1.4
_______________________________________________
anaconda-patches mailing list
anaconda-patches(a)lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches