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

RFC-037: add chef_version and ohai_version metadata #4081

Merged
merged 10 commits into from Oct 28, 2015

Conversation

lamont-granquist
Copy link
Contributor

This allows knife to upload cookbooks containing chef_version and ohai_version. When the chef-client downloads cookbooks with constraints it checks them and throws an exception if the constraints do not match. The knife command will upload cookbooks which do not match the version constraint (this is deliberate in the case where knife workstation versions differ from chef-client production versions -- injecting the production chef-client version into knife to prevent uploads is out-of-scope).

Also out of scope - including these into /universe, teaching berkshelf and the policyfile depsolver to avoid them, injecting production chef-version values into policyfiles, teaching the cookbook_versions endpoint to filter based on chef_version, etc, etc, etc, etc, etc.... This is only step number one.

This PR does go slightly beyond the RFC and includes the ability to not only pin via a simple constraint like '~> 12.3' but also to allow multiple pins to handle features that were back-ported:

chef_version ">= 11.20.0", "< 12.0"
chef_version ">= 12.6.0"

That will be satisfied by a chef version that is 11.x >= 11.20.0, or 12.x >= 12.6.0, or >= 13.

lamont-granquist added a commit to chef/chef-zero that referenced this pull request Oct 20, 2015
most of our metadata is the form of:

key "value"

but chef_version can be:

chef_version ">= 12.3.1", "< 13.0.0"

so we need a splat in method messing and need to shovel it into an
array.

relates to chef/chef#4081
@lamont-granquist
Copy link
Contributor Author

Tested on hosted and this works as designed.

  • knife upload with new code works fine even if the version pin doesn't match
  • chef-client run with new code throws the exception
  • chef-client run with old code ignores the directive when its present on the server
  • knife upload with old code throws an exception

Because of that latter point, we still need to do this:

chef_version ">= 12.0" if respond_to?(:chef_version)

So that old versions of knife can upload the cookbook.

We might want to change knife so that unknown metadata is ignored (which means a method_missing that warns and then no-ops? mild sigh...), but that's out of scope for this.

@lamont-granquist
Copy link
Contributor Author

@chef/client-core ready for review

private

def gem_dep_matches?(what, version, *deps)
return true unless deps.length > 0
deps.each do |dep|
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is the logic we want. What you have here is equiv to deps.any? {|dep| dep.match?(what, version) }. I think we want all? there.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh, I think I see how this works. Each "row" is loaded into a single dependency object so that covers the all?, and then we want an any? between each of those? That seems maybe a bit overcomplicated but I can dig it. I would still rewrite this as an any? for clarity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Heh, I think this was the last bit of code I wrote before demoing it on the last day of the summit. Its very obviously a reimplementation of #any? so I can certainly fix that...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And yeah, this is the code that handles the "we backported a feature" use case.

@danielsdeleo
Copy link
Contributor

Code and tests look good. Need to figure out the travis issue and add the docs you meant to write, then 👍

@lamont-granquist
Copy link
Contributor Author

travis was timing out on something unrelated, rebooting the test fixed it.

@lamont-granquist
Copy link
Contributor Author

Added docs, discovered that the ...to_hash and ...from_hash methods were acting on Arrays in the process so cosmetically fixed those names...

# @param version_args [Array<String>] Version constraint in String form
# @return [Array<Gem::Dependency>] Current chef_versions array
def chef_version(*version_args)
@chef_versions << Gem::Dependency.new('chef', *version_args)
Copy link
Contributor

Choose a reason for hiding this comment

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

The fact that this returns a value makes it sound like you expect it to be used as a reader too? Calling chef_versions() would shift on an empty dependency, maybe add unless version_args.empty? here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@mcquin
Copy link
Contributor

mcquin commented Oct 23, 2015

👍

@jonlives
Copy link
Contributor

👍 Thanks @lamont-granquist!

@btm
Copy link
Contributor

btm commented Oct 23, 2015

What about chef-shell? People still use that, right? Seems like we should validate there too so you get the same behavior.

@lamont-granquist
Copy link
Contributor Author

Hmmm? The point of testing solo is because there's a solo-specific block in the policy_builder/expand_node_object.rb file so we need to test both sides of that conditional. With chef-shell you'll wind up on one side or the other of that expression based on how you invoked chef-shell (solo-like or not) so we've got coverage there and it'll work.

@lamont-granquist
Copy link
Contributor Author

Turns out I did an integration test for the solo-side of that conditional, but forgot the client-side.

@thommay
Copy link
Contributor

thommay commented Oct 26, 2015

👍

@lamont-granquist
Copy link
Contributor Author

I'll push the CHANGELOG after meeting....

lamont-granquist added a commit that referenced this pull request Oct 28, 2015
RFC-037:  add chef_version and ohai_version metadata
@lamont-granquist lamont-granquist merged commit 6a306c0 into master Oct 28, 2015
@lamont-granquist lamont-granquist deleted the lcg/chef-version branch October 28, 2015 17:33
@chef chef locked and limited conversation to collaborators Nov 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants