Skip to content

Commit

Permalink
Merge pull request xapi-project#5567 from Vincent-lau/private/shul2/c…
Browse files Browse the repository at this point in the history
…orosync3-basic

CP-48027: Corosync upgrade add `cluster_stack_version` datamodel change
  • Loading branch information
Vincent-lau authored May 20, 2024
2 parents 7666f7e + d00c393 commit 772b6cb
Show file tree
Hide file tree
Showing 8,171 changed files with 8,321 additions and 8,151 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
6 changes: 6 additions & 0 deletions ocaml/idl/datamodel_cluster.ml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ let t =
(Some (VString Constants.default_smapiv3_cluster_stack))
"Simply the string 'corosync'. No other cluster stacks are \
currently supported"
; field ~qualifier:StaticRO ~lifecycle ~ty:Int "cluster_stack_version"
~default_value:(Some (VInt 2L))
"Version of cluster stack, not writable via the API. Defaulting to \
2 for backwards compatibility when upgrading from a cluster \
without this field, which means it is necessarily running version \
2 of corosync, the only cluster stack supported so far."
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:Bool "is_quorate"
~default_value:(Some (VBool false))
"Whether the cluster stack thinks the cluster is quorate"
Expand Down
2 changes: 1 addition & 1 deletion ocaml/idl/schematest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ let hash x = Digest.string x |> Digest.to_hex
(* BEWARE: if this changes, check that schema has been bumped accordingly in
ocaml/idl/datamodel_common.ml, usually schema_minor_vsn *)

let last_known_schema_hash = "8c3cb4546e7dc9e8d9d05c8194d8a3d6"
let last_known_schema_hash = "2b8b5b107eb465e97d35a68274ac18ef"

let current_schema_hash : string =
let open Datamodel_types in
Expand Down
11 changes: 6 additions & 5 deletions ocaml/tests/common/test_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -635,16 +635,17 @@ let make_cluster_host ~__context ?(ref = Ref.make ()) ?(uuid = make_uuid ())
let make_cluster_and_cluster_host ~__context ?(ref = Ref.make ())
?(uuid = make_uuid ()) ?(cluster_token = "") ?(pIF = Ref.null)
?(cluster_stack = Constants.default_smapiv3_cluster_stack)
?(allowed_operations = []) ?(current_operations = [])
?(pool_auto_join = true)
?(cluster_stack_version = 3L) ?(allowed_operations = [])
?(current_operations = []) ?(pool_auto_join = true)
?(token_timeout = Constants.default_token_timeout_s)
?(token_timeout_coefficient = Constants.default_token_timeout_coefficient_s)
?(cluster_config = []) ?(other_config = []) ?(host = Ref.null)
?(is_quorate = false) ?(quorum = 0L) ?(live_hosts = 0L) () =
Db.Cluster.create ~__context ~ref ~uuid ~cluster_token ~pending_forget:[]
~cluster_stack ~allowed_operations ~current_operations ~pool_auto_join
~token_timeout ~token_timeout_coefficient ~cluster_config ~other_config
~is_quorate ~quorum ~live_hosts ;
~cluster_stack ~cluster_stack_version ~allowed_operations
~current_operations ~pool_auto_join ~token_timeout
~token_timeout_coefficient ~cluster_config ~other_config ~is_quorate ~quorum
~live_hosts ;
let cluster_host_ref =
make_cluster_host ~__context ~cluster:ref ~host ~pIF ()
in
Expand Down
23 changes: 13 additions & 10 deletions ocaml/tests/test_cluster.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ let test_clusterd_rpc ~__context call =
; config_version= 1L
; cluster_token_timeout_ms= 20000L
; cluster_token_coefficient_ms= 1000L
; cluster_stack= Cluster_stack.Corosync3
}
in
let diag =
Expand Down Expand Up @@ -140,16 +141,18 @@ let test_invalid_parameters () =
"Cluster.create should fail upon receiving an invalid cluster stack"
Api_errors.(Server_error (invalid_cluster_stack, [cluster_stack]))
(fun () -> create_cluster ~__context ~cluster_stack () |> ignore) ;
Alcotest.check_raises "token_timeout < minimum threshold"
Api_errors.(Server_error (invalid_value, ["token_timeout"; "0.5"]))
(fun () -> create_cluster ~__context ~token_timeout:0.5 () |> ignore) ;
Alcotest.check_raises "token_timeout_coefficient < minimum threshold"
Api_errors.(
Server_error (invalid_value, ["token_timeout_coefficient"; "0.6"])
)
(fun () ->
create_cluster ~__context ~token_timeout_coefficient:0.6 () |> ignore
)
if not (Xapi_fist.allow_corosync2 ()) then (
Alcotest.check_raises "token_timeout < minimum threshold"
Api_errors.(Server_error (invalid_value, ["token_timeout"; "0.5"]))
(fun () -> create_cluster ~__context ~token_timeout:0.5 () |> ignore) ;
Alcotest.check_raises "token_timeout_coefficient < minimum threshold"
Api_errors.(
Server_error (invalid_value, ["token_timeout_coefficient"; "0.6"])
)
(fun () ->
create_cluster ~__context ~token_timeout_coefficient:0.6 () |> ignore
)
)

