Skip to content
Browse files

CA-70994: Throw a proper API error when bootloader fails.

Signed-off-by: John Else <john.else@citrix.com>
  • Loading branch information...
1 parent 9125252 commit 481845c2ad92fe04fb6af908d4659d47547dd16a @johnelse committed
View
4 ocaml/xapi/xapi_xenops.ml
@@ -1364,7 +1364,9 @@ let transform_xenops_exn ~__context f =
| Media_present -> internal "there is already media in this drive"
| Media_not_present -> internal "there is no media in this drive"
| No_bootable_device -> internal "there is no bootable device"
- | Bootloader_error(code, params) -> reraise code params
+ | Bootloader_error (uuid, msg) ->
+ let vm = Db.VM.get_by_uuid ~__context ~uuid in
+ reraise Api_errors.bootloader_failed [Ref.string_of vm; msg]
| Cannot_free_this_much_memory(needed, free) ->
reraise Api_errors.host_not_enough_free_memory [ Int64.to_string needed; Int64.to_string free ]
| Vms_failed_to_cooperate vms ->
View
14 ocaml/xenops/bootloader.ml
@@ -41,7 +41,7 @@ exception Bad_error of string
exception Unknown_bootloader of string
-exception Error_from_bootloader of (string * (string list))
+exception Error_from_bootloader of string
type t = {
kernel_path: string;
@@ -81,12 +81,12 @@ let parse_output x =
debug "Failed to parse: %s" sexpr;
raise (Bad_sexpr sexpr)
-let parse_exception x =
- match Stringext.String.split '\n' x with
- | code :: params -> raise (Error_from_bootloader (code, params))
- | _ ->
- debug "Failed to parse: %s" x;
- raise (Bad_error x)
+let parse_exception x =
+ debug "Bootloader failed: %s" x;
+ let lines = String.split '\n' x in
+ (* Since the error is a python stack trace, the last-but-one line tends to be the most useful. *)
+ let err = try List.nth (List.rev lines) 1 with _ -> raise (Bad_error x) in
+ raise (Error_from_bootloader err)
(** Extract the default kernel using the -q option *)
let extract (task: Xenops_task.t) ~bootloader ~disk ?(legacy_args="") ?(extra_args="") ?(pv_bootloader_args="") ~vm:vm_uuid () =
View
2 ocaml/xenops/bootloader.mli
@@ -19,7 +19,7 @@ exception Bad_sexpr of string
exception Bad_error of string
(** Raised when the bootloader returns an error *)
-exception Error_from_bootloader of (string * (string list))
+exception Error_from_bootloader of string
(** Raised when an unknown bootloader is used *)
exception Unknown_bootloader of string
View
2 ocaml/xenops/xenops_interface.ml
@@ -38,7 +38,7 @@ exception Media_not_ejectable
exception Media_present
exception Media_not_present
exception No_bootable_device
-exception Bootloader_error of (string * (string list))
+exception Bootloader_error of (string * string)
exception Cannot_free_this_much_memory of (int64 * int64)
exception Vms_failed_to_cooperate of string list
exception Ballooning_error of (string * string)
View
6 ocaml/xenops/xenops_server_xen.ml
@@ -1023,10 +1023,10 @@ module VM = struct
let m = Printf.sprintf "VM = %s; domid = %d; Bootloader.Unknown_bootloader %s" vm.Vm.id domid x in
debug "%s" m;
raise (Internal_error m)
- | Bootloader.Error_from_bootloader (a, b) ->
- let m = Printf.sprintf "VM = %s; domid = %d; Bootloader.Error_from_bootloader (%s, [ %s ])" vm.Vm.id domid a (String.concat "; " b) in
+ | Bootloader.Error_from_bootloader x ->
+ let m = Printf.sprintf "VM = %s; domid = %d; Bootloader.Error_from_bootloader %s" vm.Vm.id domid x in
debug "%s" m;
- raise (Bootloader_error (a, b))
+ raise (Bootloader_error (vm.Vm.id, x))
| e ->
let m = Printf.sprintf "VM = %s; domid = %d; Bootloader error: %s" vm.Vm.id domid (Printexc.to_string e) in
debug "%s" m;

0 comments on commit 481845c

Please sign in to comment.
Something went wrong with that request. Please try again.