]> 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)
committerJohn Mulligan <jmulligan@redhat.com>
Fri, 10 Dec 2021 17:18:49 +0000 (12:18 -0500)
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>
src/python-common/ceph/deployment/service_spec.py

index 48d511fc3dcf8b1a036ae4aa7978748568c43ee7..e8fd14e9ca6a99aff94464f7e2864ab2557d3024 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