Skip to content

Commit 18448ce

Browse files
committed
CP-23026 pool join: add checks for software version, product_brand
This adds a generic check that can be asked to compare multiple aspects of a product version before a host joins a pool. Currently, _product_version and _product_brand are being checked between local host and master. Signed-off-by: Christian Lindig <[email protected]>
1 parent ce4b65b commit 18448ce

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

ocaml/xapi/xapi_pool.ml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,40 @@ let pre_join_checks ~__context ~rpc ~session_id ~force =
143143
end
144144
in
145145

146+
(** [assert_version_matches] takes a list of [keys] into
147+
* [API.host_software_version] and compares each version on
148+
* localhost and pool master. A version difference or an
149+
* undefined key leads to an assertion and blocks a host to join.
150+
*)
151+
let assert_version_matches keys =
152+
let local =
153+
Helpers.get_localhost ~__context
154+
|> fun self -> Db.Host.get_record ~__context ~self
155+
|> fun r -> r.API.host_software_version in
156+
let master =
157+
get_master rpc session_id
158+
|> fun self -> Client.Host.get_record ~rpc ~session_id ~self
159+
|> fun r -> r.API.host_software_version in
160+
let api_error fmt =
161+
Printf.kprintf (fun msg ->
162+
raise Api_errors.(Server_error(pool_hosts_not_homogeneous,[msg]))) fmt in
163+
let compare key =
164+
try
165+
let local_v = List.assoc key local in
166+
let master_v = List.assoc key master in
167+
if local_v <> master_v then begin
168+
error "pool join: software versions differ localhost[%s]=%s <> master[%s]=%s"
169+
key local_v key master_v;
170+
api_error "localhost[%s]=%s master[%s]=%s" (* avoid i18n *)
171+
key local_v key master_v;
172+
end
173+
with Not_found ->
174+
error "pool join: software version for key %s is undefined" key;
175+
api_error "%s" key (* avoid i18n *)
176+
in
177+
List.iter compare keys
178+
in
179+
146180
let assert_homogeneous_updates () =
147181
let module S = Helpers.StringSet in
148182
let local_host = Helpers.get_localhost ~__context in
@@ -386,6 +420,7 @@ let pre_join_checks ~__context ~rpc ~session_id ~force =
386420
(* CA-247399: check first the API version and then the database schema *)
387421
assert_api_version_matches ();
388422
assert_db_schema_matches ();
423+
assert_version_matches Xapi_globs.([_product_version; _product_brand]);
389424
assert_homogeneous_updates ();
390425
assert_homogeneous_primary_address_type ()
391426

0 commit comments

Comments
 (0)