Skip to content

Commit f669faa

Browse files
committed
CP-311905: VM.update_secureboot_certificates_on_boot idempotent
Signed-off-by: Chunjie Zhu <chunjie.zhu@cloud.com>
1 parent df2db1c commit f669faa

2 files changed

Lines changed: 22 additions & 20 deletions

File tree

ocaml/tests/test_vm.ml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,11 @@ module VMUpdateSecurebootCertificatesOnBoot = Generic.MakeStateful (struct
251251
let string_of_input_t (state, mark) =
252252
Printf.sprintf "(%s, mark=%b)" (string_of_state state) mark
253253

254-
let string_of_error (code, args) =
255-
Printf.sprintf "%s(%s)" code (String.concat ", " args)
256-
257254
let string_of_output_t = function
258255
| Ok state ->
259256
Printf.sprintf "Ok %s" (string_of_state state)
260-
| Error err ->
261-
Printf.sprintf "Error %s" (string_of_error err)
257+
| Error (code, args) ->
258+
Printf.sprintf "Error %s(%s)" code (String.concat ", " args)
262259
end
263260

264261
module State = Test_state.XapiDb
@@ -281,14 +278,19 @@ module VMUpdateSecurebootCertificatesOnBoot = Generic.MakeStateful (struct
281278
let tests =
282279
`QuickAndAutoDocumented
283280
[
281+
(* transitions *)
284282
((`update_available, true), Ok `update_on_boot)
285283
; ((`update_on_boot, false), Ok `update_available)
284+
(* idempotent: already in desired state *)
285+
; ((`update_on_boot, true), Ok `update_on_boot)
286+
; ((`update_available, false), Ok `update_available)
287+
(* irrelevant state: raises *)
286288
; ( (`ok, true)
287289
, Error
288290
( Api_errors.operation_not_allowed
289291
, [
290292
"Cannot set update_on_boot: VM.secureboot_certificates_state \
291-
is not update_available"
293+
is not in a valid state"
292294
]
293295
)
294296
)
@@ -297,7 +299,7 @@ module VMUpdateSecurebootCertificatesOnBoot = Generic.MakeStateful (struct
297299
( Api_errors.operation_not_allowed
298300
, [
299301
"Cannot clear update_on_boot: VM.secureboot_certificates_state \
300-
is not update_on_boot"
302+
is not in a valid state"
301303
]
302304
)
303305
)

ocaml/xapi/xapi_vm.ml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,23 +1763,23 @@ let update_secureboot_certificates_on_boot ~__context ~self ~mark =
17631763
| false, `update_on_boot ->
17641764
Db.VM.set_secureboot_certificates_state ~__context ~self
17651765
~value:`update_available
1766-
| true, _ ->
1766+
| true, `update_on_boot ->
1767+
() (* already marked for update on boot — idempotent *)
1768+
| false, `update_available ->
1769+
() (* already cleared — idempotent *)
1770+
| _, _ ->
17671771
raise
17681772
(Api_errors.Server_error
17691773
( Api_errors.operation_not_allowed
17701774
, [
1771-
"Cannot set update_on_boot: VM.secureboot_certificates_state is \
1772-
not update_available"
1773-
]
1774-
)
1775-
)
1776-
| false, _ ->
1777-
raise
1778-
(Api_errors.Server_error
1779-
( Api_errors.operation_not_allowed
1780-
, [
1781-
"Cannot clear update_on_boot: VM.secureboot_certificates_state \
1782-
is not update_on_boot"
1775+
Printf.sprintf
1776+
"Cannot %s update_on_boot: VM.secureboot_certificates_state \
1777+
is not in a valid state"
1778+
( if mark then
1779+
"set"
1780+
else
1781+
"clear"
1782+
)
17831783
]
17841784
)
17851785
)

0 commit comments

Comments
 (0)