From 0d40038903e2ca3f34c8706fe82a1a78ea583a79 Mon Sep 17 00:00:00 2001 From: lifeng68 Date: Tue, 19 May 2020 04:35:07 -0400 Subject: [PATCH] CI: refact CI testcases Signed-off-by: lifeng68 --- CI/test_cases/basic_cases/basic_helpers.bash | 84 -------- .../basic_cases/create_mtab_test.bash | 48 ----- CI/test_cases/helpers.bash | 196 ++++++------------ .../{basic_cases => image_cases}/help.bash | 2 +- .../image_inspect.bash | 2 +- .../image_remove.bash | 2 +- .../image_tag.bash | 2 +- .../images_list.bash | 2 +- .../img_fs_info.bash | 2 +- .../img_status.bash | 2 +- .../registry.bash | 2 +- .../{basic_cases => image_cases}/version.bash | 2 +- 12 files changed, 69 insertions(+), 277 deletions(-) delete mode 100755 CI/test_cases/basic_cases/basic_helpers.bash delete mode 100755 CI/test_cases/basic_cases/create_mtab_test.bash rename CI/test_cases/{basic_cases => image_cases}/help.bash (98%) rename CI/test_cases/{basic_cases => image_cases}/image_inspect.bash (98%) rename CI/test_cases/{basic_cases => image_cases}/image_remove.bash (96%) rename CI/test_cases/{basic_cases => image_cases}/image_tag.bash (99%) rename CI/test_cases/{basic_cases => image_cases}/images_list.bash (98%) rename CI/test_cases/{basic_cases => image_cases}/img_fs_info.bash (97%) rename CI/test_cases/{basic_cases => image_cases}/img_status.bash (98%) rename CI/test_cases/{basic_cases => image_cases}/registry.bash (98%) rename CI/test_cases/{basic_cases => image_cases}/version.bash (99%) diff --git a/CI/test_cases/basic_cases/basic_helpers.bash b/CI/test_cases/basic_cases/basic_helpers.bash deleted file mode 100755 index e6a1fc2..0000000 --- a/CI/test_cases/basic_cases/basic_helpers.bash +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/bash - -####################################################################### -##- @Copyright (C) Huawei Technologies., 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. -##- @Description:CI -##- @Author: lifeng -##- @Create: 2020-03-30 -####################################################################### - -# testcase result -TC_RET_T=0 -declare -a lines - -# Root directory of integration tests. -INTEGRATION_ROOT=$(dirname "$(readlink -f "$BASH_SOURCE")") -LCR_ROOT_PATH="/var/lib/isulad/engines/lcr" -ISUALD_LOG="/var/lib/isulad/isulad.log" - -declare -r -i FAILURE=-1 - -function cut_output_lines() { - message=`$@ 2>&1` - retval=$? - oldifs=${IFS} - IFS=$'\n' - lines=(${message}) - IFS="${oldifs}" - return $retval -} - -function fn_check_eq() { - if [[ "$1" -ne "$2" ]];then - echo "$3" - TC_RET_T=$(($TC_RET_T+1)) - fi -} - -function fn_check_ne() { - if [[ "$1" -eq "$2" ]];then - echo "$3" - TC_RET_T=$(($TC_RET_T+1)) - fi -} - -function testcontainer() { - st=`isula inspect -f '{{json .State.Status}}' "$1"` - if ! [[ "${st}" =~ "$2" ]];then - echo "expect status $2, but get ${st}" - TC_RET_T=$(($TC_RET_T+1)) - fi -} - -function crictl() { - CRICTL=$(which crictl) - "$CRICTL" -i unix:///var/run/isulad.sock -r unix:///var/run/isulad.sock "$@" -} - -function msg_ok() -{ - echo -e "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: \033[1;32m$@\033[0m" -} - -function msg_err() -{ - echo -e "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: \033[1;31m$@\033[0m" >&2 -} - -function msg_info() -{ - echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $@" -} - -function show_result() { - [[ ${1} -ne 0 ]] && msg_err "TESTSUIT: $2 FAILED" && return ${FAILURE} - msg_ok "TESTSUIT: $2 SUCCESS" -} diff --git a/CI/test_cases/basic_cases/create_mtab_test.bash b/CI/test_cases/basic_cases/create_mtab_test.bash deleted file mode 100755 index 8e9b8d6..0000000 --- a/CI/test_cases/basic_cases/create_mtab_test.bash +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash -# -# attributes: isulad inheritance start -# concurrent: YES -# spend time: 2 - -####################################################################### -##- @Copyright (C) Huawei Technologies., 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. -##- @Description:CI -##- @Author: gaohuatao -##- @Create: 2020-05-11 -####################################################################### - -curr_path=$(dirname $(readlink -f "$0")) -data_path=$(realpath $curr_path/../data) -source ./helpers.bash - -function do_test_t() -{ - id=`isula run -tid --runtime runc busybox` - fn_check_eq "$?" "0" "run failed" - testcontainer $id running - - isula exec $id sh -c 'ls -al /etc/mtab' - fn_check_eq "$?" "0" "/etc/mtab not exist" - - isula rm -f $id - fn_check_eq "$?" "0" "rm failed" - - return $TC_RET_T -} - -ret=0 - -do_test_t -if [ $? -ne 0 ];then - let "ret=$ret + 1" -fi - -show_result $ret "creat mtab symbol link" diff --git a/CI/test_cases/helpers.bash b/CI/test_cases/helpers.bash index 5f58254..dc82e8e 100755 --- a/CI/test_cases/helpers.bash +++ b/CI/test_cases/helpers.bash @@ -1,98 +1,86 @@ #!/bin/bash -set -x - -CRICTL=$(which crictl) +####################################################################### +##- @Copyright (C) Huawei Technologies., 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. +##- @Description:CI +##- @Author: lifeng +##- @Create: 2020-03-30 +####################################################################### # testcase result TC_RET_T=0 +declare -a lines -# image to pull and run container -BUSYBOX_IMAGE="busybox:latest" +# Root directory of integration tests. +LCR_ROOT_PATH="/var/lib/isulad/engines/lcr" valgrind_log="/tmp/valgrind.log" ISUALD_LOG="/var/lib/isulad/isulad.log" -ISULAD_ROOT_DIR="/var/lib/isulad" -ISULAD_LCR_ENGINE_DIR="$ISULAD_ROOT_DIR/engines/lcr" -kubeAPIVersion="0.1.0" -iSulaRuntimeName="iSulad" -RuntimeVersion="2.0" -RuntimeAPIVersion="1.0" -Logging_Driver="json-file" -Cgroup_Driver="cgroupfs" - -# =================================================== -function echo_text() -{ - local TXT=$1 - local COLOR=$2 - - if [ "${COLOR}" = "red" ];then - echo -e "\e[1;31m${TXT} \e[0m" - elif [ "${COLOR}" = "green" ];then - echo -e "\e[1;32m${TXT} \e[0m" - elif [ "${COLOR}" = "yellow" ];then - echo -e "\e[1;33m${TXT} \e[0m" - else - echo ${TXT} + +declare -r -i FAILURE=-1 + +function cut_output_lines() { + message=`$@ 2>&1` + retval=$? + oldifs=${IFS} + IFS=$'\n' + lines=(${message}) + IFS="${oldifs}" + return $retval +} + +function fn_check_eq() { + if [[ "$1" -ne "$2" ]];then + echo "$3" + TC_RET_T=$(($TC_RET_T+1)) fi } -function ERROR() -{ - txt_str=$1 - echo_text "$txt_str" red +function fn_check_ne() { + if [[ "$1" -eq "$2" ]];then + echo "$3" + TC_RET_T=$(($TC_RET_T+1)) + fi } -function INFO() -{ - txt_str=$1 - echo_text "$txt_str" green +function testcontainer() { + st=`isula inspect -f '{{json .State.Status}}' "$1"` + if ! [[ "${st}" =~ "$2" ]];then + echo "expect status $2, but get ${st}" + TC_RET_T=$(($TC_RET_T+1)) + fi } -function DEBUG() -{ - txt_str=$1 - echo_text "$txt_str" yellow +function crictl() { + CRICTL=$(which crictl) + "$CRICTL" -i unix:///var/run/isulad.sock -r unix:///var/run/isulad.sock "$@" } -# =============================================== -function is_new_oci_image() { - ps aux | grep "isulad_kit" | grep "isula_image\.sock" > /dev/null 2>&1 - if [ $? -ne 0 ];then - DEBUG "Current use old oci image mechanism, Skip this testcase......" - exit 0 - fi +function msg_ok() +{ + echo -e "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: \033[1;32m$@\033[0m" } -function check_fn_return() { - if [[ "$1" != "$2" ]];then - ERROR "[`date`] Expect '$1' but got '$2': FAILED ($3)" - ((TC_RET_T++)) - else - INFO "[`date`] Expect '$1' and got '$2': SUCCESS ($3)" - fi +function msg_err() +{ + echo -e "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: \033[1;31m$@\033[0m" >&2 } -function check_fn_return_noskip() { - if [[ "$1" != "$2" ]];then - ERROR "[`date`] Expect '$1' but got '$2': FAILED ($3)" - exit 1 - else - INFO "[`date`] Expect '$1' and got '$2': SUCCESS ($3)" - fi +function msg_info() +{ + echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $@" } -function isulad_is_running() { - local ret=1 - for i in `seq 3`;do - isula version - if [ $? -eq 0 ];then - ret=0 - break - fi - sleep 1 - done - return ${ret} +function show_result() { + [[ ${1} -ne 0 ]] && msg_err "TESTSUIT: $2 FAILED" && return ${FAILURE} + msg_ok "TESTSUIT: $2 SUCCESS" } function wait_isulad_running() { @@ -156,57 +144,6 @@ function check_valgrind_log() { return 0 } -# Wrapper for crictl -function crictl() { - "$CRICTL" -i unix:///var/run/isulad.sock -r unix:///var/run/isulad.sock "$@" -} - -function get_cgroup_real_path() -{ - cat /proc/1/cgroup | head -n 1 | awk -F ':' '{print $3}' -} - -function get_container_interface_ip_by_pid() { - if [ $# -ne 2 ];then - return "" - fi - nsenter -t $1 -n ifconfig $2 | grep 'inet ' | sed 's/netmask.*//g' | grep -Eoe "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])" -} - -function set_ip_for_cni_bridge() { - if [ $# -ne 2 ];then - echo "set_ip_for_cni_bridge: invalid arguments, usage: set_ip_for_cni_bridge cni0 10.1.0.1" - return 1 - fi - ifconfig $1 $2 -} - -function show_result() { - if [ $1 -ne 0 ];then - echo "TESTSUIT: $2 FAILED" - return 1 - fi - echo "TESTSUIT: $2 SUCCESS" -} - -function msleep() { - if [ $# -ne 1 ];then - echo "use default sleep" - sleep $@ - return - fi - sec=$1 - env | grep GCOV - if [ $? -eq 0 ];then - ((sec=$sec+2)) - fi - sleep $sec -} - -function err() { - echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $@" >&2 -} - function init_cni_conf() { dtpath="$1" @@ -230,16 +167,3 @@ function init_cni_conf() return $TC_RET_T } - -function wait_container_state() -{ - while true - do - isula inspect -f '{{json .State.Status}}' "$1" | grep "$2" - if [ $? -eq 0 ];then - return; - fi - sleep 1 - done -} - diff --git a/CI/test_cases/basic_cases/help.bash b/CI/test_cases/image_cases/help.bash similarity index 98% rename from CI/test_cases/basic_cases/help.bash rename to CI/test_cases/image_cases/help.bash index 21526ab..5035964 100755 --- a/CI/test_cases/basic_cases/help.bash +++ b/CI/test_cases/image_cases/help.bash @@ -21,7 +21,7 @@ curr_path=$(dirname $(readlink -f "$0")) data_path=$(realpath $curr_path/../data) -source ./basic_helpers.bash +source ../helpers.bash function isulad_help() { diff --git a/CI/test_cases/basic_cases/image_inspect.bash b/CI/test_cases/image_cases/image_inspect.bash similarity index 98% rename from CI/test_cases/basic_cases/image_inspect.bash rename to CI/test_cases/image_cases/image_inspect.bash index bff63d0..6a65fe9 100755 --- a/CI/test_cases/basic_cases/image_inspect.bash +++ b/CI/test_cases/image_cases/image_inspect.bash @@ -20,7 +20,7 @@ ####################################################################### declare -r curr_path=$(dirname $(readlink -f "$0")) -source ${curr_path}/basic_helpers.bash +source ../helpers.bash function test_image_info() { diff --git a/CI/test_cases/basic_cases/image_remove.bash b/CI/test_cases/image_cases/image_remove.bash similarity index 96% rename from CI/test_cases/basic_cases/image_remove.bash rename to CI/test_cases/image_cases/image_remove.bash index de5558d..4d4ac75 100755 --- a/CI/test_cases/basic_cases/image_remove.bash +++ b/CI/test_cases/image_cases/image_remove.bash @@ -6,7 +6,7 @@ curr_path=$(dirname $(readlink -f "$0")) data_path=$(realpath $curr_path/../data) -source ./basic_helpers.bash +source ../helpers.bash do_test_t() { diff --git a/CI/test_cases/basic_cases/image_tag.bash b/CI/test_cases/image_cases/image_tag.bash similarity index 99% rename from CI/test_cases/basic_cases/image_tag.bash rename to CI/test_cases/image_cases/image_tag.bash index 6807ace..9adad1d 100755 --- a/CI/test_cases/basic_cases/image_tag.bash +++ b/CI/test_cases/image_cases/image_tag.bash @@ -20,7 +20,7 @@ ####################################################################### declare -r curr_path=$(dirname $(readlink -f "$0")) -source ${curr_path}/basic_helpers.bash +source ../helpers.bash image_busybox="busybox" image_ubuntu="ubuntu" diff --git a/CI/test_cases/basic_cases/images_list.bash b/CI/test_cases/image_cases/images_list.bash similarity index 98% rename from CI/test_cases/basic_cases/images_list.bash rename to CI/test_cases/image_cases/images_list.bash index 4617169..1cf8410 100755 --- a/CI/test_cases/basic_cases/images_list.bash +++ b/CI/test_cases/image_cases/images_list.bash @@ -20,7 +20,7 @@ ####################################################################### declare -r curr_path=$(dirname $(readlink -f "$0")) -source ${curr_path}/basic_helpers.bash +source ../helpers.bash function test_image_list() { diff --git a/CI/test_cases/basic_cases/img_fs_info.bash b/CI/test_cases/image_cases/img_fs_info.bash similarity index 97% rename from CI/test_cases/basic_cases/img_fs_info.bash rename to CI/test_cases/image_cases/img_fs_info.bash index cba0700..232df5f 100755 --- a/CI/test_cases/basic_cases/img_fs_info.bash +++ b/CI/test_cases/image_cases/img_fs_info.bash @@ -20,7 +20,7 @@ ####################################################################### declare -r curr_path=$(dirname $(readlink -f "$0")) -source ${curr_path}/basic_helpers.bash +source ../helpers.bash function test_crictl_image() { diff --git a/CI/test_cases/basic_cases/img_status.bash b/CI/test_cases/image_cases/img_status.bash similarity index 98% rename from CI/test_cases/basic_cases/img_status.bash rename to CI/test_cases/image_cases/img_status.bash index 07fd423..ba6b97e 100755 --- a/CI/test_cases/basic_cases/img_status.bash +++ b/CI/test_cases/image_cases/img_status.bash @@ -22,7 +22,7 @@ curr_path=$(dirname $(readlink -f "$0")) data_path=$(realpath $curr_path/../data) driver="overlay2" -source ./basic_helpers.bash +source ../helpers.bash function pre_test() { diff --git a/CI/test_cases/basic_cases/registry.bash b/CI/test_cases/image_cases/registry.bash similarity index 98% rename from CI/test_cases/basic_cases/registry.bash rename to CI/test_cases/image_cases/registry.bash index e27a055..ec38134 100755 --- a/CI/test_cases/basic_cases/registry.bash +++ b/CI/test_cases/image_cases/registry.bash @@ -21,7 +21,7 @@ curr_path=$(dirname $(readlink -f "$0")) data_path=$(realpath $curr_path/../data) -source ./basic_helpers.bash +source ../helpers.bash function isula_pull() { diff --git a/CI/test_cases/basic_cases/version.bash b/CI/test_cases/image_cases/version.bash similarity index 99% rename from CI/test_cases/basic_cases/version.bash rename to CI/test_cases/image_cases/version.bash index 6a65dde..6216c5d 100755 --- a/CI/test_cases/basic_cases/version.bash +++ b/CI/test_cases/image_cases/version.bash @@ -21,7 +21,7 @@ curr_path=$(dirname $(readlink -f "$0")) data_path=$(realpath $curr_path/../data) -source ./basic_helpers.bash +source ../helpers.bash function isulad_version() { -- GitLab