Skip to content

Commit 378623d

Browse files
committed
Merge tag 'v1.124.0' into uefi
Conflicts: ocaml/xapi/xapi_xenops.ml
2 parents 6384c82 + b158137 commit 378623d

26 files changed

+1469
-1383
lines changed

ocaml/tests/test_sr_update_vdis.ml

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ let assert_snapshot_of_is_not_null ~__context ~vdi_snapshot =
2525
"VDI snapshot's `snapshot_of` reference has become null"
2626
true (vdi <> Ref.null)
2727

28+
let default_vdi_info = Storage_interface.default_vdi_info
29+
2830
(* CA-254515 *)
2931
(* Tests that a single VDI snapshot from the SR is properly updating the
3032
existing snapshot in the database; the test should pass if the `snapshot_of`
@@ -38,15 +40,15 @@ let test_update_existing_snapshot () =
3840
let vdi = T.make_vdi ~__context ~uuid:vdi_uuid ~location:vdi_uuid ~sR:sr () in
3941
let vdi_snapshot_uuid = T.make_uuid () in
4042
let vdi_snapshot = T.make_vdi ~__context ~uuid:vdi_snapshot_uuid ~sR:sr
41-
~location:vdi_snapshot_uuid ~snapshot_of:vdi ~is_a_snapshot:true () in
43+
~location:vdi_snapshot_uuid ~snapshot_of:vdi ~is_a_snapshot:true () in
4244

4345
(* create mock snapshot record which we would get from an SR scan *)
4446
let vdi_snapshot_sr_record = Storage_interface.({ default_vdi_info with
45-
vdi = vdi_snapshot_uuid;
46-
uuid = Some vdi_snapshot_uuid;
47-
is_a_snapshot = true;
48-
snapshot_of = vdi_uuid;
49-
}) in
47+
vdi = Storage_interface.Vdi.of_string vdi_snapshot_uuid;
48+
uuid = Some vdi_snapshot_uuid;
49+
is_a_snapshot = true;
50+
snapshot_of = Storage_interface.Vdi.of_string vdi_uuid;
51+
}) in
5052

5153
(* attempt to reproduce the issue by updating the snapshot *)
5254
let vdi_snapshot_record = Db.VDI.get_record ~__context ~self:vdi_snapshot in
@@ -77,15 +79,15 @@ let test_update_new_vdi_and_snapshot () =
7779

7880
(* create mock VDI/snapshot records which we would get from an SR scan *)
7981
let vdi_sr_record = Storage_interface.({ default_vdi_info with
80-
vdi = vdi_uuid;
81-
uuid = Some vdi_uuid;
82-
}) in
82+
vdi = Storage_interface.Vdi.of_string vdi_uuid;
83+
uuid = Some vdi_uuid;
84+
}) in
8385
let vdi_snapshot_sr_record = Storage_interface.({ default_vdi_info with
84-
vdi = vdi_snapshot_uuid;
85-
uuid = Some vdi_snapshot_uuid;
86-
snapshot_of = vdi_uuid;
87-
is_a_snapshot = true;
88-
}) in
86+
vdi = Storage_interface.Vdi.of_string vdi_snapshot_uuid;
87+
uuid = Some vdi_snapshot_uuid;
88+
snapshot_of = Storage_interface.Vdi.of_string vdi_uuid;
89+
is_a_snapshot = true;
90+
}) in
8991

9092
(* attempt to reproduce the issue by creating the snapshot before the VDI *)
9193
Xapi_sr.update_vdis ~__context ~sr [] [vdi_sr_record; vdi_snapshot_sr_record];
@@ -107,10 +109,10 @@ let test_sharable_field_updated_for_existing_vdi () =
107109

108110
(* SR.scan returned the correct vdi_info with the up-to-date sharable field *)
109111
let vdi_sr_record = Storage_interface.({ default_vdi_info with
110-
vdi = vdi_uuid;
111-
uuid = Some vdi_uuid;
112-
sharable = true;
113-
}) in
112+
vdi = Storage_interface.Vdi.of_string vdi_uuid;
113+
uuid = Some vdi_uuid;
114+
sharable = true;
115+
}) in
114116

115117
(* When we call this function from our SR.scan XenAPI call for example, it should
116118
update the VDI's sharable field to the correct value returned by the
@@ -128,10 +130,10 @@ let test_sharable_field_correct_for_new_vdi () =
128130
(* We do not have this VDI in xapi's database. SR.scan returned it with the
129131
correct vdi_info containing the up-to-date sharable field. *)
130132
let vdi_sr_record = Storage_interface.({ default_vdi_info with
131-
vdi = vdi_uuid;
132-
uuid = Some vdi_uuid;
133-
sharable = true;
134-
}) in
133+
vdi = Storage_interface.Vdi.of_string vdi_uuid;
134+
uuid = Some vdi_uuid;
135+
sharable = true;
136+
}) in
135137

136138
(* When we call this function from our SR.scan XenAPI call for example, it should
137139
add the VDI to xapi's database with the correct sharable field returned

ocaml/tests/test_storage_migrate_state.ml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,30 @@ end
2424

2525
let sample_send_state = Storage_migrate.State.Send_state.({
2626
url = "url";
27-
dest_sr = "dest_sr";
28-
remote_info = Some {dp="remote_dp"; vdi="mirror_vdi"; url="remote_url"};
27+
dest_sr = Storage_interface.Sr.of_string "dest_sr";
28+
remote_info = Some {dp="remote_dp"; vdi=Storage_interface.Vdi.of_string "mirror_vdi"; url="remote_url"};
2929
local_dp = "local_dp";
3030
tapdev = Some (Tapctl.tapdev_of_rpc
31-
(Rpc.Dict ["minor", Rpc.Int 0L; "tapdisk_pid", Rpc.Int 0L]));
31+
(Rpc.Dict ["minor", Rpc.Int 0L; "tapdisk_pid", Rpc.Int 0L]));
3232
failed = false;
3333
watchdog = None;
3434
})
3535

3636
let sample_receive_state = Storage_migrate.State.Receive_state.({
37-
sr = "my_sr";
38-
dummy_vdi = "dummy_vdi";
39-
leaf_vdi = "leaf_vdi";
37+
sr = Storage_interface.Sr.of_string "my_sr";
38+
dummy_vdi = Storage_interface.Vdi.of_string "dummy_vdi";
39+
leaf_vdi = Storage_interface.Vdi.of_string "leaf_vdi";
4040
leaf_dp = "leaf_dp";
41-
parent_vdi = "parent_vdi";
42-
remote_vdi = "remote_vdi";
41+
parent_vdi = Storage_interface.Vdi.of_string "parent_vdi";
42+
remote_vdi = Storage_interface.Vdi.of_string "remote_vdi";
4343
})
4444

4545
let sample_copy_state = Storage_migrate.State.Copy_state.({
4646
base_dp = "base_dp";
4747
leaf_dp = "leaf_dp";
4848
remote_dp = "remote_dp";
49-
dest_sr = "dest_sr";
50-
copy_vdi = "copy_vdi";
49+
dest_sr = Storage_interface.Sr.of_string "dest_sr";
50+
copy_vdi = Storage_interface.Vdi.of_string "copy_vdi";
5151
remote_url = "remote_url";
5252
})
5353

ocaml/tests/test_vdi_cbt.ml

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
*)
1414

1515

16-
let register_smapiv2_server (module S: Storage_interface.Server_impl with type context = unit) sr_ref =
17-
let module S = Storage_interface.Server(S) in
18-
let rpc = S.process () in
16+
let register_smapiv2_server (module S: Storage_interface.Server_impl) sr_ref =
17+
let module S = Storage_interface.Server(S)() in
18+
let rpc = S.process in
1919
let dummy_query_result = Storage_interface.({ driver=""; name=""; description=""; vendor=""; copyright=""; version=""; required_api_version=""; features=[]; configuration=[]; required_cluster_stack=[] }) in
2020
Storage_mux.register sr_ref rpc "" dummy_query_result
2121

@@ -32,7 +32,7 @@ let make_smapiv2_storage_server ?vdi_enable_cbt ?vdi_disable_cbt ?vdi_list_chang
3232
let snapshot = default Storage_skeleton.VDI.snapshot vdi_snapshot
3333
let clone = default Storage_skeleton.VDI.clone vdi_snapshot
3434
end
35-
end : Storage_interface.Server_impl with type context = unit)
35+
end : Storage_interface.Server_impl)
3636

3737
let register_smapiv2_server ?vdi_enable_cbt ?vdi_disable_cbt ?vdi_list_changed_blocks ?vdi_data_destroy ?vdi_snapshot ?vdi_clone sr_ref =
3838
let s = make_smapiv2_storage_server ?vdi_enable_cbt ?vdi_disable_cbt ?vdi_list_changed_blocks ?vdi_data_destroy ?vdi_snapshot ?vdi_clone () in
@@ -47,32 +47,41 @@ let make_mock_server_infrastructure ~__context =
4747
let _: _ API.Ref.t = Test_common.make_pbd ~__context ~host ~sR ~currently_attached:true () in
4848
sR
4949

