]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
python-common: add int value validation for count and count_per_host
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 8 Dec 2021 20:33:54 +0000 (15:33 -0500)
committerSebastian Wagner <sewagner@redhat.com>
Tue, 11 Jan 2022 12:23:03 +0000 (13:23 +0100)
Add additional validation for the count and count_per_host fields
sourced from YAML.

Fixes: https://tracker.ceph.com/issues/50524
Signed-off-by: John Mulligan <jmulligan@redhat.com>
(cherry picked from commit a9ad2a50fe83ea3342b7c1bbcfb942789e965cb4)

src/python-common/ceph/deployment/service_spec.py

index b9493b2329b5753a9fcf89bd70957a93189c345e..46b6aa1649818b81ed3c268157e34d9c4a77e40e 100644 (file)
@@ -273,10 +273,24 @@ class PlacementSpec(object):
         if self.hosts and self.label:
             # TODO: a less generic Exception
             raise SpecValidationError('Host and label are mutually exclusive')
-        if self.count is not None and self.count <= 0:
-            raise SpecValidationError("num/count must be > 1")
-        if self.count_per_host is not None and self.count_per_host < 1:
-            raise SpecValidationError("count-per-host must be >= 1")
+        if self.count is not None:
+            try:
+                intval = int(self.count)
+            except (ValueError, TypeError):
+                raise SpecValidationError("num/count must be a numeric value")
+            if self.count != intval:
+                raise SpecValidationError("num/count must be an integer value")
+            if self.count <= 0:
+                raise SpecValidationError("num/count must be > 1")
+        if self.count_per_host is not None:
+            try:
+                intval = int(self.count_per_host)
+            except (ValueError, TypeError):
+                raise SpecValidationError("count-per-host must be a numeric value")
+            if self.count_per_host != intval:
+                raise SpecValidationError("count-per-host must be an integer value")
+            if self.count_per_host < 1:
+                raise SpecValidationError("count-per-host must be >= 1")
         if self.count_per_host is not None and not (
                 self.label
                 or self.hosts