From 7e34b3ae41e10180a52b622136dcfa8d2f7f8418 Mon Sep 17 00:00:00 2001 From: Ming Lu Date: Thu, 26 Sep 2024 15:54:25 +0800 Subject: [PATCH 1/2] CA-399638: The livepatches are absent in the response of /updates When applying livepatches, for one component, only the latest one will be applied. This is because the latest livepatch will always roll up all the previous ones if they are of the same component and base build ID. The bug to be fixed in this commit is that the previous livepatches with the same build ID are not returned in the response of the query on the /updates HTTP endpoint. Signed-off-by: Ming Lu --- ocaml/xapi/repository_helpers.ml | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/ocaml/xapi/repository_helpers.ml b/ocaml/xapi/repository_helpers.ml index 8a184e52f4c..51699612739 100644 --- a/ocaml/xapi/repository_helpers.ml +++ b/ocaml/xapi/repository_helpers.ml @@ -1298,12 +1298,22 @@ let with_access_token ~token ~token_id f = let msg = Printf.sprintf "%s: The token or token_id is empty" __LOC__ in raise Api_errors.(Server_error (internal_error, [msg])) -let prune_updateinfo_for_livepatches livepatches updateinfo = - let open UpdateInfo in - let lps = - List.filter (fun x -> LivePatchSet.mem x livepatches) updateinfo.livepatches +let prune_updateinfo_for_livepatches latest_lps updateinfo = + let livepatches = + let open LivePatch in + (* Keep a livepatch if it is rolled up by one of the latest livepatches. + * The latest livepatches are the ones to be applied actually. + *) + updateinfo.UpdateInfo.livepatches + |> List.filter (fun lp -> + let is_rolled_up_by latest = + latest.component = lp.component + && latest.base_build_id = lp.base_build_id + in + LivePatchSet.exists is_rolled_up_by latest_lps + ) in - {updateinfo with livepatches= lps} + {updateinfo with livepatches} let do_with_host_pending_guidances ~op guidances = List.iter From 9db858a13257b4b19b37bfc0a09276909f8a77a2 Mon Sep 17 00:00:00 2001 From: Ming Lu Date: Thu, 26 Sep 2024 19:04:29 +0800 Subject: [PATCH 2/2] CA-399638: Add unit tests Signed-off-by: Ming Lu --- ocaml/tests/test_repository_helpers.ml | 30 +++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/ocaml/tests/test_repository_helpers.ml b/ocaml/tests/test_repository_helpers.ml index dbb5b7f1a42..775c7635665 100644 --- a/ocaml/tests/test_repository_helpers.ml +++ b/ocaml/tests/test_repository_helpers.ml @@ -3881,7 +3881,29 @@ module PruneUpdateInfoForLivepatches = Generic.MakeStateless (struct ; base_build_id= "2cc28689364587682593b6a72e2a586d29996bb9" ; base_version= "4.19.19" ; base_release= "8.0.20.xs8" - ; to_version= "4.13.4" + ; to_version= "4.19.19" + ; to_release= "8.0.21.xs8" + } + + let lp2 = + LivePatch. + { + component= Livepatch.Kernel + ; base_build_id= "2cc28689364587682593b6a72e2a586d29996bb9" + ; base_version= "4.19.19" + ; base_release= "8.0.20.xs8" + ; to_version= "4.19.20" + ; to_release= "8.0.21.xs8" + } + + let lp3 = + LivePatch. + { + component= Livepatch.Kernel + ; base_build_id= "4cc28689364587682593b6a72e2a586d29996bb9" + ; base_version= "4.19.20" + ; base_release= "7.0.20.xs8" + ; to_version= "4.13.5" ; to_release= "8.0.21.xs8" } @@ -3915,6 +3937,12 @@ module PruneUpdateInfoForLivepatches = Generic.MakeStateless (struct ; ( ([], {updateinfo with livepatches= [lp0; lp1]}) , {updateinfo with livepatches= []} ) + ; ( ([lp0; lp2], {updateinfo with livepatches= [lp0; lp1; lp2; lp3]}) + , {updateinfo with livepatches= [lp0; lp1; lp2]} + ) + ; ( ([lp0], {updateinfo with livepatches= [lp0; lp1; lp2; lp3]}) + , {updateinfo with livepatches= [lp0]} + ) ] end)