50+
let alcotestable_of_def def =
51+
let pp fmt a = Format.fprintf fmt "%s" (Rpcmarshal.marshal def.Rpc.Types.ty a |> Jsonrpc.to_string) in
52+
Alcotest.testable pp (=)
53+
54+
let alco_sr = alcotestable_of_def Storage_interface.Sr.t
55+
let alco_vdi = alcotestable_of_def Storage_interface.Vdi.t
56+
5057
let test_cbt_enable_disable () =
5158
let __context = Test_common.make_test_database () in
5259
let sr_ref = Test_common.make_sr ~__context () in
5360
let sr_uuid = Db.SR.get_uuid ~__context ~self:sr_ref in
61+
let sr = Storage_interface.Sr.of_string sr_uuid in
5462
let vdi_location = "test123" in
63+
let vdi = Storage_interface.Vdi.of_string vdi_location in
5564
let vdi_ref = Test_common.make_vdi ~__context ~sR:sr_ref ~location:vdi_location () in
5665
let assert_vdi_cbt_enabled_is value msg =
5766
Alcotest.(check bool) msg value (Db.VDI.get_cbt_enabled ~__context ~self:vdi_ref) in
58-
let check_params = Alcotest.(check (option (pair string string))) in
67+
let check_params = Alcotest.(check (option (pair alco_sr alco_vdi))) in
5968

6069
let enable_cbt_params = ref None in
6170
let disable_cbt_params = ref None in
6271
register_smapiv2_server
6372
~vdi_enable_cbt:(fun _ ~dbg ~sr ~vdi -> enable_cbt_params := Some (sr, vdi))
6473
~vdi_disable_cbt:(fun _ ~dbg ~sr ~vdi -> disable_cbt_params := Some (sr, vdi))
65-
sr_uuid;
74+
sr;
6675

6776
Xapi_vdi.enable_cbt ~__context ~self:vdi_ref;
68-
check_params "The parameters should be correctly passed to SMAPIv2 from VDI.enable_cbt" (Some (sr_uuid, vdi_location)) !enable_cbt_params;
77+
check_params "The parameters should be correctly passed to SMAPIv2 from VDI.enable_cbt" (Some (sr, vdi)) !enable_cbt_params;
6978
assert_vdi_cbt_enabled_is true "cbt_enabled should be true when VDI.enable_cbt returns successfully";
7079

7180
Xapi_vdi.enable_cbt ~__context ~self:vdi_ref;
7281
assert_vdi_cbt_enabled_is true "VDI.enable_cbt should be idempotent";
7382

7483
Xapi_vdi.disable_cbt ~__context ~self:vdi_ref;
75-
check_params "The parameters should be correctly passed to SMAPIv2 from VDI.disable_cbt" (Some (sr_uuid, vdi_location)) !disable_cbt_params;
84+
check_params "The parameters should be correctly passed to SMAPIv2 from VDI.disable_cbt" (Some (sr, vdi)) !disable_cbt_params;
7685
assert_vdi_cbt_enabled_is false "cbt_enabled should be false when VDI.disable_cbt returns successfully";
7786

7887
Xapi_vdi.disable_cbt ~__context ~self:vdi_ref;
@@ -279,12 +288,12 @@ let setup_test_for_data_destroy ?(vdi_data_destroy=(fun _ ~dbg ~sr ~vdi -> ()))
279288

280289
let sR = make_mock_server_infrastructure ~__context in
281290
let vdi = Test_common.make_vdi ~__context ~is_a_snapshot:true ~managed:true ~cbt_enabled:true ~sR () in
282-
register_smapiv2_server ~vdi_data_destroy (Db.SR.get_uuid ~__context ~self:sR);
291+
register_smapiv2_server ~vdi_data_destroy (Db.SR.get_uuid ~__context ~self:sR |> Storage_interface.Sr.of_string);
283292
(__context, sR, vdi)
284293

285294
let test_allowed_operations_updated_when_necessary () =
286295
let __context, sR, self = setup_test_for_data_destroy () in
287-
register_smapiv2_server ~vdi_data_destroy:(fun _ ~dbg ~sr ~vdi -> ()) (Db.SR.get_uuid ~__context ~self:sR);
296+
register_smapiv2_server ~vdi_data_destroy:(fun _ ~dbg ~sr ~vdi -> ()) (Db.SR.get_uuid ~__context ~self:sR |> Storage_interface.Sr.of_string);
288297

