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

Fixes knife-block for chef 12 #26

Closed
wants to merge 2 commits into from

Conversation

paulpeterson
Copy link

Using chef_config_dir instead of locate_config_file

@proffalken
Copy link

Hi all,

I've just updated the travis.yml file so that it will test against ruby 2.x (the main issue that seemed to be causing it to fail previously).

It's now failing with a different error but it's been so long since I touched ruby that I've forgotten where to start. :(

The good news is that @solarce now has access to rubygems.org for this so once it's been fixed you should be able to get it merged and published.

Thanks again for all your interest,

Matt

@solarce
Copy link
Contributor

solarce commented Jan 9, 2015

Argh, somehow I wasn't watching the repo, I'm gonna do some work on getting builds passing on travis this weekend and getting issues/PRs fixed up

@onlyhavecans
Copy link
Contributor

I modified the tests to run under chef 12 and chefdk 0.4.0 but this still didn't pass tests with the following error.

/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.0.3/lib/chef/workstation_config_loader.rb:46: warning: instance variable @chef_config_dir not initialized

  1) Failure:
TestGreenAndSecureModule#test_002_it_locates_a_knife_config [/Users/bitm/Code/knife-block/test/unit/knifeblock_test.rb:38]:
FAIL: knife.rb not found!.
Expected /.*\/.chef\/knife\.rb/ to match "/Users/bitm/knife.rb".

I'm not completely sure if the test or this needs fixing. I'm new to ruby. I will look into this more when I have time.

@onlyhavecans
Copy link
Contributor

I pulled this and made local package with chef gem build knife-block.gemspec and chef gem install knife-block-0.1.1.gem and this worked with chefdk 0.4.0

@jasmeralia
Copy link
Contributor

I pulled this and installed it under chefdk 0.4.0 on OSX. It runs, but knife block list shows no configs, even though I have several that worked just fine under older chefdk versions. Knife block use is unable to switch to them either.

@ghost
Copy link

ghost commented Feb 18, 2015

It looks like ::Chef::Knife.chef_config_dir returns the user's home directory. If you concatenate '/.chef' to the end, it appears to work.

@paulpeterson
Copy link
Author

I corrected the test to run properly, everything should be in place now.

@freeyoung
Copy link

+1 for this

1 similar comment
@tya
Copy link

tya commented Feb 28, 2015

+1 for this

@solarce solarce self-assigned this Mar 1, 2015
@solarce
Copy link
Contributor

solarce commented Mar 1, 2015

@paulpeterson now that I've updated the Travis config to include a chefdk + 2.1 build, can you rebase your PR and update it? Your changes passed for me (except on 2.2, which is a known issue that's fixed in another PR i'll merge soon)

@justin-kirk-active
Copy link

Reading through the master branch code and Chef 12 code it seems we should consider the following update to master instead. The tests pass as is on 2.1 certainly.

diff --git a/lib/chef/knife/block.rb b/lib/chef/knife/block.rb
index 554d220..944a205 100644
--- a/lib/chef/knife/block.rb
+++ b/lib/chef/knife/block.rb
@@ -11,13 +11,17 @@
 class Chef
   class Knife
     def get_config_file
+      case
+        when GreenAndSecure.current_chef_version >= ::Gem::Version.new('12.0.0')
+          config[:config_file] ||= ::Chef::Knife.config_loader.config_location
       # locate_config_file is only compatible with Chef 11
-      if GreenAndSecure.current_chef_version >= ::Gem::Version.new('11.8.0')
-        config[:config_file] ||= ::Chef::Knife.locate_config_file
-      elsif GreenAndSecure.current_chef_version >= ::Gem::Version.new('11.0.0')
-        locate_config_file
-      else
-        GreenAndSecure.locate_config_file config
+        when ((GreenAndSecure.current_chef_version < ::Gem::Version.new('12.0.0')) && \
+              (GreenAndSecure.current_chef_version >= ::Gem::Version.new('11.8.0')))
+          config[:config_file] ||= ::Chef::Knife.locate_config_file
+        when GreenAndSecure.current_chef_version >= ::Gem::Version.new('11.0.0')
+          locate_config_file
+        else
+          GreenAndSecure.locate_config_file config
       end

       # if we haven't created our knife.rb yet, set defaults to ~/.chef so we can create the config.

@nshemonsky
Copy link

+1 on @justin-kirk-active's suggestion, looks to be working in chefdk 0.4.0 with chef client 12.0.3 on OSX.

@solarce
Copy link
Contributor

solarce commented Mar 8, 2015

I grabbed your changed and rebased them on top of some CI improvements I made, so this got merged with #37.

@solarce solarce closed this Mar 8, 2015
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

9 participants