From cee24589aaeb361c6d666a4ad8111291e0fad5e7 Mon Sep 17 00:00:00 2001 From: lifeng68 Date: Fri, 3 Jul 2020 17:49:20 +0800 Subject: [PATCH] CI: add test cases for inspect\stats\top\ulimit Signed-off-by: lifeng68 --- .../check_fd_leakage_of_isulad.bash | 2 +- CI/test_cases/container_cases/cni_test.bash | 2 +- CI/test_cases/container_cases/cp.bash | 2 +- CI/test_cases/container_cases/create.bash | 2 +- .../container_cases/create_mtab_test.bash | 2 +- CI/test_cases/container_cases/export.bash | 2 +- .../hook_ignore_poststart_error.bash | 2 +- .../container_cases/hook_spec_test.bash | 2 +- CI/test_cases/container_cases/inspect.bash | 149 ++++++++++++++++++ CI/test_cases/container_cases/kill.bash | 2 +- CI/test_cases/container_cases/ps.bash | 2 +- CI/test_cases/container_cases/rename.bash | 2 +- CI/test_cases/container_cases/restart.bash | 2 +- .../container_cases/restartpolicy.bash | 2 +- CI/test_cases/container_cases/rm.bash | 2 +- .../container_cases/share_ns_test.bash | 2 +- CI/test_cases/container_cases/stats.bash | 87 ++++++++++ CI/test_cases/container_cases/stop.bash | 2 +- CI/test_cases/container_cases/top.bash | 56 +++++++ CI/test_cases/container_cases/ulimit.bash | 111 +++++++++++++ CI/test_cases/container_cases/version.bash | 2 + CI/test_cases/image_cases/image_load.bash | 2 +- CI/test_cases/image_cases/image_remove.bash | 2 +- CI/test_cases/image_cases/image_tag.bash | 2 +- CI/test_cases/image_cases/registry.bash | 2 +- 25 files changed, 425 insertions(+), 20 deletions(-) create mode 100644 CI/test_cases/container_cases/inspect.bash create mode 100644 CI/test_cases/container_cases/stats.bash create mode 100644 CI/test_cases/container_cases/top.bash create mode 100644 CI/test_cases/container_cases/ulimit.bash diff --git a/CI/test_cases/container_cases/check_fd_leakage_of_isulad.bash b/CI/test_cases/container_cases/check_fd_leakage_of_isulad.bash index 4e51555..b66f03e 100755 --- a/CI/test_cases/container_cases/check_fd_leakage_of_isulad.bash +++ b/CI/test_cases/container_cases/check_fd_leakage_of_isulad.bash @@ -2,7 +2,7 @@ # # attributes: isulad inheritance fd # concurrent: NO -# spend time: 15 +# spend time: 16 ####################################################################### ##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved. # - iSulad licensed under the Mulan PSL v2. diff --git a/CI/test_cases/container_cases/cni_test.bash b/CI/test_cases/container_cases/cni_test.bash index 3910778..1f5e227 100644 --- a/CI/test_cases/container_cases/cni_test.bash +++ b/CI/test_cases/container_cases/cni_test.bash @@ -2,7 +2,7 @@ # # attributes: isulad cri cni # concurrent: NA -# spend time: 45 +# spend time: 46 curr_path=$(dirname $(readlink -f "$0")) data_path=$(realpath $curr_path/criconfigs) diff --git a/CI/test_cases/container_cases/cp.bash b/CI/test_cases/container_cases/cp.bash index a59a7f8..7f78cd7 100644 --- a/CI/test_cases/container_cases/cp.bash +++ b/CI/test_cases/container_cases/cp.bash @@ -2,7 +2,7 @@ # # attributes: isulad basic container hook # concurrent: NA -# spend time: 25 +# spend time: 8 ####################################################################### ##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved. diff --git a/CI/test_cases/container_cases/create.bash b/CI/test_cases/container_cases/create.bash index f9fca3b..055cd39 100755 --- a/CI/test_cases/container_cases/create.bash +++ b/CI/test_cases/container_cases/create.bash @@ -2,7 +2,7 @@ # # attributes: isulad inheritance create # concurrent: YES -# spend time: 4 +# spend time: 17 ####################################################################### ##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved. diff --git a/CI/test_cases/container_cases/create_mtab_test.bash b/CI/test_cases/container_cases/create_mtab_test.bash index d90d059..f079e45 100755 --- a/CI/test_cases/container_cases/create_mtab_test.bash +++ b/CI/test_cases/container_cases/create_mtab_test.bash @@ -2,7 +2,7 @@ # # attributes: isulad inheritance start # concurrent: YES -# spend time: 1 +# spend time: 2 ####################################################################### ##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved. diff --git a/CI/test_cases/container_cases/export.bash b/CI/test_cases/container_cases/export.bash index ec5078c..143be4c 100755 --- a/CI/test_cases/container_cases/export.bash +++ b/CI/test_cases/container_cases/export.bash @@ -2,7 +2,7 @@ # # attributes: isulad basic export container # concurrent: NA -# spend time: 5 +# spend time: 6 ####################################################################### ##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved. diff --git a/CI/test_cases/container_cases/hook_ignore_poststart_error.bash b/CI/test_cases/container_cases/hook_ignore_poststart_error.bash index 9556219..0d39ffe 100644 --- a/CI/test_cases/container_cases/hook_ignore_poststart_error.bash +++ b/CI/test_cases/container_cases/hook_ignore_poststart_error.bash @@ -2,7 +2,7 @@ # # attributes: isulad basic container hook # concurrent: NA -# spend time: 25 +# spend time: 7 ####################################################################### ##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved. diff --git a/CI/test_cases/container_cases/hook_spec_test.bash b/CI/test_cases/container_cases/hook_spec_test.bash index 57f6a2f..c4fa397 100644 --- a/CI/test_cases/container_cases/hook_spec_test.bash +++ b/CI/test_cases/container_cases/hook_spec_test.bash @@ -2,7 +2,7 @@ # # attributes: isulad basic container hook # concurrent: NA -# spend time: 5 +# spend time: 9 ####################################################################### ##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved. diff --git a/CI/test_cases/container_cases/inspect.bash b/CI/test_cases/container_cases/inspect.bash new file mode 100644 index 0000000..6de8278 --- /dev/null +++ b/CI/test_cases/container_cases/inspect.bash @@ -0,0 +1,149 @@ +#!/bin/bash +# +# attributes: isulad basic container hook +# concurrent: NA +# spend time: 6 + +####################################################################### +##- @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-06-03 +####################################################################### + +declare -r curr_path=$(dirname $(readlink -f "$0")) +source ../helpers.bash +test_data_path=$(realpath $curr_path/test_data) + +function test_inspect_spec() +{ + local ret=0 + local image="busybox" + local test="container inspect test => (${FUNCNAME[@]})" + + msg_info "${test} starting..." + + isula pull ${image} + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to pull image: ${image}" && return ${FAILURE} + + isula images | grep busybox + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - missing list image: ${image}" && ((ret++)) + + containername=test_inspect + + isula create --name $containername --ipc host --pid host --uts host --restart=on-failure:10 --hook-spec ${test_data_path}/test-hookspec.json --cpu-shares 100 --memory 5MB --memory-reservation 4MB --cpu-period 1000000 --cpu-quota 200000 --cpuset-cpus 1 --cpuset-mems 0 --kernel-memory 50M --pids-limit=10000 --volume /home:/root --env a=1 $image /bin/sh ls + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .Path}}' $containername 2>&1 | grep "/bin/sh" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .Args}}' $containername 2>&1 | grep "ls" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .HostConfig.IpcMode}}' $containername 2>&1 | grep "host" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .HostConfig.PidMode}}' $containername 2>&1 | grep "host" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .HostConfig.UTSMode}}' $containername 2>&1 | grep "host" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .HostConfig.RestartPolicy.Name}}' $containername 2>&1 | grep "on-failure" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .HostConfig.RestartPolicy.MaximumRetryCount}}' $containername 2>&1 | grep "10" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .HostConfig.HookSpec}}' $containername 2>&1 | grep "test-hookspec.json" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .HostConfig.Binds}}' $containername 2>&1 | grep "/home:/root" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .HostConfig.CPUShares}}' $containername 2>&1 | grep "100" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .HostConfig.Memory}}' $containername 2>&1 | grep "5242880" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .HostConfig.MemoryReservation}}' $containername 2>&1 | grep "4194304" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .HostConfig.CPUPeriod}}' $containername 2>&1 | grep "1000000" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .HostConfig.CPUQuota}}' $containername 2>&1 | grep "200000" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .HostConfig.CpusetCpus}}' $containername 2>&1 | grep "1" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .HostConfig.CpusetMems}}' $containername 2>&1 | grep "0" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .HostConfig.KernelMemory}}' $containername 2>&1 | grep "52428800" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .HostConfig.PidsLimit}}' $containername 2>&1 | grep "10000" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{.Config.Image}}' $containername 2>&1 | grep ${image} + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + image_id=$(isula inspect -f '{{.image.id}}' ${image}) + isula inspect --format='{{.Image}}' $containername 2>&1 | grep "sha256:${image_id}" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + if [ -d /sys/fs/cgroup/files ];then + grepval="100" + else + grepval="0" + fi + isula inspect --format='{{json .HostConfig.FilesLimit}}' $containername 2>&1 | grep "$grepval" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .Config.Env}}' $containername 2>&1 | grep "a=1" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .Config.Cmd}}' $containername 2>&1 | grep "ls" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula rm -f $containername + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + containername=test_inspect_entrypoint + isula create --entrypoint /bin/sh --name $containername $image -c "exit 0" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .Path}}' $containername 2>&1 | grep "/bin/sh" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .Args}}' $containername 2>&1 | grep "exit 0" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .Config.Entrypoint}}' $containername 2>&1 | grep "/bin/sh" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula inspect --format='{{json .Config.Cmd}}' $containername 2>&1 | grep "exit 0" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${image}" && ((ret++)) + + isula rm -f $containername + + msg_info "${test} finished with return ${ret}..." + return ${ret} +} + +declare -i ans=0 + +test_inspect_spec || ((ans++)) + +show_result ${ans} "${curr_path}/${0}" \ No newline at end of file diff --git a/CI/test_cases/container_cases/kill.bash b/CI/test_cases/container_cases/kill.bash index d09a48b..f156c22 100755 --- a/CI/test_cases/container_cases/kill.bash +++ b/CI/test_cases/container_cases/kill.bash @@ -2,7 +2,7 @@ # # attributes: isulad inheritance kill # concurrent: YES -# spend time: 9 +# spend time: 3 ####################################################################### ##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved. diff --git a/CI/test_cases/container_cases/ps.bash b/CI/test_cases/container_cases/ps.bash index 589ee4d..def0a2e 100755 --- a/CI/test_cases/container_cases/ps.bash +++ b/CI/test_cases/container_cases/ps.bash @@ -2,7 +2,7 @@ # # attributes: isulad inheritance ps list # concurrent: NO -# spend time: 12 +# spend time: 11 ####################################################################### ##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved. diff --git a/CI/test_cases/container_cases/rename.bash b/CI/test_cases/container_cases/rename.bash index 0347cd7..cedc402 100644 --- a/CI/test_cases/container_cases/rename.bash +++ b/CI/test_cases/container_cases/rename.bash @@ -2,7 +2,7 @@ # # attributes: isulad basic container hook # concurrent: NA -# spend time: 5 +# spend time: 7 ####################################################################### ##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved. diff --git a/CI/test_cases/container_cases/restart.bash b/CI/test_cases/container_cases/restart.bash index 677dc35..3d21d07 100755 --- a/CI/test_cases/container_cases/restart.bash +++ b/CI/test_cases/container_cases/restart.bash @@ -2,7 +2,7 @@ # # attributes: isulad inheritance restart # concurrent: YES -# spend time: 33 +# spend time: 26 ####################################################################### ##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved. diff --git a/CI/test_cases/container_cases/restartpolicy.bash b/CI/test_cases/container_cases/restartpolicy.bash index 8a26364..7c86894 100755 --- a/CI/test_cases/container_cases/restartpolicy.bash +++ b/CI/test_cases/container_cases/restartpolicy.bash @@ -2,7 +2,7 @@ # # attributes: isulad inheritance restartpolicy # concurrent: NO -# spend time: 29 +# spend time: 28 ####################################################################### ##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved. diff --git a/CI/test_cases/container_cases/rm.bash b/CI/test_cases/container_cases/rm.bash index 6990dd2..4d9fbc2 100755 --- a/CI/test_cases/container_cases/rm.bash +++ b/CI/test_cases/container_cases/rm.bash @@ -2,7 +2,7 @@ # # attributes: isulad inheritance rm # concurrent: YES -# spend time: 12 +# spend time: 24 ####################################################################### ##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved. diff --git a/CI/test_cases/container_cases/share_ns_test.bash b/CI/test_cases/container_cases/share_ns_test.bash index e9b6c7b..4fceedc 100755 --- a/CI/test_cases/container_cases/share_ns_test.bash +++ b/CI/test_cases/container_cases/share_ns_test.bash @@ -2,7 +2,7 @@ # # attributes: isulad share namepaces # concurrent: NO -# spend time: 25 +# spend time: 29 ####################################################################### ##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved. diff --git a/CI/test_cases/container_cases/stats.bash b/CI/test_cases/container_cases/stats.bash new file mode 100644 index 0000000..2daf783 --- /dev/null +++ b/CI/test_cases/container_cases/stats.bash @@ -0,0 +1,87 @@ +#!/bin/bash +# +# attributes: isulad basic container hook +# concurrent: NA +# spend time: 5 + +####################################################################### +##- @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-06-03 +####################################################################### + +declare -r curr_path=$(dirname $(readlink -f "$0")) +source ../helpers.bash + +function test_stats_spec() +{ + local ret=0 + local image="busybox" + local test="container stats test => (${FUNCNAME[@]})" + statslog=/tmp/stats.log + + msg_info "${test} starting..." + + isula pull ${image} + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to pull image: ${image}" && return ${FAILURE} + + isula images | grep busybox + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - missing list image: ${image}" && ((ret++)) + + isula stats xxxxxx 2>&1 | grep "No such container" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++)) + + isula stats - 2>&1 | grep "Invalid container name" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++)) + + container_name_stop=stats_stopped + id_stop=`isula create -t -n $container_name_stop $image /bin/sh` + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++)) + + container_name_running=stats_running + id_running=`isula run -td -n $container_name_running $image /bin/sh` + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++)) + + isula stats --no-stream > $statslog + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++)) + + cat $statslog | grep "${id_running:0:12}" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++)) + + isula stats --no-stream -a > $statslog + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++)) + + cat $statslog | grep "${id_running:0:12}" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++)) + + cat $statslog | grep "${id_stop:0:12}" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++)) + + isula stats --no-stream "$id_stop" > $statslog + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++)) + + cat $statslog | grep "${id_stop:0:12}" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++)) + + isula rm -f "$container_name_stop" "$container_name_running" + + rm -f $statslog + + msg_info "${test} finished with return ${ret}..." + return ${ret} +} + +declare -i ans=0 + +test_stats_spec || ((ans++)) + +show_result ${ans} "${curr_path}/${0}" \ No newline at end of file diff --git a/CI/test_cases/container_cases/stop.bash b/CI/test_cases/container_cases/stop.bash index 4eb8dd5..0296a2f 100755 --- a/CI/test_cases/container_cases/stop.bash +++ b/CI/test_cases/container_cases/stop.bash @@ -2,7 +2,7 @@ # # attributes: isulad inheritance stop # concurrent: YES -# spend time: 28 +# spend time: 27 ####################################################################### ##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved. diff --git a/CI/test_cases/container_cases/top.bash b/CI/test_cases/container_cases/top.bash new file mode 100644 index 0000000..6226811 --- /dev/null +++ b/CI/test_cases/container_cases/top.bash @@ -0,0 +1,56 @@ +#!/bin/bash +# +# attributes: isulad basic container hook +# concurrent: NA +# spend time: 4 + +####################################################################### +##- @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-06-03 +####################################################################### + +declare -r curr_path=$(dirname $(readlink -f "$0")) +source ../helpers.bash + +function test_top_spec() +{ + local ret=0 + local image="busybox" + local test="container top test => (${FUNCNAME[@]})" + + msg_info "${test} starting..." + + isula pull ${image} + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to pull image: ${image}" && return ${FAILURE} + + isula images | grep busybox + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - missing list image: ${image}" && ((ret++)) + + CONT=`isula run -itd $image /bin/sh` + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++)) + + isula top $CONT -ef + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++)) + + isula rm -f $CONT + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++)) + + msg_info "${test} finished with return ${ret}..." + return ${ret} +} + +declare -i ans=0 + +test_top_spec || ((ans++)) + +show_result ${ans} "${curr_path}/${0}" \ No newline at end of file diff --git a/CI/test_cases/container_cases/ulimit.bash b/CI/test_cases/container_cases/ulimit.bash new file mode 100644 index 0000000..9640cb9 --- /dev/null +++ b/CI/test_cases/container_cases/ulimit.bash @@ -0,0 +1,111 @@ +#!/bin/bash +# +# attributes: isulad inheritance restart +# concurrent: YES +# spend time: 18 + +####################################################################### +##- @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-07-1 +####################################################################### + +curr_path=$(dirname $(readlink -f "$0")) +data_path=$(realpath $curr_path/../data) +source ../helpers.bash + +function test_ulimit() +{ + local ret=0 + local image="busybox" + ulimitlog=/tmp/ulimit.log + + local test="ulimit test => (${FUNCNAME[@]})" + msg_info "${test} starting..." + + check_valgrind_log + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stop isulad failed" && ((ret++)) + + start_isulad_with_valgrind --default-ulimit nproc=2048:4096 --default-ulimit nproc=2048:8192 --default-ulimit nofile=1024:4096 + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - start isulad failed" && ((ret++)) + + isula run --ulimit nproc= $image /bin/sh > $ulimitlog 2>&1 + cat $ulimitlog | grep "delimiter '=' can't be the first or the last character" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check failed" && ((ret++)) + + isula run --ulimit nproc=1024: $image /bin/sh > $ulimitlog 2>&1 + cat $ulimitlog | grep "delimiter ':' can't be the first or the last character" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check failed" && ((ret++)) + + isula run --ulimit npro=1024:2048 $image /bin/sh > $ulimitlog 2>&1 + cat $ulimitlog | grep "Invalid ulimit type" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check failed" && ((ret++)) + + isula run --ulimit nproc=4096:2048 $image /bin/sh > $ulimitlog 2>&1 + cat $ulimitlog | grep "Ulimit soft limit must be less than or equal to hard limit" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check failed" && ((ret++)) + + isula run --ulimit nproc=2048:4096.5 $image /bin/sh > $ulimitlog 2>&1 + cat $ulimitlog | grep "Invalid ulimit hard value" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check failed" && ((ret++)) + + isula run --ulimit nproc==2048:4096 $image /bin/sh > $ulimitlog 2>&1 + cat $ulimitlog | grep "Invalid ulimit argument" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check failed" && ((ret++)) + + isula run --ulimit nproc=2048::4096 $image /bin/sh > $ulimitlog 2>&1 + cat $ulimitlog | grep "Too many limit value arguments" + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check failed" && ((ret++)) + + container_name="ulimit_test" + + isula run -td -n $container_name --ulimit nofile=20480:40960 --ulimit core=1024:2048 $image /bin/sh + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check failed" && ((ret++)) + + isula exec $container_name /bin/sh -c "cat /proc/self/limits" | grep "Max open files" |awk '{ print $(NF-1) }' |grep 40960 + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check failed" && ((ret++)) + + isula exec $container_name /bin/sh -c "cat /proc/self/limits" | grep "Max open files" |awk '{ print $(NF-2) }' |grep 20480 + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check failed" && ((ret++)) + + isula exec $container_name /bin/sh -c "cat /proc/self/limits" | grep "Max processes" |awk '{ print $(NF-1) }' |grep 8192 + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check failed" && ((ret++)) + + isula exec $container_name /bin/sh -c "cat /proc/self/limits" | grep "Max processes" |awk '{ print $(NF-2) }' |grep 2048 + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check failed" && ((ret++)) + + isula exec $container_name /bin/sh -c "cat /proc/self/limits" | grep "Max core file size" |awk '{ print $(NF-1) }' |grep 4 + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check failed" && ((ret++)) + + isula exec $container_name /bin/sh -c "cat /proc/self/limits" | grep "Max core file size" |awk '{ print $(NF-2) }' |grep 2 + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check failed" && ((ret++)) + + isula rm -f $container_name + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check failed" && ((ret++)) + + check_valgrind_log + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stop isulad failed" && ((ret++)) + + start_isulad_with_valgrind + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - start isulad failed" && ((ret++)) + + rm -rf $ulimitlog + + msg_info "${test} finished with return ${ret}..." + return ${ret} +} + +declare -i ans=0 + +test_ulimit || ((ans++)) + +show_result ${ans} "${curr_path}/${0}" diff --git a/CI/test_cases/container_cases/version.bash b/CI/test_cases/container_cases/version.bash index 6216c5d..941b4dc 100755 --- a/CI/test_cases/container_cases/version.bash +++ b/CI/test_cases/container_cases/version.bash @@ -90,6 +90,8 @@ function isula_version() echo "isula version error" TC_RET_T=$(($TC_RET_T+1)) fi + + isula info } function do_test_t() diff --git a/CI/test_cases/image_cases/image_load.bash b/CI/test_cases/image_cases/image_load.bash index 61a8fd8..a033bf6 100755 --- a/CI/test_cases/image_cases/image_load.bash +++ b/CI/test_cases/image_cases/image_load.bash @@ -2,7 +2,7 @@ # # attributes: isulad basic image # concurrent: NA -# spend time: 18 +# spend time: 22 ####################################################################### ##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved. diff --git a/CI/test_cases/image_cases/image_remove.bash b/CI/test_cases/image_cases/image_remove.bash index f1d6035..8b279c6 100755 --- a/CI/test_cases/image_cases/image_remove.bash +++ b/CI/test_cases/image_cases/image_remove.bash @@ -2,7 +2,7 @@ # # attributes: isulad basic remove image # concurrent: NA -# spend time: 8 +# spend time: 5 ####################################################################### ##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved. diff --git a/CI/test_cases/image_cases/image_tag.bash b/CI/test_cases/image_cases/image_tag.bash index 559dc40..893565c 100755 --- a/CI/test_cases/image_cases/image_tag.bash +++ b/CI/test_cases/image_cases/image_tag.bash @@ -2,7 +2,7 @@ # # attributes: isulad inheritance tag # concurrent: YES -# spend time: 9 +# spend time: 10 ####################################################################### ##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved. diff --git a/CI/test_cases/image_cases/registry.bash b/CI/test_cases/image_cases/registry.bash index 71df80e..b103be9 100755 --- a/CI/test_cases/image_cases/registry.bash +++ b/CI/test_cases/image_cases/registry.bash @@ -2,7 +2,7 @@ # # attributes: isulad inheritance version # concurrent: YES -# spend time: 7 +# spend time: 10 ####################################################################### ##- @Copyright (C) Huawei Technologies., Ltd. 2020. All rights reserved. -- GitLab