Skip to content

Commit 57eba37

Browse files
committed
CA-405643: Update DNF to DNF5
dnf has been updated to dnf5 during clean rebuild event for XS9, The command line interface changed and we need to update accordingly https://dnf5.readthedocs.io/en/latest/changes_from_dnf4.7.html Following commands update are necessary for DNF5 update - updateinfo -> advisory - config-manager "--save --setopt" -> "setopt" - reposync removed "--downloadcomps" as it is the default behavior - repoquery format output no longer has line breaker, add `\n` in format argument to bring it back and align with YUM - repoquery drop "-a" option as it is default behavior Also improve the code with strong type checking - Available|Updates for two kinds of updateinfo instead of string Signed-off-by: Lin Liu <[email protected]>
1 parent abd993a commit 57eba37

File tree

5 files changed

+161
-122
lines changed

5 files changed

+161
-122
lines changed

ocaml/tests/test_pkg_mgr.ml

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ let test_dnf_repo_query_installed =
2020
; params=
2121
[
2222
"repoquery"
23-
; "-a"
2423
; "--qf"
25-
; "%{name}:|%{epoch}:|%{version}:|%{release}:|%{arch}:|%{repoid}"
24+
; "%{name}:|%{epoch}:|%{version}:|%{release}:|%{arch}:|%{repoid}\n"
2625
; "--installed"
2726
]
2827
}
@@ -40,11 +39,10 @@ let test_dnf_repo_query_updates =
4039
; params=
4140
[
4241
"repoquery"
43-
; "-a"
4442
; "--disablerepo=*"
4543
; "--enablerepo=testrepo1,testrepo2"
4644
; "--qf"
47-
; "%{name}:|%{epoch}:|%{version}:|%{release}:|%{arch}:|%{repoid}"
45+
; "%{name}:|%{epoch}:|%{version}:|%{release}:|%{arch}:|%{repoid}\n"
4846
; "--upgrades"
4947
]
5048
}
@@ -78,7 +76,6 @@ let test_dnf_clean_repo_cache =
7876
]
7977

8078
let test_dnf_get_pkgs_from_updateinfo =
81-
let sub_command = "upgrades" in
8279
let repositories = ["testrepo1"; "testrepo2"] in
8380
[
8481
( "<null>"
@@ -91,17 +88,19 @@ let test_dnf_get_pkgs_from_updateinfo =
9188
"-q"
9289
; "--disablerepo=*"
9390
; "--enablerepo=testrepo1,testrepo2"
94-
; "updateinfo"
91+
; "advisory"
9592
; "list"
96-
; "upgrades"
93+
; "--updates"
9794
]
9895
}
99-
(Pkg_mgr.Dnf_cmd.get_pkgs_from_updateinfo ~sub_command ~repositories)
96+
(Pkg_mgr.Dnf_cmd.get_pkgs_from_updateinfo Pkg_mgr.Updateinfo.Updates
97+
~repositories
98+
)
10099
)
101100
]
102101

