@@ -20,12 +20,6 @@ open Lwt
2020
2121let vg = " myvg"
2222
23- let get_hostname host =
24- Printf. sprintf " host%d" host
25-
26- let get_local_allocator_sockpath host =
27- Printf. sprintf " /tmp/host%d-socket" host
28-
2923let vgcreate =
3024 " vgcreate <vg name> <device>: check that we can create a volume group and re-read the metadata." > ::
3125 fun () ->
@@ -42,26 +36,25 @@ let vgcreate =
4236 Lwt_main. run t
4337 )
4438
39+ let set_vg_info ~pvpath ~vg ~host =
40+ xenvm ~host [ " set-vg-info" ;
41+ " --pvpath" ; pvpath;
42+ " -S" ; xenvmd_socket;
43+ vg;
44+ " --local-allocator-path" ; la_socket host;
45+ " --uri" ; " file://local/services/xenvmd/" ^ vg;
46+ ] |> ignore_string
47+
4548let vgs_offline =
4649 " vgs <device>: check that we can read metadata without xenvmd." > ::
4750 (fun () ->
48- with_temp_file (fun filename ->
49- xenvm [ " vgcreate" ; vg; filename ] |> ignore_string;
50- mkdir_rec " /tmp/xenvm.d" 0o0755 ;
51- xenvm [ " set-vg-info" ; " --pvpath" ; filename; " -S" ; " /tmp/xenvmd" ; vg; " --local-allocator-path" ; (get_local_allocator_sockpath 1 ); " --uri" ; " file://local/services/xenvmd/" ^ vg ] |> ignore_string;
51+ with_temp_file (fun pvpath ->
52+ xenvm [ " vgcreate" ; vg; pvpath ] |> ignore_string;
53+ set_vg_info ~pvpath ~vg ~host: 1 ;
5254 xenvm [ " vgs" ; vg ] |> ignore_string
5355 )
5456 )
5557
56- let set_vg_info pvpath vg host =
57- xenvm ~host [ " set-vg-info" ;
58- " --pvpath" ; pvpath;
59- " -S" ; " /tmp/xenvmd" ;
60- vg;
61- " --local-allocator-path" ; get_local_allocator_sockpath host;
62- " --uri" ; " file://local/services/xenvmd/" ^ vg ]
63- |> ignore_string
64-
6558let is_xenvmd_ok vg =
6659 try
6760 ignore(xenvm [ " host-list" ; vg ]);
@@ -82,19 +75,22 @@ let with_xenvmd ?existing_vg ?(cleanup_vg=true) (f : string -> string -> 'a) =
8275 set_vg_info loop vg host;
8376 let config = {
8477 Config.Xenvmd. listenPort = None ;
85- listenPath = Some " /tmp/xenvmd " ;
78+ listenPath = Some xenvmd_socket ;
8679 host_allocation_quantum = 128L ;
8780 host_low_water_mark = 8L ;
8881 vg;
8982 devices = [loop];
9083 rrd_ds_owner = Some (Printf. sprintf " xenvmd-%d-stats" (Unix. getpid () ));
9184 } in
9285 Sexplib.Sexp. to_string_hum (Config.Xenvmd. sexp_of_t config)
93- |> file_of_string " test.xenvmd.conf" ;
94- let _ = Lwt_preemptive. detach (fun () -> xenvmd [ " --config" ; " ./test.xenvmd.conf" ; " --log" ; " xenvmd.log" ]) () in
86+ |> file_of_string xenvmd_conf;
87+ let _ =
88+ Lwt_preemptive. detach (fun () ->
89+ xenvmd [ " --config" ; xenvmd_conf; " --log" ; xenvmd_log]
90+ ) () in
9591 wait_for_xenvmd_to_start vg;
9692 Xenvm_client.Rpc. uri := " file://local/services/xenvmd/" ^ vg;
97- Xenvm_client. unix_domain_socket_path := " /tmp/xenvmd " ;
93+ Xenvm_client. unix_domain_socket_path := xenvmd_socket ;
9894 finally
9995 (fun () -> f vg loop)
10096 (fun () -> xenvm [ " shutdown" ; " /dev/" ^ vg ] |> ignore_string ) in
@@ -111,7 +107,7 @@ let with_xenvmd ?existing_vg ?(cleanup_vg=true) (f : string -> string -> 'a) =
111107let la_has_started host =
112108 let dm_name = " XXXdoesntexistXXX" in
113109 let s = Lwt_unix. socket Lwt_unix. PF_UNIX Lwt_unix. SOCK_STREAM 0 in
114- let sockpath = get_local_allocator_sockpath host in
110+ let sockpath = la_socket host in
115111 Lwt. catch
116112 (fun () ->
117113 Lwt_unix. connect s (Unix. ADDR_UNIX sockpath)
@@ -132,20 +128,22 @@ let la_has_started host =
132128 Lwt. return false )
133129
134130let start_local_allocator host devices =
135- let hostname = get_hostname host in
136- ignore(xenvm [ " host-create" ; vg; hostname]);
137- let config_file = Printf. sprintf " local_allocator.%s.conf" hostname in
131+ let hostname = Printf. sprintf " host%d" host in
132+ ignore(xenvm [ " host-create" ; vg; hostname ]);
138133 let config = {
139- Config.Local_allocator. socket = get_local_allocator_sockpath host;
140- localJournal = Printf. sprintf " %s-localJournal " hostname ;
134+ Config.Local_allocator. socket = la_socket host;
135+ localJournal = la_journal host ;
141136 devices = devices;
142- toLVM = Printf. sprintf " %s-toLVM " hostname ;
143- fromLVM = Printf. sprintf " %s-fromLVM " hostname ;
137+ toLVM = la_toLVM_ring host ;
138+ fromLVM = la_fromLVM_ring host ;
144139 } in
145140 Sexplib.Sexp. to_string_hum (Config.Local_allocator. sexp_of_t config)
146- |> file_of_string config_file ;
141+ |> file_of_string (la_conf host) ;
147142 ignore(xenvm [ " host-connect" ; vg; hostname]);
148- let la_thread = Lwt_preemptive. detach (fun () -> local_allocator ~host [ " --config" ; config_file; " --log" ; Printf. sprintf " la.%d.log" host ]) () in
143+ let la_thread =
144+ Lwt_preemptive. detach (fun () ->
145+ local_allocator ~host [ " --config" ; la_conf host; " --log" ; la_log host ]
146+ ) () in
149147 la_thread
150148
151149let wait_for_local_allocator_to_start host =
@@ -212,9 +210,9 @@ let upgrade =
212210 ~printer: string_of_int 2 (LVs. cardinal (Vg_IO. metadata_of vg).Vg. lvs);
213211
214212 (* Upgrade the volume to journalled *)
215- xenvm [ " upgrade" ; " --pvpath" ; " vg " ; " vg" ] |> ignore_string;
213+ xenvm [ " upgrade" ; " --pvpath" ; filename ; " vg" ] |> ignore_string;
216214 (* Check it's idempotent *)
217- xenvm [ " upgrade" ; " --pvpath" ; " vg " ; " vg" ] |> ignore_string;
215+ xenvm [ " upgrade" ; " --pvpath" ; filename ; " vg" ] |> ignore_string;
218216
219217 (* check the changing of the magic persisted *)
220218 let module Label_IO = Label. Make (Block ) in
@@ -238,9 +236,9 @@ let upgrade =
238236 );
239237
240238 (* Downgrade the volume to lvm2 *)
241- xenvm [ " downgrade" ; " --pvpath" ; " vg " ; " vg" ] |> ignore_string;
239+ xenvm [ " downgrade" ; " --pvpath" ; filename ; " vg" ] |> ignore_string;
242240 (* Check it's idempotent *)
243- xenvm [ " downgrade" ; " --pvpath" ; " vg " ; " vg" ] |> ignore_string;
241+ xenvm [ " downgrade" ; " --pvpath" ; filename ; " vg" ] |> ignore_string;
244242
245243 (* check the changing of the magic persisted *)
246244 Label_IO. read block >>:= fun label ->
@@ -654,9 +652,9 @@ let la_extend_multi_fist device =
654652 let la_dead = la_thread_1 >> = fun _ -> la_thread_2 >> = fun _ -> Lwt. return () in
655653 Lwt. choose [la_dead; (Lwt_unix. sleep 30.0 >> = fun () -> Lwt. fail Timeout )]
656654 >> = fun () ->
657- write_to_file la_thread_1 " local_allocator.1.log "
655+ write_to_file la_thread_1 (la_log 1 )
658656 >> = fun () ->
659- write_to_file la_thread_2 " local_allocator.2.log "
657+ write_to_file la_thread_2 (la_log 2 )
660658 )))
661659
662660let local_allocator_suite device = " Commands which require the local allocator" > ::: [
@@ -667,8 +665,9 @@ let local_allocator_suite device = "Commands which require the local allocator"
667665]
668666
669667let _ =
668+ Common. cleanup () ;
670669 Random. self_init () ;
671- List. iter (fun host -> let configdir = Common. get_configdir host in mkdir_rec configdir 0o0755 ) [1 ;2 ; 3 ; 4 ] in
670+ List. iter (fun host -> mkdir_rec (xenvm_confdir host) 0o755 ) [1 ; 2 ; 3 ; 4 ]
672671 let check_results_with_exit_code results =
673672 if List. exists (function RFailure _ | RError _ -> true | _ -> false ) results
674673 then exit 1 in
0 commit comments