Run "gnocchi archive-policy update" exception when definition include space character
gujun4990 opened this issue · comments
The situation is like this: I need to update a archive-policy using gnocchi command and the definition include space character. Such like this: gnocchi archive-policy update -d "granularity: 0:03:00, points: 86400" low. When running the below code, ValueError exception raised.
#gnocchiclient/v1/archive_policy_cli.py
def archive_policy_definition(string):
parts = string.split(",")
defs = {}
for part in parts:
attr, __, value = part.partition(":")
if (attr not in ['granularity', 'points', 'timespan'] or
value is None):
raise ValueError
defs[attr] = value
if len(defs) < 2:
raise ValueError
return defs
Because the attr and value don't remove these space character. So I think this is a bug.
The link is https://bugs.launchpad.net/ubuntu/+source/python-gnocchiclient/+bug/1801314 for launchpad website.
I think we need to modify the code like below:
def archive_policy_definition(string):
parts = string.split(",")
defs = {}
for part in parts:
attr, __, value = part.partition(":")
attr, value = attr.strip(), value.strip()
if (attr not in ['granularity', 'points', 'timespan'] or
value is None):
raise ValueError
defs[attr] = value
if len(defs) < 2:
raise ValueError
return defs
feel free to create a PR. i think you can just use .replace(' ','')
and get rid of spaces completely
OK, thanks for your suggestion. I have submitted a PR from the my branch to master branch. Please review it. Thank you.
Closed in #98