Skip to content

Commit 37b5f70

Browse files
committed
xapi-stdext-date: replace all usages to use clock instead
Not deleting the package and aliasing its main type to Clock.Date.t allows for a smooth transition. Signed-off-by: Pau Ruiz Safont <pau.ruizsafont@cloud.com>
1 parent 5ec5732 commit 37b5f70

File tree

115 files changed

+219
-242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+219
-242
lines changed

dune-project

+2-2
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@
338338
base64
339339
(bos :with-test)
340340
cdrom
341+
(clock (= :version))
341342
cmdliner
342343
cohttp
343344
conf-pam
@@ -398,7 +399,6 @@
398399
(xapi-idl (= :version))
399400
(xapi-inventory (= :version))
400401
(xapi-log (= :version))
401-
(xapi-stdext-date (= :version))
402402
(xapi-stdext-pervasives (= :version))
403403
(xapi-stdext-std (= :version))
404404
(xapi-stdext-threads (= :version))
@@ -604,6 +604,7 @@ This package provides an Lwt compatible interface to the library.")
604604
(alcotest :with-test)
605605
astring
606606
(base64 (>= "3.1.0"))
607+
(clock (= :version))
607608
fmt
608609
ipaddr
609610
mtime
@@ -619,7 +620,6 @@ This package provides an Lwt compatible interface to the library.")
619620
xapi-backtrace
620621
(xapi-idl (= :version))
621622
(xapi-log (= :version))
622-
(xapi-stdext-date (= :version))
623623
(xapi-stdext-pervasives (= :version))
624624
(xapi-stdext-threads (= :version))
625625
(xapi-tracing (= :version))

