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

CA-399629: make daily-license-check aware of never #6106

Merged
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
37 changes: 22 additions & 15 deletions ocaml/license/daily_license_check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,35 @@ let seconds_per_30_days = 30. *. seconds_per_day
let days_to_expiry now expiry =
(expiry /. seconds_per_day) -. (now /. seconds_per_day)

let get_expiry_date license =
List.assoc_opt "expiry" license
|> Fun.flip Option.bind (fun e -> if e = "never" then None else Some e)
|> Option.map Xapi_stdext_date.Date.of_string
|> Option.map Xapi_stdext_date.Date.to_float

let get_hosts all_license_params threshold =
List.fold_left
(fun acc (name_label, license_params) ->
let expiry = List.assoc "expiry" license_params in
let expiry = Xapi_stdext_date.Date.(to_float (of_string expiry)) in
if expiry < threshold then
name_label :: acc
else
acc
match get_expiry_date license_params with
| Some expiry when expiry < threshold ->
name_label :: acc
| _ ->
acc
)
[] all_license_params

let check_license now pool_license_state all_license_params =
let expiry = List.assoc "expiry" pool_license_state in
let expiry = Xapi_stdext_date.Date.(to_float (of_string expiry)) in
let days = days_to_expiry now expiry in
if days <= 0. then
Expired (get_hosts all_license_params now)
else if days <= 30. then
Expiring (get_hosts all_license_params (now +. seconds_per_30_days))
else
Good
match get_expiry_date pool_license_state with
| Some expiry ->
let days = days_to_expiry now expiry in
if days <= 0. then
Expired (get_hosts all_license_params now)
else if days <= 30. then
Expiring (get_hosts all_license_params (now +. seconds_per_30_days))
else
Good
| None ->
Good

let get_info_from_db rpc session =
let pool = List.hd (XenAPI.Pool.get_all rpc session) in
Expand Down
1 change: 1 addition & 0 deletions ocaml/tests/alerts/test_daily_license_check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ let expiry_samples =
[
(([("expiry", "20170101T00:00:00Z")], []), Good)
; (([("expiry", "20160701T04:01:00Z")], []), Good)
; (([("expiry", "never")], []), Good)
; (([("expiry", "20160701T04:00:00Z")], []), Expiring [])
; (([("expiry", "20160616T00:00:00Z")], []), Expiring [])
; (([("expiry", "20160601T04:00:01Z")], []), Expiring [])
Expand Down