let test_create_cleanup () =
let __context = Test_common.make_test_database () in
Expand Down
2 changes: 1 addition & 1 deletion ocaml/tests/test_cluster_host.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let create_cluster ~__context pool_auto_join =
Db.Cluster.create ~__context ~ref:cluster_ref ~uuid:cluster_uuid
~cluster_token:"token"
~cluster_stack:Constants.default_smapiv3_cluster_stack
~token_timeout:Constants.default_token_timeout_s
~cluster_stack_version:3L ~token_timeout:Constants.default_token_timeout_s
~token_timeout_coefficient:Constants.default_token_timeout_coefficient_s
~allowed_operations:[] ~current_operations:[] ~pool_auto_join
~cluster_config:[] ~other_config:[] ~pending_forget:[] ~is_quorate:false
Expand Down
47 changes: 47 additions & 0 deletions ocaml/xapi-idl/cluster/cluster_interface.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,53 @@ type node = {addr: address; id: nodeid} [@@deriving rpcty]

type all_members = node list [@@deriving rpcty]

module Cluster_stack = struct
exception Unsupported_Cluster_stack of {cluster_stack: string; version: int64}

exception Unsupported_transport of string

type t = Corosync2 | Corosync3 [@@deriving rpcty]

type transport = Udpu | Knet [@@deriving rpcty]

let transport_to_stack = function Udpu -> Corosync2 | Knet -> Corosync3

let transport_of_string = function
| "udpu" ->
Udpu
| "knet" ->
Knet
| s ->
raise (Unsupported_transport s)

let transport_to_string = function Udpu -> "udpu" | Knet -> "knet"

let cluster_stack_to_transport = function
| Corosync2 ->
Udpu
| Corosync3 ->
Knet

let cluster_stack_of_transport ts =
ts |> transport_of_string |> transport_to_stack

let of_version = function
| "corosync", 2L ->
Corosync2
| "corosync", 3L ->
Corosync3
| cluster_stack, version ->
raise (Unsupported_Cluster_stack {cluster_stack; version})
end

(** This type contains all of the information required to initialise the
cluster. All optional params will have the recommended defaults if None. *)
type init_config = {
member: address
; token_timeout_ms: int64 option
; token_coefficient_ms: int64 option
; name: string option
; cluster_stack: Cluster_stack.t
}
[@@deriving rpcty]

Expand All @@ -92,6 +132,7 @@ type cluster_config = {
; config_version: int64
; cluster_token_timeout_ms: int64
; cluster_token_coefficient_ms: int64
; cluster_stack: Cluster_stack.t
}
[@@deriving rpcty]

Expand Down Expand Up @@ -318,6 +359,12 @@ module LocalAPI (R : RPC) = struct
@-> returning unit_p err
)

let switch_cluster_stack =
let cluster_stack_p = Param.mk ~name:"cluster_stack" Cluster_stack.t in
declare "switch-cluster-stack"
["Switch cluster stack version to the target"]
(debug_info_p @-> cluster_stack_p @-> returning unit_p err)

