Skip to content
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

Merged
merged 1 commit into from
Dec 9, 2020

Conversation

evgeni
Copy link
Member

@evgeni evgeni commented Dec 8, 2020

No description provided.

@@ -204,6 +204,13 @@ def main():

module.task_timeout = 60 * 60

if 'version' in module.foreman_params and '.' not in module.foreman_params['version']:
Copy link
Member

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 '.'?

Copy link
Member Author

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?

Copy link
Member

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*))?$"

Copy link
Member Author

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)
Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member

@mdellweg mdellweg left a 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.

@evgeni evgeni merged commit 58354be into theforeman:develop Dec 9, 2020
@evgeni evgeni deleted the i1087 branch December 9, 2020 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants