Skip to content

Commit ace5fae

Browse files
committed
Merge pull request #139 from simonjbeaumont/test-name
test: Fix assert_lv_exists to check for the name it's given
2 parents 6e61256 + 870a688 commit ace5fae

File tree

1 file changed

+53
-42
lines changed

1 file changed

+53
-42
lines changed

test/test.ml

Lines changed: 53 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@ let lvchange_offline =
5858
xenvmd [ "--config"; "./test.xenvmd.conf"; "--daemon" ] |> ignore_string;
5959
Xenvm_client.Rpc.uri := "file://local/services/xenvmd/" ^ vg;
6060
Xenvm_client.unix_domain_socket_path := "/tmp/xenvmd";
61+
let name = Uuid.(to_string (create ())) in
6162
finally
6263
(fun () ->
63-
xenvm [ "lvcreate"; "-n"; "test"; "-L"; "3"; vg ] |> ignore_string;
64+
xenvm [ "lvcreate"; "-n"; name; "-L"; "3"; vg ] |> ignore_string;
6465
) (fun () ->
6566
xenvm [ "shutdown"; "/dev/"^vg ] |> ignore_string
6667
);
67-
xenvm [ "lvchange"; "-ay"; vg ^ "/test"; "--offline" ] |> ignore_string;
68+
xenvm [ "lvchange"; "-ay"; vg ^ "/" ^ name; "--offline" ] |> ignore_string;
6869
)
6970
)
7071

@@ -98,7 +99,7 @@ let assert_lv_exists ?expected_size_in_extents name =
9899
let t =
99100
Lwt.catch
100101
(fun () ->
101-
Client.get_lv "test"
102+
Client.get_lv name
102103
>>= fun (_, lv) ->
103104
match expected_size_in_extents with
104105
| None -> return ()
@@ -119,24 +120,27 @@ let free_extents () =
119120
let lvcreate_L =
120121
"lvcreate -n <name> -L <mib> <vg>: check that we can create an LV with a size in MiB" >::
121122
fun () ->
122-
xenvm [ "lvcreate"; "-n"; "test"; "-L"; "16"; vg ] |> ignore_string;
123-
assert_lv_exists ~expected_size_in_extents:4L "test";
124-
xenvm [ "lvremove"; vg ^ "/test" ] |> ignore_string
123+
let name = Uuid.(to_string (create ())) in
124+
xenvm [ "lvcreate"; "-n"; name; "-L"; "16"; vg ] |> ignore_string;
125+
assert_lv_exists ~expected_size_in_extents:4L name;
126+
xenvm [ "lvremove"; vg ^ "/" ^ name ] |> ignore_string
125127

126128
let lvcreate_l =
127129
"lvcreate -n <name> -l <extents> <vg>: check that we can create an LV with a size in extents" >::
128130
fun () ->
129-
xenvm [ "lvcreate"; "-n"; "test"; "-l"; "2"; vg ] |> ignore_string;
130-
assert_lv_exists ~expected_size_in_extents:2L "test";
131-
xenvm [ "lvremove"; vg ^ "/test" ] |> ignore_string
131+
let name = Uuid.(to_string (create ())) in
132+
xenvm [ "lvcreate"; "-n"; name; "-l"; "2"; vg ] |> ignore_string;
133+
assert_lv_exists ~expected_size_in_extents:2L name;
134+
xenvm [ "lvremove"; vg ^ "/" ^ name ] |> ignore_string
132135

133136
let lvcreate_percent =
134137
"lvcreate -n <name> -l 100%F <vg>: check that we can fill all free space in the VG" >::
135138
fun () ->
136-
xenvm [ "lvcreate"; "-n"; "test"; "-l"; "100%F"; vg ] |> ignore_string;
139+
let name = Uuid.(to_string (create ())) in
140+
xenvm [ "lvcreate"; "-n"; name; "-l"; "100%F"; vg ] |> ignore_string;
137141
let free = free_extents () in
138142
assert_equal ~printer:Int64.to_string 0L free;
139-
xenvm [ "lvremove"; vg ^ "/test" ] |> ignore_string
143+
xenvm [ "lvremove"; vg ^ "/" ^ name ] |> ignore_string
140144

141145
let kib = 1024L
142146
let mib = Int64.mul kib 1024L
@@ -161,7 +165,8 @@ let lvcreate_toobig =
161165
| e -> failwith (Printf.sprintf "Did not get Insufficient_free_space: %s" (Printexc.to_string e)))
162166
);
163167
try
164-
xenvm [ "lvcreate"; "-n"; "test"; "-l"; Int64.to_string xib; vg ] |> ignore_string;
168+
let name = Uuid.(to_string (create ())) in
169+
xenvm [ "lvcreate"; "-n"; name; "-l"; Int64.to_string xib; vg ] |> ignore_string;
165170
failwith "Did not get Insufficient_free_space"
166171
with
167172
| Bad_exit(5, _, _, stdout, stderr) ->
@@ -174,16 +179,17 @@ let lvcreate_toobig =
174179
let lvextend_toobig =
175180
"lvextend packer-virtualbox-iso-vg/swap_1 -L 1T: check that the failure is nice" >::
176181
fun () ->
177-
xenvm [ "lvcreate"; "-n"; "test"; "-l"; "100%F"; vg ] |> ignore_string;
182+
let name = Uuid.(to_string (create ())) in
183+
xenvm [ "lvcreate"; "-n"; name; "-l"; "100%F"; vg ] |> ignore_string;
178184
begin
179185
Lwt_main.run (
180186
Lwt.catch
181-
(fun () -> Client.resize "test" xib)
187+
(fun () -> Client.resize name xib)
182188
(function Xenvm_interface.Insufficient_free_space(needed, available) -> return ()
183189
| e -> failwith (Printf.sprintf "Did not get Insufficient_free_space: %s" (Printexc.to_string e)))
184190
);
185191
try
186-
xenvm [ "lvextend"; vg ^ "/test"; "-L"; Int64.to_string xib ] |> ignore_string;
192+
xenvm [ "lvextend"; vg ^ "/" ^ name; "-L"; Int64.to_string xib ] |> ignore_string;
187193
failwith "Did not get Insufficient_free_space"
188194
with
189195
| Bad_exit(5, _, _, stdout, stderr) ->
@@ -193,7 +199,7 @@ let lvextend_toobig =
193199
| e ->
194200
failwith (Printf.sprintf "Expected exit code 5: %s" (Printexc.to_string e))
195201
end;
196-
xenvm [ "lvremove"; vg ^ "/test" ] |> ignore_string
202+
xenvm [ "lvremove"; vg ^ "/" ^ name ] |> ignore_string
197203

