Skip to content
This repository has been archived by the owner on Mar 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #221 from tmatilai/librarian-option
Browse files Browse the repository at this point in the history
Librarian-Chef is not run by default when SoloCook/Bootstrap invoked from ruby
  • Loading branch information
tmatilai committed Mar 28, 2013
2 parents 0039adb + 139933c commit 538839c
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 3 deletions.
1 change: 1 addition & 0 deletions Manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@ test/support/ssh_config
test/support/test_case.rb
test/support/validation_helper.rb
test/test_helper.rb
test/tools_test.rb
5 changes: 2 additions & 3 deletions lib/chef/knife/solo_cook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class SoloCook < Knife

option :librarian,
:long => '--no-librarian',
:description => 'Skip librarian-chef install',
:default => true
:description => 'Skip librarian-chef install'

option :why_run,
:short => '-W',
Expand Down Expand Up @@ -70,7 +69,7 @@ def run

check_chef_version if config[:chef_check]
generate_node_config
librarian_install if config[:librarian]
librarian_install if config_value(:librarian, true)
rsync_kitchen
add_patches
add_solo_config unless using_custom_solorb?
Expand Down
18 changes: 18 additions & 0 deletions lib/knife-solo/tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,23 @@ def system!(command)
def windows_client?
RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
end

# Chef 10 compatible way of getting correct precedence for command line
# and configuration file options. Adds correct handling of `false` values
# to the original example in
# http://docs.opscode.com/breaking_changes_chef_11.html#knife-configuration-parameter-changes
def config_value(key, default = nil)
key = key.to_sym
if !config[key].nil?
config[key]
elsif !Chef::Config[:knife][key].nil?
# when Chef 10 support is dropped, this branch can be removed
# as Chef 11 automatically merges the values to the `config` hash
Chef::Config[:knife][key]
else
default
end
end

end
end
82 changes: 82 additions & 0 deletions test/tools_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
require 'test_helper'
require 'support/kitchen_helper'

require 'chef/config'
require 'knife-solo/tools'

class DummyToolsCommand < Chef::Knife
include KnifeSolo::Tools

option :foo,
:long => '--foo FOO'

option :boo,
:long => '--[no-]boo'
end

class ToolsTest < TestCase
include KitchenHelper

def setup
Chef::Config[:knife][:foo] = nil
Chef::Config[:knife][:boo] = nil
end

def test_config_value_defaults_to_nil
assert_nil command.config_value(:foo)
assert_nil command.config_value(:boo)
end

def test_config_value_returns_the_default
assert_equal 'bar', command.config_value(:foo, 'bar')

assert_equal true, command.config_value(:boo, true)
assert_equal false, command.config_value(:boo, false)
end

def test_config_value_uses_cli_option
assert_equal 'bar', command('--foo=bar').config_value(:foo)
assert_equal 'bar', command('--foo=bar').config_value(:foo, 'baz')

assert_equal true, command('--boo').config_value(:boo)
assert_equal true, command('--boo').config_value(:boo, false)
assert_equal false, command('--no-boo').config_value(:boo)
assert_equal false, command('--no-boo').config_value(:boo, true)
end

def test_config_value_uses_configuration
Chef::Config[:knife][:foo] = 'bar'
assert_equal 'bar', command.config_value(:foo)
assert_equal 'bar', command.config_value(:foo, 'baz')

Chef::Config[:knife][:boo] = true
assert_equal true, command.config_value(:boo)
assert_equal true, command.config_value(:boo, false)

Chef::Config[:knife][:boo] = false
assert_equal false, command.config_value(:boo)
assert_equal false, command.config_value(:boo, true)
end

def test_config_value_prefers_cli_option
Chef::Config[:knife][:foo] = 'foo'
assert_equal 'bar', command('--foo=bar').config_value(:foo)
assert_equal 'bar', command('--foo=bar').config_value(:foo, 'baz')

Chef::Config[:knife][:boo] = true
assert_equal true, command('--boo').config_value(:boo)
assert_equal true, command('--boo').config_value(:boo, false)
assert_equal false, command('--no-boo').config_value(:boo)
assert_equal false, command('--no-boo').config_value(:boo, true)

Chef::Config[:knife][:boo] = false
assert_equal true, command('--boo').config_value(:boo)
assert_equal true, command('--boo').config_value(:boo, false)
assert_equal false, command('--no-boo').config_value(:boo)
assert_equal false, command('--no-boo').config_value(:boo, true)
end

def command(*args)
knife_command(DummyToolsCommand, *args)
end
end

0 comments on commit 538839c

Please sign in to comment.