Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-CDN updates bug fix #5904

Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions ocaml/idl/datamodel_errors.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1927,6 +1927,8 @@ let _ =
() ;
error Api_errors.reposync_failed []
~doc:"Syncing with remote YUM repository failed." () ;
error Api_errors.bundle_sync_failed []
~doc:"Syncing with bundle repository failed." () ;
error Api_errors.invalid_repomd_xml [] ~doc:"The repomd.xml is invalid." () ;
error Api_errors.invalid_updateinfo_xml []
~doc:"The updateinfo.xml is invalid." () ;
Expand Down
2 changes: 2 additions & 0 deletions ocaml/xapi-consts/api_errors.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,8 @@ let sync_bundle_in_progress = add_error "SYNC_BUNDLE_IN_PROGRESS"

let reposync_failed = add_error "REPOSYNC_FAILED"

let bundle_sync_failed = add_error "BUNDLE_SYNC_FAILED"

let createrepo_failed = add_error "CREATEREPO_FAILED"

let invalid_updateinfo_xml = add_error "INVALID_UPDATEINFO_XML"
Expand Down
4 changes: 2 additions & 2 deletions ocaml/xapi/xapi_globs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -957,8 +957,8 @@ let ignore_vtpm_unimplemented = ref false

let evacuation_batch_size = ref 10

(* Max size limit of bundle file: 500 MB*)
let bundle_max_size_limit = ref (Int64.of_int (500 * 1024 * 1024))
(* Max size limit of bundle file: 1 GB*)
let bundle_max_size_limit = ref (Int64.of_int (1024 * 1024 * 1024))

type xapi_globs_spec =
| Float of float ref
Expand Down
83 changes: 51 additions & 32 deletions ocaml/xapi/xapi_pool.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3774,37 +3774,56 @@ let put_bundle_handler (req : Request.t) s _ =
~doc:"pool.sync_bundle" ~op:`sync_bundle
@@ fun () ->
Http_svr.headers s (Http.http_200_ok ()) ;
let repo =
Repository_helpers.get_single_enabled_update_repository ~__context
in
match Db.Repository.get_origin ~__context ~self:repo with
| `bundle -> (
let result =
Tar_ext.unpack_tar_file
~dir:!Xapi_globs.bundle_repository_dir
~ifd:s
~max_size_limit:!Xapi_globs.bundle_max_size_limit
let repo_opt =
try
let repo =
Repository_helpers.get_single_enabled_update_repository ~__context
in
match result with
| Ok () ->
TaskHelper.set_progress ~__context 0.8 ;
finally
(fun () ->
sync_repos ~__context ~self:pool ~repos:[repo] ~force:true
~token:"" ~token_id:""
|> ignore
)
(fun () -> Unixext.rm_rec !Xapi_globs.bundle_repository_dir)
| Error e ->
error "%s: Failed to unpack bundle with error %s" __FUNCTION__
(Tar_ext.unpack_error_to_string e) ;
TaskHelper.failed ~__context
Api_errors.(
Server_error
(bundle_unpack_failed, [Tar_ext.unpack_error_to_string e])
) ;
Http_svr.headers s (Http.http_400_badrequest ())
)
| `remote ->
raise Api_errors.(Server_error (bundle_repo_not_enabled, []))
Some repo
with e ->
TaskHelper.failed ~__context e ;
Http_svr.headers s (Http.http_400_badrequest ()) ;
None
in
match repo_opt with
| Some repo -> (
match Db.Repository.get_origin ~__context ~self:repo with
| `bundle -> (
let result =
Tar_ext.unpack_tar_file
~dir:!Xapi_globs.bundle_repository_dir
~ifd:s
~max_size_limit:!Xapi_globs.bundle_max_size_limit
in
match result with
| Ok () ->
TaskHelper.set_progress ~__context 0.8 ;
finally
(fun () ->
try
sync_repos ~__context ~self:pool ~repos:[repo] ~force:true
~token:"" ~token_id:""
|> ignore
with _ ->
raise Api_errors.(Server_error (bundle_sync_failed, []))
)
(fun () -> Unixext.rm_rec !Xapi_globs.bundle_repository_dir)
| Error e ->
error "%s: Failed to unpack bundle with error %s" __FUNCTION__
(Tar_ext.unpack_error_to_string e) ;
TaskHelper.failed ~__context
Api_errors.(
Server_error
(bundle_unpack_failed, [Tar_ext.unpack_error_to_string e])
) ;
Http_svr.headers s (Http.http_400_badrequest ())
)
| `remote ->
error "%s: Bundle repo is not enabled" __FUNCTION__ ;
TaskHelper.failed ~__context
Api_errors.(Server_error (bundle_repo_not_enabled, [])) ;
Http_svr.headers s (Http.http_400_badrequest ())
)
| None ->
()
)
Loading