289298
let assert_allowed_operations msg check =
290299
Alcotest.(check bool) msg true (check (Db.VDI.get_allowed_operations ~__context ~self))
@@ -354,10 +363,10 @@ let test_data_destroy =
354363
let __context, sR, vdi = setup_test_for_data_destroy ~vdi_data_destroy:(fun _ ~dbg ~sr ~vdi -> raise (Failure "error")) () in
355364
let original_type = Db.VDI.get_type ~__context ~self:vdi in
356365
try Xapi_vdi.data_destroy ~__context ~self:vdi with _ -> ();
357-
Alcotest.check (Alcotest_comparators.vdi_type)
358-
"data_destroy should not change the VDI's type to cbt_metadata when it did not succeed, it should preserve the original type"
359-
original_type
360-
(Db.VDI.get_type ~__context ~self:vdi)
366+
Alcotest.check (Alcotest_comparators.vdi_type)
367+
"data_destroy should not change the VDI's type to cbt_metadata when it did not succeed, it should preserve the original type"
368+
original_type
369+
(Db.VDI.get_type ~__context ~self:vdi)
361370
in
362371

363372
let test_data_destroy_timing =
@@ -384,7 +393,7 @@ let test_data_destroy =
384393
ignore (bg (fun () -> (try Xapi_vdi._data_destroy ~__context ~self:vDI ~timeout with e -> raisedexn := Some e); completed := true));
385394
Thread.delay timebox_timeout;
386395
if not !completed then
387-
Alcotest.fail (Printf.sprintf "data_destroy did not return in %f seconds" timebox_timeout);
396+
Alcotest.fail (Printf.sprintf "data_destroy did not return in %f seconds" timebox_timeout);
388397
match !raisedexn with
389398
| None -> ()
390399
| Some e -> raise e
@@ -479,24 +488,27 @@ let test_vdi_list_changed_blocks () =
479488
let __context = Test_common.make_test_database () in
480489
let sR = make_mock_server_infrastructure ~__context in
481490
let sr_uuid = Db.SR.get_uuid ~__context ~self:sR in
491+
let sr = Storage_interface.Sr.of_string sr_uuid in
482492

483493
let list_changed_blocks_params = ref None in
484494
let list_changed_blocks_string = "listchangedblocks000" in
485495

486496
let vdi_from_location = "vdi_from_location" in
487-
let vdi_from = Test_common.make_vdi ~__context ~location:vdi_from_location ~is_a_snapshot:true ~managed:true ~cbt_enabled:true ~sR () in
497+
let vdi_from_ref = Test_common.make_vdi ~__context ~location:vdi_from_location ~is_a_snapshot:true ~managed:true ~cbt_enabled:true ~sR () in
498+
let vdi_from = Storage_interface.Vdi.of_string vdi_from_location in
488499
let vdi_to_location = "vdi_to_location" in
489-
let vdi_to = Test_common.make_vdi ~__context~location:vdi_to_location ~sR ~cbt_enabled:true ~managed:true () in
500+
let vdi_to_ref = Test_common.make_vdi ~__context~location:vdi_to_location ~sR ~cbt_enabled:true ~managed:true () in
501+
let vdi_to = Storage_interface.Vdi.of_string vdi_to_location in
490502

491503
register_smapiv2_server
492504
~vdi_list_changed_blocks:(fun _ ~dbg ~sr ~vdi_from ~vdi_to -> list_changed_blocks_params := Some (sr,(vdi_from,vdi_to)); list_changed_blocks_string)
493-
(Db.SR.get_uuid ~__context ~self:sR);
505+
(Db.SR.get_uuid ~__context ~self:sR |> Storage_interface.Sr.of_string);
494506

495507
Alcotest.(check string) "VDI.list_changed_blocks"
496-
(Xapi_vdi.list_changed_blocks ~__context ~vdi_from ~vdi_to)
508+
(Xapi_vdi.list_changed_blocks ~__context ~vdi_from:vdi_from_ref ~vdi_to:vdi_to_ref)
497509
list_changed_blocks_string;
498-
Alcotest.(check (option (pair string (pair string string)))) "VDI.list_changed_blocks parameters"
499-
(Some (sr_uuid, (vdi_from_location, vdi_to_location)))
510+
Alcotest.(check (option (pair alco_sr (pair alco_vdi alco_vdi)))) "VDI.list_changed_blocks parameters"
511+
(Some (sr, (vdi_from, vdi_to)))
500512
!list_changed_blocks_params
501513

