Skip to content

Commit 17e0edd

Browse files
committed
xapi_ha: add more information to not found errors
When joining a liveset, Not_found errors could be raised, but the users did not have information on what was that it could not be found. Add which IP address and which UUID could not be found. Signed-off-by: Pau Ruiz Safont <pau.safont@vates.tech>
1 parent 3122667 commit 17e0edd

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

ocaml/xapi/xapi_ha.ml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ let ha_redo_log =
4242
(*********************************************************************************************)
4343
(* Interface with the low-level HA subsystem *)
4444

45+
exception Address_not_found of string
46+
47+
exception Uuid_not_found of string
48+
4549
(** Returns the current live set info *)
4650
let query_liveset () =
4751
let txt = call_script ~log_output:On_failure ha_query_liveset [] in
@@ -104,19 +108,21 @@ let get_uuid_to_ip_mapping () =
104108
named by UUID. *)
105109
let address_of_host_uuid uuid =
106110
let table = get_uuid_to_ip_mapping () in
107-
List.assoc_opt uuid table |> Option.to_result ~none:Not_found
111+
let uuid_not_found = Uuid_not_found uuid in
112+
List.assoc_opt uuid table |> Option.to_result ~none:uuid_not_found
108113

109114
(** Without using the Pool's database, returns the UUID of a particular host named by
110115
heartbeat IP address. This is only necesary because the liveset info doesn't include
111116
the host IP address *)
112117
let uuid_of_host_address address =
113118
let table = List.map (fun (k, v) -> (v, k)) (get_uuid_to_ip_mapping ()) in
114119
let invalid_uuid = Invalid_argument "Invalid UUID" in
120+
let address_not_found = Address_not_found address in
115121
let to_uuid str =
116122
Uuidx.of_string str |> Option.to_result ~none:invalid_uuid
117123
in
118124
List.assoc_opt address table
119-
|> Option.to_result ~none:Not_found
125+
|> Option.to_result ~none:address_not_found
120126
|> Fun.flip Result.bind to_uuid
121127

122128
let ok_or_raise map_error = function Ok v -> v | Error exn -> map_error exn
@@ -479,9 +485,12 @@ module Monitor = struct
479485
|> ok_or_raise (master_uuid_exn __FUNCTION__)
480486
in
481487
let open Xha_interface.LiveSetInformation in
488+
let uuid_not_found =
489+
Uuid_not_found (Uuidx.to_string master_uuid)
490+
in
482491
let master_info =
483492
Hashtbl.find_opt liveset.hosts master_uuid
484-
|> Option.to_result ~none:Not_found
493+
|> Option.to_result ~none:uuid_not_found
485494
|> ok_or_raise (master_not_in_liveset_exn __FUNCTION__)
486495
in
487496
if master_info.Host.liveness && master_info.Host.master then

0 commit comments

Comments
 (0)