103102
let test_dnf_config_repo =
104-
let config = ["--setopt=testrepo.accesstoken=file:///some/path"] in
103+
let config = ["accesstoken=file:///some/path"] in
105104
[
106105
( "<null>"
107106
, `Quick
@@ -111,8 +110,8 @@ let test_dnf_config_repo =
111110
; params=
112111
[
113112
"config-manager"
114-
; "--setopt=testrepo.accesstoken=file:///some/path"
115-
; "testrepo"
113+
; "setopt"
114+
; "testrepo.accesstoken=file:///some/path"
116115
]
117116
}
118117
(Pkg_mgr.Dnf_cmd.config_repo ~repo_name:"testrepo" ~config)
@@ -131,7 +130,6 @@ let test_dnf_sync_repo =
131130
"reposync"
132131
; "-p"
133132
; !Xapi_globs.local_pool_repo_dir
134-
; "--downloadcomps"
135133
; "--download-metadata"
136134
; "--delete"
137135
; "--newest-only"
@@ -170,7 +168,7 @@ let test_yum_repo_query_installed =
170168
cmd= !Xapi_globs.repoquery_cmd
171169
; params=
172170
[
173-
"-a"
171+
"--all"
174172
; "--pkgnarrow=installed"
175173
; "--qf"
176174
; "%{name}:|%{epoch}:|%{version}:|%{release}:|%{arch}:|%{repoid}"
@@ -204,7 +202,6 @@ let test_yum_clean_repo_cache =
204202
]
205203

206204
let test_yum_get_pkgs_from_updateinfo =
207-
let sub_command = "updates" in
208205
let repositories = ["testrepo1"; "testrepo2"] in
209206
[
210207
( "<null>"
@@ -222,20 +219,26 @@ let test_yum_get_pkgs_from_updateinfo =
222219
; "updates"
223220
]
224221
}
225-
(Pkg_mgr.Yum_cmd.get_pkgs_from_updateinfo ~sub_command ~repositories)
222+
(Pkg_mgr.Yum_cmd.get_pkgs_from_updateinfo Pkg_mgr.Updateinfo.Updates
223+
~repositories
224+
)
226225
)
227226
]
228227

229228
let test_yum_config_repo =
230-
let config = ["--setopt=testrepo.accesstoken=file:///some/path"] in
229+
let config = ["accesstoken=file:///some/path"] in
231230
[
232231
( "<null>"
233232
, `Quick
234233
, check
235234
{
236235
cmd= !Xapi_globs.yum_config_manager_cmd
237236
; params=
238-
["--setopt=testrepo.accesstoken=file:///some/path"; "testrepo"]
237+
[
238+
"--save"
239+
; "--setopt=testrepo.accesstoken=file:///some/path"
240+
; "testrepo"
241+
]
239242
}
240243
(Pkg_mgr.Yum_cmd.config_repo ~repo_name:"testrepo" ~config)
241244
)
@@ -252,11 +255,11 @@ let test_yum_sync_repo =
252255
[
253256
"-p"
254257
; !Xapi_globs.local_pool_repo_dir
255-
; "--downloadcomps"
256258
; "--download-metadata"
257259
; "--delete"
258260
; "--newest-only"
259261
; "--repoid=testrepo"
262+
; "--downloadcomps"
260263
; "--plugins"
261264
]
262265
}
@@ -292,11 +295,11 @@ let test_yum_repo_query_updates =
292295
cmd= !Xapi_globs.repoquery_cmd
293296
; params=
294297
[
295-
"-a"
296-
; "--disablerepo=*"
298+
"--disablerepo=*"
297299
; "--enablerepo=testrepo1,testrepo2"
298300
; "--qf"
299301
; "%{name}:|%{epoch}:|%{version}:|%{release}:|%{arch}:|%{repoid}"
302+
; "--all"
300303
; "--pkgnarrow updates"
301304
; "--plugins"
302305
]

ocaml/xapi/pkg_mgr.ml

Lines changed: 61 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ type mgr = Yum | Dnf
1616

1717
type cmd_line = {cmd: string; params: string list}
1818

19+
module Updateinfo = struct
20+
type t = Available | Updates
21+
22+
let to_string = function Available -> "available" | Updates -> "updates"
23+
end
24+
1925
let active () =
2026
match Sys.file_exists !Xapi_globs.dnf_cmd with true -> Dnf | false -> Yum
2127

@@ -27,7 +33,7 @@ module type S = sig
2733
val clean_cache : repo_name:string -> cmd_line
2834

2935
val get_pkgs_from_updateinfo :
30-
sub_command:string -> repositories:string list -> cmd_line
36+
Updateinfo.t -> repositories:string list -> cmd_line
3137

3238
val get_updates_from_upgrade_dry_run : repositories:string list -> cmd_line
3339

@@ -61,7 +67,7 @@ module type Args = sig
6167

6268
val clean_cache : string -> string list
6369

64-
val get_pkgs_from_updateinfo : string -> string list -> string list
70+
val get_pkgs_from_updateinfo : Updateinfo.t -> string list -> string list
6571

6672
val get_updates_from_upgrade_dry_run : string list -> string list
6773

@@ -84,12 +90,12 @@ end
8490

8591
let repoquery_sep = ":|"
8692

87-
let fmt =
88-
["name"; "epoch"; "version"; "release"; "arch"; "repoid"]
89-
|> List.map (fun field -> Printf.sprintf "%%{%s}" field) (* %{field} *)
90-
|> String.concat repoquery_sep
91-
9293
module Common_args = struct
94+
let fmt =
95+
["name"; "epoch"; "version"; "release"; "arch"; "repoid"]
96+
|> List.map (fun field -> Printf.sprintf "%%{%s}" field) (* %{field} *)
97+
|> String.concat repoquery_sep
98+
9399
let clean_cache = function
94100
| "*" ->
95101
["clean"; "all"]
@@ -101,20 +107,9 @@ module Common_args = struct
101107
; "all"
102108
]
103109

104-
let get_pkgs_from_updateinfo sub_command repositories =
105-
[
106-
"-q"
107-
; "--disablerepo=*"
108-
; Printf.sprintf "--enablerepo=%s" (String.concat "," repositories)
109-
; "updateinfo"
110-
; "list"
111-
; sub_command
112-
]
113-
114110
let is_obsoleted pkg_name repositories =
115111
[
116-
"-a"
117-
; "--disablerepo=*"
112+
"--disablerepo=*"
118113
; Printf.sprintf "--enablerepo=%s" (String.concat "," repositories)
119114
; "--whatobsoletes"
120115
; pkg_name
@@ -132,14 +127,14 @@ module Common_args = struct
132127

133128
let repoquery repositories =
134129
[
135-
"-a"
136-
; "--disablerepo=*"
130+
"--disablerepo=*"
137131
; Printf.sprintf "--enablerepo=%s" (String.concat "," repositories)
138-
; "--qf"
139-
; fmt
140132
]
141133

142-
let config_repo repo_name config = config @ [repo_name]
134+
let config_repo repo_name config =
135+
(* Add --setopt to repo options *)
136+
List.map (fun x -> Printf.sprintf "--setopt=%s.%s" repo_name x) config
137+
|> fun x -> ["--save"] @ x @ [repo_name]
143138

144139
let make_cache repo_name =
145140
[
@@ -153,7 +148,6 @@ module Common_args = struct
153148
[
154149
"-p"
155150
; !Xapi_globs.local_pool_repo_dir
156-
; "--downloadcomps"
157151
; "--download-metadata"
158152
; "--delete"
159153
; "--newest-only"
@@ -172,7 +166,7 @@ end
172166
module Yum_args : Args = struct
173167
include Common_args
174168

175-
let repoquery_installed () = ["-a"; "--pkgnarrow=installed"; "--qf"; fmt]
169+
let repoquery_installed () = ["--all"; "--pkgnarrow=installed"; "--qf"; fmt]
176170

177171
let pkg_cmd = !Xapi_globs.yum_cmd
178172

@@ -186,21 +180,35 @@ module Yum_args : Args = struct
186180
["--quiet"] @ Common_args.get_updates_from_upgrade_dry_run repositories
187181

188182
let is_obsoleted pkg_name repositories =
189-
Common_args.is_obsoleted pkg_name repositories @ ["--plugins"]
183+
["--all"] @ Common_args.is_obsoleted pkg_name repositories @ ["--plugins"]
190184

191185
let repoquery_available repositories =
192186
Common_args.repoquery repositories
193-
@ ["--pkgnarrow"; "available"; "--plugins"]
187+
@ ["--qf"; fmt; "--all"; "--pkgnarrow"; "available"; "--plugins"]
194188

195189
let repoquery_updates repositories =
196-
Common_args.repoquery repositories @ ["--pkgnarrow"; "updates"; "--plugins"]
190+
Common_args.repoquery repositories
191+
@ ["--qf"; fmt; "--all"; "--pkgnarrow"; "updates"; "--plugins"]
197192

198-
let sync_repo repo_name = Common_args.sync_repo repo_name @ ["--plugins"]
193+
let sync_repo repo_name =
194+
Common_args.sync_repo repo_name @ ["--downloadcomps"; "--plugins"]
199195

200196
let get_repo_config repo_name = [repo_name]
197+
198+
let get_pkgs_from_updateinfo updateinfo repositories =
199+
[
200+
"-q"
201+
; "--disablerepo=*"
202+
; Printf.sprintf "--enablerepo=%s" (String.concat "," repositories)
203+
; "updateinfo"
204+
; "list"
205+
; Updateinfo.to_string updateinfo
206+
]
201207
end
202208

203209
module Dnf_args : Args = struct
210+
include Common_args
211+
204212
let pkg_cmd = !Xapi_globs.dnf_cmd
205213

206214
let repoquery_cmd = !Xapi_globs.dnf_cmd
@@ -209,6 +217,9 @@ module Dnf_args : Args = struct
209217

210218
let reposync_cmd = !Xapi_globs.dnf_cmd
211219

220+
(* dnf5 removed ending line breaker, we need to add it back *)
221+
let fmt = Printf.sprintf "%s\n" Common_args.fmt
222+
212223
type sub_cmd = Repoquery | Repoconfig | Reposync
213224

214225
let sub_cmd_to_string = function
@@ -221,29 +232,39 @@ module Dnf_args : Args = struct
221232

222233
let add_sub_cmd sub_cmd params = [sub_cmd_to_string sub_cmd] @ params
223234

224-
include Common_args
225-
226235
let repoquery_installed () =
227-
["-a"; "--qf"; fmt; "--installed"] |> add_sub_cmd Repoquery
236+
["--qf"; fmt; "--installed"] |> add_sub_cmd Repoquery
237+
238+
let config_repo repo_name config =
239+
config |> List.map (fun x -> Printf.sprintf "%s.%s" repo_name x) |> fun x ->
240+
["setopt"] @ x |> add_sub_cmd Repoconfig
228241

229242
let is_obsoleted pkg_name repositories =
230243
Common_args.is_obsoleted pkg_name repositories |> add_sub_cmd Repoquery
231244

232245
let repoquery_available repositories =
233-
Common_args.repoquery repositories @ ["--available"]
246+
Common_args.repoquery repositories @ ["--qf"; fmt; "--available"]
234247
|> add_sub_cmd Repoquery
235248

236249
let repoquery_updates repositories =
237-
Common_args.repoquery repositories @ ["--upgrades"] |> add_sub_cmd Repoquery
238-
239-
let config_repo repo_name config =
240-
Common_args.config_repo repo_name config |> add_sub_cmd Repoconfig
250+
Common_args.repoquery repositories @ ["--qf"; fmt; "--upgrades"]
251+
|> add_sub_cmd Repoquery
241252

242253
let sync_repo repo_name =
243254
Common_args.sync_repo repo_name |> add_sub_cmd Reposync
244255

245256
let get_repo_config repo_name =
246257
["--dump"; repo_name] |> add_sub_cmd Repoconfig
258+
259+
let get_pkgs_from_updateinfo updateinfo repositories =
260+
[
261+
"-q"
262+
; "--disablerepo=*"
263+
; Printf.sprintf "--enablerepo=%s" (String.concat "," repositories)
264+
; "advisory"
265+
; "list"
266+
; (updateinfo |> Updateinfo.to_string |> fun x -> Printf.sprintf "--%s" x)
267+
]
247268
end
248269

249270
module Cmd_line (M : Args) : S = struct
@@ -256,11 +277,8 @@ module Cmd_line (M : Args) : S = struct
256277

257278
let clean_cache ~repo_name = {cmd= M.pkg_cmd; params= M.clean_cache repo_name}
258279

259-
let get_pkgs_from_updateinfo ~sub_command ~repositories =
260-
{
261-
cmd= M.pkg_cmd
262-
; params= M.get_pkgs_from_updateinfo sub_command repositories
263-
}
280+
let get_pkgs_from_updateinfo updateinfo ~repositories =
281+
{cmd= M.pkg_cmd; params= M.get_pkgs_from_updateinfo updateinfo repositories}
264282

265283
let get_updates_from_upgrade_dry_run ~repositories =
266284
{cmd= M.pkg_cmd; params= M.get_updates_from_upgrade_dry_run repositories}

ocaml/xapi/pkg_mgr.mli

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ type mgr = Yum | Dnf
1818

1919
type cmd_line = {cmd: string; params: string list}
2020

21+
module Updateinfo : sig
22+
type t = Available | Updates
23+
24+
val to_string : t -> string
25+
end
26+
2127
(** Interfaces to build command line and params for the package manager *)
2228
module type S = sig
2329
val manager : mgr
@@ -29,7 +35,7 @@ module type S = sig
2935
(** Command line and arguments to clean a repo cache *)
3036

3137
val get_pkgs_from_updateinfo :
32-
sub_command:string -> repositories:string list -> cmd_line
38+
Updateinfo.t -> repositories:string list -> cmd_line
3339
(** Command line and arguments to get packages from updateinfo *)
3440

3541
val get_updates_from_upgrade_dry_run : repositories:string list -> cmd_line

0 commit comments

Comments
 (0)