summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-09-03 17:44:34 -0700
committerJohn Keiser <jkeiser@opscode.com>2014-09-03 17:44:34 -0700
commita0b7ca95a44eaf69de1340e14c371a8db560d138 (patch)
tree3527839cc03c8ffd87d15f7ff773827b01eb32a7
parentb338ff7dfaefd64eee4465ae060d12cd7346a655 (diff)
downloadchef-a0b7ca95a44eaf69de1340e14c371a8db560d138.tar.gz
Move local_mode deeper into chef-client so it happens
after node_name has been selected
-rw-r--r--lib/chef/application.rb33
-rw-r--r--lib/chef/client.rb37
-rw-r--r--spec/integration/client/client_spec.rb2
3 files changed, 35 insertions, 37 deletions
diff --git a/lib/chef/application.rb b/lib/chef/application.rb
index ce74c5b710..f873f8b27c 100644
--- a/lib/chef/application.rb
+++ b/lib/chef/application.rb
@@ -21,7 +21,6 @@ require 'socket'
require 'chef/config'
require 'chef/config_fetcher'
require 'chef/exceptions'
-require 'chef/local_mode'
require 'chef/log'
require 'chef/platform'
require 'mixlib/cli'
@@ -41,8 +40,6 @@ class Chef::Application
# from failing due to permissions when launched as a less privileged user.
end
- attr_reader :local_mode
-
# Reconfigure the application. You'll want to override and super this method.
def reconfigure
configure_chef
@@ -188,24 +185,20 @@ class Chef::Application
# Initializes Chef::Client instance and runs it
def run_chef_client(specific_recipes = [])
- Chef::LocalMode.start do |local_mode|
- @local_mode = local_mode
- override_runlist = config[:override_runlist]
- if specific_recipes.size > 0
- override_runlist ||= []
- end
- @chef_client = Chef::Client.new(
- @chef_client_json,
- :override_runlist => config[:override_runlist],
- :specific_recipes => specific_recipes,
- :runlist => config[:runlist]
- )
- @chef_client_json = nil
-
- @chef_client.run
- @chef_client = nil
- @local_mode = nil
+ override_runlist = config[:override_runlist]
+ if specific_recipes.size > 0
+ override_runlist ||= []
end
+ @chef_client = Chef::Client.new(
+ @chef_client_json,
+ :override_runlist => config[:override_runlist],
+ :specific_recipes => specific_recipes,
+ :runlist => config[:runlist]
+ )
+ @chef_client_json = nil
+
+ @chef_client.run
+ @chef_client = nil
end
private
diff --git a/lib/chef/client.rb b/lib/chef/client.rb
index 2de3ca3e64..f14374f206 100644
--- a/lib/chef/client.rb
+++ b/lib/chef/client.rb
@@ -23,6 +23,7 @@ require 'chef/mixin/params_validate'
require 'chef/mixin/path_sanity'
require 'chef/log'
require 'chef/rest'
+require 'chef/local_mode'
require 'chef/api_client'
require 'chef/api_client/registration'
require 'chef/node'
@@ -411,30 +412,34 @@ class Chef
Chef::Log.debug("Chef-client request_id: #{request_id}")
enforce_path_sanity
run_ohai
- @events.ohai_completed(node)
- register unless Chef::Config[:solo]
+ # Pull on node_name to ensure we have a name
+ node_name
+ Chef::LocalMode.start do |local_mode|
+ @events.ohai_completed(node)
+ register unless Chef::Config[:solo]
- load_node
+ load_node
- build_node
+ build_node
- run_status.run_id = request_id
- run_status.start_clock
- Chef::Log.info("Starting Chef Run for #{node.name}")
- run_started
+ run_status.run_id = request_id
+ run_status.start_clock
+ Chef::Log.info("Starting Chef Run for #{node.name}")
+ run_started
- do_windows_admin_check
+ do_windows_admin_check
- run_context = setup_run_context
+ run_context = setup_run_context
- converge(run_context)
+ converge(run_context)
- save_updated_node
+ save_updated_node
- run_status.stop_clock
- Chef::Log.info("Chef Run complete in #{run_status.elapsed_time} seconds")
- run_completed_successfully
- @events.run_completed(node)
+ run_status.stop_clock
+ Chef::Log.info("Chef Run complete in #{run_status.elapsed_time} seconds")
+ run_completed_successfully
+ @events.run_completed(node)
+ end
true
rescue Exception => e
# CHEF-3336: Send the error first in case something goes wrong below and we don't know why
diff --git a/spec/integration/client/client_spec.rb b/spec/integration/client/client_spec.rb
index f0d978c516..7f5012274f 100644
--- a/spec/integration/client/client_spec.rb
+++ b/spec/integration/client/client_spec.rb
@@ -27,7 +27,7 @@ local_mode true
cookbook_path "#{path_to('cookbooks')}"
EOM
- result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'x::default'", :cwd => chef_dir)
+ result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'x::default' -l debug", :cwd => chef_dir)
result.error!
end