From 164697a299c34e855f1c6cae0511adbfd8d46a79 Mon Sep 17 00:00:00 2001 From: Vincent Liu Date: Tue, 5 Nov 2024 18:09:01 +0000 Subject: [PATCH] fixup! CA-400060: Sm feature intersection --- ocaml/xapi/xapi_sm.ml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ocaml/xapi/xapi_sm.ml b/ocaml/xapi/xapi_sm.ml index 163a3fa615..9badc179c0 100644 --- a/ocaml/xapi/xapi_sm.ml +++ b/ocaml/xapi/xapi_sm.ml @@ -54,7 +54,9 @@ let create_from_query_result ~__context q = let find_pending_features existing_features features = Listext.List.set_difference features existing_features -let update_pending_hosts_features ~__context self new_features = +(** [addto_pending_hosts_features ~__context self new_features] will add [new_features] +to pending features of host [self]. It then returns a list of currently pending features *) +let addto_pending_hosts_features ~__context self new_features = let host = Helpers.get_localhost ~__context in let new_features = List.map (fun (f, v) -> Smint.unparse_feature (f, v)) new_features @@ -88,6 +90,16 @@ let valid_hosts_pending_features ~__context pending_features = (List.nth_opt l 0 |> Option.fold ~none:[] ~some:Fun.id) (List.tl l) +let remove_valid_features_from_pending ~__context ~self valid_features = + let valid_features = List.map Smint.unparse_feature valid_features in + let new_pending_feature = + Db.SM.get_host_pending_features ~__context ~self + |> List.map (fun (h, pending_features) -> + (h, Listext.List.set_difference pending_features valid_features) + ) + in + Db.SM.set_host_pending_features ~__context ~self ~value:new_pending_feature + let update_from_query_result ~__context (self, r) q_result = let open Storage_interface in let _type = String.lowercase_ascii q_result.driver in @@ -97,9 +109,10 @@ let update_from_query_result ~__context (self, r) q_result = let new_features = Smint.parse_string_int64_features q_result.features |> find_pending_features existing_features - |> update_pending_hosts_features ~__context self + |> addto_pending_hosts_features ~__context self |> valid_hosts_pending_features ~__context in + remove_valid_features_from_pending ~__context ~self new_features ; let features = existing_features @ new_features in List.iter (fun (f, v) -> debug "%s: declaring new features %s:%Ld" __FUNCTION__ f v)