summaryrefslogtreecommitdiff
path: root/0061-2320-improve-CI-test.patch
blob: 1c7326c1beaf8e9408e3aa40ad9835941ec023bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
From 712d82656ac9bafda7d29be70e7dbcd761a01f98 Mon Sep 17 00:00:00 2001
From: zhongtao <zhongtao17@huawei.com>
Date: Sun, 17 Dec 2023 05:58:56 +0000
Subject: [PATCH 61/64] !2320 improve CI test * improve CI test

---
 .../container_cases/restartpolicy.sh          | 35 ++++++++++++++-----
 CI/test_cases/image_cases/image_digest.sh     | 10 +++---
 CI/test_cases/image_cases/image_search.sh     | 26 ++------------
 3 files changed, 35 insertions(+), 36 deletions(-)

diff --git a/CI/test_cases/container_cases/restartpolicy.sh b/CI/test_cases/container_cases/restartpolicy.sh
index 11c3608f..0ab09636 100755
--- a/CI/test_cases/container_cases/restartpolicy.sh
+++ b/CI/test_cases/container_cases/restartpolicy.sh
@@ -23,18 +23,37 @@ curr_path=$(dirname $(readlink -f "$0"))
 data_path=$(realpath $curr_path/../data)
 source ../helpers.sh
 
