Skip to content

Commit 442efae

Browse files
authored
Merge master into feature/config-ntp-timezone-maxcstate (#6764)
2 parents 1ee40bf + f63f5b1 commit 442efae

Some content is hidden

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

46 files changed

+389
-318
lines changed

doc/content/xapi/internals/certificates.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pool or host to be used as an API.
5353
certificate.
5454
* See below for xapi-stunnel-ca-bundle for additional certificates that
5555
can be added to a pool in support of a user-supplied host certificate.
56-
* `xe reset-server-certificate` creates a new self-signed certificate.
56+
* `xe host-reset-server-certificate` creates a new self-signed certificate.
5757

5858

5959
### `xapi-pool-tls.pem`

ocaml/database/database_test.ml

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ functor
463463
(* reference which we create *)
464464
let valid_ref = "ref1" in
465465
let valid_uuid = "uuid1" in
466+
let new_uuid = "uuid2" in
466467
let invalid_ref = "foo" in
467468
let invalid_uuid = "bar" in
468469
let t =
@@ -626,6 +627,32 @@ functor
626627
"read_field_where <valid table> <valid return> <valid field> <valid \
627628
value>" ;
628629
test_invalid_where_record "read_field_where" (Client.read_field_where t) ;
630+
631+
(* before changing the UUID, the new UUID should be missing *)
632+
expect_missing_uuid "VM" new_uuid (fun () ->
633+
let (_ : string) = Client.db_get_by_uuid t "VM" new_uuid in
634+
()
635+
) ;
636+
(* change UUID, can happen during VM import *)
637+
Client.write_field t "VM" valid_ref Db_names.uuid new_uuid ;
638+
let old_uuid = valid_uuid in
639+
(* new UUID should be found *)
640+
let r = Client.db_get_by_uuid t "VM" new_uuid in
641+
if r <> valid_ref then
642+
failwith_fmt "db_get_by_uuid <new uuid>: got %s; expected %s" r
643+
valid_ref ;
644+
let r = Client.db_get_by_uuid_opt t "VM" new_uuid in
645+
( if r <> Some valid_ref then
646+
let rs = Option.value ~default:"None" r in
647+
failwith_fmt "db_get_by_uuid_opt <new uuid>: got %s; expected %s" rs
648+
valid_ref
649+
) ;
650+
(* old UUID should not be found anymore *)
651+
expect_missing_uuid "VM" old_uuid (fun () ->
652+
let (_ : string) = Client.db_get_by_uuid t "VM" old_uuid in
653+
()
654+
) ;
655+
629656
Printf.printf "write_field <invalid table>\n" ;
630657
expect_missing_tbl "Vm" (fun () ->
631658
let (_ : unit) = Client.write_field t "Vm" "" "" "" in
@@ -842,5 +869,23 @@ functor
842869
)
843870
in
844871
Printf.printf "bad sequence: %.2f calls/sec\n%!" malign_time
845-
)
872+
) ;
873+
Client.delete_row t "VM" valid_ref ;
874+
(* after deleting the row, both old and new uuid must be missing *)
875+
expect_missing_uuid "VM" new_uuid (fun () ->
876+
let (_ : string) = Client.db_get_by_uuid t "VM" new_uuid in
877+
()
878+
) ;
879+
expect_missing_uuid "VM" old_uuid (fun () ->
880+
let (_ : string) = Client.db_get_by_uuid t "VM" old_uuid in
881+
()
882+
) ;
883+
let r = Client.db_get_by_uuid_opt t "VM" old_uuid in
884+
if not (Option.is_none r) then
885+
failwith_fmt "db_get_by_uuid_opt <old uuid>: got %s; expected None"
886+
valid_ref ;
887+
let r = Client.db_get_by_uuid_opt t "VM" new_uuid in
888+
if not (Option.is_none r) then
889+
failwith_fmt "db_get_by_uuid_opt <old uuid>: got %s; expected None"
890+
valid_ref
846891
end

ocaml/database/db_cache_impl.ml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -277,21 +277,13 @@ let read_field_where' conv t rcd =
277277
let read_field_where t rcd = read_field_where' Fun.id t rcd
278278

