diff --git a/modules/bmc/base.rb b/modules/bmc/base.rb index 77c3b1869..c227c6b01 100644 --- a/modules/bmc/base.rb +++ b/modules/bmc/base.rb @@ -46,6 +46,10 @@ def powercycle raise NotImplementedError.new end + def powerreset + raise NotImplementedError.new + end + def bootdevice raise NotImplementedError.new end diff --git a/modules/bmc/bmc_plugin.rb b/modules/bmc/bmc_plugin.rb index 6330d8b51..776bcb106 100644 --- a/modules/bmc/bmc_plugin.rb +++ b/modules/bmc/bmc_plugin.rb @@ -11,6 +11,7 @@ class Plugin < Proxy::Plugin capability 'shell' capability 'ssh' capability -> { Proxy::BMC::IPMI.providers_installed } + capability 'power_action_v2' # Load IPMI to ensure the capabilities can be determined load_classes do diff --git a/modules/bmc/redfish.rb b/modules/bmc/redfish.rb index c8095f8a8..9e4f5d4a1 100644 --- a/modules/bmc/redfish.rb +++ b/modules/bmc/redfish.rb @@ -74,6 +74,10 @@ def powercycle poweraction('PowerCycle') end + def powerreset + poweraction('ForceRestart') + end + def poweron poweraction('On') end diff --git a/test/bmc/bmc_api_test.rb b/test/bmc/bmc_api_test.rb index 61415e5dd..b50db1b88 100644 --- a/test/bmc/bmc_api_test.rb +++ b/test/bmc/bmc_api_test.rb @@ -583,6 +583,25 @@ def test_api_calls_redfish_provider_cycle assert expect.once end + def test_api_calls_ipmi_provider_reset + Rubyipmi.stubs(:is_provider_installed?).returns(true) + Proxy::BMC::IPMI.any_instance.stubs(:powerreset).returns(true) + Rack::Auth::Basic::Request.any_instance.stubs(:provided?).returns(true) + Rack::Auth::Basic::Request.any_instance.stubs(:basic?).returns(true) + Rack::Auth::Basic::Request.any_instance.stubs(:credentials).returns(['user', 'pass']) + put "/#{@host}/chassis/power/reset", { 'bmc_provider' => 'ipmitool' } + assert last_response.ok?, "Last response was not ok: #{last_response.body}" + data = JSON.parse(last_response.body) + assert_equal true, data["result"] + end + + def test_api_calls_redfish_provider_reset + expect = Proxy::BMC::Redfish.any_instance.stubs(:powerreset) + test_args = { 'bmc_provider' => 'redfish' } + put "/#{@host}/chassis/power/reset", 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 diff --git a/test/bmc/bmc_redfish_test.rb b/test/bmc/bmc_redfish_test.rb index 5ca992a73..eb0965f19 100644 --- a/test/bmc/bmc_redfish_test.rb +++ b/test/bmc/bmc_redfish_test.rb @@ -21,4 +21,11 @@ def test_redfish_provider_cycle to_return(status: 200, body: JSON.generate({})) assert @bmc.powercycle end + + def test_redfish_provider_reset + stub_request(:post, "#{@protocol}://#{@host}#{SYSTEM_DATA['Actions']['#ComputerSystem.Reset']['target']}"). + with(body: JSON.generate({"ResetType" => "ForceRestart"})). + to_return(status: 200, body: JSON.generate({})) + assert @bmc.powerreset + end end diff --git a/test/bmc/integration_test.rb b/test/bmc/integration_test.rb index d2e0e2c70..83e2cadd2 100644 --- a/test/bmc/integration_test.rb +++ b/test/bmc/integration_test.rb @@ -16,7 +16,7 @@ def test_features mod = response['bmc'] refute_nil(mod) assert_equal('running', mod['state'], Proxy::LogBuffer::Buffer.instance.info[:failed_modules][:bmc]) - assert_equal(['redfish', 'shell', 'ssh'], mod['capabilities']) + assert_equal(['power_action_v2', 'redfish', 'shell', 'ssh'], mod['capabilities']) assert_equal({}, mod['settings']) end @@ -32,7 +32,7 @@ def test_features_with_freeipmi_installed mod = response['bmc'] refute_nil(mod) assert_equal('running', mod['state'], Proxy::LogBuffer::Buffer.instance.info[:failed_modules][:bmc]) - assert_equal(['freeipmi', 'redfish', 'shell', 'ssh'], mod['capabilities']) + assert_equal(['freeipmi', 'power_action_v2', 'redfish', 'shell', 'ssh'], mod['capabilities']) assert_equal({}, mod['settings']) end