From cb4021726257e97e687c6061ce64aa5dc9f0e87d Mon Sep 17 00:00:00 2001 From: Danilo Del Busso Date: Tue, 17 Oct 2023 12:22:24 +0000 Subject: [PATCH] CA-381044: Raise error when pool.set_update_sync_enabled is called with true and empty repos Signed-off-by: Danilo Del Busso --- ocaml/idl/datamodel_errors.ml | 3 +++ ocaml/xapi-consts/api_errors.ml | 2 ++ ocaml/xapi/xapi_pool.ml | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/ocaml/idl/datamodel_errors.ml b/ocaml/idl/datamodel_errors.ml index abd0490ee64..8407711d21f 100644 --- a/ocaml/idl/datamodel_errors.ml +++ b/ocaml/idl/datamodel_errors.ml @@ -1955,6 +1955,9 @@ let _ = error Api_errors.invalid_update_sync_day ["day"] ~doc:"Invalid day of the week chosen for weekly update sync." () ; + error Api_errors.no_repositories_configured [] + ~doc:"No update repositories have been configured." () ; + message (fst Api_messages.ha_pool_overcommitted) ~doc: diff --git a/ocaml/xapi-consts/api_errors.ml b/ocaml/xapi-consts/api_errors.ml index 1da1799230e..70557f54ee9 100644 --- a/ocaml/xapi-consts/api_errors.ml +++ b/ocaml/xapi-consts/api_errors.ml @@ -1283,6 +1283,8 @@ let update_guidance_changed = "UPDATE_GUIDANCE_CHANGED" let invalid_update_sync_day = "INVALID_UPDATE_SYNC_DAY" +let no_repositories_configured = "NO_REPOSITORIES_CONFIGURED" + (* VTPMs *) let vtpm_max_amount_reached = "VTPM_MAX_AMOUNT_REACHED" diff --git a/ocaml/xapi/xapi_pool.ml b/ocaml/xapi/xapi_pool.ml index 1cbaf207e40..240075c9edb 100644 --- a/ocaml/xapi/xapi_pool.ml +++ b/ocaml/xapi/xapi_pool.ml @@ -3667,6 +3667,10 @@ let configure_update_sync ~__context ~self ~update_sync_frequency Pool_periodic_update_sync.set_enabled ~__context ~value:true let set_update_sync_enabled ~__context ~self ~value = + if value && Db.Pool.get_repositories ~__context ~self = [] then ( + error "Cannot enable automatic update syncing if there are no repositories." ; + raise Api_errors.(Server_error (no_repositories_configured, [])) + ) ; Pool_periodic_update_sync.set_enabled ~__context ~value ; Db.Pool.set_update_sync_enabled ~__context ~self ~value