Skip to content

Commit dd4ddf6

Browse files
author
stack
committed
Issue #1: Configure nodes when already powered off
1 parent f6288bf commit dd4ddf6

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

library/drac.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -902,12 +902,14 @@ def flush(module, bmc):
902902
:param bmc: A dracclient.client.DRACClient instance
903903
"""
904904
debug(module, "Flushing BIOS and/or RAID settings by rebooting")
905-
# Reboot the node.
905+
current_state = bmc.get_power_state()
906+
goal_state = 'POWER_ON' if current_state == 'POWER_OFF' else 'REBOOT'
907+
# Reboot or power on the node.
906908
try:
907-
bmc.set_power_state('REBOOT')
909+
bmc.set_power_state(goal_state)
908910
except drac_exc.BaseClientException as e:
909-
module.fail_json(msg="Failed to reboot to apply pending BIOS "
910-
"settings: %s" % repr(e))
911+
module.fail_json(msg="Failed to set power state to %s to apply "
912+
"pending BIOS settings: %s" % (goal_state, repr(e)))
911913

912914
# Wait for the reboot to flush pending jobs.
913915
try:
@@ -916,6 +918,14 @@ def flush(module, bmc):
916918
module.fail_json(msg="Failed waiting for reboot to flush "
917919
"pending BIOS settings: %s" % repr(e))
918920

921+
# Power off the node if it was previously powered off.
922+
if current_state == 'POWER_OFF':
923+
try:
924+
bmc.set_power_state('POWER_OFF')
925+
except drac_exc.BaseClientException as e:
926+
module.fail_json(msg="Failed to set power state to off: %s"
927+
% repr(e))
928+
919929

920930
def abandon_bios(module, bmc):
921931
"""Abandon uncommitted pending BIOS configuration changes.

tests/test_drac.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,7 @@ def test_configure_bios(self, mock_wait, mock_raid, mock_bios, mock_build):
11331133
}
11341134
self.module.check_mode = False
11351135
self.bmc.list_jobs.side_effect = [[FakeJob('ConfigBIOS')], []]
1136+
self.bmc.get_power_state.return_value = 'POWER ON'
11361137
drac.configure(self.module)
11371138
self.bmc.set_bios_settings.assert_called_once_with({'NumLock': 'On'})
11381139
self.bmc.commit_pending_bios_changes.assert_called_once_with(False)
@@ -1166,6 +1167,7 @@ def test_configure_raid(self, mock_wait, mock_raid, mock_bios, mock_build):
11661167
}
11671168
self.module.check_mode = False
11681169
self.bmc.list_jobs.side_effect = [[FakeJob('ConfigBIOS')], []]
1170+
self.bmc.get_power_state.return_value = 'POWER ON'
11691171
drac.configure(self.module)
11701172
self.bmc.convert_physical_disks.assert_called_once_with(
11711173
'controller1', ['pdisk1'])

0 commit comments

Comments
 (0)