+# $1 : retry limit
+# $2 : retry_interval
+# $3 : container name
+# $4 : expect restart count
+function do_retry()
+{
+    for i in $(seq 1 "$1"); do
+        count=`isula inspect --format='{{json .RestartCount}}' ${3}`
+        if [ $count -eq $4 ]; then
+            return 0
+        fi
+        sleep $2
+    done
+    echo "expect $4, get $count"
+    return 1
+}
+
 function do_test_on_failure()
 {
+    local retry_limit=15
+    local retry_interval=1
     containername=test_rp_on_failure
     isula run  --name $containername  -td --restart on-failure:3  busybox /bin/sh -c "exit 2"
     fn_check_eq "$?" "0" "run failed"
 
-    sleep 8
-    count=`isula inspect --format='{{json .RestartCount}}' $containername`
-    if [[ $count != "3"  ]];then
-        echo "expect 3 but get $count"
+    do_retry ${retry_limit} ${retry_interval} ${containername} 3
+    if [[ $? -ne 0 ]];then
         TC_RET_T=$(($TC_RET_T+1))
     fi
+
+    isula stop -t 0 $containername
     testcontainer $containername exited
 
     isula rm $containername
@@ -43,14 +62,14 @@ function do_test_on_failure()
 
 function do_test_unless_stopped()
 {
+    local retry_limit=15
+    local retry_interval=1
     containername=test_rp_unless_stopped
     isula run  --name $containername  -td --restart unless-stopped  busybox /bin/sh -c "exit 2"
     fn_check_eq "$?" "0" "run failed"
 
-    sleep 8
-    count=`isula inspect --format='{{json .RestartCount}}' $containername`
-    if [[ $count == "0"  ]];then
-        echo "expect not 0 but get $count"
+    do_retry ${retry_limit} ${retry_interval} ${containername} 0
+    if [[ $? -ne 0 ]];then
         TC_RET_T=$(($TC_RET_T+1))
     fi
 
diff --git a/CI/test_cases/image_cases/image_digest.sh b/CI/test_cases/image_cases/image_digest.sh
index e30f29f0..cc8b0e48 100755
--- a/CI/test_cases/image_cases/image_digest.sh
+++ b/CI/test_cases/image_cases/image_digest.sh
@@ -25,14 +25,14 @@ source ../helpers.sh
 function test_image_with_digest()
 {
   local ret=0
-  local image="busybox"
-  local image2="ubuntu"
-  local image_digest="busybox@sha256:5cd3db04b8be5773388576a83177aff4f40a03457a63855f4b9cbe30542b9a43"
+  local image="3laho3y3.mirror.aliyuncs.com/library/busybox"
+  local image2="3laho3y3.mirror.aliyuncs.com/library/ubuntu"
+  local image_digest="3laho3y3.mirror.aliyuncs.com/library/busybox@sha256:62ffc2ed7554e4c6d360bce40bbcf196573dd27c4ce080641a2c59867e732dee"
   local test="pull && inspect && tag image with digest test => (${FUNCNAME[@]})"
 
   msg_info "${test} starting..."
 
-  isula pull docker.io/library/${image_digest}
+  isula pull ${image_digest}
   [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to pull image: ${image}" && return ${FAILURE}
   
   isula tag ${image_digest} ${image}:digest_test
@@ -71,7 +71,7 @@ function test_image_with_digest()
   isula inspect -f '{{.image.repo_tags}}' ${image_digest} | grep "${image}:digest_test"
   [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - image digest delete error: ${image_digest}" && ((ret++))
 
-  isula pull docker.io/library/${image2}:latest
+  isula pull ${image2}:latest
   [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to pull image: ${image2}" && return ${FAILURE}
 
   digest=$(isula inspect "${image2}:latest" | grep "@sha256" | awk -F"\"" '{print $2}')
diff --git a/CI/test_cases/image_cases/image_search.sh b/CI/test_cases/image_cases/image_search.sh
index 1d281cb2..11af02f1 100755
--- a/CI/test_cases/image_cases/image_search.sh
+++ b/CI/test_cases/image_cases/image_search.sh
@@ -33,6 +33,7 @@ function test_image_search()
   [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stop isulad failed" && return ${FAILURE}
 
   msg_info "${test} starting..."
+  rm -rf /etc/isulad/daemon.bak
   cp /etc/isulad/daemon.json /etc/isulad/daemon.bak
   sed -i "/registry-mirrors/a\        \"docker.io\"," /etc/isulad/daemon.json
 
@@ -49,39 +50,18 @@ function test_image_search()
   [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} -  search  ${invalid_image} should fail as it's search name is invalid" && return ${FAILURE}
 
   # test search options   
-  isula search --no-trunc ${image}
-  [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to search images with no-trunc: ${image}" && ((ret++))
-
-  isula search --limit 5 ${image}
-  [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to search images with limit: ${image}" && ((ret++))
+  isula search  --no-trunc --limit 5 --filter stars=3  --filter is-official=true  --filter is-automated=false  --format "table {{.Name}}\t{{.IsOfficial}}" ${image}
+  [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to search images with search options: ${image}" && ((ret++))
 
   isula search --limit -1 ${image} 2>&1 | grep "Invalid value"
   [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to search images with limit: ${image} and and catch error msg" && ((ret++))
 
-  isula search --filter stars=3 ${image}
-  [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to search images with filter stars: ${image}" && ((ret++))
-
-  isula search --filter is-official=true ${image}
-  [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to search images with filter is-official: ${image}" && ((ret++))
-
-  isula search --filter is-automated=true ${image} 2>&1 | grep "AUTOMATED"
-  [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to search images with filter is-automated: ${image}" && ((ret++))
-
   isula search --filter aa=true ${image} 2>&1 | grep "Invalid filter"
   [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to set filter for search ${image} and catch error msg" && ((ret++))
 
-  isula search ${image} 2>&1 | grep "NAME"
-  [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to search images with default table format: ${image}" && ((ret++))
-
-  isula search --format "table {{.IsAutomated}}\t{{.IsOfficial}}" ${image} 2>&1 | grep "AUTOMATED"
-  [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to search images with table format: ${image}" && ((ret++))
-
   isula search --format "{{Name}}" ${image} 2>&1 | grep "invalid format field"
   [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to set format for search ${image} and catch error msg" && ((ret++))
 
-  isula search --format "{{.Name}}" ${image} 2>&1
-  [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to search images with none-table format: ${image}" && ((ret++))
-
   cp -f /etc/isulad/daemon.bak /etc/isulad/daemon.json
 
   check_valgrind_log
-- 
2.42.0