198204
let file_exists filename =
199205
try
@@ -211,48 +217,52 @@ let mapper_path_of name = "/dev/mapper/" ^ vg ^ "-" ^ name
211217
let lvchange_addtag =
212218
"lvchange vg/lv [--addtag|--removetag]: check that we can add tags" >::
213219
fun () ->
214-
xenvm [ "lvcreate"; "-n"; "test"; "-L"; "3"; vg ] |> ignore_string;
215-
assert_lv_exists ~expected_size_in_extents:1L "test";
216-
xenvm [ "lvchange"; vg ^ "/test"; "--addtag"; "hidden" ] |> ignore_string;
217-
let vg_metadata, lv_metadata = Lwt_main.run (Client.get_lv "test") in
220+
let name = Uuid.(to_string (create ())) in
221+
xenvm [ "lvcreate"; "-n"; name; "-L"; "3"; vg ] |> ignore_string;
222+
assert_lv_exists ~expected_size_in_extents:1L name;
223+
xenvm [ "lvchange"; vg ^ "/" ^ name; "--addtag"; "hidden" ] |> ignore_string;
224+
let vg_metadata, lv_metadata = Lwt_main.run (Client.get_lv name) in
218225
let tags = List.map Lvm.Name.Tag.to_string lv_metadata.Lvm.Lv.tags in
219226
if not(List.mem "hidden" tags)
220227
then failwith "Failed to add 'hidden' tag";
221-
xenvm [ "lvremove"; vg ^ "/test" ] |> ignore_string
228+
xenvm [ "lvremove"; vg ^ "/" ^ name ] |> ignore_string
222229

223230
let lvchange_deltag =
224231
"lvchange vg/lv [--addtag|--deltag]: check that we can add and remove tags" >::
225232
fun () ->
226-
xenvm [ "lvcreate"; "-n"; "test"; "-L"; "3"; vg ] |> ignore_string;
227-
assert_lv_exists ~expected_size_in_extents:1L "test";
228-
xenvm [ "lvchange"; vg ^ "/test"; "--addtag"; "hidden" ] |> ignore_string;
229-
xenvm [ "lvchange"; vg ^ "/test"; "--deltag"; "hidden" ] |> ignore_string;
230-
let vg_metadata, lv_metadata = Lwt_main.run (Client.get_lv "test") in
233+
let name = Uuid.(to_string (create ())) in
234+
xenvm [ "lvcreate"; "-n"; name; "-L"; "3"; vg ] |> ignore_string;
235+
assert_lv_exists ~expected_size_in_extents:1L name;
236+
xenvm [ "lvchange"; vg ^ "/" ^ name; "--addtag"; "hidden" ] |> ignore_string;
237+
xenvm [ "lvchange"; vg ^ "/" ^ name; "--deltag"; "hidden" ] |> ignore_string;
238+
let vg_metadata, lv_metadata = Lwt_main.run (Client.get_lv name) in
231239
let tags = List.map Lvm.Name.Tag.to_string lv_metadata.Lvm.Lv.tags in
232240
if List.mem "hidden" tags
233241
then failwith "Failed to remove 'hidden' tag";
234-
xenvm [ "lvremove"; vg ^ "/test" ] |> ignore_string
242+
xenvm [ "lvremove"; vg ^ "/" ^ name ] |> ignore_string
235243

