Skip to content

Commit 3eafb5e

Browse files
authored
Merge pull request xapi-project#3142 from gaborigloi/fix_rpu_vdi_allowed_ops
CA-260262: Restrict allowed VDI operations during rolling pool upgrade to those supported by older releases
2 parents 878678b + 365213c commit 3eafb5e

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

ocaml/xapi/test_vdi_allowed_operations.ml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,45 @@ let test_cbt =
272272
; "test_vdi_cbt_enabled_check" >:: test_vdi_cbt_enabled_check
273273
]
274274

275+
(** The set of allowed operations must be restricted during rolling pool
276+
upgrade to the enums known by older releases. *)
277+
let test_operations_restricted_during_rpu =
278+
let test_check_operation_error () =
279+
let __context = Mock.make_context_with_new_db "Mock context" in
280+
let master = Test_common.make_host __context () in
281+
let pool = Test_common.make_pool ~__context ~master () in
282+
Db.Pool.add_to_other_config ~__context ~self:pool ~key:Xapi_globs.rolling_upgrade_in_progress ~value:"x";
283+
run_assert_equal_with_vdi
284+
~__context
285+
~sm_fun:(fun sm -> Db.SM.set_features ~__context ~self:sm ~value:["VDI_MIRROR",1L])
286+
`mirror
287+
(Some(Api_errors.not_supported_during_upgrade, []));
288+
Db.Pool.remove_from_other_config ~__context ~self:pool ~key:Xapi_globs.rolling_upgrade_in_progress;
289+
run_assert_equal_with_vdi
290+
~__context
291+
~sm_fun:(fun sm -> Db.SM.set_features ~__context ~self:sm ~value:["VDI_MIRROR",1L])
292+
`mirror
293+
None
294+
in
295+
296+
let test_update_allowed_operations () =
297+
let __context = Mock.make_context_with_new_db "Mock context" in
298+
let master = Test_common.make_host __context () in
299+
let pool = Test_common.make_pool ~__context ~master () in
300+
Db.Pool.add_to_other_config ~__context ~self:pool ~key:Xapi_globs.rolling_upgrade_in_progress ~value:"x";
301+
let self, _ = setup_test ~__context ~vdi_fun:(fun vdi -> Db.VDI.set_type ~__context ~self:vdi ~value:`user) () in
302+
Xapi_vdi.update_allowed_operations ~__context ~self;
303+
OUnit.assert_bool "update_allowed_operations should exclude `enable_cbt during RPU" (not @@ List.mem `enable_cbt (Db.VDI.get_allowed_operations ~__context ~self));
304+
Db.Pool.remove_from_other_config ~__context ~self:pool ~key:Xapi_globs.rolling_upgrade_in_progress;
305+
Xapi_vdi.update_allowed_operations ~__context ~self;
306+
OUnit.assert_bool "update_allowed_operations should consider `enable_cbt when RPU is not running" (List.mem `enable_cbt (Db.VDI.get_allowed_operations ~__context ~self))
307+
in
308+
309+
"test_operations_restricted_during_rpu" >:::
310+
[ "test_check_operation_error" >:: test_check_operation_error
311+
; "test_update_allowed_operations" >:: test_update_allowed_operations
312+
]
313+
275314
let test =
276315
"test_vdi_allowed_operations" >:::
277316
[
@@ -280,4 +319,5 @@ let test =
280319
"test_ca125187" >:: test_ca125187;
281320
"test_ca126097" >:: test_ca126097;
282321
test_cbt;
322+
test_operations_restricted_during_rpu;
283323
]

ocaml/xapi/xapi_globs.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,20 @@ let rpu_allowed_vm_operations = [
454454
`update_allowed_operations;
455455
]
456456

457+
let rpu_allowed_vdi_operations = [
458+
`clone;
459+
`copy;
460+
`resize;
461+
`resize_online;
462+
`snapshot;
463+
`destroy;
464+
`forget;
465+
`update;
466+
`force_unlock;
467+
`generate_config;
468+
`blocked;
469+
]
470+
457471
(* Viridian key name (goes in platform flags) *)
458472
let viridian_key_name = "viridian"
459473
(* Viridian key value (set in new templates, in built-in templates on upgrade and when Orlando PV drivers up-to-date first detected) *)

ocaml/xapi/xapi_vdi.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ let check_operation_error ~__context ?(sr_records=[]) ?(pbd_records=[]) ?(vbd_re
7070
4. for other operations, fail if any VBD has currently-attached=true or any VBD
7171
has a current_operation itself
7272
5. HA prevents you from deleting statefiles or metadata volumes
73+
6. During rolling pool upgrade, only operations known by older releases are allowed
7374
*)
75+
if Helpers.rolling_upgrade_in_progress ~__context &&
76+
not (List.mem op Xapi_globs.rpu_allowed_vdi_operations)
77+
then Some (Api_errors.not_supported_during_upgrade, [])
78+
else
7479
(* Don't fail with other_operation_in_progress if VDI mirroring is in progress
7580
* and destroy is called as part of VDI mirroring *)
7681
let is_vdi_mirroring_in_progress = (List.exists (fun (_, op) -> op = `mirror) current_ops) && (op = `destroy) in
@@ -241,6 +246,11 @@ let update_allowed_operations_internal ~__context ~self ~sr_records ~pbd_records
241246
let check x = match check_operation_error ~__context ~sr_records ~pbd_records ~vbd_records ha_enabled all self x with None -> [ x ] | _ -> [] in
242247
List.fold_left (fun accu op -> check op @ accu) []
243248
(Listext.List.set_difference Xapi_vdi_helpers.all_ops [`blocked]) in
249+
let allowed =
250+
if Helpers.rolling_upgrade_in_progress ~__context
251+
then Listext.List.intersect allowed Xapi_globs.rpu_allowed_vdi_operations
252+
else allowed
253+
in
244254
Db.VDI.set_allowed_operations ~__context ~self ~value:allowed
245255

246256
let update_allowed_operations ~__context ~self : unit =

0 commit comments

Comments
 (0)