Skip to content

Commit

Permalink
Merge "bootconfig: fix BCDStore SetBooleanElement order"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and openstack-gerrit committed Jun 20, 2024
2 parents 5b624b5 + c6e10ab commit bf61aec
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
11 changes: 8 additions & 3 deletions cloudbaseinit/tests/utils/windows/test_bootconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,15 @@ def _test_enable_auto_recovery(self, mock_get_current_bcd_store,
mock_success=True, mock_enable=True):
mock_store = mock.Mock()
mock_get_current_bcd_store.return_value = mock_store
mock_store.SetBooleanElement.side_effect = ((mock_success,),)
mock_store.SetBooleanElement.return_value = ()

mock_get_element = mock.MagicMock()
mock_get_element.Boolean = mock_success
mock_store.GetElement.return_value = [mock_get_element]

expected_call = (
self.bootconfig.BCDLIBRARY_BOOLEAN_AUTO_RECOVERY_ENABLED,
mock_enable)
mock_enable,
self.bootconfig.BCDLIBRARY_BOOLEAN_AUTO_RECOVERY_ENABLED)
if not mock_success:
self.assertRaises(exception.CloudbaseInitException,
self.bootconfig.enable_auto_recovery,
Expand Down
16 changes: 11 additions & 5 deletions cloudbaseinit/utils/windows/bootconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,15 @@ def set_current_bcd_device_to_boot_partition():
def enable_auto_recovery(enable):
current_store = _get_current_bcd_store()

success, = current_store.SetBooleanElement(
BCDLIBRARY_BOOLEAN_AUTO_RECOVERY_ENABLED, enable)
if not success:
current_store.SetBooleanElement(
enable,
BCDLIBRARY_BOOLEAN_AUTO_RECOVERY_ENABLED)

current_state = current_store.GetElement(
BCDLIBRARY_BOOLEAN_AUTO_RECOVERY_ENABLED)[0].Boolean

if current_state != enable:
raise exception.CloudbaseInitException(
"Cannot set boolean element: %s" %
BCDLIBRARY_BOOLEAN_AUTO_RECOVERY_ENABLED)
"Cannot set boolean element: '%s'. "
"Current state '%s' != desired state '%s'." %
(BCDLIBRARY_BOOLEAN_AUTO_RECOVERY_ENABLED, current_state, enable))

0 comments on commit bf61aec

Please sign in to comment.