diff --git a/actions.yaml b/actions.yaml index f7839d49..0081c6f0 100644 --- a/actions.yaml +++ b/actions.yaml @@ -256,7 +256,10 @@ pool-set: type: string description: "Any valid Ceph key from http://docs.ceph.com/docs/master/rados/operations/pools/#set-pool-values" value: - type: string + # LP: #1838650 - unfortunately, Juju appears to consider '3' on the + # command line as not being a string, and has to be quoted as "'3'". So, + # we actually let the charm do the verification, and let any value + # through here. description: "The value to set" required: - key diff --git a/actions/pool_set.py b/actions/pool_set.py index 8549fe70..39ee9345 100755 --- a/actions/pool_set.py +++ b/actions/pool_set.py @@ -32,7 +32,8 @@ if __name__ == '__main__': 'value': value} try: - handle_set_pool_value(service='admin', request=request) + # Bug: #1838650 -- force coercion to an int for the value if required. + handle_set_pool_value(service='admin', request=request, coerce=True) except CalledProcessError as e: log(str(e)) action_fail("Setting pool key: {} and value: {} failed with " diff --git a/lib/charms_ceph/broker.py b/lib/charms_ceph/broker.py index 726f9498..15552cd8 100644 --- a/lib/charms_ceph/broker.py +++ b/lib/charms_ceph/broker.py @@ -540,11 +540,13 @@ def handle_remove_cache_tier(request, service): pool.remove_cache_tier(cache_pool=cache_pool) -def handle_set_pool_value(request, service): +def handle_set_pool_value(request, service, coerce=False): """Sets an arbitrary pool value. :param request: dict of request operations and params :param service: The ceph client to run the command under. + :param coerce: Try to parse/coerce the value into the correct type. + Used by the action code that only gets Str from Juju :returns: dict. exit-code and reason if not 0 """ # Set arbitrary pool values @@ -558,6 +560,16 @@ def handle_set_pool_value(request, service): # Get the validation method validator_params = POOL_KEYS[params['key']] + # BUG: #1838650 - the function needs to try to coerce the value param to + # the type required for the validator to pass. Note, if this blows, then + # the param isn't parsable to the correct type. + if coerce: + try: + params['value'] = validator_params[0](params['value']) + except ValueError: + raise RuntimeError("Value {} isn't of type {}" + .format(params['value'], validator_params[0])) + # end of BUG: #1838650 if len(validator_params) == 1: # Validate that what the user passed is actually legal per Ceph's rules validator(params['value'], validator_params[0])