From: John Mulligan Date: Wed, 8 Dec 2021 20:33:54 +0000 (-0500) Subject: python-common: add int value validation for count and count_per_host X-Git-Tag: v16.2.8~260^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2c38ea578b76f302d3eb839a83cce2598e97cf48;p=ceph.git python-common: add int value validation for count and count_per_host 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 (cherry picked from commit a9ad2a50fe83ea3342b7c1bbcfb942789e965cb4) --- diff --git a/src/python-common/ceph/deployment/service_spec.py b/src/python-common/ceph/deployment/service_spec.py index b9493b2329b5..46b6aa164981 100644 --- a/src/python-common/ceph/deployment/service_spec.py +++ b/src/python-common/ceph/deployment/service_spec.py @@ -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