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
2 changes: 1 addition & 1 deletion modules/bmc/redfish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def poweroff(soft = false)
end

def powercycle
poweraction('ForceRestart')
poweraction('PowerCycle')
end

def poweron
Expand Down
11 changes: 11 additions & 0 deletions test/bmc/bmc_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
require 'json'
require 'bmc/bmc_plugin'
require 'bmc/bmc_api'
require 'bmc/redfish'
require 'test/bmc/redfish_test_helper'

ENV['RACK_ENV'] = 'test'

Expand All @@ -13,6 +15,7 @@

class BmcApiTest < Test::Unit::TestCase
include Rack::Test::Methods
include RedfishTestHelper

def app
Proxy::BMC::Api.new
Expand All @@ -25,6 +28,7 @@ def setup
provider ||= ENV["ipmiprovider"] || "ipmitool"
@args = { 'bmc_provider' => provider, 'blah' => 'test' }
authorize user, pass
mask_redfish_acceess
end

def test_api_throws_401_error_when_auth_is_not_provided
Expand Down Expand Up @@ -572,6 +576,13 @@ def test_api_throws_400_error_when_get_sensors_action_list_execption
assert_equal 400, last_response.status
end

def test_api_calls_redfish_provider_cycle
expect = Proxy::BMC::Redfish.any_instance.stubs(:powercycle)
test_args = { 'bmc_provider' => 'redfish' }
put "/#{@host}/chassis/power/cycle", 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
24 changes: 24 additions & 0 deletions test/bmc/bmc_redfish_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'test_helper'
require 'bmc/bmc_plugin'
require 'bmc/redfish'
require 'test/bmc/redfish_test_helper'
require 'json'

class BmcRedfishTest < Test::Unit::TestCase
include RedfishTestHelper

def setup
@host = "host"
@protocol = "https"
mask_redfish_acceess(protocol: @protocol, host: @host)
@args = { :username => "user", :password => "pass", :host => @host }
@bmc = Proxy::BMC::Redfish.new(@args)
end

def test_redfish_provider_cycle
stub_request(:post, "#{@protocol}://#{@host}#{SYSTEM_DATA['Actions']['#ComputerSystem.Reset']['target']}").
with(body: JSON.generate({"ResetType" => "PowerCycle"})).
to_return(status: 200, body: JSON.generate({}))
assert @bmc.powercycle
end
end
51 changes: 51 additions & 0 deletions test/bmc/redfish_test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'json'

module RedfishTestHelper
ROOT_DATA = {
"Name" => "Redfish Server Test Mock",
"Systems" => {
"@odata.id" => "/redfish/v1/Systems",
},
"Managers" => {
"@odata.id" => "/redfish/v1/Managers",
},
"@odata.id" => "/redfish/v1",
}.freeze

SYSTEMS_DATA = {
"@odata.id" => "/redfish/v1/Systems",
"Members" => [
{ "@odata.id" => "/redfish/v1/Systems/TESTSYSTEM" },
],
}.freeze

SYSTEM_DATA = {
"@odata.id" => "/redfish/v1/Systems/TESTSYSTEM",
"Manufacture" => "Server Vendor",
"IndicatorLED" => "Off",
"PowerState" => "On",
"Boot" => {
"BootSourceOverrideTarget" => "Pxe",
},
"Model" => "TestServer A",
"SerialNumber" => "AA645",
"AssetTag" => "ax",
"Actions" => {
"#ComputerSystem.Reset" => {
"target" => "/redfish/v1/Systems/TESTSYSTEM/Actions/ComputerSystem.Reset",
},
},
}.freeze

def mask_redfish_acceess(protocol: "https", host: "host")
# root
stub_request(:get, "#{protocol}://#{host}#{ROOT_DATA['@odata.id']}").
to_return(status: 200, body: JSON.generate(ROOT_DATA))
# root.systems
stub_request(:get, "#{protocol}://#{host}#{SYSTEMS_DATA['@odata.id']}").
to_return(status: 200, body: JSON.generate(SYSTEMS_DATA))
# root.system
stub_request(:get, "#{protocol}://#{host}#{SYSTEM_DATA['@odata.id']}").
to_return(status: 200, body: JSON.generate(SYSTEM_DATA))
end
end