http-lib.opam

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ depends: [
1313
"alcotest" {with-test}
1414
"astring"
1515
"base64" {>= "3.1.0"}
16+
"clock" {= version}
1617
"fmt"
1718
"ipaddr"
1819
"mtime"
@@ -28,7 +29,6 @@ depends: [
2829
"xapi-backtrace"
2930
"xapi-idl" {= version}
3031
"xapi-log" {= version}
31-
"xapi-stdext-date" {= version}
3232
"xapi-stdext-pervasives" {= version}
3333
"xapi-stdext-threads" {= version}
3434
"xapi-tracing" {= version}

ocaml/alerts/certificate/certificate_check.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module XenAPI = Client.Client
2-
module Date = Xapi_stdext_date.Date
2+
module Date = Clock.Date
33

44
type cert =
55
| CA of API.ref_Certificate * API.datetime

ocaml/alerts/certificate/certificate_check.mli

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
val alert : (Rpc.call -> Rpc.response) -> [< `session] Ref.t -> unit
1616

17-
(* Below exposed only for ease of testing *)
17+
(* Below exposed only for ease of testing, drop any documentation *)
18+
(**/**)
1819

1920
type cert =
2021
| CA of API.ref_Certificate * API.datetime
@@ -25,11 +26,11 @@ val certificate_description : cert -> string
2526

2627
val alert_conditions : cert -> (int * (string * int64)) list
2728

28-
val get_expiry : cert -> Xapi_stdext_date.Date.t
29+
val get_expiry : cert -> Clock.Date.t
2930

3031
val maybe_generate_alert :
31-
Xapi_stdext_date.Date.t
32+
Clock.Date.t
3233
-> string
3334
-> (int * (string * int64)) list
34-
-> Xapi_stdext_date.Date.t
35+
-> Clock.Date.t
3536
-> (string * (string * int64)) option

ocaml/alerts/certificate/dune

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
(modes best)
55
(libraries
66
astring
7+
ptime
78
xapi-expiry-alerts
89
xapi-client
910
xapi-consts
1011
xapi-types
11-
xapi-stdext-date
12+
clock
1213
)
1314
)
1415

@@ -18,7 +19,7 @@
1819
(modules certificate_check_main)
1920
(libraries
2021
certificate_check
21-
22+
2223
http_lib
2324
xapi-client
2425
xapi-types

ocaml/alerts/dune

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
(name expiry_alert)
33
(public_name xapi-expiry-alerts)
44
(libraries
5+
clock
56
xapi-client
67
xapi-types
7-
xapi-stdext-date
88
)
99
)

ocaml/alerts/expiry_alert.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*)
1414

1515
module XenAPI = Client.Client
16-
module Date = Xapi_stdext_date.Date
16+
module Date = Clock.Date
1717

1818
type message_name = string
1919

@@ -37,7 +37,7 @@ type raw_alert = {
3737
; obj_uuid: string
3838
; obj_description: string
3939
; alert_conditions: (remaining_days * message_id) list
40-
; expiry: Xapi_stdext_date.Date.t (* when the obj will expire *)
40+
; expiry: Date.t (* when the obj will expire *)
4141
}
4242

4343
let seconds_per_day = 3600. *. 24.
@@ -87,7 +87,7 @@ let filter_messages msg_name_list msg_obj_uuid alert all_msgs =
8787
)
8888

8989
let alert ~rpc ~session_id raw_alerts =
90-
let now = Date.now () in
90+
let now = Clock.Date.now () in
9191
let all_msgs = all_messages rpc session_id in
9292
List.iter
9393
(fun {cls; obj_uuid; obj_description; alert_conditions; expiry} ->

ocaml/alerts/expiry_alert.mli

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type raw_alert = {
5555
* sent, and when it has expired, message "host_server_certificate_expired"
5656
* should be sent.
5757
*)
58-
; expiry: Xapi_stdext_date.Date.t
58+
; expiry: Clock.Date.t
5959
(* the last second when the obj is valid, it will expire in the next second *)
6060
}
6161

@@ -69,17 +69,17 @@ val alert :
6969

7070
(* Below exposed only for ease of testing *)
7171

72-
val message_body : string -> Xapi_stdext_date.Date.t -> string
72+
val message_body : string -> Clock.Date.t -> string
7373

7474
val expired_message : string -> string
7575

7676
val expiring_message : string -> string
7777

7878
val maybe_generate_alert :
79-
Xapi_stdext_date.Date.t
79+
Clock.Date.t
8080
-> string
8181
-> (remaining_days * message_id) list
82-
-> Xapi_stdext_date.Date.t
82+
-> Clock.Date.t
8383
-> (string * message_id) option
8484
(** An inner function exposed only for ease of testing, it returns None if there is no
8585
need for an expiry alert as it is not expiring or expired yet, otherwise an "alert"

ocaml/forkexecd/lib/dune

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
xapi-log
1616
xapi-stdext-pervasives
1717
xapi-stdext-unix
18-
xapi-stdext-date
1918
xapi-tracing
2019
)
2120
(preprocess (per_module ((pps ppx_deriving_rpc) Fe))))

ocaml/forkexecd/lib/fe_systemctl.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ let exists ~service = Sys.file_exists (path service)
139139
(** creation time of [path] as a string *)
140140
let ctime path =
141141
let ctime = Unix.((stat path).st_ctime) in
142-
Xapi_stdext_date.Date.(of_unix_time ctime |> to_rfc3339)
142+
Clock.Date.(of_unix_time ctime |> to_rfc3339)
143143

144144
let start_transient ?env ?properties ?(exec_ty = Type.Simple) ~service cmd args
145145
=

ocaml/idl/datamodel_types.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
2727
*)
2828
module Date = struct
29-
module Date = Xapi_stdext_date.Date
29+
module Date = Clock.Date
3030
include Date
3131

3232
let t_of_rpc rpc = Date.of_iso8601 (Rpc.string_of_rpc rpc)

ocaml/idl/datamodel_types.mli

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module Date : sig
2-
include module type of Xapi_stdext_date.Date
2+
include module type of Clock.Date
33

4-
val t_of_rpc : Rpc.t -> Xapi_stdext_date.Date.t
4+
val t_of_rpc : Rpc.t -> Clock.Date.t
55

6-
val rpc_of_t : Xapi_stdext_date.Date.t -> Rpc.t
6+
val rpc_of_t : Clock.Date.t -> Rpc.t
77
end
88

99
val oss_since_303 : string option

ocaml/idl/dune

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
xapi-backtrace
1717
xapi-consts
1818
xapi-schema
19-
xapi-stdext-date
19+
clock
2020
xapi-stdext-std
2121
)
2222
(wrapped false)

ocaml/idl/ocaml_backend/gen_api.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ let gen_client_types _config highapi =
401401
; ["module Ref = Ref"]
402402
; [
403403
"module Date = struct"
404-
; " open Xapi_stdext_date"
404+
; " module Date = Clock.Date"
405405
; " include Date"
406406
; " let rpc_of_t x = DateTime (Date.to_rfc3339 x)"
407407
; " let t_of_rpc = function String x | DateTime x -> Date.of_iso8601 \

ocaml/libs/http-lib/dune

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
xapi-consts.xapi_version
2626
xapi-idl.updates
2727
xapi-log
28-
xapi-stdext-date
28+
clock
2929
xapi-stdext-pervasives
3030
xapi-stdext-threads
3131
xapi-stdext-unix

ocaml/libs/http-lib/xMLRPC.ml

+2-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ module To = struct
6868
let boolean b = value (box "boolean" [pcdata (if b then "1" else "0")])
6969

7070
let datetime s =
71-
value (box "dateTime.iso8601" [pcdata (Xapi_stdext_date.Date.to_rfc3339 s)])
71+
value (box "dateTime.iso8601" [pcdata (Clock.Date.to_rfc3339 s)])
7272

7373
let double x =
7474
let txt =
@@ -197,8 +197,7 @@ module From = struct
197197
let boolean = value (singleton ["boolean"] (( <> ) (Xml.PCData "0")))
198198

199199
let datetime x =
200-
Xapi_stdext_date.Date.of_iso8601
201-
(value (singleton ["dateTime.iso8601"] (pcdata id)) x)
200+
Clock.Date.of_iso8601 (value (singleton ["dateTime.iso8601"] (pcdata id)) x)
202201

203202
let double = value (singleton ["double"] (pcdata float_of_string))
204203

ocaml/libs/http-lib/xMLRPC.mli

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ module To : sig
5959
val boolean : bool -> xmlrpc
6060
(** Marshal a boolean. *)
6161

62-
val datetime : Xapi_stdext_date.Date.t -> xmlrpc
62+
val datetime : Clock.Date.t -> xmlrpc
6363
(** Marshal a date-time. *)
6464

6565
val double : float -> xmlrpc
@@ -98,7 +98,7 @@ module From : sig
9898
val boolean : xmlrpc -> bool
9999
(** Parse a boolean. *)
100100

101-
val datetime : xmlrpc -> Xapi_stdext_date.Date.t
101+
val datetime : xmlrpc -> Clock.Date.t
102102
(** Parse a date-time. *)
103103

104104
val double : xmlrpc -> float

ocaml/libs/xapi-stdext/lib/xapi-stdext-date/date.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*)
1414

1515
(** date-time with support for keeping timezone for ISO 8601 conversion *)
16-
type t
16+
type t = Clock.Date.t
1717

1818
(** Conversions *)
1919

ocaml/license/daily_license_check.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module XenAPI = Client.Client
2-
module Date = Xapi_stdext_date.Date
2+
module Date = Clock.Date
33

44
type result = Good | Expiring of string list | Expired of string list
55

@@ -18,7 +18,7 @@ let days_to_expiry ~expiry now =
1818
let get_expiry_date pool_license =
1919
List.assoc_opt "expiry" pool_license
2020
|> Fun.flip Option.bind (fun e -> if e = "never" then None else Some e)
21-
|> Option.map Xapi_stdext_date.Date.of_iso8601
21+
|> Option.map Clock.Date.of_iso8601
2222

2323
let get_hosts all_license_params threshold =
2424
List.filter_map

ocaml/license/daily_license_check_main.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let _ =
1414
in
1515
Xapi_stdext_pervasives.Pervasiveext.finally
1616
(fun () ->
17-
let now = Xapi_stdext_date.Date.now () in
17+
let now = Clock.Date.now () in
1818
let pool, pool_license_state, all_license_params =
1919
Daily_license_check.get_info_from_db rpc session_id
2020
in

ocaml/license/dune

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
xapi-consts
99
xapi-client
1010
xapi-types
11-
xapi-stdext-date
11+
clock
1212
)
1313
)
1414

@@ -21,7 +21,7 @@
2121
http_lib
2222
xapi-client
2323
xapi-types
24-
xapi-stdext-date
24+
clock
2525
xapi-stdext-pervasives
2626
)
2727
)

ocaml/quicktest/dune

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
xapi_internal
3232
xapi-log
3333
xapi-types
34-
xapi-stdext-date
34+
clock
3535
xapi-stdext-pervasives
3636
xapi-stdext-std
3737
xapi-stdext-threads

ocaml/quicktest/qt.ml

+3-4
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ module Time = struct
100100

101101
let now () = Unix.gettimeofday ()
102102

103-
let of_field = Xapi_stdext_date.Date.to_unix_time
103+
let of_field = Clock.Date.to_unix_time
104104

105-
let pp t = Xapi_stdext_date.Date.(of_unix_time t |> to_rfc3339)
105+
let pp t = Clock.Date.(of_unix_time t |> to_rfc3339)
106106

107107
let check t ~after ~before =
108108
Alcotest.(check bool)
@@ -268,8 +268,7 @@ module VDI = struct
268268
)
269269
; ( `Same
270270
, "snapshot_time"
271-
, fun vdi ->
272-
vdi.API.vDI_snapshot_time |> Xapi_stdext_date.Date.to_rfc3339
271+
, fun vdi -> vdi.API.vDI_snapshot_time |> Clock.Date.to_rfc3339
273272
)
274273
; (`Same, "virtual_size", fun vdi -> vdi.API.vDI_location)
275274
]

ocaml/quicktest/qt.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module Time : sig
3434

3535
val now : unit -> t
3636

37-
val of_field : Xapi_stdext_date.Date.t -> t
37+
val of_field : Clock.Date.t -> t
3838

3939
val pp : t -> string
4040

ocaml/quicktest/quicktest_date.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Client = Client.Client
2-
module Date = Xapi_stdext_date.Date
2+
module Date = Clock.Date
33

44
let test_host_get_server_localtime rpc session_id () =
55
let host = Client.Host.get_by_uuid ~rpc ~session_id ~uuid:Qt.localhost_uuid in

ocaml/quicktest/quicktest_event.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ let event_message_test rpc session_id () =
381381
) ;
382382
let messages =
383383
Client.Client.Message.get ~rpc ~session_id ~cls ~obj_uuid
384-
~since:Xapi_stdext_date.Date.epoch
384+
~since:Clock.Date.epoch
385385
in
386386
let has_msg m = List.exists (fun (r, _) -> r = m) messages in
387387
Alcotest.(check bool)

ocaml/quicktest/quicktest_vdi.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ let vdi_bad_introduce rpc session_id sr_info () =
139139
~location:(Ref.string_of (Ref.make ()))
140140
~xenstore_data:[] ~sm_config:[] ~managed:true ~virtual_size:0L
141141
~physical_utilisation:0L ~metadata_of_pool:Ref.null
142-
~is_a_snapshot:false ~snapshot_time:Xapi_stdext_date.Date.epoch
142+
~is_a_snapshot:false ~snapshot_time:Clock.Date.epoch
143143
~snapshot_of:Ref.null
144144
in
145145
Alcotest.fail
@@ -161,7 +161,7 @@ let vdi_bad_introduce rpc session_id sr_info () =
161161
~other_config:[] ~location:vdir.API.vDI_location ~xenstore_data:[]
162162
~sm_config:[] ~managed:true ~virtual_size:0L
163163
~physical_utilisation:0L ~metadata_of_pool:Ref.null
164-
~is_a_snapshot:false ~snapshot_time:Xapi_stdext_date.Date.epoch
164+
~is_a_snapshot:false ~snapshot_time:Clock.Date.epoch
165165
~snapshot_of:Ref.null
166166
in
167167
Alcotest.fail

0 commit comments

Comments
 (0)