module UPDATES = struct
open TypeCombinators

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0"?><methodCall><methodName>create</methodName><params><param><value><struct><member><name>init_config</name><value><struct><member><name>member</name><value><array><data><value>Extended</value><value><struct><member><name>hostname</name><value>hostname</value></member><member><name>hostuuid</name><value>hostuuid</value></member><member><name>ip</name><value>127.0.0.1</value></member></struct></value></data></array></value></member></struct></value></member><member><name>dbg</name><value>dbg</value></member></struct></value></param></params></methodCall>
<?xml version="1.0"?><methodCall><methodName>create</methodName><params><param><value><struct><member><name>init_config</name><value><struct><member><name>cluster_stack</name><value>Corosync3</value></member><member><name>member</name><value><array><data><value>Extended</value><value><struct><member><name>hostname</name><value>hostname</value></member><member><name>hostuuid</name><value>hostuuid</value></member><member><name>ip</name><value>127.0.0.1</value></member></struct></value></data></array></value></member></struct></value></member><member><name>dbg</name><value>dbg</value></member></struct></value></param></params></methodCall>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0"?><methodCall><methodName>create</methodName><params><param><value><struct><member><name>init_config</name><value><struct><member><name>member</name><value><array><data><value>Extended</value><value><struct><member><name>hostname</name><value>hostname</value></member><member><name>hostuuid</name><value>hostuuid</value></member><member><name>ip</name><value>::1</value></member></struct></value></data></array></value></member></struct></value></member><member><name>dbg</name><value>dbg</value></member></struct></value></param></params></methodCall>
<?xml version="1.0"?><methodCall><methodName>create</methodName><params><param><value><struct><member><name>init_config</name><value><struct><member><name>cluster_stack</name><value>Corosync3</value></member><member><name>member</name><value><array><data><value>Extended</value><value><struct><member><name>hostname</name><value>hostname</value></member><member><name>hostuuid</name><value>hostuuid</value></member><member><name>ip</name><value>::1</value></member></struct></value></data></array></value></member></struct></value></member><member><name>dbg</name><value>dbg</value></member></struct></value></param></params></methodCall>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0"?><methodCall><methodName>create</methodName><params><param><value><struct><member><name>init_config</name><value><struct><member><name>token_coefficient_ms</name><value>0</value></member><member><name>token_timeout_ms</name><value>0</value></member><member><name>member</name><value><array><data><value>Extended</value><value><struct><member><name>hostname</name><value>hostname</value></member><member><name>hostuuid</name><value>hostuuid</value></member><member><name>ip</name><value>::1</value></member></struct></value></data></array></value></member></struct></value></member><member><name>dbg</name><value>dbg</value></member></struct></value></param></params></methodCall>
<?xml version="1.0"?><methodCall><methodName>create</methodName><params><param><value><struct><member><name>init_config</name><value><struct><member><name>cluster_stack</name><value>Corosync3</value></member><member><name>token_coefficient_ms</name><value>0</value></member><member><name>token_timeout_ms</name><value>0</value></member><member><name>member</name><value><array><data><value>Extended</value><value><struct><member><name>hostname</name><value>hostname</value></member><member><name>hostuuid</name><value>hostuuid</value></member><member><name>ip</name><value>::1</value></member></struct></value></data></array></value></member></struct></value></member><member><name>dbg</name><value>dbg</value></member></struct></value></param></params></methodCall>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0"?><methodCall><methodName>create</methodName><params><param><value><struct><member><name>init_config</name><value><struct><member><name>token_coefficient_ms</name><value>0</value></member><member><name>token_timeout_ms</name><value>0</value></member><member><name>member</name><value><array><data><value>IPv4</value><value>member</value></data></array></value></member></struct></value></member><member><name>dbg</name><value>dbg</value></member></struct></value></param></params></methodCall>
<?xml version="1.0"?><methodCall><methodName>create</methodName><params><param><value><struct><member><name>init_config</name><value><struct><member><name>cluster_stack</name><value>Corosync3</value></member><member><name>token_coefficient_ms</name><value>0</value></member><member><name>token_timeout_ms</name><value>0</value></member><member><name>member</name><value><array><data><value>IPv4</value><value>member</value></data></array></value></member></struct></value></member><member><name>dbg</name><value>dbg</value></member></struct></value></param></params></methodCall>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0"?><methodCall><methodName>create</methodName><params><param><value><struct><member><name>init_config</name><value><struct><member><name>name</name><value>name</value></member><member><name>member</name><value><array><data><value>Extended</value><value><struct><member><name>hostname</name><value>hostname</value></member><member><name>hostuuid</name><value>hostuuid</value></member><member><name>ip</name><value>127.0.0.1</value></member></struct></value></data></array></value></member></struct></value></member><member><name>dbg</name><value>dbg</value></member></struct></value></param></params></methodCall>
<?xml version="1.0"?><methodCall><methodName>create</methodName><params><param><value><struct><member><name>init_config</name><value><struct><member><name>cluster_stack</name><value>Corosync3</value></member><member><name>name</name><value>name</value></member><member><name>member</name><value><array><data><value>Extended</value><value><struct><member><name>hostname</name><value>hostname</value></member><member><name>hostuuid</name><value>hostuuid</value></member><member><name>ip</name><value>127.0.0.1</value></member></struct></value></data></array></value></member></struct></value></member><member><name>dbg</name><value>dbg</value></member></struct></value></param></params></methodCall>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0"?><methodCall><methodName>create</methodName><params><param><value><struct><member><name>init_config</name><value><struct><member><name>name</name><value>name</value></member><member><name>member</name><value><array><data><value>Extended</value><value><struct><member><name>hostname</name><value>hostname</value></member><member><name>hostuuid</name><value>hostuuid</value></member><member><name>ip</name><value>::1</value></member></struct></value></data></array></value></member></struct></value></member><member><name>dbg</name><value>dbg</value></member></struct></value></param></params></methodCall>
<?xml version="1.0"?><methodCall><methodName>create</methodName><params><param><value><struct><member><name>init_config</name><value><struct><member><name>cluster_stack</name><value>Corosync3</value></member><member><name>name</name><value>name</value></member><member><name>member</name><value><array><data><value>Extended</value><value><struct><member><name>hostname</name><value>hostname</value></member><member><name>hostuuid</name><value>hostuuid</value></member><member><name>ip</name><value>::1</value></member></struct></value></data></array></value></member></struct></value></member><member><name>dbg</name><value>dbg</value></member></struct></value></param></params></methodCall>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0"?><methodCall><methodName>create</methodName><params><param><value><struct><member><name>init_config</name><value><struct><member><name>name</name><value>name</value></member><member><name>member</name><value><array><data><value>IPv4</value><value>member</value></data></array></value></member></struct></value></member><member><name>dbg</name><value>dbg</value></member></struct></value></param></params></methodCall>
<?xml version="1.0"?><methodCall><methodName>create</methodName><params><param><value><struct><member><name>init_config</name><value><struct><member><name>cluster_stack</name><value>Corosync3</value></member><member><name>name</name><value>name</value></member><member><name>member</name><value><array><data><value>IPv4</value><value>member</value></data></array></value></member></struct></value></member><member><name>dbg</name><value>dbg</value></member></struct></value></param></params></methodCall>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0"?><methodCall><methodName>create</methodName><params><param><value><struct><member><name>init_config</name><value><struct><member><name>name</name><value>name</value></member><member><name>token_timeout_ms</name><value>0</value></member><member><name>member</name><value><array><data><value>Extended</value><value><struct><member><name>hostname</name><value>hostname</value></member><member><name>hostuuid</name><value>hostuuid</value></member><member><name>ip</name><value>127.0.0.1</value></member></struct></value></data></array></value></member></struct></value></member><member><name>dbg</name><value>dbg</value></member></struct></value></param></params></methodCall>
<?xml version="1.0"?><methodCall><methodName>create</methodName><params><param><value><struct><member><name>init_config</name><value><struct><member><name>cluster_stack</name><value>Corosync3</value></member><member><name>name</name><value>name</value></member><member><name>token_timeout_ms</name><value>0</value></member><member><name>member</name><value><array><data><value>Extended</value><value><struct><member><name>hostname</name><value>hostname</value></member><member><name>hostuuid</name><value>hostuuid</value></member><member><name>ip</name><value>127.0.0.1</value></member></struct></value></data></array></value></member></struct></value></member><member><name>dbg</name><value>dbg</value></member></struct></value></param></params></methodCall>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0"?><methodCall><methodName>create</methodName><params><param><value><struct><member><name>init_config</name><value><struct><member><name>name</name><value>name</value></member><member><name>token_timeout_ms</name><value>0</value></member><member><name>member</name><value><array><data><value>Extended</value><value><struct><member><name>hostname</name><value>hostname</value></member><member><name>hostuuid</name><value>hostuuid</value></member><member><name>ip</name><value>::1</value></member></struct></value></data></array></value></member></struct></value></member><member><name>dbg</name><value>dbg</value></member></struct></value></param></params></methodCall>
<?xml version="1.0"?><methodCall><methodName>create</methodName><params><param><value><struct><member><name>init_config</name><value><struct><member><name>cluster_stack</name><value>Corosync3</value></member><member><name>name</name><value>name</value></member><member><name>token_timeout_ms</name><value>0</value></member><member><name>member</name><value><array><data><value>Extended</value><value><struct><member><name>hostname</name><value>hostname</value></member><member><name>hostuuid</name><value>hostuuid</value></member><member><name>ip</name><value>::1</value></member></struct></value></data></array></value></member></struct></value></member><member><name>dbg</name><value>dbg</value></member></struct></value></param></params></methodCall>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0"?><methodCall><methodName>create</methodName><params><param><value><struct><member><name>init_config</name><value><struct><member><name>name</name><value>name</value></member><member><name>token_timeout_ms</name><value>0</value></member><member><name>member</name><value><array><data><value>IPv4</value><value>member</value></data></array></value></member></struct></value></member><member><name>dbg</name><value>dbg</value></member></struct></value></param></params></methodCall>
<?xml version="1.0"?><methodCall><methodName>create</methodName><params><param><value><struct><member><name>init_config</name><value><struct><member><name>cluster_stack</name><value>Corosync3</value></member><member><name>name</name><value>name</value></member><member><name>token_timeout_ms</name><value>0</value></member><member><name>member</name><value><array><data><value>IPv4</value><value>member</value></data></array></value></member></struct></value></member><member><name>dbg</name><value>dbg</value></member></struct></value></param></params></methodCall>
Loading

0 comments on commit 772b6cb

Please sign in to comment.