Merge "optimize share size check"

This commit is contained in:
Zuul 2021-05-11 00:53:15 +00:00 committed by Gerrit Code Review
commit 80460424e0
1 changed files with 3 additions and 10 deletions

View File

@ -199,20 +199,13 @@ class API(base.Base):
else: else:
snapshot = None snapshot = None
def as_int(s): if not strutils.is_int_like(size) or int(size) <= 0:
try:
return int(s)
except (ValueError, TypeError):
return s
# tolerate size as stringified int
size = as_int(size)
if not isinstance(size, int) or size <= 0:
msg = (_("Share size '%s' must be an integer and greater than 0") msg = (_("Share size '%s' must be an integer and greater than 0")
% size) % size)
raise exception.InvalidInput(reason=msg) raise exception.InvalidInput(reason=msg)
# make sure size has been convert to int.
size = int(size)
if snapshot and size < snapshot['size']: if snapshot and size < snapshot['size']:
msg = (_("Share size '%s' must be equal or greater " msg = (_("Share size '%s' must be equal or greater "
"than snapshot size") % size) "than snapshot size") % size)