KubeOS: fix code check
Signed-off-by: Yuhang Wei <weiyuhang3@huawei.com>
This commit is contained in:
parent
bb813952f0
commit
5b52aae82f
84
0020-fix-mutex-locking-in-agent_impl.rs.patch
Normal file
84
0020-fix-mutex-locking-in-agent_impl.rs.patch
Normal file
@ -0,0 +1,84 @@
|
||||
From 0b4843d4514cd8b7e653990025d0ecd5e80d56ba Mon Sep 17 00:00:00 2001
|
||||
From: Yuhang Wei <weiyuhang3@huawei.com>
|
||||
Date: Tue, 20 Feb 2024 10:18:27 +0800
|
||||
Subject: [PATCH 1/2] fix: mutex locking in agent_impl.rs
|
||||
|
||||
Signed-off-by: Yuhang Wei <weiyuhang3@huawei.com>
|
||||
---
|
||||
KubeOS-Rust/agent/src/rpc/agent_impl.rs | 32 +++++++++++++++++++++----
|
||||
1 file changed, 28 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/KubeOS-Rust/agent/src/rpc/agent_impl.rs b/KubeOS-Rust/agent/src/rpc/agent_impl.rs
|
||||
index 5f3a3259..ab826413 100644
|
||||
--- a/KubeOS-Rust/agent/src/rpc/agent_impl.rs
|
||||
+++ b/KubeOS-Rust/agent/src/rpc/agent_impl.rs
|
||||
@@ -57,7 +57,10 @@ impl Default for AgentImpl {
|
||||
|
||||
impl AgentImpl {
|
||||
fn prepare_upgrade_impl(&self, req: UpgradeRequest) -> Result<Response> {
|
||||
- let _lock = self.mutex.lock().unwrap();
|
||||
+ let lock = self.mutex.try_lock();
|
||||
+ if lock.is_err() {
|
||||
+ bail!("os-agent is processing another request");
|
||||
+ }
|
||||
debug!("Received an 'prepare upgrade' request: {:?}", req);
|
||||
info!("Start preparing for upgrading to version: {}", req.version);
|
||||
|
||||
@@ -76,7 +79,10 @@ impl AgentImpl {
|
||||
}
|
||||
|
||||
fn upgrade_impl(&self) -> Result<Response> {
|
||||
- let _lock = self.mutex.lock().unwrap();
|
||||
+ let lock = self.mutex.try_lock();
|
||||
+ if lock.is_err() {
|
||||
+ bail!("os-agent is processing another request");
|
||||
+ }
|
||||
info!("Start to upgrade");
|
||||
let command_executor = RealCommandExecutor {};
|
||||
let (_, next_partition_info) = get_partition_info(&command_executor)?;
|
||||
@@ -91,7 +97,10 @@ impl AgentImpl {
|
||||
}
|
||||
|
||||
fn configure_impl(&self, mut req: ConfigureRequest) -> Result<Response> {
|
||||
- let _lock = self.mutex.lock().unwrap();
|
||||
+ let lock = self.mutex.try_lock();
|
||||
+ if lock.is_err() {
|
||||
+ bail!("os-agent is processing another request");
|
||||
+ }
|
||||
debug!("Received a 'configure' request: {:?}", req);
|
||||
info!("Start to configure");
|
||||
let config_map = &*CONFIG_TEMPLATE;
|
||||
@@ -108,7 +117,10 @@ impl AgentImpl {
|
||||
}
|
||||
|
||||
fn rollback_impl(&self) -> Result<Response> {
|
||||
- let _lock = self.mutex.lock().unwrap();
|
||||
+ let lock = self.mutex.try_lock();
|
||||
+ if lock.is_err() {
|
||||
+ bail!("os-agent is processing another request");
|
||||
+ }
|
||||
info!("Start to rollback");
|
||||
let command_executor = RealCommandExecutor {};
|
||||
let (_, next_partition_info) = get_partition_info(&command_executor)?;
|
||||
@@ -172,6 +184,18 @@ mod test {
|
||||
};
|
||||
let res = agent.configure(req);
|
||||
assert!(res.is_err());
|
||||
+
|
||||
+ // test lock
|
||||
+ let _lock = agent.mutex.lock().unwrap();
|
||||
+ let req = ConfigureRequest {
|
||||
+ configs: vec![Sysconfig {
|
||||
+ model: "kernel.sysctl".to_string(),
|
||||
+ config_path: "".to_string(),
|
||||
+ contents: HashMap::new(),
|
||||
+ }],
|
||||
+ };
|
||||
+ let res = agent.configure(req);
|
||||
+ assert!(res.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
--
|
||||
2.34.1
|
||||
|
||||
@ -0,0 +1,38 @@
|
||||
From 3bbb48b9e2569514caa88b9d67aa14d67a48432f Mon Sep 17 00:00:00 2001
|
||||
From: Yuhang Wei <weiyuhang3@huawei.com>
|
||||
Date: Tue, 20 Feb 2024 10:18:42 +0800
|
||||
Subject: [PATCH 2/2] fix: partition info retrieval in get_partition_info
|
||||
function
|
||||
|
||||
Signed-off-by: Yuhang Wei <weiyuhang3@huawei.com>
|
||||
---
|
||||
KubeOS-Rust/manager/src/utils/partition.rs | 7 ++++++-
|
||||
1 file changed, 6 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/KubeOS-Rust/manager/src/utils/partition.rs b/KubeOS-Rust/manager/src/utils/partition.rs
|
||||
index fcfa2d8b..799b4b35 100644
|
||||
--- a/KubeOS-Rust/manager/src/utils/partition.rs
|
||||
+++ b/KubeOS-Rust/manager/src/utils/partition.rs
|
||||
@@ -50,7 +50,7 @@ pub fn get_partition_info<T: CommandExecutor>(executor: &T) -> Result<(Partition
|
||||
}
|
||||
}
|
||||
}
|
||||
- if cur_partition.device.is_empty() {
|
||||
+ if cur_partition.menuentry.is_empty() {
|
||||
bail!("Failed to get partition info, lsblk output: {}", lsblk);
|
||||
}
|
||||
Ok((cur_partition, next_partition))
|
||||
@@ -108,5 +108,10 @@ mod tests {
|
||||
mock.expect_run_command_with_output().times(1).returning(|_, _| Ok(command_output3.to_string()));
|
||||
let res = get_partition_info(&mock);
|
||||
assert!(res.is_err());
|
||||
+
|
||||
+ let command_output4 = "sda4 / ext4";
|
||||
+ mock.expect_run_command_with_output().times(1).returning(|_, _| Ok(command_output4.to_string()));
|
||||
+ let res = get_partition_info(&mock);
|
||||
+ assert!(res.is_err());
|
||||
}
|
||||
}
|
||||
--
|
||||
2.34.1
|
||||
|
||||
10
KubeOS.spec
10
KubeOS.spec
@ -2,7 +2,7 @@
|
||||
|
||||
Name: KubeOS
|
||||
Version: 1.0.5
|
||||
Release: 2
|
||||
Release: 4
|
||||
Summary: O&M platform used to update the whole OS as an entirety
|
||||
License: Mulan PSL v2
|
||||
Source0: https://gitee.com/openeuler/KubeOS/repository/archive/v%{version}.tar.gz
|
||||
@ -25,6 +25,8 @@ Patch16: 0016-proxy-fix-code-review-issues.patch
|
||||
Patch17: 0017-fix-clippy-warnings-and-fmt-code.patch
|
||||
Patch18: 0018-Bump-tokio-to-1.28.0.patch
|
||||
Patch19: 0019-build-update-vendor.patch
|
||||
Patch20: 0020-fix-mutex-locking-in-agent_impl.rs.patch
|
||||
Patch21: 0021-fix-partition-info-retrieval-in-get_partition_info-f.patch
|
||||
|
||||
BuildRoot: %{_tmppath}/%{name}-%{version}-build
|
||||
BuildRequires: make rust cargo openssl-devel
|
||||
@ -136,6 +138,12 @@ install -p -m 0600 ./files/os-release %{buildroot}/opt/kubeOS/files
|
||||
rm -rfv %{buildroot}
|
||||
|
||||
%changelog
|
||||
* Fri Feb 23 2024 Yuhang Wei<weiyuhang3@huawei.com> - 1.0.5-4
|
||||
- Type:requirement
|
||||
- CVE:NA
|
||||
- SUG:restart
|
||||
- DESC:fix code check
|
||||
|
||||
* Mon Feb 05 2024 Yuhang Wei<weiyuhang3@huawei.com> - 1.0.5-3
|
||||
- Type:requirement
|
||||
- CVE:NA
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user