Skip to content

Commit 6c7d41b

Browse files
committed
CA-423064: Also check group upgrade when determining updates available
Signed-off-by: Alex Brett <[email protected]>
1 parent 01c9a6d commit 6c7d41b

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

ocaml/xapi/pkg_mgr.ml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ module type S = sig
3737

3838
val get_updates_from_upgrade_dry_run : repositories:string list -> cmd_line
3939

40+
val get_updates_from_group_upgrade_dry_run : repositories:string list -> cmd_line
41+
4042
val is_obsoleted : pkg_name:string -> repositories:string list -> cmd_line
4143

4244
val repoquery_updates : repositories:string list -> cmd_line
@@ -73,6 +75,8 @@ module type Args = sig
7375

7476
val get_updates_from_upgrade_dry_run : string list -> string list
7577

78+
val get_updates_from_group_upgrade_dry_run : string list -> string list
79+
7680
val is_obsoleted : string -> string list -> string list
7781

7882
val repoquery_updates : string list -> string list
@@ -129,6 +133,16 @@ module Common_args = struct
129133
; "upgrade"
130134
]
131135

136+
let get_updates_from_group_upgrade_dry_run repositories =
137+
[
138+
"--disablerepo=*"
139+
; Printf.sprintf "--enablerepo=%s" (String.concat "," repositories)
140+
; "--assumeno"
141+
; "group"
142+
; "upgrade"
143+
; "*"
144+
]
145+
132146
let repoquery repositories =
133147
[
134148
"--disablerepo=*"
@@ -193,6 +207,9 @@ module Yum_args : Args = struct
193207
let get_updates_from_upgrade_dry_run repositories =
194208
["--quiet"] @ Common_args.get_updates_from_upgrade_dry_run repositories
195209

210+
let get_updates_from_group_upgrade_dry_run repositories =
211+
["--quiet"] @ Common_args.get_updates_from_group_upgrade_dry_run repositories
212+
196213
let is_obsoleted pkg_name repositories =
197214
["--all"] @ Common_args.is_obsoleted pkg_name repositories @ ["--plugins"]
198215

@@ -297,6 +314,9 @@ module Cmd_line (M : Args) : S = struct
297314
let get_updates_from_upgrade_dry_run ~repositories =
298315
{cmd= M.pkg_cmd; params= M.get_updates_from_upgrade_dry_run repositories}
299316

317+
let get_updates_from_group_upgrade_dry_run ~repositories =
318+
{cmd= M.pkg_cmd; params= M.get_updates_from_group_upgrade_dry_run repositories}
319+
300320
let is_obsoleted ~pkg_name ~repositories =
301321
{cmd= M.repoquery_cmd; params= M.is_obsoleted pkg_name repositories}
302322

ocaml/xapi/pkg_mgr.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ module type S = sig
4141
val get_updates_from_upgrade_dry_run : repositories:string list -> cmd_line
4242
(** Command line and arguments to dry run an upgrade, with repositories enabled *)
4343

44+
val get_updates_from_group_upgrade_dry_run : repositories:string list -> cmd_line
45+
(** Command line and arguments to dry run a group upgrade, with repositories enabled *)
46+
4447
val is_obsoleted : pkg_name:string -> repositories:string list -> cmd_line
4548
(** Command line and arguments to check whether a package is obsoleted by any other
4649
* package in given repositories *)

ocaml/xapi/repository.ml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,20 @@ let get_host_updates_in_json ~__context ~installed =
558558
let latest_updates' =
559559
get_updates_from_yum_upgrade_dry_run repositories
560560
in
561+
let latest_updates_group' =
562+
get_updates_from_yum_group_upgrade_dry_run repositories
563+
in
564+
let latest_updates_combined' =
565+
match (latest_updates', latest_updates_group') with
566+
| Some pkgs', Some group_pkgs' ->
567+
Some (List.sort_uniq compare (pkgs' @ group_pkgs'))
568+
| Some pkgs', None ->
569+
Some pkgs'
570+
| None, Some group_pkgs' ->
571+
Some group_pkgs'
572+
| None, None ->
573+
None
574+
in
561575
let latest_updates'' = get_updates_from_repoquery repositories in
562576
(* To ensure the updating function will not strand, use redundant
563577
* functions to get the update/installation list.
@@ -569,7 +583,7 @@ let get_host_updates_in_json ~__context ~installed =
569583
let fail_on_error = Xapi_fist.fail_on_error_in_yum_upgrade_dry_run () in
570584
let latest_updates =
571585
get_latest_updates_from_redundancy ~fail_on_error
572-
~pkgs:latest_updates' ~fallback_pkgs:latest_updates''
586+
~pkgs:latest_updates_combined' ~fallback_pkgs:latest_updates''
573587
in
574588
List.iter (fun r -> clean_yum_cache r) repositories ;
575589
let latest_updates_in_json =

ocaml/xapi/repository_helpers.ml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,8 +771,10 @@ module YumUpgradeOutput = struct
771771
| false -> (
772772
take_till is_eol <* end_of_line >>= function
773773
| ( "Installing:"
774+
| "Installing group/module packages:"
774775
| "Updating:"
775776
| "Upgrading:"
777+
| "Upgrading groups:"
776778
| "Removing:"
777779
| "Reinstalling:"
778780
| "Downgrading:"
@@ -890,6 +892,7 @@ module YumUpgradeOutput = struct
890892
|> List.filter (fun (section, _) ->
891893
match section with
892894
| "Installing:"
895+
| "Installing group/module packages:"
893896
| "Updating:"
894897
| "Upgrading:"
895898
| "Installing for dependencies:"
@@ -958,6 +961,31 @@ let get_updates_from_yum_upgrade_dry_run repositories =
958961
error "%s" (ExnHelper.string_of_exn e) ;
959962
None
960963

964+
let get_updates_from_yum_group_upgrade_dry_run repositories =
965+
let Pkg_mgr.{cmd; params} =
966+
Pkgs.get_updates_from_group_upgrade_dry_run ~repositories
967+
in
968+
match Forkhelpers.execute_command_get_output cmd params with
969+
| _, _ ->
970+
Some []
971+
| exception Forkhelpers.Spawn_internal_error (stderr, stdout, Unix.WEXITED 1)
972+
-> (
973+
(*Yum put the details to stderr while dnf to stdout*)
974+
(match Pkgs.manager with Yum -> stderr | Dnf -> stdout)
975+
|> YumUpgradeOutput.parse_output_of_dry_run
976+
|> function
977+
| Ok (pkgs, Some txn_file) ->
978+
Unixext.unlink_safe txn_file ;
979+
Some pkgs
980+
| Ok (pkgs, None) ->
981+
Some pkgs
982+
| Error msg ->
983+
error "%s" msg ; None
984+
)
985+
| exception e ->
986+
error "%s" (ExnHelper.string_of_exn e) ;
987+
None
988+
961989
let get_latest_updates_from_redundancy ~fail_on_error ~pkgs ~fallback_pkgs =
962990
let err = "Failed to parse output of 'yum upgrade (dry run)' correctly" in
963991
let get_latest_updates_from_redundancy' ~fail_on_error ~pkgs ~fallback_pkgs =

0 commit comments

Comments
 (0)