Skip to content

Commit

Permalink
Merge pull request #5205 from danilo-delbusso/private/danilod/sync_se…
Browse files Browse the repository at this point in the history
…tting_CA-381044

CA-381044: Raise error when `pool.set_update_sync_enabled` is called with `true` and empty repos
  • Loading branch information
robhoes authored Oct 17, 2023
2 parents 47be79b + cb40217 commit 23666e2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ocaml/idl/datamodel_errors.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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 @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions ocaml/xapi/xapi_pool.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 23666e2

Please sign in to comment.