168 lines
7.8 KiB
Diff
168 lines
7.8 KiB
Diff
From 415d7dca6175136ca4c1c780f1e512fd363d01c4 Mon Sep 17 00:00:00 2001
|
||
From: liuxu <liuxu156@huawei.com>
|
||
Date: Fri, 3 Nov 2023 14:27:45 +0800
|
||
Subject: [PATCH 02/14] sandbox:adapt UT when del m_containers and
|
||
m_containersMutex
|
||
|
||
---
|
||
.../design/detailed/Sandbox/sandbox_design_zh.md | 16 +---------------
|
||
test/mocks/sandbox_mock.cc | 11 -----------
|
||
test/mocks/sandbox_mock.h | 4 ----
|
||
test/sandbox/sandbox/sandbox_ut.cc | 14 --------------
|
||
4 files changed, 1 insertion(+), 44 deletions(-)
|
||
|
||
diff --git a/docs/design/detailed/Sandbox/sandbox_design_zh.md b/docs/design/detailed/Sandbox/sandbox_design_zh.md
|
||
index 86acd70b..109094cb 100644
|
||
--- a/docs/design/detailed/Sandbox/sandbox_design_zh.md
|
||
+++ b/docs/design/detailed/Sandbox/sandbox_design_zh.md
|
||
@@ -99,7 +99,6 @@ auto GetNetworkSettings() -> const std::string &;
|
||
auto GetCreatedAt() -> uint64_t;
|
||
auto GetPid() -> uint32_t;
|
||
auto GetTaskAddress() const -> const std::string &;
|
||
-auto GetContainers() -> std::vector<std::string>;
|
||
|
||
// 设置和更新sandbox的变量值
|
||
void SetNetMode(const std::string &mode);
|
||
@@ -108,9 +107,6 @@ void AddAnnotations(const std::string &key, const std::string &value);
|
||
void RemoveAnnotations(const std::string &key);
|
||
void AddLabels(const std::string &key, const std::string &value);
|
||
void RemoveLabels(const std::string &key);
|
||
-void AddContainer(const std::string &id);
|
||
-void SetConatiners(const std::vector<std::string> &cons);
|
||
-void RemoveContainer(const std::string &id);
|
||
void UpdateNetworkSettings(const std::string &settingsJson, Errors &error);
|
||
auto UpdateStatsInfo(const StatsInfo &info) -> StatsInfo;
|
||
void SetNetworkReady(bool ready);
|
||
@@ -252,16 +248,12 @@ public:
|
||
auto GetCreatedAt() -> uint64_t;
|
||
auto GetPid() -> uint32_t;
|
||
auto GetTaskAddress() const -> const std::string &;
|
||
- auto GetContainers() -> std::vector<std::string>;
|
||
void SetNetMode(const std::string &mode);
|
||
void SetController(std::shared_ptr<Controller> controller);
|
||
void AddAnnotations(const std::string &key, const std::string &value);
|
||
void RemoveAnnotations(const std::string &key);
|
||
void AddLabels(const std::string &key, const std::string &value);
|
||
void RemoveLabels(const std::string &key);
|
||
- void AddContainer(const std::string &id);
|
||
- void SetConatiners(const std::vector<std::string> &cons);
|
||
- void RemoveContainer(const std::string &id);
|
||
void UpdateNetworkSettings(const std::string &settingsJson, Errors &error);
|
||
auto UpdateStatsInfo(const StatsInfo &info) -> StatsInfo;
|
||
void SetNetworkReady(bool ready);
|
||
@@ -347,9 +339,6 @@ private:
|
||
std::string m_networkMode;
|
||
bool m_networkReady;
|
||
std::string m_networkSettings;
|
||
- // container id lists
|
||
- std::vector<std::string> m_containers;
|
||
- RWMutex m_containersMutex;
|
||
// TOOD: m_sandboxConfig is a protobuf message, it can be converted to json string directly
|
||
// if save json string directly for sandbox recover, we need to consider hot
|
||
// upgrade between different CRI versions
|
||
@@ -410,9 +399,7 @@ std::string m_netNsPath;
|
||
std::string m_networkMode;
|
||
bool m_networkReady;
|
||
std::string m_networkSettings;
|
||
-// container id lists
|
||
-std::vector<std::string> m_containers;
|
||
-RWMutex m_containersMutex;
|
||
+
|
||
// TOOD: m_sandboxConfig is a protobuf message, it can be converted to json string directly
|
||
// if save json string directly for sandbox recover, we need to consider hot
|
||
// upgrade between different CRI versions
|
||
@@ -430,7 +417,6 @@ std::set<uint32_t> m_vsockPorts;
|
||
|
||
1. m_mutex: 保障并发sandbox的生命周期操作(start, stop, remove)
|
||
2. m_stateMutex:保障并发对m_state,m_statsInfo,m_networkSettings的修改与读取
|
||
-3. m_containersMutex:保障对m_containers的并发操作
|
||
|
||
## 4.2 sandbox manage 模块
|
||
|
||
diff --git a/test/mocks/sandbox_mock.cc b/test/mocks/sandbox_mock.cc
|
||
index ab6c2d60..e5aefdda 100644
|
||
--- a/test/mocks/sandbox_mock.cc
|
||
+++ b/test/mocks/sandbox_mock.cc
|
||
@@ -77,14 +77,6 @@ const std::string &Sandbox::GetRuntimeHandle() const
|
||
return defaultStr;
|
||
}
|
||
|
||
-std::vector<std::string> Sandbox::GetContainers()
|
||
-{
|
||
- if (g_sandbox_mock != nullptr) {
|
||
- return g_sandbox_mock->GetContainers();
|
||
- }
|
||
- return defaultVec;
|
||
-}
|
||
-
|
||
const runtime::v1::PodSandboxConfig & Sandbox::GetSandboxConfig() const
|
||
{
|
||
if (g_sandbox_mock != nullptr) {
|
||
@@ -154,9 +146,6 @@ void Sandbox::AddAnnotations(const std::string &key, const std::string &value) {
|
||
void Sandbox::RemoveAnnotations(const std::string &key) {}
|
||
void Sandbox::AddLabels(const std::string &key, const std::string &value) {}
|
||
void Sandbox::RemoveLabels(const std::string &key) {}
|
||
-void Sandbox::AddContainer(const std::string &id) {}
|
||
-void Sandbox::SetConatiners(const std::vector<std::string> &cons) {}
|
||
-void Sandbox::RemoveContainer(const std::string &id) {}
|
||
void Sandbox::UpdateNetworkSettings(const std::string &settingsJson, Errors &error) {}
|
||
void Sandbox::PrepareSandboxDirs(Errors &error) {}
|
||
void Sandbox::CleanupSandboxDirs() {}
|
||
diff --git a/test/mocks/sandbox_mock.h b/test/mocks/sandbox_mock.h
|
||
index 6b46dca6..341042e9 100644
|
||
--- a/test/mocks/sandbox_mock.h
|
||
+++ b/test/mocks/sandbox_mock.h
|
||
@@ -31,7 +31,6 @@ public:
|
||
MOCK_METHOD0(GetName, const std::string & ());
|
||
MOCK_METHOD0(GetSandboxer, const std::string & ());
|
||
MOCK_METHOD0(GetRuntimeHandle, const std::string & ());
|
||
- MOCK_METHOD0(GetContainers, std::vector<std::string>());
|
||
MOCK_METHOD0(GetSandboxConfig, const runtime::v1::PodSandboxConfig &());
|
||
MOCK_METHOD0(GetMutableSandboxConfig, std::shared_ptr<runtime::v1::PodSandboxConfig>());
|
||
MOCK_METHOD0(GetRootDir, const std::string & ());
|
||
@@ -46,9 +45,6 @@ public:
|
||
MOCK_METHOD1(RemoveAnnotations, void(const std::string &key));
|
||
MOCK_METHOD2(AddLabels, void(const std::string &key, const std::string &value));
|
||
MOCK_METHOD1(RemoveLabels, void(const std::string &key));
|
||
- MOCK_METHOD1(AddContainer, void(const std::string &id));
|
||
- MOCK_METHOD1(SetConatiners, void(const std::vector<std::string> &cons));
|
||
- MOCK_METHOD1(RemoveContainer, void(const std::string &id));
|
||
MOCK_METHOD2(UpdateNetworkSettings, void(const std::string &settingsJson, Errors &error));
|
||
MOCK_METHOD1(UpdateStatsInfo, StatsInfo(const StatsInfo &info));
|
||
MOCK_METHOD1(SetNetworkReady, void(bool ready));
|
||
diff --git a/test/sandbox/sandbox/sandbox_ut.cc b/test/sandbox/sandbox/sandbox_ut.cc
|
||
index 494fb543..dd84d8fb 100644
|
||
--- a/test/sandbox/sandbox/sandbox_ut.cc
|
||
+++ b/test/sandbox/sandbox/sandbox_ut.cc
|
||
@@ -49,7 +49,6 @@ TEST_F(SandboxTest, TestDefaultGetters)
|
||
ASSERT_STREQ(sandbox->GetRuntime().c_str(), info.runtime.c_str());
|
||
ASSERT_STREQ(sandbox->GetSandboxer().c_str(), info.sandboxer.c_str());
|
||
ASSERT_STREQ(sandbox->GetRuntimeHandle().c_str(), info.runtimeHandler.c_str());
|
||
- ASSERT_EQ(sandbox->GetContainers().size(), 0);
|
||
ASSERT_STREQ(sandbox->GetRootDir().c_str(), sandbox_rootdir.c_str());
|
||
ASSERT_STREQ(sandbox->GetStateDir().c_str(), sandbox_statedir.c_str());
|
||
ASSERT_STREQ(sandbox->GetResolvPath().c_str(), (sandbox_rootdir + "/resolv.conf").c_str());
|
||
@@ -85,19 +84,6 @@ TEST_F(SandboxTest, TestGettersAndSetters)
|
||
sandbox->RemoveLabels("key");
|
||
EXPECT_TRUE(sandbox->GetSandboxConfig().labels().empty());
|
||
|
||
- std::string containerId = "container_id";
|
||
- sandbox->AddContainer(containerId);
|
||
- auto Mycontainers = sandbox->GetContainers();
|
||
- auto it = std::find(Mycontainers.begin(), Mycontainers.end(), containerId);
|
||
- EXPECT_NE(Mycontainers.end(), it);
|
||
-
|
||
- sandbox->RemoveContainer(containerId);
|
||
- EXPECT_EQ(sandbox->GetContainers().size(), 0);
|
||
-
|
||
- std::vector<std::string> containers = {"container1", "container2"};
|
||
- sandbox->SetConatiners(containers);
|
||
- EXPECT_EQ(sandbox->GetContainers(), containers);
|
||
-
|
||
StatsInfo statsInfo = {1234, 100};
|
||
sandbox->UpdateStatsInfo(statsInfo);
|
||
EXPECT_EQ(sandbox->GetStatsInfo().timestamp, statsInfo.timestamp);
|
||
--
|
||
2.42.0
|
||
|