From a9ad2a50fe83ea3342b7c1bbcfb942789e965cb4 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Wed, 8 Dec 2021 15:33:54 -0500 Subject: [PATCH] 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 --- .../ceph/deployment/service_spec.py | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/python-common/ceph/deployment/service_spec.py b/src/python-common/ceph/deployment/service_spec.py index 48d511fc3dcf8..e8fd14e9ca6a9 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 -- 2.39.5