Skip to content

Commit 5ed4f90

Browse files
committed
CA-160971: Improve patch_apply failure error reporting
Raise a proper Api_error if patch_apply fails when patch backup files are created And user tries to re-apply the patch Signed-off-by: Sharad Yadav <[email protected]>
1 parent 3634dcb commit 5ed4f90

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

ocaml/idl/api_errors.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ let patch_precheck_failed_wrong_server_build = "PATCH_PRECHECK_FAILED_WRONG_SERV
335335
let patch_precheck_failed_vm_running = "PATCH_PRECHECK_FAILED_VM_RUNNING"
336336
let patch_precheck_tools_iso_mounted = "PATCH_PRECHECK_FAILED_ISO_MOUNTED"
337337
let patch_apply_failed = "PATCH_APPLY_FAILED"
338+
let patch_apply_failed_backup_files_exists = "PATCH_APPLY_FAILED_BACKUP_FILES_EXISTS"
338339
let cannot_find_oem_backup_partition = "CANNOT_FIND_OEM_BACKUP_PARTITION"
339340
let only_allowed_on_oem_edition = "ONLY_ALLOWED_ON_OEM_EDITION"
340341
let not_allowed_on_oem_edition = "NOT_ALLOWED_ON_OEM_EDITION"

ocaml/idl/datamodel.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,8 @@ let _ =
10911091
~doc:"This patch has already been applied" ();
10921092
error Api_errors.patch_apply_failed [ "output" ]
10931093
~doc:"The patch apply failed. Please see attached output." ();
1094+
error Api_errors.patch_apply_failed_backup_files_exists [ "output" ]
1095+
~doc:"The patch apply failed" ();
10941096
error Api_errors.patch_precheck_failed_unknown_error [ "patch"; "info" ]
10951097
~doc:"The patch precheck stage failed with an unknown error. See attached info for more details." ();
10961098
error Api_errors.patch_precheck_failed_prerequisite_missing [ "patch"; "prerequisite_patch_uuid_list" ]

ocaml/xapi/xapi_pool_patch.ml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,18 @@ let apply ~__context ~self ~host =
645645
output;
646646

647647
| Failure(log, exn) ->
648-
debug "error from patch application: %s" log;
649-
raise (Api_errors.Server_error(Api_errors.patch_apply_failed, [log]))
648+
debug "error from patch application: %s" log;
649+
let error_string = "Backup files already present - aborting." in
650+
if List.length (Xstringext.String.find_all error_string log) = 0 then
651+
raise (Api_errors.Server_error(Api_errors.patch_apply_failed, [log]))
652+
else begin
653+
let xml = Xml.parse_string log in
654+
match xml with
655+
| Element ("error", [("errorcode", "PATCH_PRECHECK_FAILED_UNKNOWN_ERROR")], [Element("info", _, [PCData info])]) ->
656+
raise (Api_errors.Server_error(Api_errors.patch_apply_failed_backup_files_exists, [info]))
657+
| _ ->
658+
raise (Bad_precheck_xml "Could not find element info")
659+
end
650660
end
651661

652662
let pool_apply ~__context ~self =

0 commit comments

Comments
 (0)