Skip to content

Commit 8633964

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, poweraction_fix_3_17 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 200f394 commit 8633964

File tree

8 files changed

+34
-3
lines changed

8 files changed

+34
-3
lines changed

modules/bmc/base.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ def powercycle
4646
raise NotImplementedError.new
4747
end
4848

49+
def powerreboot
50+
raise NotImplementedError.new
51+
end
52+
4953
def bootdevice
5054
raise NotImplementedError.new
5155
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/bmc_plugin.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Plugin < Proxy::Plugin
1111
capability 'shell'
1212
capability 'ssh'
1313
capability -> { Proxy::BMC::IPMI.providers_installed }
14+
capability 'poweraction_fix_3_17'
1415

1516
# Load IPMI to ensure the capabilities can be determined
1617
load_classes do

modules/bmc/redfish.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ def powercycle
7474
poweraction('PowerCycle')
7575
end
7676

77+
def powerreboot
78+
poweraction('GracefulRestart')
79+
end
80+
7781
def poweron
7882
poweraction('On')
7983
end

test/bmc/bmc_api_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,13 @@ def test_api_calls_redfish_provider_cycle
583583
assert expect.once
584584
end
585585

586+
def test_api_calls_redfish_provider_reboot
587+
expect = Proxy::BMC::Redfish.any_instance.stubs(:powerreboot)
588+
test_args = { 'bmc_provider' => 'redfish' }
589+
put "/#{@host}/chassis/power/reboot", test_args
590+
assert expect.once
591+
end
592+
586593
def test_api_can_pass_options_in_body
587594
Rubyipmi.stubs(:is_provider_installed?).returns(true)
588595
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
@@ -21,4 +21,11 @@ def test_redfish_provider_cycle
2121
to_return(status: 200, body: JSON.generate({}))
2222
assert @bmc.powercycle
2323
end
24+
25+
def test_redfish_provider_reboot
26+
stub_request(:post, "#{@protocol}://#{@host}#{SYSTEM_DATA['Actions']['#ComputerSystem.Reset']['target']}").
27+
with(body: JSON.generate({ "ResetType" => "GracefulRestart" })).
28+
to_return(status: 200, body: JSON.generate({}))
29+
assert @bmc.powerreboot
30+
end
2431
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

test/bmc/integration_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_features
1616
mod = response['bmc']
1717
refute_nil(mod)
1818
assert_equal('running', mod['state'], Proxy::LogBuffer::Buffer.instance.info[:failed_modules][:bmc])
19-
assert_equal(['redfish', 'shell', 'ssh'], mod['capabilities'])
19+
assert_equal(['poweraction_fix_3_17', 'redfish', 'shell', 'ssh'], mod['capabilities'])
2020

2121
assert_equal({}, mod['settings'])
2222
end
@@ -32,7 +32,7 @@ def test_features_with_freeipmi_installed
3232
mod = response['bmc']
3333
refute_nil(mod)
3434
assert_equal('running', mod['state'], Proxy::LogBuffer::Buffer.instance.info[:failed_modules][:bmc])
35-
assert_equal(['freeipmi', 'redfish', 'shell', 'ssh'], mod['capabilities'])
35+
assert_equal(['freeipmi', 'poweraction_fix_3_17', 'redfish', 'shell', 'ssh'], mod['capabilities'])
3636

3737
assert_equal({}, mod['settings'])
3838
end

0 commit comments

Comments
 (0)