236244
let lvchange_n =
237245
"lvchange -an <device>: check that we can deactivate a volume" >::
238246
fun () ->
239-
xenvm [ "lvcreate"; "-n"; "test"; "-L"; "3"; vg ] |> ignore_string;
240-
assert_lv_exists ~expected_size_in_extents:1L "test";
241-
let vg_metadata, lv_metadata = Lwt_main.run (Client.get_lv "test") in
242-
let name = Mapper.name_of vg_metadata lv_metadata in
243-
xenvm [ "lvchange"; "-ay"; "/dev/" ^ vg ^ "/test" ] |> ignore_string;
247+
let name = Uuid.(to_string (create ())) in
248+
xenvm [ "lvcreate"; "-n"; name; "-L"; "3"; vg ] |> ignore_string;
249+
assert_lv_exists ~expected_size_in_extents:1L name;
250+
let vg_metadata, lv_metadata = Lwt_main.run (Client.get_lv name) in
251+
let map_name = Mapper.name_of vg_metadata lv_metadata in
252+
xenvm [ "lvchange"; "-ay"; "/dev/" ^ vg ^ "/" ^ name ] |> ignore_string;
244253
if not !Common.use_mock then begin (* FIXME: #99 *)
245-
assert_equal ~printer:string_of_bool true (file_exists (dev_path_of "test"));
246-
assert_equal ~printer:string_of_bool true (file_exists (mapper_path_of "test"));
247-
assert_equal ~printer:string_of_bool true (dm_exists name);
254+
assert_equal ~printer:string_of_bool true (file_exists (dev_path_of name));
255+
assert_equal ~printer:string_of_bool true (file_exists (mapper_path_of name));
256+
assert_equal ~printer:string_of_bool true (dm_exists map_name);
248257
end;
249-
xenvm [ "lvchange"; "-an"; "/dev/" ^ vg ^ "/test" ] |> ignore_string;
258+
xenvm [ "lvchange"; "-an"; "/dev/" ^ vg ^ "/" ^ name ] |> ignore_string;
250259
if not !Common.use_mock then begin (* FIXME: #99 *)
251-
assert_equal ~printer:string_of_bool false (file_exists (dev_path_of"test"));
252-
assert_equal ~printer:string_of_bool false (file_exists (mapper_path_of"test"));
253-
assert_equal ~printer:string_of_bool false (dm_exists name);
260+
assert_equal ~printer:string_of_bool false (file_exists (dev_path_of name));
261+
assert_equal ~printer:string_of_bool false (file_exists (mapper_path_of name));
262+
assert_equal ~printer:string_of_bool false (dm_exists map_name);
263+
254264
end;
255-
xenvm [ "lvremove"; vg ^ "/test" ] |> ignore_string
265+
xenvm [ "lvremove"; vg ^ "/" ^ name ] |> ignore_string
256266

257267
let parse_int x =
258268
int_of_string (String.trim x)
@@ -265,12 +275,13 @@ let vgs_online =
265275
let expected = Lvm.Vg.LVs.cardinal metadata.Lvm.Vg.lvs in
266276
assert_equal ~printer:string_of_int expected count;
267277
(* The new LV will be cached: *)
268-
xenvm [ "lvcreate"; "-n"; "test"; "-L"; "3"; vg ] |> ignore_string;
278+
let name = Uuid.(to_string (create ())) in
279+
xenvm [ "lvcreate"; "-n"; name; "-L"; "3"; vg ] |> ignore_string;
269280
(* This should use the network, not the on-disk metadata: *)
270281
let count = xenvm [ "vgs"; "/dev/" ^ vg; "--noheadings"; "-o"; "lv_count" ] |> parse_int in
271282
(* Did we see the new volume? *)
272283
assert_equal ~printer:string_of_int (expected+1) count;
273-
xenvm [ "lvremove"; vg ^ "/test" ] |> ignore_string
284+
xenvm [ "lvremove"; vg ^ "/" ^ name ] |> ignore_string
274285
)
275286

276287
let xenvmd_suite = "Commands which require xenvmd" >::: [

0 commit comments

Comments
 (0)