Skip to content

Commit af23262

Browse files
committed
Fixes #38498 - Add Reboot power operation to Redfish provider
Bug #3073 is caused by 3 things: 1. Foreman core doesn't call BMC proxy's API correctly - Changing power state to 'Reboot' via Web GUI calls BMC proxy's 'soft' power action - Changing power state to 'Reset' via Web GUI calls BMC proxy's 'cycle' power action 2. Foreman BMC proxy doesn't support reboot at all BMC provider 3. Foreman BMC proxy doesn't support reset(powerreset) at Redfish provider 2nd & 3rd item are mentioned in #38498. And this PR fixes 2nd item. For backward compatibility, power_action_v2 capability is introduced to smart proxy at PRs related to #38498. PR related to #3073 adds logic to determine if smart proxy supports this capability into Foreman core.
1 parent f03ed81 commit af23262

File tree

6 files changed

+31
-1
lines changed

6 files changed

+31
-1
lines changed

modules/bmc/base.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ def powerreset
5050
raise NotImplementedError.new
5151
end
5252

53+
def powerreboot
54+
raise NotImplementedError.new
55+
end
56+
5357
def bootdevice
5458
raise NotImplementedError.new
5559
end

modules/bmc/bmc_api.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class Api < ::Sinatra::Base
163163
put "/:host/chassis/power/?:action?" do
164164
# return hint on valid options
165165
if params[:action].nil?
166-
return { :actions => ["on", "off", "cycle", "soft", "reset"] }.to_json
166+
return { :actions => ["on", "off", "cycle", "soft", "reset", "reboot"] }.to_json
167167
end
168168
bmc_setup
169169
begin
@@ -178,6 +178,8 @@ class Api < ::Sinatra::Base
178178
{ :action => params[:action], :result => @bmc.poweroff(true) }.to_json
179179
when "reset"
180180
{ :action => params[:action], :result => @bmc.powerreset }.to_json
181+
when "reboot"
182+
{ :action => params[:action], :result => @bmc.powerreboot }.to_json
181183
else
182184
{ :error => "The action: #{params[:action]} is not a valid action" }.to_json
183185
end

modules/bmc/redfish.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ def powerreset
7878
poweraction('ForceRestart')
7979
end
8080

81+
def powerreboot
82+
poweraction('GracefulRestart')
83+
end
84+
8185
def poweron
8286
poweraction('On')
8387
end

test/bmc/bmc_api_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,13 @@ def test_api_calls_redfish_provider_reset
602602
assert expect.once
603603
end
604604

605+
def test_api_calls_redfish_provider_reboot
606+
expect = Proxy::BMC::Redfish.any_instance.stubs(:powerreboot)
607+
test_args = { 'bmc_provider' => 'redfish' }
608+
put "/#{@host}/chassis/power/reboot", test_args
609+
assert expect.once
610+
end
611+
605612
def test_api_can_pass_options_in_body
606613
Rubyipmi.stubs(:is_provider_installed?).returns(true)
607614
args = { 'bmc_provider' => 'freeipmi', :options => {:driver => 'lan20', :privilege => 'USER'} }.to_json

test/bmc/bmc_redfish_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,11 @@ def test_redfish_provider_reset
2828
to_return(status: 200, body: JSON.generate({}))
2929
assert @bmc.powerreset
3030
end
31+
32+
def test_redfish_provider_reboot
33+
stub_request(:post, "#{@protocol}://#{@host}#{SYSTEM_DATA['Actions']['#ComputerSystem.Reset']['target']}").
34+
with(body: JSON.generate({ "ResetType" => "GracefulRestart" })).
35+
to_return(status: 200, body: JSON.generate({}))
36+
assert @bmc.powerreboot
37+
end
3138
end

test/bmc/bmc_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ def test_should_power_reset
5656
assert bmc.powerreset
5757
end
5858

59+
def test_should_power_reboot
60+
assert_raise(NotImplementedError) do
61+
bmc.powerreboot
62+
end
63+
end
64+
5965
def test_should_bootpxe
6066
Rubyipmi::Ipmitool::Chassis.any_instance.expects(:bootpxe).returns(true)
6167
bmc.bootpxe

0 commit comments

Comments
 (0)