From eaad0bfcd96ffba436413a46bde5bb96db4e754e Mon Sep 17 00:00:00 2001 From: zhongtao Date: Thu, 15 Sep 2022 15:43:42 +1400 Subject: [PATCH 10/11] Add timezone CI test Signed-off-by: zhongtao --- CI/test_cases/container_cases/timezone.sh | 85 +++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 CI/test_cases/container_cases/timezone.sh diff --git a/CI/test_cases/container_cases/timezone.sh b/CI/test_cases/container_cases/timezone.sh new file mode 100644 index 00000000..d434477d --- /dev/null +++ b/CI/test_cases/container_cases/timezone.sh @@ -0,0 +1,85 @@ +#!/bin/bash +# +# attributes: isulad timezone +# concurrent: NA +# spend time: 10 + +####################################################################### +##- Copyright (c) Huawei Technologies Co., Ltd. 2022. 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: zhongtao +##- @Create: 2022-09-13 +####################################################################### + +source ../helpers.sh +curcnt_timezone=`readlink /etc/localtime` + +function do_check_timezone() +{ + ln -sf $1 /etc/localtime + localtime=`date "+%:z" | sed 's/://g'` + + check_valgrind_log + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stop isulad failed" && return ${FAILURE} + + start_isulad_with_valgrind + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - start isulad failed" && return ${FAILURE} + + containername="test_timezone" + + isula run --name $containername $2 /bin/sh + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && return ${FAILURE} + + containertime=`isula inspect -f "{{.State.StartedAt}}" $containername | tail -c 7 | sed 's/://g'` + fn_check_eq "$localtime" "$containertime" "localtime is $localtime get: $containertime" + + isula rm -f $containername +} + +function test_timezone() +{ + local image="busybox" + local test="container timezone 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}" && return ${FAILURE} + + do_check_timezone "/usr/share/zoneinfo/Pacific/Kiritimati" "$image" + do_check_timezone "/usr/share/zoneinfo/right/Canada/Newfoundland" "$image" + do_check_timezone "/usr/share/zoneinfo/Asia/Kolkata" "$image" + do_check_timezone "/usr/share/zoneinfo/right/Pacific/Chatham" "$image" + do_check_timezone "/usr/share/zoneinfo/Etc/GMT" "$image" + + ln -sf $curcnt_timezone /etc/localtime + + isula rmi ${image} + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to remove image ${image}" && return ${FAILURE} + + check_valgrind_log + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stop isulad failed" && return ${FAILURE} + + start_isulad_with_valgrind + [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - start isulad failed" && return ${FAILURE} + + msg_info "${test} finished with return ${TC_RET_T}..." + return $TC_RET_T +} + +declare -i ans=0 + +test_timezone || ((ans++)) + +show_result ${ans} "${curr_path}/${0}" -- 2.25.1