summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Doherty <cdoherty@getchef.com>2014-09-05 17:45:08 -0700
committerChris Doherty <cdoherty@getchef.com>2014-09-10 16:34:29 -0700
commitbfa023f1ba3e962a1d2c0179b4209ce44c734506 (patch)
treea363ddadf988225c72192850ed444a92eb9993ab
parent601ec3416004a62c7baef0f3cacf09d2c62f375e (diff)
downloadchef-bfa023f1ba3e962a1d2c0179b4209ce44c734506.tar.gz
Elaborate the specs a bit to make sure we're generating the correct reboot shell string.
-rw-r--r--lib/chef/platform/rebooter.rb8
-rw-r--r--spec/functional/rebooter_spec.rb38
2 files changed, 29 insertions, 17 deletions
diff --git a/lib/chef/platform/rebooter.rb b/lib/chef/platform/rebooter.rb
index d471b3838e..75213b3fc7 100644
--- a/lib/chef/platform/rebooter.rb
+++ b/lib/chef/platform/rebooter.rb
@@ -20,7 +20,6 @@ require 'chef/dsl/reboot_pending'
require 'chef/log'
require 'chef/platform'
-# this has whatever's needed to reboot the server, on whichever platform.
class Chef
class Platform
module Rebooter
@@ -33,10 +32,9 @@ class Chef
cmd = if Chef::Platform.windows?
"shutdown /r /t #{reboot_info[:delay_mins]} /c \"#{reboot_info[:reason]}\""
else
- shutdown_time = reboot_info[:delay_mins] > 0 ? reboot_info[:reboot_timeout] : "now"
- "shutdown -r #{shutdown_time}"
+ # probably Linux-only.
+ "shutdown -r +#{reboot_info[:delay_mins]} \"#{reboot_info[:reason]}\""
end
- Chef::Log.warn "Shutdown command (not running): '#{cmd}'"
shell_out!(cmd)
end
@@ -49,7 +47,7 @@ class Chef
reboot!
end
end
- end # end class instance stuff.
+ end
end
end
end
diff --git a/spec/functional/rebooter_spec.rb b/spec/functional/rebooter_spec.rb
index f1365c04db..4ead20bb0b 100644
--- a/spec/functional/rebooter_spec.rb
+++ b/spec/functional/rebooter_spec.rb
@@ -24,7 +24,7 @@ describe Chef::Platform::Rebooter do
{
:delay_mins => 5,
:requested_by => "reboot resource functional test",
- :reason => "reboot resource spec test"
+ :reason => "rebooter spec test"
}
end
@@ -45,21 +45,35 @@ describe Chef::Platform::Rebooter do
describe '#reboot_if_needed!' do
- # test that it's producing the correct commands.
- it 'should call #shell_out! when reboot has been requested' do
- run_context.request_reboot(reboot_info)
-
- expect(rebooter).to receive(:shell_out!).once.with('shutdown /r /t 5 /c "reboot resource spec test"')
- expect(rebooter).to receive(:reboot_if_needed!).once.and_call_original
- rebooter.reboot_if_needed!(run_context.node)
-
- run_context.cancel_reboot
- end
-
it 'should not call #shell_out! when reboot has not been requested' do
expect(rebooter).to receive(:shell_out!).exactly(0).times
expect(rebooter).to receive(:reboot_if_needed!).once.and_call_original
rebooter.reboot_if_needed!(run_context.node)
end
+
+ describe 'calling #shell_out! when reboot has been requested' do
+
+ before(:each) do
+ run_context.request_reboot(reboot_info)
+ end
+
+ after(:each) do
+ run_context.cancel_reboot
+ end
+
+ it 'should produce the correct string on Windows' do
+ Chef::Platform.stub(:windows?).and_return(true)
+ expect(rebooter).to receive(:shell_out!).once.with('shutdown /r /t 5 /c "rebooter spec test"')
+ expect(rebooter).to receive(:reboot_if_needed!).once.and_call_original
+ rebooter.reboot_if_needed!(run_context.node)
+ end
+
+ it 'should produce the correct (Linux-specific) string on non-Windows' do
+ Chef::Platform.stub(:windows?).and_return(false)
+ expect(rebooter).to receive(:shell_out!).once.with('shutdown -r +5 "rebooter spec test"')
+ expect(rebooter).to receive(:reboot_if_needed!).once.and_call_original
+ rebooter.reboot_if_needed!(run_context.node)
+ end
+ end
end
end