Skip to content

Commit

Permalink
Merge pull request #5189 from xcp-ng/quicktest-filter-leak-vdi
Browse files Browse the repository at this point in the history
Only count VDIs on tested SRs
  • Loading branch information
robhoes authored Oct 27, 2023
2 parents 89d5e68 + 0e0ef81 commit d8cad73
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions ocaml/quicktest/qt_filter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,49 @@ let count_vdis rpc session_id sr =
in
List.length managed_vdis

let get_test_sr_uuid () =
match (!A.use_default_sr, !A.sr) with
| true, _ ->
let pool = Qt.get_pool !A.rpc !session_id in
let sr =
Client.Client.Pool.get_default_SR ~rpc:!A.rpc ~session_id:!session_id
~self:pool
in
Client.Client.SR.get_uuid ~rpc:!A.rpc ~session_id:!session_id ~self:sr
| _, uuid when uuid <> "" ->
uuid
| _, _ ->
""

(** Called before the quicktests start to save the original state.
This data will be used by [finish] to check for any resource leaks. *)
let init () =
session_id := Qt.init_session !A.rpc !A.username !A.password ;
let test_sr_uuid = get_test_sr_uuid () in
Client.Client.SR.get_all_records ~rpc:!A.rpc ~session_id:!session_id
|> List.iter (fun (ref, sr) ->
if List.mem `scan sr.API.sR_allowed_operations then
let before = count_vdis !A.rpc !session_id ref in
Hashtbl.add vdi_count sr.API.sR_uuid before
if test_sr_uuid = "" || sr.API.sR_uuid = test_sr_uuid then
if List.mem `scan sr.API.sR_allowed_operations then
let before = count_vdis !A.rpc !session_id ref in
Hashtbl.add vdi_count sr.API.sR_uuid before
)

(** Called at the end of the quicktests to check that no resources leaked
during the test run *)
let finish () =
let test_sr_uuid = get_test_sr_uuid () in
Client.Client.SR.get_all_records ~rpc:!A.rpc ~session_id:!session_id
|> List.iter (fun (ref, sr) ->
match Hashtbl.find_opt vdi_count sr.API.sR_uuid with
| Some before ->
if List.mem `scan sr.API.sR_allowed_operations then
let after = count_vdis !A.rpc !session_id ref in
if after <> before then
failwith
(Printf.sprintf "VDIs leaked on SR %s: before=%d, after=%d"
sr.API.sR_uuid before after
)
if test_sr_uuid = "" || sr.API.sR_uuid = test_sr_uuid then
if List.mem `scan sr.API.sR_allowed_operations then
let after = count_vdis !A.rpc !session_id ref in
if after <> before then
failwith
(Printf.sprintf "VDIs leaked on SR %s: before=%d, after=%d"
sr.API.sR_uuid before after
)
| None ->
()
)
Expand Down

0 comments on commit d8cad73

Please sign in to comment.