-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cv_version: ensure version param has a minor part #1091
Conversation
@@ -204,6 +204,13 @@ def main(): | |||
|
|||
module.task_timeout = 60 * 60 | |||
|
|||
if 'version' in module.foreman_params and '.' not in module.foreman_params['version']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if you get "2.3.4.5"? Should we check for exactly one '.'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So something like:
if 'version' in module.foreman_params and module.foreman_params['version'].count('.') != 1:
err_msg = "The 'version' needs to be in the format 'X.Y', not '{0}'".format(module.foreman_params['version'])
if module.foreman_params['version'].count('.') > 1:
module.fail_json(err_msg)
else:
try:
major_version = int(module.foreman_params['version'])
module.foreman_params['version'] = "{0}.0".format(major_version)
except ValueError:
module.fail_json(err_msg)
still doesn't catch "what.lol" as a version, but I'd not go that far right now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i thought checking a regex like r"^(\d*)(?:\.(\d*))?$"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just used ^\d+\.\d+$
and then relied on int()
throwing a ValueError
;)
if 'version' in module.foreman_params and '.' not in module.foreman_params['version']: | ||
try: | ||
major_version = int(module.foreman_params['version']) | ||
module.foreman_params['version'] = "{0}.0".format(major_version) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this branch emit a warning, so the user knows their playbook is not exactly correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if hammer accepts it we should maybe also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed to read the logic twice, but i think it covers all cases now.
No description provided.