提交 263e29ac 编写于 作者: O openeuler-ci-bot 提交者: Gitee

!69 isulad: add isula runtime ops llt

Merge pull request !69 from jing-rui/dev
......@@ -247,6 +247,10 @@ static int get_runtime_args(const char *runtime, const char ***args)
defs_map_string_object_runtimes *runtimes = NULL;
size_t i = 0;
if (runtime == NULL) {
return 0;
}
if (isulad_server_conf_rdlock()) {
ERROR("failed to lock server config");
goto out;
......@@ -677,14 +681,21 @@ out:
int rt_isula_create(const char *id, const char *runtime,
const rt_create_params_t *params)
{
oci_runtime_spec *config = params->oci_config_data;
oci_runtime_spec *config = NULL;
const char *cmd = NULL;
const char **runtime_args = NULL;
size_t runtime_args_len = get_runtime_args(runtime, &runtime_args);
size_t runtime_args_len = 0;
int ret = 0;
char workdir[PATH_MAX] = {0};
shim_client_process_state p = {0};
if (id == NULL || runtime == NULL || params == NULL) {
ERROR("nullptr arguments not allowed");
return -1;
}
config = params->oci_config_data;
runtime_args_len = get_runtime_args(runtime, &runtime_args);
if (snprintf(workdir, sizeof(workdir), "%s/%s", params->state, id) < 0) {
INFO("make full workdir failed");
ret = -1;
......@@ -727,6 +738,10 @@ int rt_isula_start(const char *id, const char *runtime,
pid_t pid = 0;
int ret = 0;
if (id == NULL || runtime == NULL || params == NULL || pid_info == NULL) {
ERROR("nullptr arguments not allowed");
return -1;
}
if (snprintf(workdir, sizeof(workdir), "%s/%s", params->state, id) < 0) {
ERROR("%s: missing shim workdir", id);
return -1;
......@@ -772,6 +787,16 @@ int rt_isula_clean_resource(const char *id, const char *runtime,
{
char workdir[PATH_MAX] = {0};
if (id == NULL || runtime == NULL || params == NULL) {
ERROR("nullptr arguments not allowed");
return -1;
}
if (params->statepath == NULL) {
ERROR("missing state path");
return -1;
}
if (snprintf(workdir, sizeof(workdir), "%s/%s", params->statepath, id) < 0) {
ERROR("failed get shim workdir");
return -1;
......@@ -796,6 +821,14 @@ int rt_isula_rm(const char *id, const char *runtime, const rt_rm_params_t *param
{
char libdir[PATH_MAX] = {0};
if (id == NULL || runtime == NULL || params == NULL) {
ERROR("nullptr arguments not allowed");
return -1;
}
if (params->rootpath == NULL) {
ERROR("missing root path");
return -1;
}
if (snprintf(libdir, sizeof(libdir), "%s/%s", params->rootpath, id) < 0) {
ERROR("failed get shim workdir");
return -1;
......@@ -845,9 +878,9 @@ int rt_isula_exec(const char *id, const char *runtime,
const rt_exec_params_t *params, int *exit_code)
{
char *exec_id = NULL;
defs_process *process = params->spec;
defs_process *process = NULL;
const char **runtime_args = NULL;
size_t runtime_args_len = get_runtime_args(runtime, &runtime_args);
size_t runtime_args_len = 0;
char workdir[PATH_MAX] = {0};
const char *cmd = NULL;
int ret = 0;
......@@ -855,6 +888,13 @@ int rt_isula_exec(const char *id, const char *runtime,
int pid = 0;
shim_client_process_state p = {0};
if (id == NULL || runtime == NULL || params == NULL || exit_code == NULL) {
ERROR("nullptr arguments not allowed");
return -1;
}
process = params->spec;
runtime_args_len = get_runtime_args(runtime, &runtime_args);
ret = snprintf(bundle, sizeof(bundle), "%s/%s", params->rootpath, id);
if (ret < 0) {
ERROR("failed join bundle path for exec");
......@@ -926,6 +966,11 @@ int rt_isula_status(const char *id, const char *runtime,
char workdir[PATH_MAX] = {0};
int ret = 0;
if (id == NULL || runtime == NULL || params == NULL || status == NULL) {
ERROR("nullptr arguments not allowed");
return -1;
}
ret = snprintf(workdir, sizeof(workdir), "%s/%s", params->state, id);
if (ret < 0) {
ERROR("failed join full workdir %s/%s", params->rootpath, id);
......
......@@ -41,3 +41,8 @@ bool has_mount_for(container_t *cont, const char *mpath)
}
return false;
}
int container_read_proc(uint32_t pid, container_pid_t *pid_info)
{
return 0;
}
......@@ -97,3 +97,18 @@ char *conf_get_isulad_storage_driver()
}
return nullptr;
}
int isulad_server_conf_rdlock()
{
return 0;
}
int isulad_server_conf_unlock()
{
return 0;
}
struct service_arguments *conf_get_server_conf()
{
return NULL;
}
project(iSulad_LLT)
add_subdirectory(lcr)
add_subdirectory(isula)
project(iSulad_LLT)
SET(EXE isula_rt_ops_llt)
add_executable(${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/log.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/sha256/sha256.c
${CMAKE_BINARY_DIR}/json/json_common.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/path.c
${CMAKE_BINARY_DIR}/json/host_config.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/libisulad.c
${CMAKE_BINARY_DIR}/json/defs.c
${CMAKE_BINARY_DIR}/json/container_config_v2.c
${CMAKE_BINARY_DIR}/json/container_config.c
${CMAKE_BINARY_DIR}/json/oci_runtime_spec.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/services/execution/spec/sysinfo.c
${CMAKE_BINARY_DIR}/json/oci_runtime_config_linux.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cmd/commander.c
${CMAKE_BINARY_DIR}/json/isulad_daemon_configs.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/json/schema/src/read_file.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cmd/isulad/arguments.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/image/oci/oci_llt_common.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/containers_store_mock.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/namespace_mock.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/container_unix_mock.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/engine_mock.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/isulad_config_mock.cc
${CMAKE_BINARY_DIR}/json/imagetool_image.c
${CMAKE_BINARY_DIR}/json/oci_image_spec.c
${CMAKE_BINARY_DIR}/json/shim_client_process_state.c
${CMAKE_BINARY_DIR}/json/oci_runtime_state.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/runtime/isula/isula_rt_ops.c
isula_rt_ops_llt.cc)
target_include_directories(${EXE} PUBLIC
${GTEST_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../../include
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils
${CMAKE_CURRENT_SOURCE_DIR}/../../../src
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/map
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/services/execution/manager
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/services/execution/events
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/runtime
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/runtime/isula
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/services/execution/spec
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/json
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/engines
${CMAKE_BINARY_DIR}/json
${CMAKE_BINARY_DIR}/conf
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/sha256
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/config
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cmd
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/services/graphdriver
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/json/schema/src
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/console
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks
)
#set_target_properties(${EXE} PROPERTIES LINK_FLAGS)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} -lgrpc++ -lprotobuf -lcrypto -lyajl -lz)
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
* iSulad licensed under the Mulan PSL v1.
* You can use this software according to the terms and conditions of the Mulan PSL v1.
* You may obtain a copy of Mulan PSL v1 at:
* http://license.coscl.org.cn/MulanPSL
* 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 v1 for more details.
* Description: isula runtime ops llt
* Author: jingrui
* Create: 2020-02-15
*/
#include <stdlib.h>
#include <stdio.h>
#include <gtest/gtest.h>
#include "mock.h"
#include "isula_rt_ops.h"
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "engine_mock.h"
#include "isulad_config_mock.h"
#include "utils.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 namespace std;
class IsulaRtOpsUnitTest : public testing::Test {
public:
void SetUp() override
{
MockEngine_SetMock(&m_engine);
::testing::Mock::AllowLeak(&m_engine);
MockIsuladConf_SetMock(&m_isulad_conf);
::testing::Mock::AllowLeak(&m_isulad_conf);
}
void TearDown() override
{
MockEngine_SetMock(nullptr);
MockIsuladConf_SetMock(nullptr);
}
NiceMock<MockEngine> m_engine;
NiceMock<MockIsuladConf> m_isulad_conf;
};
TEST(isula_rt_ops_llt, test_rt_isula_detect)
{
// All parameter NULL
ASSERT_FALSE(rt_isula_detect(NULL));
ASSERT_TRUE(rt_isula_detect("kata-runtime"));
ASSERT_TRUE(rt_isula_detect("kata-me"));
ASSERT_TRUE(rt_isula_detect("runc"));
ASSERT_FALSE(rt_isula_detect("lcr"));
}
TEST_F(IsulaRtOpsUnitTest, test_rt_isula_create)
{
ASSERT_EQ(rt_isula_create(nullptr, nullptr, nullptr), -1);
ASSERT_EQ(rt_isula_create("123", nullptr, nullptr), -1);
ASSERT_EQ(rt_isula_create("123", "kata-runtime", nullptr), -1);
}
TEST_F(IsulaRtOpsUnitTest, test_rt_isula_start)
{
rt_start_params_t params = {};
ASSERT_EQ(rt_isula_start(nullptr, nullptr, nullptr, nullptr), -1);
ASSERT_EQ(rt_isula_start("123", nullptr, nullptr, nullptr), -1);
ASSERT_EQ(rt_isula_start("123", "kata-runtime", nullptr, nullptr), -1);
ASSERT_EQ(rt_isula_start("123", "kata-runtime", &params, nullptr), -1);
}
TEST_F(IsulaRtOpsUnitTest, test_rt_isula_clean_resource)
{
rt_clean_params_t params = {};
ASSERT_EQ(rt_isula_clean_resource(nullptr, nullptr, nullptr), -1);
ASSERT_EQ(rt_isula_clean_resource("123", nullptr, nullptr), -1);
ASSERT_EQ(rt_isula_clean_resource("123", "kata-runtime", nullptr), -1);
ASSERT_EQ(rt_isula_clean_resource("123", "kata-runtime", &params), -1);
params.statepath = "/var/run/isulad/kata-runtime/123";
ASSERT_EQ(rt_isula_clean_resource("123", "kata-runtime", &params), 0);
}
TEST_F(IsulaRtOpsUnitTest, test_rt_isula_rm)
{
rt_rm_params_t params = {};
ASSERT_EQ(rt_isula_rm(nullptr, nullptr, nullptr), -1);
ASSERT_EQ(rt_isula_rm("123", nullptr, nullptr), -1);
ASSERT_EQ(rt_isula_rm("123", "kata-runtime", nullptr), -1);
ASSERT_EQ(rt_isula_rm("123", "kata-runtime", &params), -1);
params.rootpath = "/var/lib/isulad/kata-runtime/123";
ASSERT_EQ(rt_isula_rm("123", "kata-runtime", &params), 0);
}
TEST_F(IsulaRtOpsUnitTest, test_rt_isula_exec)
{
rt_exec_params_t params = {};
ASSERT_EQ(rt_isula_exec(nullptr, nullptr, nullptr, nullptr), -1);
ASSERT_EQ(rt_isula_exec("123", nullptr, nullptr, nullptr), -1);
ASSERT_EQ(rt_isula_exec("123", "kata-runtime", nullptr, nullptr), -1);
ASSERT_EQ(rt_isula_exec("123", "kata-runtime", &params, nullptr), -1);
}
TEST_F(IsulaRtOpsUnitTest, test_rt_isula_status)
{
rt_status_params_t params = {};
struct engine_container_status_info status = {};
ASSERT_EQ(rt_isula_status(nullptr, nullptr, nullptr, nullptr), -1);
ASSERT_EQ(rt_isula_status("123", nullptr, nullptr, nullptr), -1);
ASSERT_EQ(rt_isula_status("123", "kata-runtime", nullptr, nullptr), -1);
ASSERT_EQ(rt_isula_status("123", "kata-runtime", &params, nullptr), -1);
params.state="/var/run/isulad/kata-runtime";
ASSERT_EQ(rt_isula_status("123", "kata-runtime", &params, &status), -1);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册