diff options
author | Chris Doherty <cdoherty@getchef.com> | 2014-09-08 15:49:04 -0700 |
---|---|---|
committer | Chris Doherty <cdoherty@getchef.com> | 2014-09-10 16:34:30 -0700 |
commit | 2456f0c47df72268e1c73c9c5109771a59f10938 (patch) | |
tree | 198ae2e1136693d9dc28bab44ab272527195ec00 | |
parent | bfa023f1ba3e962a1d2c0179b4209ce44c734506 (diff) | |
download | chef-2456f0c47df72268e1c73c9c5109771a59f10938.tar.gz |
Rename actions to :request_reboot_on_successful_run and :reboot_interrupt_run.
-rw-r--r-- | lib/chef/provider/reboot.rb | 28 | ||||
-rw-r--r-- | lib/chef/resource/reboot.rb | 2 | ||||
-rw-r--r-- | spec/functional/rebooter_spec.rb | 1 | ||||
-rw-r--r-- | spec/functional/resource/reboot_spec.rb | 11 |
4 files changed, 31 insertions, 11 deletions
diff --git a/lib/chef/provider/reboot.rb b/lib/chef/provider/reboot.rb index ffd5c5f936..a8abcb3b57 100644 --- a/lib/chef/provider/reboot.rb +++ b/lib/chef/provider/reboot.rb @@ -34,20 +34,32 @@ class Chef @current_resource end - def action_request + def request_reboot + node.run_context.request_reboot( + :delay_mins => @new_resource.delay_mins, + :reason => @new_resource.reason, + :timestamp => Time.now, + :requested_by => @new_resource.name + ) + end + + def action_request_reboot_on_successful_run converge_by("request a system reboot to occur if the run succeeds") do Chef::Log.warn "Reboot requested:'#{@new_resource.name}'" - node.run_context.request_reboot( - :delay_mins => @new_resource.delay_mins, - :reason => @new_resource.reason, - :timestamp => Time.now, - :requested_by => @new_resource.name - ) + request_reboot + end + end + + def action_reboot_interrupt_run + converge_by("rebooting the system immediately") do + Chef::Log.warn "Rebooting system immediately, requested by '#{@new_resource.name}'" + request_reboot + Chef::Platform::Rebooter.reboot!(node) end end def action_cancel - converge_by("cancel any existing system reboot request") do + converge_by("cancel any existing end-of-run reboot request") do Chef::Log.warn "Reboot canceled: '#{@new_resource.name}'" node.run_context.cancel_reboot end diff --git a/lib/chef/resource/reboot.rb b/lib/chef/resource/reboot.rb index 47ba9b33bb..44c04d25dc 100644 --- a/lib/chef/resource/reboot.rb +++ b/lib/chef/resource/reboot.rb @@ -25,7 +25,7 @@ class Chef super @resource_name = :reboot @provider = Chef::Provider::Reboot - @allowed_actions = [:request, :cancel] + @allowed_actions = [:request_reboot_on_successful_run, :reboot_interrupt_run, :cancel] @reason = "Reboot by Chef" @delay_mins = 0 diff --git a/spec/functional/rebooter_spec.rb b/spec/functional/rebooter_spec.rb index 4ead20bb0b..218b47b74e 100644 --- a/spec/functional/rebooter_spec.rb +++ b/spec/functional/rebooter_spec.rb @@ -54,6 +54,7 @@ describe Chef::Platform::Rebooter do describe 'calling #shell_out! when reboot has been requested' do before(:each) do + Chef::Platform.stub(:node).and_return(run_context.node) run_context.request_reboot(reboot_info) end diff --git a/spec/functional/resource/reboot_spec.rb b/spec/functional/resource/reboot_spec.rb index 7d571657ef..78feae6839 100644 --- a/spec/functional/resource/reboot_spec.rb +++ b/spec/functional/resource/reboot_spec.rb @@ -44,9 +44,9 @@ describe Chef::Resource::Reboot do # the currently defined behavior for multiple calls to this resource is "last one wins." - describe 'the request action' do + describe 'the request_reboot_on_successful_run action' do before do - resource.run_action(:request) + resource.run_action(:request_reboot_on_successful_run) end after do @@ -64,6 +64,13 @@ describe Chef::Resource::Reboot do end end + describe 'the reboot_interrupt_run action' do + it 'should have attempted to reboot the server' do + expect(Chef::Platform::Rebooter).to receive(:reboot!).once + resource.run_action(:reboot_interrupt_run) + end + end + describe "the cancel action" do before do resource.run_context.request_reboot(expected) |