summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaire McQuin <mcquin@users.noreply.github.com>2014-06-11 16:04:12 -0700
committerClaire McQuin <mcquin@users.noreply.github.com>2014-06-11 16:04:12 -0700
commit56d6cc8b2c24afd4bf6e3001a3635fa2beeec700 (patch)
tree4869d0ffd9c7e0b32b3c95bc7ab3a8725119fc28
parentf267978ccbba62c7e50a6b4722fb6f2aa0ef34d4 (diff)
parent0fe170b0b72f6990ae7ccb55196f16196cd8d3cc (diff)
downloadchef-56d6cc8b2c24afd4bf6e3001a3635fa2beeec700.tar.gz
Merge pull request #1443 from opscode/ryancragun/CHEF-5314_11-master
[CHEF-5314] Support override_runlist CLI option in shef/chef-shell
-rw-r--r--lib/chef/shell.rb7
-rw-r--r--lib/chef/shell/shell_session.rb6
-rw-r--r--spec/functional/shell_spec.rb10
-rw-r--r--spec/unit/shell/shell_session_spec.rb44
4 files changed, 62 insertions, 5 deletions
diff --git a/lib/chef/shell.rb b/lib/chef/shell.rb
index 1519c47d88..33c10e22a6 100644
--- a/lib/chef/shell.rb
+++ b/lib/chef/shell.rb
@@ -53,6 +53,7 @@ module Shell
IRB::ExtendCommandBundle.instance_variable_get(:@ALIASES).delete(irb_help)
parse_opts
+ Chef::Config[:shell_config] = options.config
# HACK: this duplicates the functions of IRB.start, but we have to do it
# to get access to the main object before irb starts.
@@ -258,6 +259,12 @@ FOOTER
:proc => lambda {|v| puts "Chef: #{::Chef::VERSION}"},
:exit => 0
+ option :override_runlist,
+ :short => "-o RunlistItem,RunlistItem...",
+ :long => "--override-runlist RunlistItem,RunlistItem...",
+ :description => "Replace current run list with specified items",
+ :proc => lambda { |items| items.split(',').map { |item| Chef::RunList::RunListItem.new(item) }}
+
def self.print_help
instance = new
instance.parse_options([])
diff --git a/lib/chef/shell/shell_session.rb b/lib/chef/shell/shell_session.rb
index 2f4d9375eb..a158020116 100644
--- a/lib/chef/shell/shell_session.rb
+++ b/lib/chef/shell/shell_session.rb
@@ -151,7 +151,7 @@ module Shell
def rebuild_node
Chef::Config[:solo] = true
- @client = Chef::Client.new
+ @client = Chef::Client.new(nil, Chef::Config[:shell_config])
@client.run_ohai
@client.load_node
@client.build_node
@@ -183,7 +183,7 @@ module Shell
def rebuild_node
# Tell the client we're chef solo so it won't try to contact the server
Chef::Config[:solo] = true
- @client = Chef::Client.new
+ @client = Chef::Client.new(nil, Chef::Config[:shell_config])
@client.run_ohai
@client.load_node
@client.build_node
@@ -214,7 +214,7 @@ module Shell
def rebuild_node
# Make sure the client knows this is not chef solo
Chef::Config[:solo] = false
- @client = Chef::Client.new
+ @client = Chef::Client.new(nil, Chef::Config[:shell_config])
@client.run_ohai
@client.register
@client.load_node
diff --git a/spec/functional/shell_spec.rb b/spec/functional/shell_spec.rb
index 64bd28f16c..f2ce3f53e4 100644
--- a/spec/functional/shell_spec.rb
+++ b/spec/functional/shell_spec.rb
@@ -118,5 +118,15 @@ describe Shell do
output.should include("===fatal===")
expect(exitstatus).to eq(0)
end
+
+ it "sets the override_runlist from the command line" do
+ output, exitstatus = run_chef_shell_with("-o 'override::foo,override::bar'") do |out, keyboard|
+ show_recipes_code = %q[puts "#{node.recipes.inspect}"]
+ keyboard.puts(show_recipes_code)
+ read_until(out, show_recipes_code)
+ end
+ output.should include(%q{["override::foo", "override::bar"]})
+ expect(exitstatus).to eq(0)
+ end
end
end
diff --git a/spec/unit/shell/shell_session_spec.rb b/spec/unit/shell/shell_session_spec.rb
index e5fc46e945..92a2e5d538 100644
--- a/spec/unit/shell/shell_session_spec.rb
+++ b/spec/unit/shell/shell_session_spec.rb
@@ -48,20 +48,37 @@ describe Shell::ShellSession do
end
describe Shell::ClientSession do
- it "builds the node's run_context with the proper environment" do
+ before do
+ Chef::Config[:shell_config] = { :override_runlist => [Chef::RunList::RunListItem.new('shell::override')] }
@session = Shell::ClientSession.instance
@node = Chef::Node.build("foo")
@session.node = @node
- @session.instance_variable_set(:@client, double(:sync_cookbooks => {}))
+ @client = double("Chef::Client.new",
+ :run_ohai => true,
+ :load_node => true,
+ :build_node => true,
+ :register => true,
+ :sync_cookbooks => {})
+ end
+
+ it "builds the node's run_context with the proper environment" do
+ @session.instance_variable_set(:@client, @client)
@expansion = Chef::RunList::RunListExpansion.new(@node.chef_environment, [])
@node.run_list.should_receive(:expand).with(@node.chef_environment).and_return(@expansion)
@session.rebuild_context
end
+
+ it "passes the shell CLI args to the client" do
+ Chef::Client.should_receive(:new).with(nil, Chef::Config[:shell_config]).and_return(@client)
+ @session.send(:rebuild_node)
+ end
+
end
describe Shell::StandAloneSession do
before do
+ Chef::Config[:shell_config] = { :override_runlist => [Chef::RunList::RunListItem.new('shell::override')] }
@session = Shell::StandAloneSession.instance
@node = @session.node = Chef::Node.new
@events = Chef::EventDispatch::Dispatcher.new
@@ -97,10 +114,22 @@ describe Shell::StandAloneSession do
@recipe.run_chef.should == :converged
end
+ it "passes the shell CLI args to the client" do
+ @client = double("Chef::Client.new",
+ :run_ohai => true,
+ :load_node => true,
+ :build_node => true,
+ :register => true,
+ :sync_cookbooks => {})
+ Chef::Client.should_receive(:new).with(nil, Chef::Config[:shell_config]).and_return(@client)
+ @session.send(:rebuild_node)
+ end
+
end
describe Shell::SoloSession do
before do
+ Chef::Config[:shell_config] = { :override_runlist => [Chef::RunList::RunListItem.new('shell::override')] }
Chef::Config[:shell_solo] = true
@session = Shell::SoloSession.instance
@node = Chef::Node.new
@@ -151,4 +180,15 @@ describe Shell::SoloSession do
@recipe.run_chef.should == :converged
end
+ it "passes the shell CLI args to the client" do
+ @client = double("Chef::Client.new",
+ :run_ohai => true,
+ :load_node => true,
+ :build_node => true,
+ :register => true,
+ :sync_cookbooks => {})
+ Chef::Client.should_receive(:new).with(nil, Chef::Config[:shell_config]).and_return(@client)
+ @session.send(:rebuild_node)
+ end
+
end