502514
let test =

ocaml/xapi-consts/api_messages.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ let host_cpu_features_down = addMessage "HOST_CPU_FEATURES_DOWN" 3L
132132
let host_cpu_features_up = addMessage "HOST_CPU_FEATURES_UP" 5L
133133
let pool_cpu_features_down = addMessage "POOL_CPU_FEATURES_DOWN" 5L
134134
let pool_cpu_features_up = addMessage "POOL_CPU_FEATURES_UP" 5L
135+
let host_low_memory = addMessage "HOST_LOW_MEMORY" 2L
135136

136137
(* Cluster messages *)
137138
let cluster_host_enable_failed = addMessage "CLUSTER_HOST_ENABLE_FAILED" 3L

ocaml/xapi/attach_helpers.ml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,3 @@ let with_vbds rpc session_id __context vm vdis mode f =
101101
List.iter (Helpers.log_exn_continue "destroying VBD on VM"
102102
(fun self -> Client.VBD.destroy rpc session_id self)) !vbds))
103103

104-
(** Separates the implementations of the given backend returned from
105-
the VDI.attach2 SMAPIv2 call based on their type *)
106-
let implementations_of_backend backend =
107-
let open Storage_interface in
108-
List.fold_left
109-
(fun (xendisks, blockdevices, files, nbds) implementation ->
110-
match implementation with
111-
| XenDisk xendisk -> (xendisk::xendisks, blockdevices, files, nbds)
112-
| BlockDevice blockdevice -> (xendisks, blockdevice::blockdevices, files, nbds)
113-
| File file -> (xendisks, blockdevices, file::files, nbds)
114-
| Nbd nbd -> (xendisks, blockdevices, files, nbd::nbds)
115-
)
116-
([], [], [], [])
117-
backend.implementations

ocaml/xapi/cli_operations.ml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,9 +1473,10 @@ let sr_probe printer rpc session_id params =
14731473
try
14741474
(* If it's the new format, try to print it more nicely *)
14751475
let open Storage_interface in
1476-
match probe_result_of_rpc (Xmlrpc.of_string txt) with
1477-
| Raw x -> printer (Cli_printer.PList [ x ])
1478-
| Probe x -> failwith "Not implemented, this return type is for probe_ext"
1476+
match Rpcmarshal.unmarshal probe_result.Rpc.Types.ty (Xmlrpc.of_string txt) with
1477+
| Ok (Raw x) -> printer (Cli_printer.PList [ x ])
1478+
| Ok (Probe x) -> failwith "Not implemented, this return type is for probe_ext"
1479+
| Error (`Msg m) -> failwith (Printf.sprintf "Failed to unmarshal probe result: %s" m)
14791480
with _ ->
14801481
printer (Cli_printer.PList [txt])
14811482

@@ -1514,12 +1515,12 @@ let sr_probe_ext printer rpc session_id params =
15141515
printer (Cli_printer.PMsg "The following SRs were found:");
15151516
List.iteri
15161517
(fun i (sr, probe_result) ->
1517-
printer (Cli_printer.PMsg (Printf.sprintf "SR %d:" i));
1518-
printer (Cli_printer.PTable [print_sr sr]);
1519-
printer (Cli_printer.PMsg (Printf.sprintf "SR %d configuration:" i));
1520-
printer (Cli_printer.PTable [probe_result.API.probe_result_configuration]);
1521-
printer (Cli_printer.PMsg (Printf.sprintf "SR %d extra information:" i));
1522-
printer (Cli_printer.PTable [probe_result.API.probe_result_extra_info]);
1518+
printer (Cli_printer.PMsg (Printf.sprintf "SR %d:" i));
1519+
printer (Cli_printer.PTable [print_sr sr]);
1520+
printer (Cli_printer.PMsg (Printf.sprintf "SR %d configuration:" i));
1521+
printer (Cli_printer.PTable [probe_result.API.probe_result_configuration]);
1522+
printer (Cli_printer.PMsg (Printf.sprintf "SR %d extra information:" i));
1523+
printer (Cli_printer.PTable [probe_result.API.probe_result_extra_info]);
15231524
)
15241525
srs;
15251526
end;

0 commit comments

Comments
 (0)