279279
let db_get_by_uuid t tbl uuid_val =
280-
match
281-
read_field_where' Schema.CachedValue.string_of t
282-
{
283-
table= tbl
284-
; return= Db_names.ref
285-
; where_field= Db_names.uuid
286-
; where_value= uuid_val
287-
}
288-
with
289-
| [] ->
290-
raise (Read_missing_uuid (tbl, "", uuid_val))
291-
| [r] ->
280+
let db = get_database t in
281+
match Database.lookup_uuid uuid_val db with
282+
| Some (tbl', r) when String.equal tbl tbl' ->
292283
r
293284
| _ ->
294-
raise (Too_many_values (tbl, "", uuid_val))
285+
(* we didn't find the UUID, or it belonged to another table *)
286+
raise (Read_missing_uuid (tbl, "", uuid_val))
295287

296288
let db_get_by_uuid_opt t tbl uuid_val =
297289
match

ocaml/database/db_cache_types.ml

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ module Database = struct
508508

509509
let lookup_key key db = KeyMap.find_opt (Ref key) db.keymap
510510

511+
let lookup_uuid key db = KeyMap.find_opt (Uuid key) db.keymap
512+
511513
let make schema =
512514
{
513515
tables= TableSet.empty
@@ -615,6 +617,33 @@ let update_many_to_many g tblname objref f db =
615617
db
616618
(Schema.many_to_many tblname (Database.schema db))
617619

620+
let uuid_of ~tblname ~objref db =
621+
try
622+
Some
623+
(Schema.Value.Unsafe_cast.string
624+
(Row.find Db_names.uuid
625+
(Table.find objref (TableSet.find tblname (Database.tableset db)))
626+
)
627+
)
628+
with _ -> None
629+
630+
let maybe_update_uuid_keymap ~tblname ~objref ~fldname ~newval db =
631+
if fldname = Db_names.uuid then
632+
db
633+
|> Database.update_keymap @@ fun keymap ->
634+
let keymap =
635+
match uuid_of ~tblname ~objref db with
636+
| None ->
637+
keymap
638+
| Some uuid ->
639+
KeyMap.remove (Uuid uuid) keymap
640+
in
641+
KeyMap.add_unique tblname Db_names.uuid
642+
(Uuid (Schema.Value.Unsafe_cast.string newval))
643+
(tblname, objref) keymap
644+
else
645+
db
646+
618647
let set_field tblname objref fldname newval db =
619648
if fldname = Db_names.ref then
620649
failwith (Printf.sprintf "Cannot safely update field: %s" fldname) ;
@@ -632,6 +661,7 @@ let set_field tblname objref fldname newval db =
632661
if need_other_table_update then
633662
let g = Manifest.generation (Database.manifest db) in
634663
db
664+
|> maybe_update_uuid_keymap ~tblname ~objref ~fldname ~newval
635665
|> update_many_to_many g tblname objref remove_from_set
636666
|> update_one_to_many g tblname objref remove_from_set
637667
|> Database.update
@@ -646,6 +676,7 @@ let set_field tblname objref fldname newval db =
646676
else
647677
let g = Manifest.generation (Database.manifest db) in
648678
db
679+
|> maybe_update_uuid_keymap ~tblname ~objref ~fldname ~newval
649680
|> ((fun _ -> newval)
650681
|> Row.update g fldname empty
651682
|> Table.update g objref Row.empty
@@ -696,16 +727,7 @@ let add_row tblname objref newval db =
696727
|> Database.increment
697728

698729
let remove_row tblname objref db =
699-
let uuid =
700-
try
701-
Some
702-
(Schema.Value.Unsafe_cast.string
703-
(Row.find Db_names.uuid
704-
(Table.find objref (TableSet.find tblname (Database.tableset db)))
705-
)
706-
)
707-
with _ -> None
708-
in
730+
let uuid = uuid_of ~tblname ~objref db in
709731
let g = db.Database.manifest.Manifest.generation_count in
710732
db
711733
|> Database.update_keymap (fun m ->

ocaml/database/db_cache_types.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ module Database : sig
195195

196196
val lookup_key : string -> t -> (string * string) option
197197

198+
val lookup_uuid : string -> t -> (string * string) option
199+
198200
val reindex : t -> t
199201

200202
val register_callback : string -> (update -> t -> unit) -> t -> t

ocaml/idl/datamodel.ml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11005,6 +11005,16 @@ let http_actions =
1100511005
, []
1100611006
)
1100711007
)
11008+
(* For XC < 8460 compatibility, remove when out of support *)
11009+
; ( "get_vm_rrds"
11010+
, ( Get
11011+
, "/vm_rrds"
11012+
, true
11013+
, [String_query_arg "uuid"; Bool_query_arg "json"]
11014+
, _R_READ_ONLY
11015+
, []
11016+
)
11017+
)
1100811018
; ( Constants.get_host_rrd
1100911019
, ( Get
1101011020
, Constants.get_host_rrd_uri
@@ -11014,6 +11024,10 @@ let http_actions =
1101411024
, []
1101511025
)
1101611026
)
11027+
(* For XC < 8460 compatibility, remove when out of support *)
11028+
; ( "get_host_rrds"
11029+
, (Get, "/host_rrds", true, [Bool_query_arg "json"], _R_READ_ONLY, [])
11030+
)
1101711031
; ( Constants.get_sr_rrd
1101811032
, ( Get
1101911033
, Constants.get_sr_rrd_uri
@@ -11081,6 +11095,7 @@ let http_actions =
1108111095
)
1108211096
; (* XMLRPC callback *)
1108311097
("post_root", (Post, "/", false, [], _R_READ_ONLY, []))
11098+
; ("post_RPC2", (Post, "/RPC2", false, [], _R_READ_ONLY, []))
1108411099
; (* JSON callback *)
1108511100
("post_json", (Post, Constants.json_uri, false, [], _R_READ_ONLY, []))
1108611101
; ("post_root_options", (Options, "/", false, [], _R_READ_ONLY, []))
@@ -11133,6 +11148,7 @@ let http_actions =
1113311148
let public_http_actions_with_no_rbac_check =
1113411149
[
1113511150
"post_root"
11151+
; "post_RPC2"
1113611152
; (* XMLRPC (API) calls -> checks RBAC internally *)
1113711153
"post_cli"
1113811154
; (* CLI commands -> calls XMLRPC *)

ocaml/idl/datamodel_pool.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ open Datamodel_types
55
let operations =
66
Enum
77
( "pool_allowed_operations"
8-
, (* FIXME: This should really be called `pool_operations`, to avoid confusion with the Pool.allowed_operations field *)
9-
[
8+
, [
109
("ha_enable", "Indicates this pool is in the process of enabling HA")
1110
; ("ha_disable", "Indicates this pool is in the process of disabling HA")
1211
; ( "cluster_create"

ocaml/idl/datamodel_vm.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,7 @@ let assert_can_migrate =
17421742
; {
17431743
param_type= Map (String, String)
17441744
; param_name= "dest"
1745-
; param_doc= "The result of a VM.migrate_receive call."
1745+
; param_doc= "The result of a Host.migrate_receive call."
17461746
; param_release= tampa_release
17471747
; param_default= None
17481748
}
@@ -1797,7 +1797,7 @@ let assert_can_migrate_sender =
17971797
(Ref _vm, "vm", "The VM")
17981798
; ( Map (String, String)
17991799
, "dest"
1800-
, "The result of a VM.migrate_receive call."
1800+
, "The result of a Host.migrate_receive call."
18011801
)
18021802
; (Bool, "live", "Live migration")
18031803
; ( Map (Ref _vdi, Ref _sr)

ocaml/libs/http-lib/http.ml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ end
505505
module Request = struct
506506
type t = {
507507
m: method_t
508-
; uri: string
508+
; path: string
509509
; query: (string * string) list
510510
; version: string
511511
; frame: bool
@@ -528,7 +528,7 @@ module Request = struct
528528
let empty =
529529
{
530530
m= Unknown ""
531-
; uri= ""
531+
; path= ""
532532
; query= []
533533
; version= ""
534534
; frame= false
@@ -563,7 +563,7 @@ module Request = struct
563563
; host
564564
; user_agent= Some user_agent
565565
; m= meth
566-
; uri= path
566+
; path
567567
; additional_headers= headers
568568
; body
569569
; accept
@@ -577,10 +577,10 @@ module Request = struct
577577
String.concat "; " (List.map (fun (k, v) -> k ^ "=" ^ v) x)
578578
in
579579
Printf.sprintf
580-
"{ frame = %b; method = %s; uri = %s; query = [ %s ]; content_length = [ \
581-
%s ]; transfer encoding = %s; version = %s; cookie = [ %s ]; task = %s; \
582-
subtask_of = %s; content-type = %s; host = %s; user_agent = %s; }"
583-
x.frame (string_of_method_t x.m) x.uri (kvpairs x.query)
580+
"{ frame = %b; method = %s; path = %s; query = [ %s ]; content_length = \
581+
[ %s ]; transfer encoding = %s; version = %s; cookie = [ %s ]; task = \
582+
%s; subtask_of = %s; content-type = %s; host = %s; user_agent = %s; }"
583+
x.frame (string_of_method_t x.m) x.path (kvpairs x.query)
584584
(Option.fold ~none:"" ~some:Int64.to_string x.content_length)
585585
(Option.value ~default:"" x.transfer_encoding)
586586
x.version "(value filtered)" (* cookies *)
@@ -642,7 +642,7 @@ module Request = struct
642642
[(Hdr.connection ^ ": " ^ if x.close then "close" else "keep-alive")]
643643
in
644644
[
645-
Printf.sprintf "%s %s%s HTTP/%s" (string_of_method_t x.m) x.uri query
645+
Printf.sprintf "%s %s%s HTTP/%s" (string_of_method_t x.m) x.path query
646646
x.version
647647
]
648648
@ cookie
@@ -809,17 +809,17 @@ module Url = struct
809809

810810
type scheme = Http of http | File of file
811811

812-
type data = {uri: string; query_params: (string * string) list}
812+
type data = {path: string; query_params: (string * string) list}
813813

814814
type t = scheme * data
815815

816-
let file_equal a b = String.equal a.path b.path
816+
let file_equal (a : file) (b : file) = String.equal a.path b.path
817817

818818
let query_params_equal (ak, av) (bk, bv) =
819819
String.equal ak bk && String.equal av bv
820820

821821
let data_equal a b =
822-
String.equal a.uri b.uri
822+
String.equal a.path b.path
823823
&& List.equal query_params_equal a.query_params b.query_params
824824

825825
let http_equal a b =
@@ -858,7 +858,7 @@ module Url = struct
858858
in
859859
let data =
860860
{
861-
uri= (match Uri.path_unencoded uri with "" -> "/" | path -> path)
861+
path= (match Uri.path_unencoded uri with "" -> "/" | path -> path)
862862
; query_params= Uri.query uri |> List.map query
863863
}
864864
in
@@ -872,19 +872,19 @@ module Url = struct
872872
(scheme ~ssl:true, data)
873873
| Some "file" ->
874874
let scheme = File {path= Uri.path_unencoded uri} in
875-
(scheme, {data with uri= "/"})
875+
(scheme, {data with path= "/"})
876876
| _ ->
877877
failwith "unsupported URI scheme"
878878
with e ->
879879
fail "%s: can't parse '%s': %s" __FUNCTION__ url (Printexc.to_string e)
880880

881-
let data_to_string {uri; query_params= params} =
881+
let data_to_string {path; query_params= params} =
882882
let kvpairs x =
883883
String.concat "&"
884884
(List.map (fun (k, v) -> urlencode k ^ "=" ^ urlencode v) x)
885885
in
886886
let params = if params = [] then "" else "?" ^ kvpairs params in
887-
uri ^ params
887+
path ^ params
888888

889889
let to_string scheme =
890890
let query (k, v) = (k, [v]) in
@@ -893,7 +893,7 @@ module Url = struct
893893
| File {path}, {query_params= params; _} ->
894894
Uri.make ~scheme:"file" ~path ~query:(List.map query params) ()
895895
|> Uri.to_string
896-
| Http h, {uri; query_params= params} ->
896+
| Http h, {path; query_params= params} ->
897897
let auth =
898898
match h.auth with
899899
| Some (Basic (username, password)) ->
@@ -905,16 +905,16 @@ module Url = struct
905905
in
906906
Uri.make
907907
~scheme:(if h.ssl then "https" else "http")
908-
~host:h.host ?port:h.port ?userinfo:auth ~path:uri
908+
~host:h.host ?port:h.port ?userinfo:auth ~path
909909
~query:(List.map query params) ()
910910
|> Uri.to_string
911911
in
912912
debug "%s: %s" __FUNCTION__ str ;
913913
str
914914

915-
let get_uri (_scheme, data) = data.uri
915+
let get_path (_scheme, data) = data.path
916916

917-
let set_uri (scheme, data) u = (scheme, {data with uri= u})
917+
let set_path (scheme, data) u = (scheme, {data with path= u})
918918

919919
let get_query_params (_scheme, data) = data.query_params
920920

0 commit comments

Comments
 (0)