197 lines
9.6 KiB
Diff
197 lines
9.6 KiB
Diff
|
|
From fed39fc1ff83f016828d10c8fcbbf26762236dfa Mon Sep 17 00:00:00 2001
|
||
|
|
From: Yuhang Wei <weiyuhang3@huawei.com>
|
||
|
|
Date: Wed, 24 Jan 2024 15:49:53 +0800
|
||
|
|
Subject: [PATCH 13/13] fix: logs content, grammar and format
|
||
|
|
|
||
|
|
Signed-off-by: Yuhang Wei <weiyuhang3@huawei.com>
|
||
|
|
---
|
||
|
|
KubeOS-Rust/agent/src/function.rs | 3 ++-
|
||
|
|
KubeOS-Rust/manager/src/sys_mgmt/config.rs | 8 ++++----
|
||
|
|
KubeOS-Rust/manager/src/sys_mgmt/containerd_image.rs | 2 +-
|
||
|
|
KubeOS-Rust/manager/src/sys_mgmt/disk_image.rs | 2 +-
|
||
|
|
KubeOS-Rust/manager/src/sys_mgmt/docker_image.rs | 6 +++---
|
||
|
|
KubeOS-Rust/manager/src/utils/common.rs | 8 +++-----
|
||
|
|
KubeOS-Rust/manager/src/utils/executor.rs | 7 ++++---
|
||
|
|
KubeOS-Rust/manager/src/utils/image_manager.rs | 2 +-
|
||
|
|
8 files changed, 19 insertions(+), 19 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/KubeOS-Rust/agent/src/function.rs b/KubeOS-Rust/agent/src/function.rs
|
||
|
|
index 2c97347..9789d95 100644
|
||
|
|
--- a/KubeOS-Rust/agent/src/function.rs
|
||
|
|
+++ b/KubeOS-Rust/agent/src/function.rs
|
||
|
|
@@ -25,7 +25,8 @@ impl RpcFunction {
|
||
|
|
F: FnOnce() -> anyhow::Result<T>,
|
||
|
|
{
|
||
|
|
(f)().map_err(|e| {
|
||
|
|
- error!("{:?}", e);
|
||
|
|
+ let error_message = format!("{:#}", e);
|
||
|
|
+ error!("{}", error_message.replace('\n', " ").replace('\r', ""));
|
||
|
|
Error { code: ErrorCode::ServerError(RPC_OP_ERROR), message: format!("{:?}", e), data: None }
|
||
|
|
})
|
||
|
|
}
|
||
|
|
diff --git a/KubeOS-Rust/manager/src/sys_mgmt/config.rs b/KubeOS-Rust/manager/src/sys_mgmt/config.rs
|
||
|
|
index 48517b4..a629756 100644
|
||
|
|
--- a/KubeOS-Rust/manager/src/sys_mgmt/config.rs
|
||
|
|
+++ b/KubeOS-Rust/manager/src/sys_mgmt/config.rs
|
||
|
|
@@ -66,7 +66,7 @@ pub struct GrubCmdline {
|
||
|
|
|
||
|
|
impl Configuration for KernelSysctl {
|
||
|
|
fn set_config(&self, config: &mut Sysconfig) -> Result<()> {
|
||
|
|
- info!("Start set kernel.sysctl");
|
||
|
|
+ info!("Start setting kernel.sysctl");
|
||
|
|
for (key, key_info) in config.contents.iter() {
|
||
|
|
let proc_path = self.get_proc_path(key);
|
||
|
|
if key_info.operation == "delete" {
|
||
|
|
@@ -99,7 +99,7 @@ impl KernelSysctl {
|
||
|
|
|
||
|
|
impl Configuration for KernelSysctlPersist {
|
||
|
|
fn set_config(&self, config: &mut Sysconfig) -> Result<()> {
|
||
|
|
- info!("Start set kernel.sysctl.persist");
|
||
|
|
+ info!("Start setting kernel.sysctl.persist");
|
||
|
|
let mut config_path = &values::DEFAULT_KERNEL_CONFIG_PATH.to_string();
|
||
|
|
if !config.config_path.is_empty() {
|
||
|
|
config_path = &config.config_path;
|
||
|
|
@@ -247,9 +247,9 @@ fn handle_add_key(expect_configs: &HashMap<String, KeyInfo>, is_only_key_valid:
|
||
|
|
impl Configuration for GrubCmdline {
|
||
|
|
fn set_config(&self, config: &mut Sysconfig) -> Result<()> {
|
||
|
|
if self.is_cur_partition {
|
||
|
|
- info!("Start set grub.cmdline.current configuration");
|
||
|
|
+ info!("Start setting grub.cmdline.current configuration");
|
||
|
|
} else {
|
||
|
|
- info!("Start set grub.cmdline.next configuration");
|
||
|
|
+ info!("Start setting grub.cmdline.next configuration");
|
||
|
|
}
|
||
|
|
if !is_file_exist(&self.grub_path) {
|
||
|
|
bail!("Failed to find grub.cfg file");
|
||
|
|
diff --git a/KubeOS-Rust/manager/src/sys_mgmt/containerd_image.rs b/KubeOS-Rust/manager/src/sys_mgmt/containerd_image.rs
|
||
|
|
index dd7036f..5b0d0b7 100644
|
||
|
|
--- a/KubeOS-Rust/manager/src/sys_mgmt/containerd_image.rs
|
||
|
|
+++ b/KubeOS-Rust/manager/src/sys_mgmt/containerd_image.rs
|
||
|
|
@@ -72,7 +72,7 @@ impl<T: CommandExecutor> CtrImageHandler<T> {
|
||
|
|
.mount_path
|
||
|
|
.to_str()
|
||
|
|
.ok_or_else(|| anyhow!("Failed to get mount path: {}", self.paths.mount_path.display()))?;
|
||
|
|
- info!("Start get rootfs {}", image_name);
|
||
|
|
+ info!("Start getting rootfs {}", image_name);
|
||
|
|
self.check_and_unmount(mount_path)?;
|
||
|
|
self.executor
|
||
|
|
.run_command("ctr", &["-n", DEFAULT_NAMESPACE, "images", "mount", "--rw", image_name, mount_path])?;
|
||
|
|
diff --git a/KubeOS-Rust/manager/src/sys_mgmt/disk_image.rs b/KubeOS-Rust/manager/src/sys_mgmt/disk_image.rs
|
||
|
|
index 7c64bf0..6d836dc 100644
|
||
|
|
--- a/KubeOS-Rust/manager/src/sys_mgmt/disk_image.rs
|
||
|
|
+++ b/KubeOS-Rust/manager/src/sys_mgmt/disk_image.rs
|
||
|
|
@@ -71,7 +71,7 @@ impl<T: CommandExecutor> DiskImageHandler<T> {
|
||
|
|
}
|
||
|
|
|
||
|
|
fn checksum_match(&self, file_path: &str, check_sum: &str) -> Result<()> {
|
||
|
|
- trace!("Start to check checksum");
|
||
|
|
+ info!("Start checking image checksum");
|
||
|
|
let check_sum = check_sum.to_ascii_lowercase();
|
||
|
|
let file = fs::read(file_path)?;
|
||
|
|
let mut hasher = Sha256::new();
|
||
|
|
diff --git a/KubeOS-Rust/manager/src/sys_mgmt/docker_image.rs b/KubeOS-Rust/manager/src/sys_mgmt/docker_image.rs
|
||
|
|
index 177dfeb..a8bbee2 100644
|
||
|
|
--- a/KubeOS-Rust/manager/src/sys_mgmt/docker_image.rs
|
||
|
|
+++ b/KubeOS-Rust/manager/src/sys_mgmt/docker_image.rs
|
||
|
|
@@ -42,16 +42,16 @@ impl<T: CommandExecutor> DockerImageHandler<T> {
|
||
|
|
is_valid_image_name(image_name)?;
|
||
|
|
let cli = "docker";
|
||
|
|
remove_image_if_exist(cli, image_name, &self.executor)?;
|
||
|
|
- info!("Start pull image {}", image_name);
|
||
|
|
+ info!("Start pulling image {}", image_name);
|
||
|
|
pull_image(cli, image_name, &self.executor)?;
|
||
|
|
- info!("Start check image digest");
|
||
|
|
+ info!("Start checking image digest");
|
||
|
|
check_oci_image_digest(cli, image_name, &req.check_sum, &self.executor)?;
|
||
|
|
Ok(())
|
||
|
|
}
|
||
|
|
|
||
|
|
fn get_rootfs_archive(&self, req: &UpgradeRequest) -> Result<()> {
|
||
|
|
let image_name = &req.container_image;
|
||
|
|
- info!("Start get rootfs {}", image_name);
|
||
|
|
+ info!("Start getting rootfs {}", image_name);
|
||
|
|
self.check_and_rm_container()?;
|
||
|
|
debug!("Create container {}", self.container_name);
|
||
|
|
let container_id =
|
||
|
|
diff --git a/KubeOS-Rust/manager/src/utils/common.rs b/KubeOS-Rust/manager/src/utils/common.rs
|
||
|
|
index da8c8c3..a6d62a0 100644
|
||
|
|
--- a/KubeOS-Rust/manager/src/utils/common.rs
|
||
|
|
+++ b/KubeOS-Rust/manager/src/utils/common.rs
|
||
|
|
@@ -79,7 +79,6 @@ pub fn check_disk_size<P: AsRef<Path>>(need_bytes: i64, path: P) -> Result<()> {
|
||
|
|
if available_space < need_bytes {
|
||
|
|
bail!("Space is not enough for downloading");
|
||
|
|
}
|
||
|
|
- info!("There is enough disk space to upgrade");
|
||
|
|
Ok(())
|
||
|
|
}
|
||
|
|
|
||
|
|
@@ -88,9 +87,8 @@ pub fn clean_env<P>(update_path: P, mount_path: P, image_path: P) -> Result<()>
|
||
|
|
where
|
||
|
|
P: AsRef<Path>,
|
||
|
|
{
|
||
|
|
- info!("Clean up the residual upgrade environment");
|
||
|
|
if is_mounted(&mount_path)? {
|
||
|
|
- debug!("Umount {}", mount_path.as_ref().display());
|
||
|
|
+ debug!("Umount \"{}\"", mount_path.as_ref().display());
|
||
|
|
if let Err(errno) = mount::umount2(mount_path.as_ref(), MntFlags::MNT_FORCE) {
|
||
|
|
bail!("Failed to umount {} in clean_env: {}", mount_path.as_ref().display(), errno);
|
||
|
|
}
|
||
|
|
@@ -104,10 +102,10 @@ where
|
||
|
|
pub fn delete_file_or_dir<P: AsRef<Path>>(path: P) -> Result<()> {
|
||
|
|
if is_file_exist(&path) {
|
||
|
|
if fs::metadata(&path)?.is_file() {
|
||
|
|
- debug!("Delete file {}", path.as_ref().display());
|
||
|
|
+ info!("Delete file \"{}\"", path.as_ref().display());
|
||
|
|
fs::remove_file(&path)?;
|
||
|
|
} else {
|
||
|
|
- debug!("Delete directory {}", path.as_ref().display());
|
||
|
|
+ info!("Delete directory \"{}\"", path.as_ref().display());
|
||
|
|
fs::remove_dir_all(&path)?;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
diff --git a/KubeOS-Rust/manager/src/utils/executor.rs b/KubeOS-Rust/manager/src/utils/executor.rs
|
||
|
|
index 8f4cb25..c87bf2a 100644
|
||
|
|
--- a/KubeOS-Rust/manager/src/utils/executor.rs
|
||
|
|
+++ b/KubeOS-Rust/manager/src/utils/executor.rs
|
||
|
|
@@ -28,8 +28,9 @@ impl CommandExecutor for RealCommandExecutor {
|
||
|
|
trace!("run_command: {} {:?}", name, args);
|
||
|
|
let output = Command::new(name).args(args).output()?;
|
||
|
|
if !output.status.success() {
|
||
|
|
+ let stdout = String::from_utf8_lossy(&output.stdout);
|
||
|
|
let error_message = String::from_utf8_lossy(&output.stderr);
|
||
|
|
- bail!("Failed to run command: {} {:?}, stderr: {}", name, args, error_message);
|
||
|
|
+ bail!("Failed to run command: {} {:?}, stdout: \"{}\", stderr: \"{}\"", name, args, stdout, error_message);
|
||
|
|
}
|
||
|
|
debug!("run_command: {} {:?} done", name, args);
|
||
|
|
Ok(())
|
||
|
|
@@ -38,11 +39,11 @@ impl CommandExecutor for RealCommandExecutor {
|
||
|
|
fn run_command_with_output<'a>(&self, name: &'a str, args: &[&'a str]) -> Result<String> {
|
||
|
|
trace!("run_command_with_output: {} {:?}", name, args);
|
||
|
|
let output = Command::new(name).args(args).output()?;
|
||
|
|
+ let stdout = String::from_utf8_lossy(&output.stdout).to_string();
|
||
|
|
if !output.status.success() {
|
||
|
|
let error_message = String::from_utf8_lossy(&output.stderr);
|
||
|
|
- bail!("Failed to run command: {} {:?}, stderr: {}", name, args, error_message);
|
||
|
|
+ bail!("Failed to run command: {} {:?}, stdout: \"{}\", stderr: \"{}\"", name, args, stdout, error_message);
|
||
|
|
}
|
||
|
|
- let stdout = String::from_utf8_lossy(&output.stdout).to_string();
|
||
|
|
debug!("run_command_with_output: {} {:?} done", name, args);
|
||
|
|
Ok(stdout.trim_end_matches('\n').to_string())
|
||
|
|
}
|
||
|
|
diff --git a/KubeOS-Rust/manager/src/utils/image_manager.rs b/KubeOS-Rust/manager/src/utils/image_manager.rs
|
||
|
|
index dc82323..90806cf 100644
|
||
|
|
--- a/KubeOS-Rust/manager/src/utils/image_manager.rs
|
||
|
|
+++ b/KubeOS-Rust/manager/src/utils/image_manager.rs
|
||
|
|
@@ -89,7 +89,7 @@ impl<T: CommandExecutor> UpgradeImageManager<T> {
|
||
|
|
self.format_image()?;
|
||
|
|
self.mount_image()?;
|
||
|
|
self.extract_tar_to_image()?;
|
||
|
|
- // Pass empty image_path to clean_env to avoid delete image file
|
||
|
|
+ // Pass empty image_path to clean_env but avoid deleting the upgrade image
|
||
|
|
clean_env(&self.paths.update_path, &self.paths.mount_path, &PathBuf::new())?;
|
||
|
|
Ok(self)
|
||
|
|
}
|
||
|
|
--
|
||
|
|
2.34.1
|
||
|
|
|