Skip to content

Commit

Permalink
add CI testcase for update oci spec in start op
Browse files Browse the repository at this point in the history
Signed-off-by: haozi007 <liuhao27@huawei.com>
  • Loading branch information
duguhaotian committed Oct 19, 2023
1 parent a5be6b6 commit 3db983b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
50 changes: 48 additions & 2 deletions CI/test_cases/container_cases/dev_cgroup_rule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ source ../helpers.sh
function test_cpu_dev_cgoup_rule_spec()
{
local ret=0
local runtime=$1
local image="busybox"
local test="container device cgroup rule test => (${FUNCNAME[@]})"
local test="container device cgroup rule test with (${runtime}) => (${FUNCNAME[@]})"
local test_dev="/dev/testA"

msg_info "${test} starting..."

Expand All @@ -36,6 +38,47 @@ function test_cpu_dev_cgoup_rule_spec()
isula images | grep busybox
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - missing list image: ${image}" && ((ret++))

rm -f $test_dev
priv_cid=$(isula run -tid --privileged --runtime $runtime $image /bin/sh)
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - run priviledged container failed" && ((ret++))
priv_major_88_cnt=$(cat ${RUNTIME_ROOT_PATH}/${runtime}/$priv_cid/config.json | grep "major\": 88" | wc -l)
priv_minor_88_cnt=$(cat ${RUNTIME_ROOT_PATH}/${runtime}/$priv_cid/config.json | grep "minor\": 88" | wc -l)

mknod $test_dev c 88 88
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - mknod failed" && ((ret++))
isula restart -t 0 $priv_cid
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - restart priviledge container failed" && ((ret++))
cnt=$(cat ${RUNTIME_ROOT_PATH}/${runtime}/$priv_cid/config.json | grep "major\": 88" | wc -l)
[[ $? -ne 0 ]]&& [[ $cnt -le $priv_major_88_cnt ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check device major failed" && ((ret++))
cnt=$(cat ${RUNTIME_ROOT_PATH}/${runtime}/$priv_cid/config.json | grep "minor\": 88" | wc -l)
[[ $? -ne 0 ]] && [[ $cnt -le $priv_minor_88_cnt ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check device minor failed" && ((ret++))
isula rm -f $priv_cid

cid=$(isula run -tid --device "$test_dev:$test_dev" --runtime $runtime $image /bin/sh)
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - run container failed" && ((ret++))
cnt=$(cat ${RUNTIME_ROOT_PATH}/${runtime}/$cid/config.json | grep "major\": 88" | wc -l)
[[ $? -ne 0 ]]&& [[ $cnt -ne 2 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check device major failed" && ((ret++))
cnt=$(cat ${RUNTIME_ROOT_PATH}/${runtime}/$cid/config.json | grep "minor\": 88" | wc -l)
[[ $? -ne 0 ]] && [[ $cnt -ne 2 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check device minor failed" && ((ret++))
isula exec -it $cid sh -c "cat /sys/fs/cgroup/devices/devices.list" | grep "c 88:88 rwm"
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check c 88:88 rwm: ${image}" && ((ret++))
isula stop -t 0 $cid
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stop container failed" && ((ret++))
rm -f $test_dev
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - rm device failed" && ((ret++))
mknod $test_dev c 99 99
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - mknod failed" && ((ret++))
isula start $cid
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - start container failed" && ((ret++))
cnt=$(cat ${RUNTIME_ROOT_PATH}/${runtime}/$cid/config.json | grep "major\": 99" | wc -l)
[[ $? -ne 0 ]]&& [[ $cnt -ne 2 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check device major failed" && ((ret++))
cnt=$(cat ${RUNTIME_ROOT_PATH}/${runtime}/$cid/config.json | grep "minor\": 99" | wc -l)
[[ $? -ne 0 ]] && [[ $cnt -ne 2 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check device minor failed" && ((ret++))
isula exec -it $cid sh -c "cat /sys/fs/cgroup/devices/devices.list" | grep "c 99:99 rwm"
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check c 99:99 rwm: ${image}" && ((ret++))
isula rm -f $cid
rm -f $test_dev

isula run -itd --device-cgroup-rule='b *:*' busybox 2>&1 | grep "Invalid value"
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - Invalid value" && ((ret++))

Expand Down Expand Up @@ -93,6 +136,9 @@ function test_cpu_dev_cgoup_rule_spec()

declare -i ans=0

test_cpu_dev_cgoup_rule_spec || ((ans++))
for element in ${RUNTIME_LIST[@]};
do
test_cpu_dev_cgoup_rule_spec $element || ((ans++))
done

show_result ${ans} "${curr_path}/${0}"
13 changes: 13 additions & 0 deletions CI/test_cases/container_cases/ulimit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,25 @@ function test_ulimit()
local test="ulimit test with (${runtime})=> (${FUNCNAME[@]})"
msg_info "${test} starting..."

cid=$(isula run -tid --runtime $runtime $image /bin/sh)
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check failed" && ((ret++))
cat ${RUNTIME_ROOT_PATH}/${runtime}/$cid/config.json | grep "RLIMIT_"
[[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check rlimit failed" && ((ret++))

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++))

# if default ulimit of isulad changed, isula start should do update ulimit of oci spec
isula restart -t 0 $cid
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - restart failed" && ((ret++))
cat ${RUNTIME_ROOT_PATH}/${runtime}/$cid/config.json | grep "RLIMIT_"
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - check rlimit failed after restart" && ((ret++))
isula rm -f $cid
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - rm container failed" && ((ret++))

isula run --ulimit nproc= $image --runtime $runtime /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++))
Expand Down

0 comments on commit 3db983b

Please sign in to comment.