Skip to content

Commit bf61aec

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "bootconfig: fix BCDStore SetBooleanElement order"
2 parents 5b624b5 + c6e10ab commit bf61aec

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

cloudbaseinit/tests/utils/windows/test_bootconfig.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,15 @@ def _test_enable_auto_recovery(self, mock_get_current_bcd_store,
152152
mock_success=True, mock_enable=True):
153153
mock_store = mock.Mock()
154154
mock_get_current_bcd_store.return_value = mock_store
155-
mock_store.SetBooleanElement.side_effect = ((mock_success,),)
155+
mock_store.SetBooleanElement.return_value = ()
156+
157+
mock_get_element = mock.MagicMock()
158+
mock_get_element.Boolean = mock_success
159+
mock_store.GetElement.return_value = [mock_get_element]
160+
156161
expected_call = (
157-
self.bootconfig.BCDLIBRARY_BOOLEAN_AUTO_RECOVERY_ENABLED,
158-
mock_enable)
162+
mock_enable,
163+
self.bootconfig.BCDLIBRARY_BOOLEAN_AUTO_RECOVERY_ENABLED)
159164
if not mock_success:
160165
self.assertRaises(exception.CloudbaseInitException,
161166
self.bootconfig.enable_auto_recovery,

cloudbaseinit/utils/windows/bootconfig.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,15 @@ def set_current_bcd_device_to_boot_partition():
9696
def enable_auto_recovery(enable):
9797
current_store = _get_current_bcd_store()
9898

99-
success, = current_store.SetBooleanElement(
100-
BCDLIBRARY_BOOLEAN_AUTO_RECOVERY_ENABLED, enable)
101-
if not success:
99+
current_store.SetBooleanElement(
100+
enable,
101+
BCDLIBRARY_BOOLEAN_AUTO_RECOVERY_ENABLED)
102+
103+
current_state = current_store.GetElement(
104+
BCDLIBRARY_BOOLEAN_AUTO_RECOVERY_ENABLED)[0].Boolean
105+
106+
if current_state != enable:
102107
raise exception.CloudbaseInitException(
103-
"Cannot set boolean element: %s" %
104-
BCDLIBRARY_BOOLEAN_AUTO_RECOVERY_ENABLED)
108+
"Cannot set boolean element: '%s'. "
109+
"Current state '%s' != desired state '%s'." %
110+
(BCDLIBRARY_BOOLEAN_AUTO_RECOVERY_ENABLED, current_state, enable))

0 commit comments

Comments
 (0)