!154 [sync] PR-153: remove installed rpm if unreboot and improve log info for rollback operation
From: @openeuler-sync-bot Reviewed-by: @zhu-yuncheng Signed-off-by: @zhu-yuncheng
This commit is contained in:
commit
86a2339d2e
@ -0,0 +1,152 @@
|
||||
From 88f2784a4673edb9ff0a185ea43beccb5108ece0 Mon Sep 17 00:00:00 2001
|
||||
From: wang-guangge <wangguangge@huawei.com>
|
||||
Date: Fri, 22 Dec 2023 18:44:27 +0800
|
||||
Subject: [PATCH] improve rollback_manage.py
|
||||
|
||||
---
|
||||
ceres/manages/rollback_manage.py | 73 ++++++++++++++++++++++++++------
|
||||
1 file changed, 61 insertions(+), 12 deletions(-)
|
||||
|
||||
diff --git a/ceres/manages/rollback_manage.py b/ceres/manages/rollback_manage.py
|
||||
index 0f30d29..160a74c 100644
|
||||
--- a/ceres/manages/rollback_manage.py
|
||||
+++ b/ceres/manages/rollback_manage.py
|
||||
@@ -237,19 +237,67 @@ class RollbackManage:
|
||||
log.append(result_log)
|
||||
if result_code != TaskExecuteRes.SUCCEED:
|
||||
return TaskExecuteRes.FAIL, os.linesep.join(log)
|
||||
+
|
||||
+ result_code, result_log = self._remove_kernel_rpm(installed_rpm)
|
||||
+ if result_log:
|
||||
+ log.append(result_log)
|
||||
+ if result_code != TaskExecuteRes.SUCCEED:
|
||||
+ return TaskExecuteRes.FAIL, os.linesep.join(log)
|
||||
|
||||
result_code, result_log = self._change_boot_kernel_version(target_rpm)
|
||||
if result_log:
|
||||
log.append(result_log)
|
||||
if result_code != TaskExecuteRes.SUCCEED:
|
||||
return TaskExecuteRes.FAIL, os.linesep.join(log)
|
||||
-
|
||||
+
|
||||
return TaskExecuteRes.SUCCEED, os.linesep.join(log)
|
||||
-
|
||||
+
|
||||
+ def _remove_kernel_rpm(self, installed_rpm: str) -> Tuple[str, str]:
|
||||
+ """
|
||||
+ Remove the kernel rpm if the installed kernel rpm is not in use.
|
||||
+
|
||||
+ Args:
|
||||
+ installed_rpm(str): the installed kernel in executed fix task
|
||||
+
|
||||
+ Returns:
|
||||
+ Tuple[str, str]: a tuple containing two elements (remove result, log)
|
||||
+ """
|
||||
+ code, stdout, stderr = execute_shell_command(f"rpm -qa | grep {installed_rpm}")
|
||||
+ # 'rpm -qa' shows installed rpm
|
||||
+ # e.g.
|
||||
+ # [root@openEuler ~]# rpm -qa | grep kernel-4.19.90-2112.8.0.0131.oe1.x86_64
|
||||
+ # kernel-4.19.90-2112.8.0.0131.oe1.x86_64
|
||||
+ if code != CommandExitCode.SUCCEED or installed_rpm not in stdout:
|
||||
+ tmp_log = f"The {installed_rpm} is not installed. Please check the input parameter."
|
||||
+ LOGGER.error(tmp_log)
|
||||
+ return TaskExecuteRes.FAIL, tmp_log
|
||||
+
|
||||
+ code, current_evra, stderr = execute_shell_command(f"uname -r")
|
||||
+ # 'uname -r' show the kernel version-release.arch of the current system
|
||||
+ # e.g.
|
||||
+ # [root@openEuler ~]# uname -r
|
||||
+ # 5.10.0-136.12.0.86.oe2203sp1.x86_64
|
||||
+ if code != CommandExitCode.SUCCEED:
|
||||
+ LOGGER.error(stderr)
|
||||
+ return TaskExecuteRes.FAIL, current_evra + stderr
|
||||
+
|
||||
+ # version-release.arch
|
||||
+ installed_evra = installed_rpm.split("-", 1)[1]
|
||||
+
|
||||
+ if installed_evra == current_evra:
|
||||
+ return TaskExecuteRes.SUCCEED, f"Preserve the {installed_rpm} due to it is in use."
|
||||
+
|
||||
+ code, stdout, stderr = execute_shell_command(f"dnf remove {installed_rpm} -y")
|
||||
+ if code != CommandExitCode.SUCCEED:
|
||||
+ LOGGER.error(stderr)
|
||||
+ return TaskExecuteRes.FAIL, stdout + stderr
|
||||
+
|
||||
+ return TaskExecuteRes.SUCCEED, stdout
|
||||
+
|
||||
def _check_boot_kernel_version(self, installed_rpm: str) -> Tuple[str, str]:
|
||||
"""
|
||||
Check if the boot kernel version is consistent with the installed kernel version. If not, it indicates
|
||||
- that the executed fix task has been tampered.
|
||||
+ that the environment after executed fix task has been tampered.
|
||||
|
||||
Args:
|
||||
installed_rpm(str): the installed rpm in executed fix task
|
||||
@@ -270,8 +318,8 @@ class RollbackManage:
|
||||
evra = installed_rpm.split("-", 1)[1]
|
||||
if evra not in stdout:
|
||||
tmp_log = (
|
||||
- "The grubby default kernel version is not consistent with installed kernel version. "
|
||||
- "The executed fix task has been tampered."
|
||||
+ f"The default boot kernel version is not consistent with {installed_rpm}. "
|
||||
+ "The environment after executed fix task has been tampered."
|
||||
)
|
||||
LOGGER.error(tmp_log)
|
||||
return TaskExecuteRes.FAIL, tmp_log
|
||||
@@ -281,7 +329,7 @@ class RollbackManage:
|
||||
def _check_current_kernel_version(self, installed_rpm: str, target_rpm: str) -> Tuple[str, str]:
|
||||
"""
|
||||
Check if the current kernel version is consistent with the installed kernel version or target kernel
|
||||
- version. If not, it indicates that the executed fix task has been tampered.
|
||||
+ version. If not, it indicates that the environment after executed fix task has been tampered.
|
||||
|
||||
Args:
|
||||
installed_rpm(str): the installed rpm in executed fix task
|
||||
@@ -304,8 +352,8 @@ class RollbackManage:
|
||||
|
||||
if installed_evra != current_evra and target_evra != current_evra:
|
||||
tmp_log = (
|
||||
- "The current kernel version is not consistent with installed kernel version or target kernel version. "
|
||||
- "The executed fix task has been tampered."
|
||||
+ f"The current kernel version is neither {installed_rpm} nor {target_rpm}. "
|
||||
+ "The environment after executed fix task has been tampered."
|
||||
)
|
||||
LOGGER.error(tmp_log)
|
||||
return TaskExecuteRes.FAIL, tmp_log
|
||||
@@ -314,7 +362,8 @@ class RollbackManage:
|
||||
|
||||
def _check_if_target_rpm_installed(self, target_rpm: str) -> Tuple[str, str]:
|
||||
"""
|
||||
- Check if the target kernel is installed. If not, it indicates that the executed fix task has been tampered.
|
||||
+ Check if the target kernel is installed. If not, it indicates that the environment after executed fix
|
||||
+ task has been tampered.
|
||||
|
||||
Args:
|
||||
target_rpm(str): the target rpm for rollback task
|
||||
@@ -328,7 +377,7 @@ class RollbackManage:
|
||||
# [root@openEuler ~]# rpm -qa | grep kernel-4.19.90-2112.8.0.0131.oe1.x86_64
|
||||
# kernel-4.19.90-2112.8.0.0131.oe1.x86_64
|
||||
if code != CommandExitCode.SUCCEED or target_rpm not in stdout:
|
||||
- tmp_log = "The target kernel of rollback task is not installed. The executed fix task has been tampered."
|
||||
+ tmp_log = "The target kernel of rollback task is not installed. The environment after executed fix task has been tampered."
|
||||
LOGGER.error(tmp_log)
|
||||
return TaskExecuteRes.FAIL, tmp_log
|
||||
|
||||
@@ -336,7 +385,7 @@ class RollbackManage:
|
||||
|
||||
def _change_boot_kernel_version(self, target_rpm: str) -> Tuple[str, str]:
|
||||
"""
|
||||
- Change the grubby default kernel version to target kernel version.
|
||||
+ Change the default boot kernel version to target kernel version.
|
||||
|
||||
Args:
|
||||
target_rpm(str): the target rpm for rollback task
|
||||
@@ -358,4 +407,4 @@ class RollbackManage:
|
||||
LOGGER.error(stderr)
|
||||
return TaskExecuteRes.FAIL, stdout + stderr
|
||||
|
||||
- return TaskExecuteRes.SUCCEED, f"Change boot kernel version to {target_rpm} successfully."
|
||||
+ return TaskExecuteRes.SUCCEED, f"Change default boot kernel version to {target_rpm} successfully."
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
Name: aops-ceres
|
||||
Version: v1.4.1
|
||||
Release: 3
|
||||
Release: 4
|
||||
Summary: An agent which needs to be adopted in client, it managers some plugins, such as gala-gopher(kpi collection), fluentd(log collection) and so on.
|
||||
License: MulanPSL2
|
||||
URL: https://gitee.com/openeuler/%{name}
|
||||
@ -15,6 +15,7 @@ Provides: aops-ceres
|
||||
Conflicts: aops-agent
|
||||
Patch0001: 0001-improve-status-judgement-and-hotupgrade-logic.patch
|
||||
Patch0002: 0002-support-restore-grubby-if-kabi-check-failed.patch
|
||||
Patch0003: 0003-remove-installed-rpm-if-unreboot-and-improve-log-for-rollback.patch
|
||||
|
||||
%description
|
||||
An agent which needs to be adopted in client, it managers some plugins, such as gala-gopher(kpi collection), fluentd(log collection) and so on.
|
||||
@ -87,6 +88,9 @@ install -b -m500 ./extra-tools/da-tool/script/da-tool.sh ${RPM_BUILD_ROOT}
|
||||
%attr(0500, root, root) %{_bindir}/da-tool-analysis
|
||||
|
||||
%changelog
|
||||
* Fri Dec 22 2023 wangguangge<wangguangge@huawei.com> - v1.4.1-4
|
||||
- support remove installed rpm if unreboot and improve log info for rollback operation
|
||||
|
||||
* Wed Dec 20 2023 wangguangge<wangguangge@huawei.com> - v1.4.1-3
|
||||
- support restore default grubby boot kernel if kernel kabi check failed
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user