summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAJ Christensen <aj@junglistheavy.industries>2014-12-30 11:39:55 +1300
committerBryan McLellan <btm@opscode.com>2015-02-09 21:58:39 -0500
commit95be9a0418b8db7b224092ef3e15282b5ae97eee (patch)
tree02c5ef4fa4fac28adf1a0abe5033e7b2642b3274
parent955bce9ed05d6c69a37c506dc9e24a6e407e1a4d (diff)
downloadchef-95be9a0418b8db7b224092ef3e15282b5ae97eee.tar.gz
Refs #2709: Isolate/fix the no-fork fault
* Share specific recipes code to application parent * Update specs to passing, update specs to RSpec 3. * Specs for set_specific_recipes, solo, client.
-rw-r--r--lib/chef/application.rb30
-rw-r--r--lib/chef/application/client.rb2
-rw-r--r--lib/chef/application/solo.rb2
-rw-r--r--spec/spec_helper.rb9
-rw-r--r--spec/unit/application/client_spec.rb7
-rw-r--r--spec/unit/application/solo_spec.rb5
-rw-r--r--spec/unit/application_spec.rb35
7 files changed, 76 insertions, 14 deletions
diff --git a/lib/chef/application.rb b/lib/chef/application.rb
index 6c85f951f6..297e46ef3c 100644
--- a/lib/chef/application.rb
+++ b/lib/chef/application.rb
@@ -104,6 +104,12 @@ class Chef
Chef::Config.merge!(config)
end
+ def set_specific_recipes
+ Chef::Config[:specific_recipes] =
+ cli_arguments.map { |file| File.expand_path(file) } if
+ cli_arguments.respond_to?(:map)
+ end
+
# Initialize and configure the logger.
# === Loggers and Formatters
# In Chef 10.x and previous, the Logger was the primary/only way that Chef
@@ -200,16 +206,18 @@ class Chef
# Initializes Chef::Client instance and runs it
def run_chef_client(specific_recipes = [])
+ unless specific_recipes.respond_to?(:size)
+ raise ArgumentError, 'received non-Array like specific_recipes argument'
+ end
+
Chef::LocalMode.with_server_connectivity do
override_runlist = config[:override_runlist]
- if specific_recipes.size > 0
- override_runlist ||= []
- end
+ override_runlist ||= [] if specific_recipes.size > 0
@chef_client = Chef::Client.new(
@chef_client_json,
- :override_runlist => config[:override_runlist],
- :specific_recipes => specific_recipes,
- :runlist => config[:runlist]
+ override_runlist: override_runlist,
+ specific_recipes: specific_recipes,
+ runlist: config[:runlist]
)
@chef_client_json = nil
@@ -239,7 +247,7 @@ class Chef
# Override the TERM signal.
trap('TERM') do
Chef::Log.debug("SIGTERM received during converge," +
- " finishing converge to exit normally (send SIGINT to terminate immediately)")
+ " finishing converge to exit normally (send SIGINT to terminate immediately)")
end
@chef_client.run
@@ -253,7 +261,7 @@ class Chef
# TERM singal is received (exit gracefully)
trap('TERM') do
Chef::Log.debug("SIGTERM received during converge," +
- " finishing converge to exit normally (send SIGINT to terminate immediately)")
+ " finishing converge to exit normally (send SIGINT to terminate immediately)")
end
client_solo = Chef::Config[:solo] ? "chef-solo" : "chef-client"
@@ -299,7 +307,7 @@ class Chef
def configure_http_proxy
if http_proxy = Chef::Config[:http_proxy]
http_proxy_string = configure_proxy("http", http_proxy,
- Chef::Config[:http_proxy_user], Chef::Config[:http_proxy_pass])
+ Chef::Config[:http_proxy_user], Chef::Config[:http_proxy_pass])
env['http_proxy'] = http_proxy_string unless env['http_proxy']
env['HTTP_PROXY'] = http_proxy_string unless env['HTTP_PROXY']
end
@@ -309,7 +317,7 @@ class Chef
def configure_https_proxy
if https_proxy = Chef::Config[:https_proxy]
https_proxy_string = configure_proxy("https", https_proxy,
- Chef::Config[:https_proxy_user], Chef::Config[:https_proxy_pass])
+ Chef::Config[:https_proxy_user], Chef::Config[:https_proxy_pass])
env['https_proxy'] = https_proxy_string unless env['https_proxy']
env['HTTPS_PROXY'] = https_proxy_string unless env['HTTPS_PROXY']
end
@@ -319,7 +327,7 @@ class Chef
def configure_ftp_proxy
if ftp_proxy = Chef::Config[:ftp_proxy]
ftp_proxy_string = configure_proxy("ftp", ftp_proxy,
- Chef::Config[:ftp_proxy_user], Chef::Config[:ftp_proxy_pass])
+ Chef::Config[:ftp_proxy_user], Chef::Config[:ftp_proxy_pass])
env['ftp_proxy'] = ftp_proxy_string unless env['ftp_proxy']
env['FTP_PROXY'] = ftp_proxy_string unless env['FTP_PROXY']
end
diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb
index c0635e1cb5..d5dc936f83 100644
--- a/lib/chef/application/client.rb
+++ b/lib/chef/application/client.rb
@@ -264,7 +264,7 @@ class Chef::Application::Client < Chef::Application
raise Chef::Exceptions::PIDFileLockfileMatch if Chef::Util::PathHelper.paths_eql? (Chef::Config[:pid_file] || '' ), (Chef::Config[:lockfile] || '')
- Chef::Config[:specific_recipes] = cli_arguments.map { |file| File.expand_path(file) }
+ set_specific_recipes
Chef::Config[:chef_server_url] = config[:chef_server_url] if config.has_key? :chef_server_url
diff --git a/lib/chef/application/solo.rb b/lib/chef/application/solo.rb
index c919c2b48b..97a1952d0f 100644
--- a/lib/chef/application/solo.rb
+++ b/lib/chef/application/solo.rb
@@ -189,6 +189,8 @@ class Chef::Application::Solo < Chef::Application
def reconfigure
super
+ set_specific_recipes
+
Chef::Config[:solo] = true
if Chef::Config[:daemonize]
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index ad1f3f5d0d..8888efc424 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -83,8 +83,13 @@ Dir["spec/support/**/*.rb"].
OHAI_SYSTEM = Ohai::System.new
OHAI_SYSTEM.all_plugins("platform")
-TEST_PLATFORM = OHAI_SYSTEM["platform"].dup.freeze
-TEST_PLATFORM_VERSION = OHAI_SYSTEM["platform_version"].dup.freeze
+
+TEST_PLATFORM =
+ (OHAI_SYSTEM['platform'] ||
+ 'unknown_test_platform').dup.freeze
+TEST_PLATFORM_VERSION =
+ (OHAI_SYSTEM['platform_version'] ||
+ 'unknown_platform_version').dup.freeze
RSpec.configure do |config|
config.include(Matchers)
diff --git a/spec/unit/application/client_spec.rb b/spec/unit/application/client_spec.rb
index cce3d11577..894836198f 100644
--- a/spec/unit/application/client_spec.rb
+++ b/spec/unit/application/client_spec.rb
@@ -42,6 +42,13 @@ describe Chef::Application::Client, "reconfigure" do
ARGV.replace(@original_argv)
end
+ describe 'parse cli_arguments' do
+ it 'should call set_specific_recipes' do
+ expect(app).to receive(:set_specific_recipes).and_return(true)
+ app.reconfigure
+ end
+ end
+
describe "when configured to not fork the client process" do
before do
Chef::Config[:client_fork] = false
diff --git a/spec/unit/application/solo_spec.rb b/spec/unit/application/solo_spec.rb
index 2a07ff38ad..1785ecfc86 100644
--- a/spec/unit/application/solo_spec.rb
+++ b/spec/unit/application/solo_spec.rb
@@ -34,6 +34,11 @@ describe Chef::Application::Solo do
end
describe "configuring the application" do
+ it 'should call set_specific_recipes' do
+ expect(app).to receive(:set_specific_recipes)
+ app.reconfigure
+ end
+
it "should set solo mode to true" do
app.reconfigure
expect(Chef::Config[:solo]).to be_truthy
diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb
index 210f875fbe..f5a2c72aa0 100644
--- a/spec/unit/application_spec.rb
+++ b/spec/unit/application_spec.rb
@@ -56,6 +56,11 @@ describe Chef::Application do
expect(@app).to receive(:configure_proxy_environment_variables).and_return(true)
@app.reconfigure
end
+
+ it 'should not receive set_specific_recipes' do
+ expect(@app).to_not receive(:set_specific_recipes)
+ @app.reconfigure
+ end
end
describe Chef::Application do
@@ -473,6 +478,36 @@ describe Chef::Application do
end
end
+ describe 'run_chef_client' do
+ context 'with an application' do
+ let(:app) { Chef::Application.new }
+
+ context 'when called with an invalid argument' do
+ before do
+ allow(app).to receive(:fork_chef_client).and_return(true)
+ allow(app).to receive(:run_with_graceful_exit_option).and_return(true)
+ end
+
+ it 'should raise an argument error detailing the problem' do
+ specific_recipes_regexp = Regexp.new 'received non-Array like specific_recipes argument'
+ expect { app.run_chef_client(nil) }.to raise_error(ArgumentError, specific_recipes_regexp)
+ end
+ end
+
+ context 'when called with an Array-like argument (#size)' do
+ before do
+ allow(app).to receive(:fork_chef_client).and_return(true)
+ allow(app).to receive(:run_with_graceful_exit_option).and_return(true)
+ end
+
+ it 'should be cool' do
+ expect { app.run_chef_client([]) }.not_to raise_error
+ end
+ end
+ end
+
+ end
+
describe "configuration errors" do
before do
expect(Process).to receive(:exit)