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
3737let 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 ~s R ~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+
5057let 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 ~s R: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 ~s R () 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
285294let 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 ~s R () in
497+ let vdi_from_ref = Test_common. make_vdi ~__context ~location: vdi_from_location ~is_a_snapshot: true ~managed: true ~cbt_enabled: true ~s R () 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 ~s R ~cbt_enabled: true ~managed: true () in
500+ let vdi_to_ref = Test_common. make_vdi ~__context~location: vdi_to_location ~s R ~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
502514let test =
0 commit comments