Skip to content

Commit 890362f

Browse files
authored
quicktest: speed up running quicktests (#6815)
I intended to write some new VM tests, and the existing VM lifecycle tests looked like a good starting point. But it turns out that we stopped running this test completely when we dropped the `CoreOS` template. Use a memtest ISO instead of the CoreOS template. Also optimize various startup and shutdown code in quicktest, because even a no-op test that did nothing took 14s to run. Draft PR, because it needs more testing, and I'm not entirely happy with how the SR filtering works, e.g. this test still won't run if `-default-sr` is passed (and passing `-default-sr` is very useful during development because it further cuts down startup time by 5s). I should then be able to reuse this code in the new tests that I'm writing.
2 parents ac1d2d2 + b132632 commit 890362f

2 files changed

Lines changed: 35 additions & 20 deletions

File tree

ocaml/quicktest/qt.ml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,20 @@ module VM = struct
119119
let other = "Other install media"
120120

121121
let find rpc session_id startswith =
122-
let vms = Client.Client.VM.get_all ~rpc ~session_id in
122+
let vms = Client.Client.VM.get_all_records ~rpc ~session_id in
123123
match
124124
List.filter
125-
(fun self ->
126-
String.starts_with ~prefix:startswith
127-
(Client.Client.VM.get_name_label ~rpc ~session_id ~self)
128-
&& Client.Client.VM.get_is_a_template ~rpc ~session_id ~self
125+
(fun (_, self) ->
126+
String.starts_with ~prefix:startswith self.API.vM_name_label
127+
&& self.API.vM_is_a_template
129128
)
130129
vms
131130
with
132131
| [] ->
133132
None
134-
| x :: _ ->
135-
Printf.printf "Choosing template with name: %s\n"
136-
(Client.Client.VM.get_name_label ~rpc ~session_id ~self:x) ;
137-
Some x
133+
| (r, vm) :: _ ->
134+
Printf.printf "Choosing template with name: %s\n" vm.API.vM_name_label ;
135+
Some r
138136
end
139137

140138
let install rpc session_id ~template ~name ?sr () =

ocaml/quicktest/qt_filter.ml

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ let vdi_count = Hashtbl.create 4
1717
let count_vdis rpc session_id sr =
1818
Client.Client.SR.scan ~rpc ~session_id ~sr ;
1919
let managed_vdis =
20-
Client.Client.SR.get_VDIs ~rpc ~session_id ~self:sr
20+
let expr =
21+
Printf.sprintf {|field "SR"="%s" and field "managed" = "true"|}
22+
(Ref.string_of sr)
23+
in
24+
Client.Client.VDI.get_all_records_where ~rpc ~session_id ~expr
2125
(* NB vhd backends may delete records beneath us *)
22-
|> Valid_ref_list.filter (fun vdi ->
23-
Client.Client.VDI.get_managed ~rpc ~session_id ~self:vdi
24-
)
2526
in
2627
List.length managed_vdis
2728

@@ -47,7 +48,14 @@ let init () =
4748
Client.Client.SR.get_all_records ~rpc:!A.rpc ~session_id:!session_id
4849
|> List.iter (fun (ref, sr) ->
4950
if test_sr_uuid = "" || sr.API.sR_uuid = test_sr_uuid then
50-
if List.mem `scan sr.API.sR_allowed_operations then
51+
if
52+
List.(
53+
mem `scan sr.API.sR_allowed_operations
54+
&& (mem `vdi_create sr.API.sR_allowed_operations
55+
|| mem `vdi_destroy sr.API.sR_allowed_operations
56+
)
57+
)
58+
then
5159
let before = count_vdis !A.rpc !session_id ref in
5260
Hashtbl.add vdi_count sr.API.sR_uuid before
5361
)
@@ -61,7 +69,14 @@ let finish () =
6169
match Hashtbl.find_opt vdi_count sr.API.sR_uuid with
6270
| Some before ->
6371
if test_sr_uuid = "" || sr.API.sR_uuid = test_sr_uuid then
64-
if List.mem `scan sr.API.sR_allowed_operations then
72+
if
73+
List.(
74+
mem `scan sr.API.sR_allowed_operations
75+
&& (mem `vdi_create sr.API.sR_allowed_operations
76+
|| mem `vdi_destroy sr.API.sR_allowed_operations
77+
)
78+
)
79+
then
6580
let after = count_vdis !A.rpc !session_id ref in
6681
if after <> before then
6782
failwith
@@ -264,10 +279,11 @@ module SR = struct
264279
List.mem `vdi_create sr_info.Qt.allowed_operations
265280
&& List.mem `vdi_destroy sr_info.Qt.allowed_operations
266281
|| not
267-
(is_empty
282+
(Seq.is_empty
268283
(Client.Client.SR.get_VDIs ~rpc:!A.rpc ~session_id:!session_id
269284
~self:sr_info.Qt.sr
270-
|> List.filter (fun vdi ->
285+
|> List.to_seq
286+
|> Seq.filter (fun vdi ->
271287
not
272288
(Client.Client.VDI.get_missing ~rpc:!A.rpc
273289
~session_id:!session_id ~self:vdi
@@ -346,9 +362,9 @@ module SR = struct
346362
let list_srs srs = with_xapi_query srs
347363

348364
let f srs tcs =
349-
for_each
350-
(fun test_case -> List.map (specialise test_case) (list_srs srs))
351-
tcs
365+
let srs = list_srs srs in
366+
if srs = [] then Printf.eprintf "No SRs found that match condition\n" ;
367+
for_each (fun test_case -> List.map (specialise test_case) srs) tcs
352368
end
353369

354370
let sr = SR.f
@@ -358,6 +374,7 @@ let vm_template template_name =
358374
with_xapi_query @@ fun () ->
359375
match Qt.VM.Template.find !A.rpc !session_id template_name with
360376
| None ->
377+
Printf.eprintf "Template not found: %S\n" template_name ;
361378
[]
362379
| Some vm_template ->
363380
[(name, speed, test vm_template)]

0 commit comments

Comments
 (0)