104 lines
3.6 KiB
Diff
104 lines
3.6 KiB
Diff
From 1ce1c474dcbd3c4f8285f595e6a9071c81f88396 Mon Sep 17 00:00:00 2001
|
|
From: gongzt <gong_zhengtang@163.com>
|
|
Date: Fri, 2 Jun 2023 15:56:03 +0800
|
|
Subject: [PATCH 1/1] Add dnf full repair
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
---
|
|
hotpatch/hotupgrade.py | 57 +++++++++++++++++++++++++++++++++++++++---
|
|
1 file changed, 53 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/hotpatch/hotupgrade.py b/hotpatch/hotupgrade.py
|
|
index 4f6a6fb..6adafda 100644
|
|
--- a/hotpatch/hotupgrade.py
|
|
+++ b/hotpatch/hotupgrade.py
|
|
@@ -20,9 +20,11 @@ from dnf.cli.option_parser import OptionParser
|
|
from dnf.cli.output import Output
|
|
from dnfpluginscore import _, logger
|
|
|
|
-from .syscare import Syscare
|
|
+from .syscare import Syscare, cmd_output, SUCCEED
|
|
from .hotpatch_updateinfo import HotpatchUpdateInfo
|
|
|
|
+EMPTY_TAG = "-"
|
|
+
|
|
|
|
@dnf.plugin.register_command
|
|
class HotupgradeCommand(dnf.cli.Command):
|
|
@@ -61,7 +63,8 @@ class HotupgradeCommand(dnf.cli.Command):
|
|
advisory_pkgs = self.get_hotpatch_based_on_advisory(self.opts.advisory)
|
|
self.hp_list = cve_pkgs + advisory_pkgs
|
|
else:
|
|
- raise dnf.exceptions.Error(_('No qualified rpm package name or cve/advisory id.'))
|
|
+ self.hp_list = self.upgrade_all()
|
|
+ logger.info(_("Gonna apply these hot patches:%s"), self.hp_list)
|
|
|
|
hp_target_map = self._get_available_hotpatches(self.hp_list)
|
|
if not hp_target_map:
|
|
@@ -177,8 +180,8 @@ class HotupgradeCommand(dnf.cli.Command):
|
|
def _remove_hot_patches(self, target_patch_map: dict) -> None:
|
|
output = Output(self.base, dnf.conf.Conf())
|
|
logger.info(_("Gonna remove these hot patches: %s"), list(target_patch_map.values()))
|
|
- #remove_flag = output.userconfirm()
|
|
- #if not remove_flag:
|
|
+ # remove_flag = output.userconfirm()
|
|
+ # if not remove_flag:
|
|
# raise dnf.exceptions.Error(_('Operation aborted.'))
|
|
|
|
self.syscare.save()
|
|
@@ -266,3 +269,49 @@ class HotupgradeCommand(dnf.cli.Command):
|
|
for hp in advisory_hp_dict.values():
|
|
hp_list += hp
|
|
return list(set(hp_list))
|
|
+
|
|
+ @staticmethod
|
|
+ def get_hot_updateinfo_list():
|
|
+ """
|
|
+ Find all hotpatches and upgrade all
|
|
+ use command : dnf hot-updateinfo list cves
|
|
+ Last metadata expiration check: 0:48:26 ago on 2023年06月01日 星期四 20时29分55秒.
|
|
+ CVE-2023-3332 Low/Sec. - -
|
|
+ CVE-2023-3331 Low/Sec. - -
|
|
+ CVE-2023-1112 Important/Sec. - patch-redis-6.2.5-1-HP001-1-1.x86_64
|
|
+ CVE-2023-1111 Important/Sec. - patch-redis-6.2.5-1-HP001-1-1.x86_64
|
|
+
|
|
+ return:list
|
|
+ [["CVE-2023-3332","Low/Sec.", "-" ,"-"]]
|
|
+
|
|
+ """
|
|
+ cmd = ["dnf", "hot-updateinfo", "list", "cves"]
|
|
+
|
|
+ output, return_code = cmd_output(cmd)
|
|
+ if return_code != SUCCEED:
|
|
+ return []
|
|
+
|
|
+ content = output.split('\n')
|
|
+ if len(content) <= 2:
|
|
+ return []
|
|
+ result = []
|
|
+ for item in content[1:-1]:
|
|
+ tmp = item.split()
|
|
+ result.append(tmp)
|
|
+ return result
|
|
+
|
|
+ def upgrade_all(self):
|
|
+ """
|
|
+ upgrade all exist cve and hot patches
|
|
+
|
|
+ Return:
|
|
+ find all patches and return patches list
|
|
+ e.g.:
|
|
+ ['patch-redis-6.2.5-1-HP2-1-1.x86_64']
|
|
+ """
|
|
+ hotpatchs_info = self.get_hot_updateinfo_list()
|
|
+ hp_list = []
|
|
+ for item in hotpatchs_info:
|
|
+ if item[-1] != EMPTY_TAG:
|
|
+ hp_list.append(item[-1])
|
|
+ return list(set(hp_list))
|
|
--
|
|
2.33.0
|
|
|