Skip to content

Commit a2debf0

Browse files
authored
CA-423760: Retain host.last_update_hash on an ejected host (#6951)
Generally an ejected host can be considered as a fresh-installed one. But in practice, the update level (the hash) is useful to determine the update state of an ejected host. One of the cases is a host was ejected from a pool. In this case, the retained applied update hash is useful to determine if the host can join the pool again easily.
2 parents e5f453e + 0470797 commit a2debf0

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

ocaml/xapi/dbsync_slave.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,21 @@ let create_localhost ~__context info =
5252
in
5353
(* me = None on firstboot only *)
5454
if me = None then
55+
(* Restore the host.last_update_hash when this is an ejected host. *)
56+
let last_update_hash =
57+
let k = "last_update_hash" in
58+
let x = Localdb.get k |> Option.value ~default:"" in
59+
(try Localdb.del k with _ -> ()) ;
60+
x
61+
in
5562
let (_ : API.ref_host) =
5663
Xapi_host.create ~__context ~uuid:info.uuid ~name_label:info.hostname
5764
~name_description:"" ~hostname:info.hostname ~address:ip
5865
~external_auth_type:"" ~external_auth_service_name:""
5966
~external_auth_configuration:[] ~license_params:[] ~edition:""
6067
~license_server:[("address", "localhost"); ("port", "27000")]
6168
~local_cache_sr:Ref.null ~chipset_info:[] ~ssl_legacy:false
62-
~last_software_update:Date.epoch ~last_update_hash:""
69+
~last_software_update:Date.epoch ~last_update_hash
6370
~ssh_enabled:Constants.default_ssh_enabled
6471
~ssh_enabled_timeout:Constants.default_ssh_enabled_timeout
6572
~ssh_expiry:Date.epoch

ocaml/xapi/xapi_pool.ml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1963,6 +1963,7 @@ let eject_self ~__context ~host =
19631963
(Db.Pool.get_current_operations ~__context ~self:pool)
19641964
then
19651965
raise Api_errors.(Server_error (not_supported_during_upgrade, [])) ;
1966+
let last_update_hash = Db.Host.get_last_update_hash ~__context ~self:host in
19661967
if Pool_role.is_master () then
19671968
raise Cannot_eject_master
19681969
else (* Fail the operation if any VMs are running here (except dom0) *)
@@ -2093,6 +2094,8 @@ let eject_self ~__context ~host =
20932094
pif.API.pIF_ipv6_configuration_mode
20942095
|> String.uncapitalize_ascii
20952096
in
2097+
Localdb.put "last_update_hash" last_update_hash ;
2098+
debug "Saved last_update_hash %S to localdb." last_update_hash ;
20962099
let write_first_boot_management_interface_configuration_file () =
20972100
(* During firstboot, now inventory has an empty MANAGEMENT_INTERFACE *)
20982101
let bridge = "" in
@@ -3705,8 +3708,16 @@ let set_repositories ~__context ~self ~value =
37053708
)
37063709
value ;
37073710
Db.Pool.set_repositories ~__context ~self ~value ;
3708-
if Db.Pool.get_repositories ~__context ~self = [] then
3711+
if Db.Pool.get_repositories ~__context ~self = [] then (
37093712
Db.Pool.set_last_update_sync ~__context ~self ~value:Date.epoch ;
3713+
(* The host.latest_synced_updates_applied can't be refreshed by
3714+
pool.sync_updates. So reset it here. *)
3715+
Db.Host.get_all ~__context
3716+
|> List.iter (fun h ->
3717+
Db.Host.set_latest_synced_updates_applied ~__context ~self:h
3718+
~value:`unknown
3719+
)
3720+
) ;
37103721
disable_unsupported_periodic_sync_updates ~__context ~self ~repos:value
37113722

37123723
let add_repository ~__context ~self ~value =

0 commit comments

Comments
 (0)