storage: Move alloc/cap validation to validate()

Doing this at property set time is overly noisy. Follow the same
pattern of VirtualDisk and only do this in the validate() function.

https://bugzilla.redhat.com/show_bug.cgi?id=1433239
This commit is contained in:
Cole Robinson 2017-03-17 12:00:03 -04:00
parent c08226182e
commit 9c8ffe51da
2 changed files with 18 additions and 34 deletions

View File

@ -345,10 +345,11 @@ class _StorageCreator(_StorageBase):
if self._vol_install:
self._vol_install.validate()
else:
if self._size is None:
raise ValueError(_("size is required for non-existent disk "
"'%s'" % self.get_path()))
return
if self._size is None:
raise ValueError(_("size is required for non-existent disk "
"'%s'" % self.get_path()))
err, msg = self.is_size_conflict()
if err:

View File

@ -683,22 +683,6 @@ class StorageVolume(_StorageObject):
raise ValueError(_("Name '%s' already in use by another volume." %
name))
def _validate_allocation(self, val):
ret = self.is_size_conflict(allocation=val)
if ret[0]:
raise ValueError(ret[1])
elif ret[1]:
logging.warn(ret[1])
return val
def _validate_capacity(self, val):
ret = self.is_size_conflict(capacity=val)
if ret[0]:
raise ValueError(ret[1])
elif ret[1]:
logging.warn(ret[1])
return val
def _default_format(self):
if self.file_type == self.TYPE_FILE:
return "raw"
@ -728,10 +712,8 @@ class StorageVolume(_StorageObject):
type = XMLProperty("./@type")
key = XMLProperty("./key")
capacity = XMLProperty("./capacity", is_int=True,
validate_cb=_validate_capacity)
allocation = XMLProperty("./allocation", is_int=True,
validate_cb=_validate_allocation)
capacity = XMLProperty("./capacity", is_int=True)
allocation = XMLProperty("./allocation", is_int=True)
format = XMLProperty("./target/format/@type", default_cb=_default_format)
target_path = XMLProperty("./target/path")
backing_store = XMLProperty("./backingStore/path")
@ -809,6 +791,12 @@ class StorageVolume(_StorageObject):
"setting allocation equal to capacity"))
self.allocation = self.capacity
isfatal, errmsg = self.is_size_conflict()
if isfatal:
raise ValueError(errmsg)
if errmsg:
logging.warn(errmsg)
def install(self, meter=None):
"""
Build and install storage volume from xml
@ -891,7 +879,7 @@ class StorageVolume(_StorageObject):
time.sleep(1)
def is_size_conflict(self, capacity=None, allocation=None):
def is_size_conflict(self):
"""
Report if requested size exceeds its pool's available amount
@ -900,27 +888,22 @@ class StorageVolume(_StorageObject):
2. String message if some collision was encountered.
@rtype: 2 element C{tuple}: (C{bool}, C{str})
"""
if capacity is None:
capacity = self.capacity
if allocation is None:
allocation = self.allocation
if not self.pool:
return (False, "")
# pool info is [pool state, capacity, allocation, available]
avail = self.pool.info()[3]
if allocation > avail:
if self.allocation > avail:
return (True, _("There is not enough free space on the storage "
"pool to create the volume. "
"(%d M requested allocation > %d M available)") %
((allocation / (1024 * 1024)),
((self.allocation / (1024 * 1024)),
(avail / (1024 * 1024))))
elif capacity > avail:
elif self.capacity > avail:
return (False, _("The requested volume capacity will exceed the "
"available pool space when the volume is fully "
"allocated. "
"(%d M requested capacity > %d M available)") %
((capacity / (1024 * 1024)),
((self.capacity / (1024 * 1024)),
(avail / (1024 * 1024))))
return (False, "")