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
|
From 94122c5752936b4f5db14521cdd0f39a3dec6851 Mon Sep 17 00:00:00 2001
From: zhongtao <zhongtao17@huawei.com>
Date: Thu, 7 Dec 2023 03:32:15 +0000
Subject: [PATCH 49/64] !2298 bugfix for hook_ignore_poststart_error run in oci
runtime * bugfix for hook_ignore_poststart_error run in oci runtime
---
.../hook_ignore_poststart_error.sh | 70 +++++++++++++------
1 file changed, 50 insertions(+), 20 deletions(-)
diff --git a/CI/test_cases/container_cases/hook_ignore_poststart_error.sh b/CI/test_cases/container_cases/hook_ignore_poststart_error.sh
index 8c636f7e..38b6f021 100755
--- a/CI/test_cases/container_cases/hook_ignore_poststart_error.sh
+++ b/CI/test_cases/container_cases/hook_ignore_poststart_error.sh
@@ -24,6 +24,48 @@ source ../helpers.sh
test_data_path=$(realpath $curr_path/test_data)
+# $1 hook process
+# $2 container id
+# $3 expect container status
+# $4 process statement
+function test_kill_hook()
+{
+ for a in `seq 20`
+ do
+ bpid=`ps aux | grep "$1" | grep -v grep | awk '{print $2}'`
+ if [ "x" != "x$bpid" ];then
+ kill -9 $bpid
+ break
+ else
+ sleep .5
+ continue
+ fi
+ done
+
+ if [ "x" != "x$4" ];then
+ for a in `seq 20`
+ do
+ bpid=`ps aux | grep "$4" | grep -v grep | awk '{print $2}'`
+ if [ "x" != "x$bpid" ];then
+ kill -9 $bpid
+ break
+ else
+ sleep .5
+ continue
+ fi
+ done
+ fi
+
+ status=`isula inspect -f '{{json .State.Status}}' $2`
+ if [ "$status" == "$3" ];then
+ echo "get right status"
+ return 0
+ else
+ echo "expect $2 $3, but get $status"
+ return 1
+ fi
+}
+
function test_hook_ignore_poststart_error_spec()
{
local ret=0
@@ -42,27 +84,15 @@ function test_hook_ignore_poststart_error_spec()
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - missing list image: ${image}" && ((ret++))
isula run -n $CONT -itd --runtime $runtime --hook-spec ${test_data_path}/oci_hook_poststart_check.json ${image} &
-
- for a in `seq 20`
- do
- bpid=`ps aux | grep "poststart.sh" | grep -v grep | awk '{print $2}'`
- if [ "x" != "x$bpid" ];then
- kill -9 $bpid
- break
- else
- sleep .5
- continue
- fi
- done
-
- status=`isula inspect -f '{{json .State.Status}}' $CONT`
- if [ "$status" == "\"running\"" ];then
- echo "get right status"
+
+ # when runc container run poststart hook, the process structure is different from lxc
+ if [ $runtime == "lcr" ]; then
+ test_kill_hook "poststart.sh" $CONT \"running\"
else
- echo "expect $CONT running, but get $status"
- ret++
+ test_kill_hook "poststart.sh" $CONT \"exited\" "sleep 300"
fi
-
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to test kill hook: ${image}" && ((ret++))
+
isula stop -t 0 ${CONT}
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to stop ${CONT}" && ((ret++))
@@ -77,7 +107,7 @@ declare -i ans=0
for element in ${RUNTIME_LIST[@]};
do
- test_hook_ignore_poststart_error_spec $1 || ((ans++))
+ test_hook_ignore_poststart_error_spec $element || ((ans++))
done
show_result ${ans} "${curr_path}/${0}"
--
2.42.0
|