From 2cdcc5cf2bc031a3a3d6af9dc7c1d8dcf092c0d1 Mon Sep 17 00:00:00 2001
From: haixin <haixin@inspur.com>
Date: Tue, 8 Dec 2020 19:49:20 +0800
Subject: [PATCH] optimize share size check

Change-Id: I1685e92a2e1baccbbefde31a4b28046768846eec
---
 manila/share/api.py | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/manila/share/api.py b/manila/share/api.py
index bd3c9c4ec5..1a6e6102d3 100644
--- a/manila/share/api.py
+++ b/manila/share/api.py
@@ -199,20 +199,13 @@ class API(base.Base):
         else:
             snapshot = None
 
-        def as_int(s):
-            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:
+        if not strutils.is_int_like(size) or int(size) <= 0:
             msg = (_("Share size '%s' must be an integer and greater than 0")
                    % size)
             raise exception.InvalidInput(reason=msg)
 
+        # make sure size has been convert to int.
+        size = int(size)
         if snapshot and size < snapshot['size']:
             msg = (_("Share size '%s' must be equal or greater "
                      "than snapshot size") % size)