diff --git a/0001-fix-CNI_ARGS-value-when-there-is-no-args.patch b/0001-fix-CNI_ARGS-value-when-there-is-no-args.patch deleted file mode 100644 index 8c4be104bb0646b0f48d146d45f2c63750f589a8..0000000000000000000000000000000000000000 --- a/0001-fix-CNI_ARGS-value-when-there-is-no-args.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 2888c4de723200b85888cc7c2cf8b5c0b9a3c59e Mon Sep 17 00:00:00 2001 -From: zhangxiaoyu -Date: Thu, 4 Feb 2021 10:49:43 +0800 -Subject: [PATCH 1/2] fix CNI_ARGS value when there is no args - -Signed-off-by: zhangxiaoyu ---- - src/invoke/args.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/invoke/args.c b/src/invoke/args.c -index dae484e..2b357ed 100644 ---- a/src/invoke/args.c -+++ b/src/invoke/args.c -@@ -126,7 +126,7 @@ static int add_cni_envs(const struct cni_args *cniargs, size_t *pos, char **resu - } - result[i++] = buffer; - buffer = NULL; -- nret = asprintf(&buffer, "%s=%s", ENV_CNI_ARGS, plugin_args_str); -+ nret = asprintf(&buffer, "%s=%s", ENV_CNI_ARGS, plugin_args_str == NULL ? "" : plugin_args_str); - if (nret < 0) { - ERROR("Sprintf failed"); - goto free_out; --- -2.25.1 - diff --git a/0002-add-error-info-for-failed-run-cni-plugin.patch b/0002-add-error-info-for-failed-run-cni-plugin.patch deleted file mode 100644 index 7e494b3fd1939f657b50144a2508c49b28475fc0..0000000000000000000000000000000000000000 --- a/0002-add-error-info-for-failed-run-cni-plugin.patch +++ /dev/null @@ -1,27 +0,0 @@ -From 70b8a1516207cb9af774c6742d0973e022f3265b Mon Sep 17 00:00:00 2001 -From: haozi007 -Date: Fri, 26 Mar 2021 17:42:02 +0800 -Subject: [PATCH 2/2] add error info for failed run cni plugin - -Signed-off-by: haozi007 ---- - src/api.c | 3 +++ - 1 file changed, 3 insertions(+) - -diff --git a/src/api.c b/src/api.c -index 97d166d..52d193f 100644 ---- a/src/api.c -+++ b/src/api.c -@@ -348,6 +348,9 @@ static int run_cni_plugin(const struct network_config_list *list, size_t i, cons - *pret = NULL; - ret = exec_plugin_with_result(plugin_path, net.bytes, cargs, pret, err); - } -+ if (ret != 0) { -+ ERROR("pod %s CNI op failed with %s", rc->container_id, net.bytes); -+ } - free_out: - free_cni_args(cargs); - free(plugin_path); --- -2.25.1 - diff --git a/0003-add-testcase-for-clibcni.patch b/0003-add-testcase-for-clibcni.patch deleted file mode 100644 index 306982a8de51af52d754d2d9ce537e43843942b7..0000000000000000000000000000000000000000 --- a/0003-add-testcase-for-clibcni.patch +++ /dev/null @@ -1,397 +0,0 @@ -From 678baec08a80c65950180dd0e4c403c03d628693 Mon Sep 17 00:00:00 2001 -From: haozi007 -Date: Thu, 16 Sep 2021 04:57:01 +0100 -Subject: [PATCH] add testcase for clibcni - -Signed-off-by: haozi007 ---- - CMakeLists.txt | 5 + - clibcni.spec | 8 +- - tests/CMakeLists.txt | 48 ++++++++++ - tests/api_llt.cpp | 185 +++++++++++++++++++++++++++++++++++++ - tests/main.cpp | 22 +++++ - tests/utils/CMakeLists.txt | 7 ++ - tests/utils/constants.h | 37 ++++++++ - 7 files changed, 310 insertions(+), 2 deletions(-) - create mode 100644 tests/CMakeLists.txt - create mode 100644 tests/api_llt.cpp - create mode 100644 tests/main.cpp - create mode 100644 tests/utils/CMakeLists.txt - create mode 100644 tests/utils/constants.h - -diff --git a/CMakeLists.txt b/CMakeLists.txt -index a5c7fec..fad4472 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -58,6 +58,11 @@ endif() - - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src) - -+option(ENABLE_UT "enble ut testcase" OFF) -+if (ENABLE_UT STREQUAL "ON") -+ add_subdirectory(tests) -+endif() -+ - # install all files - install(FILES ${CMAKE_BINARY_DIR}/conf/clibcni.pc - DESTINATION ${LIB_INSTALL_DIR_DEFAULT}/pkgconfig PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE) -diff --git a/clibcni.spec b/clibcni.spec -index fa2046b..784538a 100644 ---- a/clibcni.spec -+++ b/clibcni.spec -@@ -12,7 +12,7 @@ BuildRoot: %{_tmppath}/%{name}-%{version} - - BuildRequires: gcc - BuildRequires: cmake --BuildRequires: lcr-devel yajl-devel -+BuildRequires: lcr-devel yajl-devel gtest-devel - - Requires: lcr - -@@ -44,9 +44,13 @@ the %{name}-libs package contains libraries for running %{name} applications. - %build - mkdir -p build - cd build --%cmake -DDEBUG=ON -DLIB_INSTALL_DIR=%{_libdir} ../ -+%cmake -DDEBUG=ON -DENABLE_UT=ON -DLIB_INSTALL_DIR=%{_libdir} ../ - %make_build - -+pushd tests -+ctest -V -+popd -+ - %install - rm -rf %{buildroot} - cd build -diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt -new file mode 100644 -index 0000000..6cb2c7b ---- /dev/null -+++ b/tests/CMakeLists.txt -@@ -0,0 +1,48 @@ -+enable_testing() -+find_package(GTest REQUIRED) -+ -+set(CMAKE_C_COMPILER "g++" CACHE PATH "c compiler") -+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") -+ -+include_directories( -+ ${GTEST_INCLUDE_DIR} -+ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} -+ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/utils -+ PUBLIC ${CMAKE_SOURCE_DIR}/src -+ PUBLIC ${CMAKE_SOURCE_DIR}/src/version/ -+ PUBLIC ${CMAKE_SOURCE_DIR}/src/types/ -+ PUBLIC ${CMAKE_SOURCE_DIR}/src/invoke/ -+ PUBLIC ${CMAKE_SOURCE_DIR}/src/json -+ PUBLIC ${CMAKE_SOURCE_DIR}/src/json/schema/src -+ PUBLIC ${CMAKE_BINARY_DIR}/json -+ PUBLIC ${CMAKE_BINARY_DIR}/conf -+ ) -+ -+add_subdirectory(utils) -+ -+macro(_DEFINE_NEW_TEST) -+ add_executable(${ARGV0} -+ ${TESTS_UTILS_SRCS} -+ main.cpp -+ ${ARGV0}.cpp -+ ) -+ -+ target_link_libraries(${ARGV0} -+ clibcni -+ gtest -+ -lyajl -+ pthread -+ ) -+ -+ add_test( -+ NAME ${ARGV1} -+ COMMAND ${ARGV0} -+ ) -+endmacro() -+ -+# --------------- testcase add here ----------------- -+# api testcase -+_DEFINE_NEW_TEST(api_llt api_testcase) -+ -+# --------------- testcase add finish ----------------- -+ -diff --git a/tests/api_llt.cpp b/tests/api_llt.cpp -new file mode 100644 -index 0000000..d21ec01 ---- /dev/null -+++ b/tests/api_llt.cpp -@@ -0,0 +1,185 @@ -+/* -+ * Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved. -+ * clibcni 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: haozi007 -+ * Create: 2021-09-16 -+ * Description: provide cni api functions -+ */ -+#include -+ -+#include -+ -+#include -+#include -+ -+#include "api.h" -+#include "version.h" -+#include "conf.h" -+#include "constants.h" -+ -+ -+void api_check_network_config_list(struct cni_network_list_conf *conf, const char *target_name, bool check_plugin_name) -+{ -+ /* check network_config_list */ -+ ASSERT_NE(conf, nullptr); -+ ASSERT_NE(conf->first_plugin_name, nullptr); -+ ASSERT_NE(conf->first_plugin_type, nullptr); -+ EXPECT_STREQ(target_name, conf->name); -+ ASSERT_NE(conf->bytes, nullptr); -+ -+ struct network_config_list *tmp = NULL; -+ char *err = NULL; -+ int ret = conflist_from_bytes(conf->bytes, &tmp, &err); -+ if (ret != 0) { -+ std::cout << "conflist parse failed:" << err << std::endl; -+ } -+ free(err); -+ ASSERT_EQ(ret , 0); -+ -+ /* check net_conf_list */ -+ EXPECT_STREQ("0.3.0", tmp->list->cni_version); -+ EXPECT_STREQ(target_name, tmp->list->name); -+ ASSERT_NE(tmp->list->plugins, nullptr); -+ ASSERT_EQ(tmp->list->plugins_len, 2); -+ EXPECT_STREQ("0.3.0", tmp->list->plugins[0]->cni_version); -+ if (check_plugin_name) { -+ EXPECT_STREQ(target_name, tmp->list->plugins[0]->name); -+ } -+ EXPECT_STREQ("bridge", tmp->list->plugins[0]->type); -+ ASSERT_EQ(tmp->list->plugins[0]->dns, nullptr); -+ ASSERT_EQ(tmp->list->plugins[0]->runtime_config, nullptr); -+ ASSERT_EQ(tmp->list->plugins[0]->capabilities, nullptr); -+ ASSERT_EQ(tmp->list->plugins[0]->prev_result, nullptr); -+ EXPECT_STREQ("10.1.0.1", tmp->list->plugins[1]->dns->nameservers[0]); -+ EXPECT_STREQ("bridge", tmp->list->plugins[1]->type); -+ -+ free_network_config_list(tmp); -+} -+ -+TEST(api_testcases, cni_conflist_from_bytes) -+{ -+ int ret; -+ struct cni_network_list_conf *new_list = NULL; -+ char *err = NULL; -+ -+ ret = cni_conflist_from_bytes(COMMON_CONF_LIST, &new_list, &err); -+ if (ret != 0) { -+ std::cout << "conflist parse failed:" << err << std::endl; -+ } -+ free(err); -+ std::cout << new_list->bytes << std::endl; -+ -+ api_check_network_config_list(new_list, "default", true); -+ -+ free(err); -+ free_cni_network_list_conf(new_list); -+} -+ -+void api_check_network_config_list_from_conf(struct cni_network_list_conf *conf, const char *target_name, bool check_plugin_name) -+{ -+ /* check network_config_list */ -+ ASSERT_NE(conf, nullptr); -+ ASSERT_NE(conf->first_plugin_name, nullptr); -+ ASSERT_NE(conf->first_plugin_type, nullptr); -+ EXPECT_STREQ(target_name, conf->name); -+ ASSERT_NE(conf->bytes, nullptr); -+ -+ struct network_config_list *tmp = NULL; -+ char *err = NULL; -+ int ret = conflist_from_bytes(conf->bytes, &tmp, &err); -+ if (ret != 0) { -+ std::cout << "conflist parse failed:" << err << std::endl; -+ } -+ free(err); -+ ASSERT_EQ(ret , 0); -+ -+ /* check net_conf_list */ -+ EXPECT_STREQ("0.3.0", tmp->list->cni_version); -+ EXPECT_STREQ(target_name, tmp->list->name); -+ ASSERT_NE(tmp->list->plugins, nullptr); -+ ASSERT_EQ(tmp->list->plugins_len, 1); -+ EXPECT_STREQ("0.3.0", tmp->list->plugins[0]->cni_version); -+ if (check_plugin_name) { -+ EXPECT_STREQ(target_name, tmp->list->plugins[0]->name); -+ } -+ EXPECT_STREQ("bridge", tmp->list->plugins[0]->type); -+ ASSERT_NE(tmp->list->plugins[0]->dns, nullptr); -+ EXPECT_STREQ("10.1.0.1", tmp->list->plugins[0]->dns->nameservers[0]); -+ EXPECT_STREQ("bridge", tmp->list->plugins[0]->type); -+ ASSERT_EQ(tmp->list->plugins[0]->runtime_config, nullptr); -+ ASSERT_EQ(tmp->list->plugins[0]->capabilities, nullptr); -+ ASSERT_EQ(tmp->list->plugins[0]->prev_result, nullptr); -+ ASSERT_NE(tmp->list->plugins[0]->ipam, nullptr); -+ EXPECT_STREQ("host-local", tmp->list->plugins[0]->ipam->type); -+ EXPECT_STREQ("10.1.0.0/16", tmp->list->plugins[0]->ipam->subnet); -+ EXPECT_STREQ("10.1.0.1", tmp->list->plugins[0]->ipam->gateway); -+ -+ free_network_config_list(tmp); -+} -+ -+TEST(api_testcases, cni_conflist_from_conf) -+{ -+ int ret; -+ struct cni_network_list_conf *new_list = NULL; -+ char *err = NULL; -+ struct cni_network_conf test = { -+ .name = "default", -+ .type = "bridge", -+ .bytes = COMMON_CONF, -+ }; -+ -+ ret = cni_conflist_from_conf(&test, &new_list, &err); -+ if (ret != 0) { -+ std::cout << "conflist parse failed:" << err << std::endl; -+ } -+ free(err); -+ std::cout << new_list->bytes << std::endl; -+ -+ api_check_network_config_list_from_conf(new_list, "default", true); -+ -+ free(err); -+ free_cni_network_list_conf(new_list); -+} -+ -+TEST(api_testcases, get_version_info) -+{ -+ const std::string CNI_PLUGIN_PATH = "/opt/cni/bin/"; -+ char *err = nullptr; -+ struct plugin_info *pinfo = nullptr; -+ size_t i = 0; -+ int ret = 0; -+ char *paths[] = {strdup(CNI_PLUGIN_PATH.c_str()), nullptr}; -+ const std::string bridge_name = "bridge"; -+ -+ ret = cni_get_version_info(bridge_name.c_str(), paths, &pinfo, &err); -+ if (ret != 0) { -+ if (strstr(err, "No such file or directory") != nullptr) { -+ std::cout << "Skip: cni_get_version_info api cause by no bridge plugin found" << std::endl; -+ return; -+ } -+ std::cout << "Get version failed:" << err << std::endl; -+ } -+ ASSERT_EQ(ret, 0); -+ -+ /* check plugin info */ -+ EXPECT_STREQ("0.4.0", pinfo->cniversion); -+ ASSERT_LE(0, pinfo->supported_versions_len); -+ for (i = 0; i < pinfo->supported_versions_len; i++) { -+ if (strcmp(pinfo->supported_versions[i], CURRENT_VERSION) == 0) { -+ break; -+ } -+ } -+ ASSERT_LE(i, pinfo->supported_versions_len); -+ -+ free_plugin_info(pinfo); -+ free(paths[0]); -+ paths[0] = nullptr; -+} -+ -diff --git a/tests/main.cpp b/tests/main.cpp -new file mode 100644 -index 0000000..7a4bc09 ---- /dev/null -+++ b/tests/main.cpp -@@ -0,0 +1,22 @@ -+/* -+ * Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved. -+ * clibcni 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: haozi007 -+ * Create: 2021-09-16 -+ * Description: provide cni api functions -+ */ -+ -+#include "gtest/gtest.h" -+ -+int main(int argc, char **argv) { -+ testing::InitGoogleTest(&argc, argv); -+ -+ return RUN_ALL_TESTS(); -+} -diff --git a/tests/utils/CMakeLists.txt b/tests/utils/CMakeLists.txt -new file mode 100644 -index 0000000..9b01eb6 ---- /dev/null -+++ b/tests/utils/CMakeLists.txt -@@ -0,0 +1,7 @@ -+# get current directory sources files -+aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} local_cutils_srcs) -+ -+set(TESTS_UTILS_SRCS -+ ${local_cutils_srcs} -+ PARENT_SCOPE -+ ) -diff --git a/tests/utils/constants.h b/tests/utils/constants.h -new file mode 100644 -index 0000000..1f06bfc ---- /dev/null -+++ b/tests/utils/constants.h -@@ -0,0 +1,37 @@ -+/* -+ * Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved. -+ * clibcni 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: haozi007 -+ * Create: 2021-09-16 -+ * Description: provide cni api functions -+ */ -+#ifndef _TESTS_CONSTANTS_H -+#define _TESTS_CONSTANTS_H -+ -+#ifdef __cplusplus -+extern "C" { -+#endif -+ -+#define DEFAULT_CNI_BIN_PATH "/opt/cni/bin" -+ -+#define COMMON_CONF_LIST "{\"cniVersion\":\"0.3.0\",\"name\":\"default\", \ -+ \"plugins\":[{\"cniVersion\":\"0.3.0\", \"name\":\"default\",\"type\":\"bridge\"}, \ -+ {\"name\": \"exist\",\"type\": \"bridge\", \"dns\": {\"nameservers\": [\"10.1.0.1\"]}}]}" -+ -+#define COMMON_CONF "{\"cniVersion\":\"0.3.0\",\"name\":\"default\", \ -+ \"type\": \"bridge\", \"bridge\": \"cni0\", \"isGateway\": \"true\", \ -+ \"ipam\": {\"type\": \"host-local\", \"subnet\": \"10.1.0.0/16\", \"gateway\": \"10.1.0.1\"},\ -+ \"dns\": {\"nameservers\": [\"10.1.0.1\"]}}" -+ -+#ifdef __cplusplus -+} -+#endif -+ -+#endif --- -2.20.1 - diff --git a/clibcni.spec b/clibcni.spec index b7b9ca9285da1cb222be5762d28639689b4e29a0..6934896051da55ccd3f1efc0b01431c804591654 100644 --- a/clibcni.spec +++ b/clibcni.spec @@ -1,5 +1,5 @@ -%global _version 2.0.4 -%global _release 20210916.073015.gitf0a2cb38 +%global _version 2.0.5 +%global _release 1 Name: clibcni Version: %{_version} Release: %{_release} @@ -10,10 +10,6 @@ URL: https://gitee.com/openeuler/clibcni Source0: https://gitee.com/openeuler/clibcni/repository/archive/v%{version}.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version} -Patch0001: 0001-fix-CNI_ARGS-value-when-there-is-no-args.patch -Patch0002: 0002-add-error-info-for-failed-run-cni-plugin.patch -Patch0003: 0003-add-testcase-for-clibcni.patch - BuildRequires: gcc git gcc-c++ BuildRequires: cmake BuildRequires: lcr-devel yajl-devel gtest-devel @@ -93,6 +89,12 @@ rm -rf %{buildroot} %{_libdir}/pkgconfig/%{name}.pc %changelog +* Tue Oct 12 2021 wujing - 2.0.5-1 +- Type: sync +- ID: NA +- SUG: NA +- DESC: upgrade to 2.0.5 + * Mon Jun 28 2021 haozi007 - 2.0.4-20210628.190359.git14c104bc - Type: add g++ to build require - ID: NA diff --git a/v2.0.4.tar.gz b/v2.0.4.tar.gz deleted file mode 100644 index 1bb723309bfb51b3b14e3494cb046cfef11fff57..0000000000000000000000000000000000000000 Binary files a/v2.0.4.tar.gz and /dev/null differ diff --git a/v2.0.5.tar.gz b/v2.0.5.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..7f280f5fc255659159b916434b93ab05b344969a Binary files /dev/null and b/v2.0.5.tar.gz differ