Skip to content
Draft
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
5 changes: 4 additions & 1 deletion bundler.d/bmc.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
group :bmc do
gem 'rubyipmi', '>= 0.10.0'
gem 'redfish_client', '>= 0.6.0'
# Temporarily use forked redfish_client with ETag support (draft PR)
# TODO: Update to released version once PR is merged
gem 'redfish_client', git: 'https://github.com/spesnova717/redfish-client-ruby.git', branch: 'feature/redfish-etag-support'
# gem 'redfish_client', '>= 0.7.0' # Uncomment after PR is merged
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# observer is a transitive dependency of rubyipmi
# Changed from a default gem to a bundled gem in Ruby 3.4 See https://stdgems.org/new-in/3.4/
# This is a workaround, till https://github.com/logicminds/rubyipmi/pull/61 is live
Expand Down
13 changes: 6 additions & 7 deletions modules/bmc/redfish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,12 @@ def bootdevice=(args = { :device => nil, :reboot => false, :persistent => false
'disk' => 'Hdd',
'pxe' => 'Pxe' }

system.patch(
payload: {
'Boot' => {
'BootSourceOverrideTarget' => devmap[args[:device]],
'BootSourceOverrideEnabled' => args[:persistent] ? 'Enabled' : 'Once',
},
})
system.patch_if_match({
'Boot' => {
'BootSourceOverrideTarget' => devmap[args[:device]],
'BootSourceOverrideEnabled' => args[:persistent] ? 'Enabled' : 'Once',
},
})
powercycle if args[:reboot]
end

Expand Down
126 changes: 126 additions & 0 deletions test/bmc/bmc_redfish_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,130 @@ def test_redfish_provider_reboot
to_return(status: 200, body: JSON.generate({}))
assert @bmc.powerreboot
end

def test_bootdevice_pxe_uses_patch_if_match
# Test that bootdevice uses patch_if_match for PXE boot
system_mock = mock('system')

system_mock.expects(:patch_if_match).with(
'Boot' => {
'BootSourceOverrideTarget' => 'Pxe',
'BootSourceOverrideEnabled' => 'Once',
}
).returns(true)

@bmc.expects(:system).returns(system_mock)
@bmc.expects(:powercycle).never

result = @bmc.bootdevice = { :device => 'pxe', :reboot => false, :persistent => false }
assert_not_nil result
end

def test_bootdevice_disk_persistent_uses_patch_if_match
# Test that bootdevice uses patch_if_match with persistent boot
system_mock = mock('system')

system_mock.expects(:patch_if_match).with(
'Boot' => {
'BootSourceOverrideTarget' => 'Hdd',
'BootSourceOverrideEnabled' => 'Enabled',
}
).returns(true)

@bmc.expects(:system).returns(system_mock)
@bmc.expects(:powercycle).never

result = @bmc.bootdevice = { :device => 'disk', :reboot => false, :persistent => true }
assert_not_nil result
end

def test_bootdevice_with_reboot
# Test bootdevice with reboot option
system_mock = mock('system')

system_mock.expects(:patch_if_match).with(
'Boot' => {
'BootSourceOverrideTarget' => 'Pxe',
'BootSourceOverrideEnabled' => 'Enabled',
}
).returns(true)

@bmc.expects(:system).returns(system_mock)
@bmc.expects(:powercycle).once

result = @bmc.bootdevice = { :device => 'pxe', :reboot => true, :persistent => true }
assert_not_nil result
end

def test_bootpxe_calls_bootdevice
# Test that convenience method bootpxe works
system_mock = mock('system')

system_mock.expects(:patch_if_match).with(
'Boot' => {
'BootSourceOverrideTarget' => 'Pxe',
'BootSourceOverrideEnabled' => 'Once',
}
).returns(true)

@bmc.expects(:system).returns(system_mock)
@bmc.expects(:powercycle).never

result = @bmc.bootpxe(false, false)
assert_not_nil result
end

def test_bootdisk_calls_bootdevice
# Test that convenience method bootdisk works
system_mock = mock('system')

system_mock.expects(:patch_if_match).with(
'Boot' => {
'BootSourceOverrideTarget' => 'Hdd',
'BootSourceOverrideEnabled' => 'Once',
}
).returns(true)

@bmc.expects(:system).returns(system_mock)
@bmc.expects(:powercycle).never

result = @bmc.bootdisk(false, false)
assert_not_nil result
end

def test_bootbios_calls_bootdevice
# Test that convenience method bootbios works
system_mock = mock('system')

system_mock.expects(:patch_if_match).with(
'Boot' => {
'BootSourceOverrideTarget' => 'BiosSetup',
'BootSourceOverrideEnabled' => 'Once',
}
).returns(true)

@bmc.expects(:system).returns(system_mock)
@bmc.expects(:powercycle).never

result = @bmc.bootbios(false, false)
assert_not_nil result
end

def test_bootcdrom_calls_bootdevice
# Test that convenience method bootcdrom works
system_mock = mock('system')

system_mock.expects(:patch_if_match).with(
'Boot' => {
'BootSourceOverrideTarget' => 'Cd',
'BootSourceOverrideEnabled' => 'Once',
}
).returns(true)

@bmc.expects(:system).returns(system_mock)
@bmc.expects(:powercycle).never

result = @bmc.bootcdrom(false, false)
assert_not_nil result
end
end