summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2019-08-27 15:20:44 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2019-08-28 10:53:34 -0700
commit72562e52a3fdc325f1bfe12d42f75a12a8c7307d (patch)
tree5568278a6d481e11d336e7746dde1815445c3428
parentdd0009d7e77f192cadb1632f2159a6dbc880980f (diff)
downloadchef-72562e52a3fdc325f1bfe12d42f75a12a8c7307d.tar.gz
fail on interval runs on windows
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/application/base.rb7
-rw-r--r--lib/chef/application/client.rb8
-rw-r--r--lib/chef/application/solo.rb8
-rw-r--r--spec/unit/application/client_spec.rb11
-rw-r--r--spec/unit/application/solo_spec.rb11
-rw-r--r--spec/unit/application_spec.rb2
6 files changed, 29 insertions, 18 deletions
diff --git a/lib/chef/application/base.rb b/lib/chef/application/base.rb
index fea3d844ce..c5bff9874e 100644
--- a/lib/chef/application/base.rb
+++ b/lib/chef/application/base.rb
@@ -340,6 +340,13 @@ class Chef::Application::Base < Chef::Application
private
+ def windows_interval_error_message
+ "Windows #{Chef::Dist::PRODUCT} interval runs are not supported in #{Chef::Dist::PRODUCT} 15 and later." +
+ "\nConfiguration settings:" +
+ ("\n interval = #{Chef::Config[:interval]} seconds" if Chef::Config[:interval]).to_s +
+ "\nPlease manage #{Chef::Dist::PRODUCT} as a scheduled task instead."
+ end
+
def unforked_interval_error_message
"Unforked #{Chef::Dist::PRODUCT} interval runs are disabled by default." +
"\nConfiguration settings:" +
diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb
index 0fc5ca7711..890ecbd385 100644
--- a/lib/chef/application/client.rb
+++ b/lib/chef/application/client.rb
@@ -128,8 +128,12 @@ class Chef::Application::Client < Chef::Application::Base
Chef::Config[:client_fork] = !!Chef::Config[:interval]
end
- if !Chef::Config[:client_fork] && Chef::Config[:interval] && !Chef::Platform.windows?
- Chef::Application.fatal!(unforked_interval_error_message)
+ if Chef::Config[:interval]
+ if Chef::Platform.windows?
+ Chef::Application.fatal!(windows_interval_error_message)
+ elsif !Chef::Config[:client_fork]
+ Chef::Application.fatal!(unforked_interval_error_message)
+ end
end
if Chef::Config[:json_attribs]
diff --git a/lib/chef/application/solo.rb b/lib/chef/application/solo.rb
index bce95c2841..da9ec7f566 100644
--- a/lib/chef/application/solo.rb
+++ b/lib/chef/application/solo.rb
@@ -102,7 +102,13 @@ class Chef::Application::Solo < Chef::Application::Base
Chef::Config[:client_fork] = !!Chef::Config[:interval]
end
- Chef::Application.fatal!(unforked_interval_error_message) if !Chef::Config[:client_fork] && Chef::Config[:interval]
+ if Chef::Config[:interval]
+ if Chef::Platform.windows?
+ Chef::Application.fatal!(windows_interval_error_message)
+ elsif !Chef::Config[:client_fork]
+ Chef::Application.fatal!(unforked_interval_error_message)
+ end
+ end
if Chef::Config[:recipe_url]
cookbooks_path = Array(Chef::Config[:cookbook_path]).detect { |e| Pathname.new(e).cleanpath.to_s =~ %r{/cookbooks/*$} }
diff --git a/spec/unit/application/client_spec.rb b/spec/unit/application/client_spec.rb
index 0773fc70fd..d4ed403197 100644
--- a/spec/unit/application/client_spec.rb
+++ b/spec/unit/application/client_spec.rb
@@ -1,6 +1,6 @@
# Author:: AJ Christensen (<aj@junglist.gen.nz>)
-# Copyright:: Copyright 2008-2018, Chef Software Inc.
+# Copyright:: Copyright 2008-2019, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -85,7 +85,6 @@ describe Chef::Application::Client, "reconfigure" do
allow(app).to receive(:trap)
allow(app).to receive(:configure_logging).and_return(true)
- Chef::Config[:interval] = 10
Chef::Config[:once] = false
@@ -162,7 +161,7 @@ describe Chef::Application::Client, "reconfigure" do
it_behaves_like "sets the configuration", "--no-fork", client_fork: false
end
- context "with an interval" do
+ context "with an interval", :unix_only do
it_behaves_like "sets the configuration", "--interval 1800", client_fork: true
end
@@ -322,7 +321,7 @@ describe Chef::Application::Client, "reconfigure" do
Chef::Config[:splay] = nil
end
- it "should terminal with message when interval is given" do
+ it "should terminate with message when interval is given" do
Chef::Config[:interval] = 600
allow(ChefConfig).to receive(:windows?).and_return(false)
expect(Chef::Application).to receive(:fatal!).with(
@@ -340,8 +339,8 @@ Enable .* interval runs by setting `:client_fork = true` in your config file or
allow(ChefConfig).to receive(:windows?).and_return(true)
end
- it "should not terminate" do
- expect(Chef::Application).not_to receive(:fatal!)
+ it "should terminate" do
+ expect(Chef::Application).to receive(:fatal!)
app.reconfigure
end
end
diff --git a/spec/unit/application/solo_spec.rb b/spec/unit/application/solo_spec.rb
index 3f540d24e2..e701ff190c 100644
--- a/spec/unit/application/solo_spec.rb
+++ b/spec/unit/application/solo_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: AJ Christensen (<aj@junglist.gen.nz>)
-# Copyright:: Copyright 2008-2018, Chef Software Inc.
+# Copyright:: Copyright 2008-2019, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -64,18 +64,13 @@ describe Chef::Application::Solo do
end
it "should terminate with message" do
- expect(Chef::Application).to receive(:fatal!).with(
- /Unforked .* interval runs are disabled by default\.
-Configuration settings:
- interval = 600 seconds
-Enable .* interval runs by setting `:client_fork = true` in your config file or adding `--fork` to your command line options\./
- )
+ expect(Chef::Application).to receive(:fatal!).with(/interval runs are disabled/)
app.reconfigure
end
end
end
- describe "when in daemonized mode and no interval has been set" do
+ describe "when in daemonized mode and no interval has been set", :unix_only do
before do
Chef::Config[:daemonize] = true
end
diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb
index e94f9b74ae..7a787d1f3f 100644
--- a/spec/unit/application_spec.rb
+++ b/spec/unit/application_spec.rb
@@ -1,7 +1,7 @@
#
# Author:: AJ Christensen (<aj@junglist.gen.nz>)
# Author:: Mark Mzyk (mmzyk@chef.io)
-# Copyright:: Copyright 2008-2018, Chef Software Inc.
+# Copyright:: Copyright 2008-2019, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");