blob: 4df3b4bdad61bf21ff0b191184bc0f0813acca34 (
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
|
#!/bin/sh
. "${TEST_SCRIPTS_DIR}/unit.sh"
# Invalid path
required_result 1 <<EOF
run_event_init() failed, ret=2
EOF
unit_test run_event_test /a/b/c list
scriptdir=$(TMPDIR="$CTDB_TEST_TMP_DIR" mktemp -d)
# Empty directory
ok <<EOF
No event scripts found
EOF
unit_test run_event_test "$scriptdir" list
cat > "$scriptdir/prog" <<EOF
#!/bin/sh
echo hello
EOF
# Invalid script, doesn't end in ".script"
ok <<EOF
No event scripts found
EOF
unit_test run_event_test "$scriptdir" list
# Is not found because enabling "prog" actually looks for "prog.script"
ok <<EOF
Script enable prog completed with result=2
EOF
unit_test run_event_test "$scriptdir" enable prog
required_result 1 <<EOF
EOF
unit_test test -x "${scriptdir}/prog"
cat > "$scriptdir/11.foo.script" <<EOF
#!/bin/sh
echo hello
EOF
# Valid script
ok <<EOF
11.foo
EOF
unit_test run_event_test "$scriptdir" list
ok <<EOF
Script enable 11.foo completed with result=0
EOF
unit_test run_event_test "$scriptdir" enable 11.foo
ok <<EOF
EOF
unit_test test -x "${scriptdir}/11.foo.script"
ok <<EOF
11.foo: hello
Event monitor completed with result=0
11.foo result=0
EOF
unit_test run_event_test "$scriptdir" run 10 monitor
cat > "$scriptdir/22.bar.script" <<EOF
#!/bin/sh
exit 1
EOF
# Multiple scripts
ok <<EOF
11.foo
22.bar
EOF
unit_test run_event_test "$scriptdir" list
ok <<EOF
Script enable 22.bar completed with result=0
EOF
unit_test run_event_test "$scriptdir" enable 22.bar
ok <<EOF
11.foo: hello
Event monitor completed with result=1
11.foo result=0
22.bar result=1
EOF
unit_test run_event_test "$scriptdir" run 10 monitor
# Disable script
ok <<EOF
Script disable 22.bar completed with result=0
EOF
unit_test run_event_test "$scriptdir" disable 22.bar
required_result 1 <<EOF
EOF
unit_test test -x "${scriptdir}/22.bar.script"
ok <<EOF
11.foo: hello
Event monitor completed with result=0
11.foo result=0
22.bar result=-$(errcode ENOEXEC)
EOF
unit_test run_event_test "$scriptdir" run 10 monitor
cat > "$scriptdir/22.bar.script" <<EOF
#!/bin/sh
echo before sleep
sleep 10
echo after sleep
EOF
# Timed out script
ok <<EOF
Script enable 22.bar completed with result=0
EOF
unit_test run_event_test "$scriptdir" enable 22.bar
ok <<EOF
11.foo: hello
22.bar: before sleep
Event monitor completed with result=-$(errcode ETIMEDOUT)
11.foo result=0
22.bar result=-$(errcode ETIMEDOUT)
EOF
unit_test run_event_test "$scriptdir" run 5 monitor
rm -rf "$scriptdir"
exit 0
|