Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions ocaml/quicktest/qt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,29 @@ module VM = struct
cmd @ Option.fold ~none:[] ~some:(fun x -> ["sr-uuid=" ^ x]) sr_uuid
in
let newvm_uuid = cli_cmd cmd in
Client.Client.VM.get_by_uuid ~rpc ~session_id ~uuid:newvm_uuid
(newvm_uuid, Client.Client.VM.get_by_uuid ~rpc ~session_id ~uuid:newvm_uuid)

let uninstall rpc session_id vm =
let uuid = Client.Client.VM.get_uuid ~rpc ~session_id ~self:vm in
cli_cmd ["vm-uninstall"; "uuid=" ^ uuid; "--force"] |> ignore

let with_new rpc session_id ~template ?sr f =
let vm =
let with_new rpc session_id ~template ?iso ?sr f =
let uuid, vm =
install rpc session_id ~template ~name:"temp_quicktest_vm" ?sr ()
in
iso
|> Option.iter (fun iso ->
let (_ : string) =
cli_cmd
[
"vm-cd-add"
; "uuid=" ^ uuid
; "cd-name=" ^ iso.API.vDI_name_label
; "device=0"
]
in
()
) ;
Xapi_stdext_pervasives.Pervasiveext.finally
(fun () -> f vm)
(fun () -> uninstall rpc session_id vm)
Expand Down
1 change: 1 addition & 0 deletions ocaml/quicktest/qt.mli
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module VM : sig
rpc
-> API.ref_session
-> template:API.ref_VM
-> ?iso:API.vDI_t
-> ?sr:API.ref_SR
-> (API.ref_VM -> 'a)
-> 'a
Expand Down
11 changes: 10 additions & 1 deletion ocaml/quicktest/qt_filter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ module SR = struct
<> "iso"
)

let is_iso =
sr_filter (fun sr_info ->
Client.Client.SR.get_content_type ~rpc:!A.rpc ~session_id:!session_id
~self:sr_info.Qt.sr
= "iso"
)

let is_empty = function [] -> true | _ :: _ -> false

let with_any_vdi =
Expand Down Expand Up @@ -347,6 +354,8 @@ module SR = struct

let f srs tcs =
let srs = list_srs srs in
if srs = [] then
Printf.eprintf "No SRs found that match condition\n" ;
for_each (fun test_case -> List.map (specialise test_case) srs) tcs
end

Expand All @@ -357,7 +366,7 @@ let vm_template template_name =
with_xapi_query @@ fun () ->
match Qt.VM.Template.find !A.rpc !session_id template_name with
| None ->
Printf.eprintf "Template not found: %S\n" template_name;
Printf.eprintf "Template not found: %S\n" template_name ;
[]
Comment on lines 368 to 370
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit, but this hunk is in the wrong change. It should be in the previous commit.

| Some vm_template ->
[(name, speed, test vm_template)]
Expand Down
2 changes: 2 additions & 0 deletions ocaml/quicktest/qt_filter.mli
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ module SR : sig

val not_iso : srs -> srs

val is_iso : srs -> srs

val with_any_vdi : srs -> srs
(** Selects SRs that either have a VDI or we can create & destroy a VDI on them.
This filter should be called from tests using [VDI.with_any] *)
Expand Down
29 changes: 24 additions & 5 deletions ocaml/quicktest/quicktest_vm_lifecycle.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,37 @@ let one rpc session_id vm test =
| Halted ->
wait_for_domid (fun domid' -> domid' = -1L)

let test rpc session_id sr_info vm_template () =
let test rpc session_id sr_info vm_template iso_info () =
let sr = sr_info.Qt.sr in
Qt.VM.with_new rpc session_id ~template:vm_template ~sr (fun vm ->
List.iter (one rpc session_id vm) all_possible_tests
)
let expr =
Printf.sprintf {|field "SR" = "%s"|} (Ref.string_of iso_info.Qt.sr)
in
let prefix = "memtest" in
let isos =
Client.Client.VDI.get_all_records_where ~rpc ~session_id ~expr
|> List.filter (fun (_, iso) ->
String.starts_with ~prefix iso.API.vDI_name_label
)
|> List.sort (fun (_, a) (_, b) ->
-String.compare a.API.vDI_name_label b.API.vDI_name_label
)
in
match isos with
| [] ->
Printf.eprintf "No ISO found with prefix %S\n%!" prefix
| (_, iso) :: _ ->
Printf.eprintf "Choosing ISO %S\n%!" iso.API.vDI_name_label ;
Qt.VM.with_new rpc session_id ~template:vm_template ~iso ~sr (fun vm ->
List.iter (one rpc session_id vm) all_possible_tests
)

let tests () =
let open Qt_filter in
[
[("VM lifecycle tests", `Slow, test)]
|> conn
|> sr SR.(all |> allowed_operations [`vdi_create])
|> vm_template "CoreOS"
|> vm_template Qt.VM.Template.other
|> sr SR.(all |> is_iso)
]
|> List.concat
Loading