Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions modules/bmc/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def powerreset
raise NotImplementedError.new
end

def powerreboot
raise NotImplementedError.new
end

def bootdevice
raise NotImplementedError.new
end
Expand Down
4 changes: 3 additions & 1 deletion modules/bmc/bmc_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class Api < ::Sinatra::Base
put "/:host/chassis/power/?:action?" do
# return hint on valid options
if params[:action].nil?
return { :actions => ["on", "off", "cycle", "soft", "reset"] }.to_json
return { :actions => ["on", "off", "cycle", "soft", "reset", "reboot"] }.to_json
end
bmc_setup
begin
Expand All @@ -178,6 +178,8 @@ class Api < ::Sinatra::Base
{ :action => params[:action], :result => @bmc.poweroff(true) }.to_json
when "reset"
{ :action => params[:action], :result => @bmc.powerreset }.to_json
when "reboot"
{ :action => params[:action], :result => @bmc.powerreboot }.to_json
else
{ :error => "The action: #{params[:action]} is not a valid action" }.to_json
end
Expand Down
4 changes: 4 additions & 0 deletions modules/bmc/redfish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ def powerreset
poweraction('ForceRestart')
end

def powerreboot
poweraction('GracefulRestart')
end

def poweron
poweraction('On')
end
Expand Down
7 changes: 7 additions & 0 deletions test/bmc/bmc_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,13 @@ def test_api_calls_redfish_provider_reset
assert expect.once
end

def test_api_calls_redfish_provider_reboot
expect = Proxy::BMC::Redfish.any_instance.stubs(:powerreboot)
test_args = { 'bmc_provider' => 'redfish' }
put "/#{@host}/chassis/power/reboot", test_args
assert expect.once
end

def test_api_can_pass_options_in_body
Rubyipmi.stubs(:is_provider_installed?).returns(true)
args = { 'bmc_provider' => 'freeipmi', :options => {:driver => 'lan20', :privilege => 'USER'} }.to_json
Expand Down
7 changes: 7 additions & 0 deletions test/bmc/bmc_redfish_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ def test_redfish_provider_reset
to_return(status: 200, body: JSON.generate({}))
assert @bmc.powerreset
end

def test_redfish_provider_reboot
stub_request(:post, "#{@protocol}://#{@host}#{SYSTEM_DATA['Actions']['#ComputerSystem.Reset']['target']}").
with(body: JSON.generate({ "ResetType" => "GracefulRestart" })).
to_return(status: 200, body: JSON.generate({}))
assert @bmc.powerreboot
end
end
6 changes: 6 additions & 0 deletions test/bmc/bmc_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ def test_should_power_reset
assert bmc.powerreset
end

def test_should_power_reboot
assert_raise(NotImplementedError) do
bmc.powerreboot
end
end

def test_should_bootpxe
Rubyipmi::Ipmitool::Chassis.any_instance.expects(:bootpxe).returns(true)
bmc.bootpxe
Expand Down