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

Add version_cmp for FreeBSD pkg. #36550

Merged
merged 1 commit into from
Sep 27, 2016
Merged

Conversation

rickyninja
Copy link
Contributor

What does this PR do?

Enable pkg compare_version for FreeBSD.

What issues does this PR fix or reference?

None I'm aware of.

Previous Behavior

Seems like it's falling back to a generic salt version_cmp, but doesn't work right for FreeBSD.

New Behavior

Version comparison works for FreeBSD packages.

Tests written?

No

Please review Salt's Contributing Guide for best practices.

@@ -165,6 +165,10 @@ def _fulfills_version_spec(versions, oper, desired_version,
otherwise returns False
'''
cmp_func = __salt__.get('pkg.version_cmp')
# stripping "with_origin" dict wrapper
if salt.utils.is_freebsd():
if type(versions) is dict and 'version' in versions:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@terminalmage @rickyninja and I stared at this for a while to see if we should be doing something inside pkgng.py to disable with_origin but neither of us could determine if that was the right intent. This seems good to me in all cases but I'm interested if you have any feedback.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type checking should be using isinstance, since it more gracefully handles subclasses. Not saying we'll ever subclass dict here, but it's a good way of future-proofing against potential future breakage.

With regard to disabling with_origin, I'm not familiar with this option, I did not add support for it. It seems to default to False though, looking at the source code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, it's handled in any case with the type inspection.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amontalban ok with these changes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kev009 LGTM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like I said, we should not be using simple type matching here. Can we get this changed to:

if isinstance(versions, dict) and 'version' in versions:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I amended the commit to switch to isinstance last night. You can see in "Files changed" tab, but not here in discussion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@terminalmage this appears to be an artifact of the new GitHub reviews changes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it does, I'm use to seeing a note that the comments are on an outdated diff when the PR is updated, and it doesn't appear to do that now.

@@ -1241,10 +1245,14 @@ def installed(
failed_hold = None
if targets or to_reinstall:
reinstall = bool(to_reinstall)
force = False
if salt.utils.is_freebsd():
force = True # Downgrades need to be forced.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't appear to be part of adding a version_cmp function. Is this related to another issue?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's necessary for version comparison to apply, pkg wont honor a downgrade without it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was testing with pkg.installed. You can not install a package when the version is less than the currently installed version without doing a force.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this wasn't mentioned at all in the pull request message, so I wasn't sure. Thanks for the clarification.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rickyninja Thanks for the additional explanation. I did merge this, but it might need to be tweaked a little now that I think about it. The way we decide whether or not a downgrade needs to be done is typically handled within the execution module itself (see for instance yumpkg.py).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@terminalmage You're welcome. This is my first time looking at the salt code, so I wasn't aware of the yumpkg downgrade stuff. If you need any more changes from me in a follow-up pull request please let me know.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rickyninja sure thing! It'll work as-is for now, but the code should be moved into pkgng.py probably. We try to keep platform-specific stuff out of the state module when possible, because it results in different behavior when executed via the state and via just calling pkg.install on the salt CLI.

@terminalmage terminalmage merged commit 57ec792 into saltstack:2015.8 Sep 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants