From c5c8f9d4db93d34366209185137a6d8203e8735c Mon Sep 17 00:00:00 2001 From: Matej Marusak Date: Tue, 20 Jul 2021 12:24:02 +0200 Subject: [PATCH 1/2] kpatch: Add subcommand to only install patches This command is very similar to `auto` but it does not subscribe to patches for future kernels. --- kpatch.py | 6 ++++-- man/dnf.kpatch.8 | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/kpatch.py b/kpatch.py index f3891cd..96bfd70 100644 --- a/kpatch.py +++ b/kpatch.py @@ -76,14 +76,14 @@ def __init__(self, cli): @staticmethod def set_argparser(parser): - parser.add_argument('action', metavar="auto|manual|status") + parser.add_argument('action', metavar="auto|manual|install|status") def configure(self): demands = self.cli.demands demands.root_user = True - if self.opts.action == "auto": + if self.opts.action in ["auto", "install"]: demands.resolving = True demands.sack_activation = True demands.available_repos = True @@ -148,6 +148,8 @@ def run(self): conf.getboolean('main', KPATCH_UPDATE_OPT)): kp_status = "auto" logger.info(_("kpatch update setting: {}").format(kp_status)) + elif action == "install": + self._install_missing_kpp_pkgs() else: raise dnf.exceptions.Error(_("Invalid argument: {}").format(action)) diff --git a/man/dnf.kpatch.8 b/man/dnf.kpatch.8 index 8ae5b84..8cd1933 100644 --- a/man/dnf.kpatch.8 +++ b/man/dnf.kpatch.8 @@ -25,6 +25,9 @@ automatic kpatch\-patch installation for future kernel installations. .B manual Disables automatic installation of kpatch-patch packages. .TP +.B install +Installs missing kpatch\-patch packages for installed kernels. +.TP .B status Queries the current installation setting of \fBdnf\-kpatch\fR. .RE From a5d30ac6241501af471c1ff935f31118489fdf31 Mon Sep 17 00:00:00 2001 From: Matej Marusak Date: Tue, 20 Jul 2021 13:38:39 +0200 Subject: [PATCH 2/2] kpatch: Show available patches in `status` --- kpatch.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/kpatch.py b/kpatch.py index 96bfd70..2fd9005 100644 --- a/kpatch.py +++ b/kpatch.py @@ -83,7 +83,7 @@ def configure(self): demands = self.cli.demands demands.root_user = True - if self.opts.action in ["auto", "install"]: + if self.opts.action in ["auto", "install", "status"]: demands.resolving = True demands.sack_activation = True demands.available_repos = True @@ -93,6 +93,26 @@ def configure(self): demands.available_repos = False + def _list_missing_kpp_pkgs(self): + kpps = [] + + installed_kernels = self.base.sack.query().installed().filter(name=KERNEL_PKG_NAME) + + for kernel_pkg in installed_kernels: + kpp_pkg_name = _kpp_name_from_kernel_pkg(kernel_pkg) + installed = self.base.sack.query().installed().filter(name=kpp_pkg_name).run() + if installed: + sub_q = self.base.sack.query().filter(name=kpp_pkg_name, release=installed[0].release, version=installed[0].version) + kpp_pkgs_query = self.base.sack.query().filter(name=kpp_pkg_name, arch=kernel_pkg.arch).latest().difference(sub_q) + else: + kpp_pkgs_query = self.base.sack.query().filter(name=kpp_pkg_name, arch=kernel_pkg.arch).latest() + + for pkg in kpp_pkgs_query: + kpps.append(str(pkg)) + + return kpps + + def _install_missing_kpp_pkgs(self): installed_kernels = self.base.sack.query().installed().filter(name=KERNEL_PKG_NAME) @@ -147,7 +167,12 @@ def run(self): conf.has_option('main', KPATCH_UPDATE_OPT) and conf.getboolean('main', KPATCH_UPDATE_OPT)): kp_status = "auto" - logger.info(_("kpatch update setting: {}").format(kp_status)) + logger.info(_("Kpatch update setting: {}").format(kp_status)) + + kpps = self._list_missing_kpp_pkgs() + if kpps: + logger.info(_("Available patches: {}").format(", ".join(kpps))) + elif action == "install": self._install_missing_kpp_pkgs() else: @@ -194,8 +219,8 @@ def resolved(self): explicit_kpp_install = [] for tr_item in self.base.transaction: # It might not be safe to check tr_item.pkg.name as there might be - # some dnf internal transaction items not linked to any pacakge. - # Check first whether the action is a pacakge related action + # some dnf internal transaction items not linked to any package. + # Check first whether the action is a package related action if tr_item.action in dnf.transaction.FORWARD_ACTIONS: if tr_item.pkg.name == KERNEL_PKG_NAME: need_kpp_for.append(tr_item.pkg)