提交 3174fdcb 编写于 作者: Z Zhangxiaoyu 提交者: lifeng68

add driver llt

Signed-off-by: NZhangxiaoyu <zhangxiaoyu58@huawei.com>
上级 374e3fa0
......@@ -154,6 +154,7 @@ RUN export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH && \
cd ~ && \
git clone https://gitee.com/src-openeuler/grpc.git && \
cd grpc && \
git checkout -b openEuler-20.03-LTS-tag openEuler-20.03-LTS-tag && \
tar -xzvf grpc-1.22.0.tar.gz && \
cd grpc-1.22.0 && \
make -j $(nproc) && \
......@@ -200,8 +201,8 @@ RUN export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH && \
cd ~ && \
git clone https://gitee.com/src-openeuler/http-parser.git && \
cd http-parser && \
tar -xzvf http-parser-2.9.2.tar.gz && \
cd http-parser-2.9.2 && \
tar -xzvf http-parser-2.9.4.tar.gz && \
cd http-parser-2.9.4 && \
make -j CFLAGS="-Wno-error" && \
make CFLAGS="-Wno-error" install && \
ldconfig
......@@ -212,9 +213,8 @@ RUN export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH && \
cd ~ && \
git clone https://gitee.com/src-openeuler/libwebsockets.git && \
cd libwebsockets && \
tar -xzvf libwebsockets-2.4.2.tar.gz && \
cd libwebsockets-2.4.2 && \
patch -p1 -F1 -s < ../libwebsockets-fix-coredump.patch && \
tar -xzvf libwebsockets-4.0.1.tar.gz && \
cd libwebsockets-4.0.1 && \
mkdir build && \
cd build && \
cmake -DLWS_WITH_SSL=0 -DLWS_MAX_SMP=32 -DCMAKE_BUILD_TYPE=Debug ../ && \
......
......@@ -2,4 +2,4 @@ project(iSulad_UT)
add_subdirectory(images)
add_subdirectory(rootfs)
# add_subdirectory(layers)
add_subdirectory(layers)
project(iSulad_UT)
SET(DRIVER_EXE storage_driver_ut)
add_executable(${DRIVER_EXE}
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/utils.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/utils_regex.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/utils_verify.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/utils_array.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/utils_string.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/utils_convert.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/utils_file.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/utils_fs.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/util_atomic.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/utils_base64.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/utils_timestamp.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/path.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/map/map.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/map/rb_tree.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/tar/util_archive.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/sha256/sha256.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/libisulad.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/image/oci/storage/layer_store/graphdriver/driver.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/image/oci/storage/layer_store/graphdriver/devmapper/driver_devmapper.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/image/oci/storage/layer_store/graphdriver/devmapper/metadata_store.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/image/oci/storage/layer_store/graphdriver/quota/project_quota.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../mocks/driver_quota_mock.cc
storage_driver_ut.cpp)
target_include_directories(${DRIVER_EXE} PUBLIC
${GTEST_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../../../../include
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/tar
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/map
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/sha256
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/console
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/image
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/image/oci/storage
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/image/oci/storage/layer_store/graphdriver
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/image/oci/storage/layer_store/graphdriver/devmapper/
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/image/oci/storage/layer_store/graphdriver/overlay2
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/image/oci/storage/layer_store/graphdriver/quota
${CMAKE_CURRENT_SOURCE_DIR}/../../../../mocks
)
target_link_libraries(${DRIVER_EXE}
${GTEST_BOTH_LIBRARIES}
${GMOCK_LIBRARY}
${GMOCK_MAIN_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
${ISULA_LIBUTILS_LIBRARY}
${LIBTAR_LIBRARY}
-lwebsockets -lcrypto -lyajl -larchive -ldevmapper -lz)
#[[
SET(EXE storage_layers_ut)
aux_source_directory(${CMAKE_BINARY_DIR}/json json_files)
......@@ -70,3 +129,4 @@ target_link_libraries(${EXE}
${GMOCK_MAIN_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
-lwebsockets -lcrypto -lyajl -larchive -ldevmapper -lz)
]]
\ No newline at end of file
root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
mail:x:8:
kmem:x:9:
wheel:x:10:root
cdrom:x:11:
dialout:x:18:
floppy:x:19:
video:x:28:
audio:x:29:
tape:x:32:
www-data:x:33:
operator:x:37:
utmp:x:43:
plugdev:x:46:
staff:x:50:
lock:x:54:
netdev:x:82:
users:x:100:
nogroup:x:65534:
root:x:0:0:root:/root:/bin/sh
daemon:x:1:1:daemon:/usr/sbin:/bin/false
bin:x:2:2:bin:/bin:/bin/false
sys:x:3:3:sys:/dev:/bin/false
sync:x:4:100:sync:/bin:/bin/sync
mail:x:8:8:mail:/var/spool/mail:/bin/false
www-data:x:33:33:www-data:/var/www:/bin/false
operator:x:37:37:Operator:/var:/bin/false
nobody:x:65534:65534:nobody:/home:/bin/false
root:*:::::::
daemon:*:::::::
bin:*:::::::
sys:*:::::::
sync:*:::::::
mail:*:::::::
www-data:*:::::::
operator:*:::::::
nobody:*:::::::
../9c27e219663c25e0f28493790cc0b88bc973ba3b1686355f221c38a36978ac63/diff
\ No newline at end of file
../1be74353c3d0fd55fb5638a52953e6f1bc441e5b1710921db9ec2aa202725569/diff
\ No newline at end of file
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: zhangxiaoyu
* Create: 2020-06-24
* Description: provide oci storage driver unit test
******************************************************************************/
#include "driver.h"
#include <cstddef>
#include <cstring>
#include <iostream>
#include <climits>
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "path.h"
#include "utils_array.h"
#include "driver_overlay2.h"
#include "driver_quota_mock.h"
using ::testing::Args;
using ::testing::ByRef;
using ::testing::SetArgPointee;
using ::testing::DoAll;
using ::testing::NiceMock;
using ::testing::Return;
using ::testing::NotNull;
using ::testing::AtLeast;
using ::testing::Invoke;
using ::testing::_;
using ::testing::FLAGS_gmock_catch_leaked_mocks;
std::string GetDirectory()
{
char abs_path[PATH_MAX];
int ret = readlink("/proc/self/exe", abs_path, sizeof(abs_path));
if (ret < 0 || (size_t)ret >= sizeof(abs_path)) {
return "";
}
for (int i { ret }; i >= 0; --i) {
if (abs_path[i] == '/') {
abs_path[i + 1] = '\0';
break;
}
}
return static_cast<std::string>(abs_path);
}
bool dirExists(const char *path)
{
DIR *dp = NULL;
if ((dp = opendir(path)) == NULL) {
return false;
}
closedir(dp);
return true;
}
int invokeGetPageSize()
{
std::string abs_mount = "rw,"
"lowerdir=/var/lib/isulad/data/overlay/9c27e219663c25e0f28493790cc0b88bc973ba3b1686355f221c38a36978ac63/empty,"
"upperdir=/var/lib/isulad/data/overlay/9c27e219663c25e0f28493790cc0b88bc973ba3b1686355f221c38a36978ac63/diff,"
"workdir=/var/lib/isulad/data/overlay/9c27e219663c25e0f28493790cc0b88bc973ba3b1686355f221c38a36978ac63/work";
return abs_mount.length() - 1;
}
int invokeIOCtl(int fd, int cmd)
{
return 0;
}
int invokeQuotaCtl(int cmd, const char* special, int id, caddr_t addr)
{
#define XFS_QUOTA_PDQ_ACCT (1<<4) // project quota accounting
#define XFS_QUOTA_PDQ_ENFD (1<<5) // project quota limits enforcement
fs_quota_stat_t* fs_quota_stat_info = (fs_quota_stat_t *)addr;
fs_quota_stat_info->qs_flags = XFS_QUOTA_PDQ_ACCT | XFS_QUOTA_PDQ_ENFD;
return 0;
}
class StorageDriverUnitTest : public testing::Test {
protected:
void SetUp() override
{
MockDriverQuota_SetMock(&m_driver_quota_mock);
std::string isulad_dir { "/var/lib/isulad/" };
std::string root_dir = isulad_dir + "data";
std::string run_dir = isulad_dir + "data/run";
std::string data_dir = GetDirectory() + "/data";
struct storage_module_init_options *opts;
ASSERT_STRNE(cleanpath(data_dir.c_str(), data_path, sizeof(data_path)), nullptr);
std::string cp_command = "cp -r " + std::string(data_path) + " " + isulad_dir;
ASSERT_EQ(system(cp_command.c_str()), 0);
std::string mkdir = "mkdir -p " + root_dir + "/overlay/1be74353c3d0fd55fb5638a52953e6f1bc441e5b1710921db9ec2aa202725569/merged "
+ root_dir + "/overlay/1be74353c3d0fd55fb5638a52953e6f1bc441e5b1710921db9ec2aa202725569/work && "
"mkdir -p " + root_dir + "/overlay/9c27e219663c25e0f28493790cc0b88bc973ba3b1686355f221c38a36978ac63/empty "
+ root_dir + "/overlay/9c27e219663c25e0f28493790cc0b88bc973ba3b1686355f221c38a36978ac63/merged "
+ root_dir + "/overlay/9c27e219663c25e0f28493790cc0b88bc973ba3b1686355f221c38a36978ac63/work ";
ASSERT_EQ(system(mkdir.c_str()), 0);
opts = (struct storage_module_init_options *)malloc(sizeof(struct storage_module_init_options));
opts->storage_root = strdup(root_dir.c_str());
opts->storage_run_root = strdup(run_dir.c_str());
opts->driver_name = strdup("overlay");
opts->driver_opts = (char **)malloc(4 * sizeof(char *));
opts->driver_opts[0] = strdup("overlay2.basesize=128M");
opts->driver_opts[1] = strdup("overlay2.override_kernel_check=true");
opts->driver_opts[2] = strdup("overlay2.skip_mount_home=false");
opts->driver_opts[3] = strdup("overlay2.mountopt=rw");
opts->driver_opts_len = 4;
EXPECT_CALL(m_driver_quota_mock, QuotaCtl(_, _, _, _)).WillRepeatedly(Invoke(invokeQuotaCtl));
ASSERT_EQ(graphdriver_init(opts), 0);
free(opts->storage_root);
free(opts->storage_run_root);
free(opts->driver_name);
util_free_array_by_len(opts->driver_opts, opts->driver_opts_len);
free(opts);
}
void TearDown() override
{
MockDriverQuota_SetMock(nullptr);
ASSERT_EQ(graphdriver_cleanup(), 0);
std::string rm_command = "rm -rf /var/lib/isulad/data";
ASSERT_EQ(system(rm_command.c_str()), 0);
}
NiceMock<MockDriverQuota> m_driver_quota_mock;
char data_path[PATH_MAX] = { 0x00 };
};
TEST_F(StorageDriverUnitTest, test_graphdriver_layer_exists)
{
std::string id { "9c27e219663c25e0f28493790cc0b88bc973ba3b1686355f221c38a36978ac63" };
std::string incorrectId { "eb29745b8228e1e97c01b1d5c2554a319c00a94d8dd5746a3904222ad65a13f8" };
ASSERT_TRUE(graphdriver_layer_exists(id.c_str()));
ASSERT_FALSE(graphdriver_layer_exists(incorrectId.c_str()));
}
TEST_F(StorageDriverUnitTest, test_graphdriver_create_rw)
{
std::string id { "eb29745b8228e1e97c01b1d5c2554a319c00a94d8dd5746a3904222ad65a13f8" };
struct driver_create_opts *create_opts;
create_opts = (struct driver_create_opts *)malloc(sizeof(struct driver_create_opts));
ASSERT_NE(create_opts, nullptr);
create_opts->mount_label = strdup("mount_label");
create_opts->storage_opt = (json_map_string_string *)malloc(sizeof(json_map_string_string));
ASSERT_NE(create_opts->storage_opt, nullptr);
create_opts->storage_opt->keys = (char **)malloc(sizeof(char *));
create_opts->storage_opt->values = (char **)malloc(sizeof(char *));
create_opts->storage_opt->keys[0] = strdup("size");
create_opts->storage_opt->values[0] = strdup("128M");
create_opts->storage_opt->len = 1;
EXPECT_CALL(m_driver_quota_mock, IOCtl(_, _)).WillRepeatedly(Invoke(invokeIOCtl));
ASSERT_EQ(graphdriver_create_rw(id.c_str(), nullptr, create_opts), 0);
ASSERT_TRUE(graphdriver_layer_exists(id.c_str()));
ASSERT_EQ(graphdriver_rm_layer(id.c_str()), 0);
ASSERT_FALSE(graphdriver_layer_exists(id.c_str()));
free_driver_create_opts(create_opts);
}
TEST_F(StorageDriverUnitTest, test_graphdriver_mount_layer)
{
std::string id { "9c27e219663c25e0f28493790cc0b88bc973ba3b1686355f221c38a36978ac63" };
std::string merged_dir = "/var/lib/isulad/data/overlay/" + id + "/merged";
struct driver_mount_opts *mount_opts = nullptr;
char* mount_dir = nullptr;
EXPECT_CALL(m_driver_quota_mock, GetPageSize()).WillRepeatedly(Invoke(invokeGetPageSize));
FLAGS_gmock_catch_leaked_mocks = false; // the exit in the child without deleting the mock object
mount_dir = graphdriver_mount_layer(id.c_str(), mount_opts);
ASSERT_STREQ(mount_dir, merged_dir.c_str());
FLAGS_gmock_catch_leaked_mocks = true;
ASSERT_EQ(graphdriver_umount_layer(id.c_str()), 0);
free(mount_dir);
mount_dir = nullptr;
mount_opts = (struct driver_mount_opts *)malloc(sizeof(struct driver_mount_opts));
ASSERT_NE(mount_opts, nullptr);
mount_opts->mount_label = strdup("mount_label");
mount_opts->options = (char **)malloc(1 * sizeof(char *));
mount_opts->options[0] = strdup("ro");
mount_opts->options_len = 1;
FLAGS_gmock_catch_leaked_mocks = false;
mount_dir = graphdriver_mount_layer(id.c_str(), mount_opts);
ASSERT_STREQ(mount_dir, merged_dir.c_str());
FLAGS_gmock_catch_leaked_mocks = true;
ASSERT_EQ(graphdriver_umount_layer(id.c_str()), 0);
free_driver_mount_opts(mount_opts);
free(mount_dir);
}
TEST_F(StorageDriverUnitTest, test_graphdriver_try_repair_lowers)
{
std::string id { "1be74353c3d0fd55fb5638a52953e6f1bc441e5b1710921db9ec2aa202725569" };
ASSERT_EQ(graphdriver_try_repair_lowers(id.c_str(), nullptr), 0);
}
TEST(StorageOverlay2QuotaOptionsTest, test_overlay2_is_quota_options)
{
std::vector<std::string> options { "overlay2.size", "overlay2.basesize" };
for(auto option : options) {
ASSERT_TRUE(overlay2_is_quota_options(nullptr, option.c_str()));
}
}
\ No newline at end of file
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: zhangxiaoyu
* Create: 2020-06-20
* Description: provide driver quota mock
******************************************************************************/
#include "driver_quota_mock.h"
namespace {
MockDriverQuota *g_driver_quota_mock = NULL;
}
void MockDriverQuota_SetMock(MockDriverQuota* mock)
{
g_driver_quota_mock = mock;
}
int getpagesize()
{
if (g_driver_quota_mock != nullptr) {
return g_driver_quota_mock->GetPageSize();
}
return 0;
}
int ioctl(int fd, unsigned long int cmd, ...)
{
if (g_driver_quota_mock != nullptr) {
return g_driver_quota_mock->IOCtl(fd, cmd);
}
return 0;
}
int quotactl(int cmd, const char* special, int id, caddr_t addr)
{
if (g_driver_quota_mock != nullptr) {
return g_driver_quota_mock->QuotaCtl(cmd, special, id, addr);
}
return 0;
}
\ No newline at end of file
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: zhangxiaoyu
* Create: 2020-06-20
* Description: provide driver quota mock
******************************************************************************/
#ifndef DRIVER_QUOTA_MOCK_H_
#define DRIVER_QUOTA_MOCK_H_
#include <gmock/gmock.h>
#include "project_quota.h"
class MockDriverQuota {
public:
virtual ~MockDriverQuota() = default;
MOCK_METHOD0(GetPageSize, int());
MOCK_METHOD2(IOCtl, int(int, unsigned long int));
MOCK_METHOD4(QuotaCtl, int(int, const char*, int, caddr_t));
};
void MockDriverQuota_SetMock(MockDriverQuota* mock);
#endif // DRIVER_QUOTA_MOCK_H_
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册