summaryrefslogtreecommitdiffstats
path: root/ctdb/tests/UNIT/cunit/tunable_test_001.sh
blob: c68cd69c64a0b969a95fcb9b6a4e5985f0d8d869 (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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#!/bin/sh

. "${TEST_SCRIPTS_DIR}/unit.sh"

tfile="${CTDB_TEST_TMP_DIR}/tunable.$$"

remove_files ()
{
	rm -f "$tfile"
}
test_cleanup remove_files

defaults="\
SeqnumInterval=1000
ControlTimeout=60
TraverseTimeout=20
KeepaliveInterval=5
KeepaliveLimit=5
RecoverTimeout=30
RecoverInterval=1
ElectionTimeout=3
TakeoverTimeout=9
MonitorInterval=15
TickleUpdateInterval=20
EventScriptTimeout=30
MonitorTimeoutCount=20
RecoveryGracePeriod=120
RecoveryBanPeriod=300
DatabaseHashSize=100001
DatabaseMaxDead=5
RerecoveryTimeout=10
EnableBans=1
NoIPFailback=0
VerboseMemoryNames=0
RecdPingTimeout=60
RecdFailCount=10
LogLatencyMs=0
RecLockLatencyMs=1000
RecoveryDropAllIPs=120
VacuumInterval=10
VacuumMaxRunTime=120
RepackLimit=10000
VacuumFastPathCount=60
MaxQueueDropMsg=1000000
AllowUnhealthyDBRead=0
StatHistoryInterval=1
DeferredAttachTO=120
AllowClientDBAttach=1
FetchCollapse=1
HopcountMakeSticky=50
StickyDuration=600
StickyPindown=200
NoIPTakeover=0
DBRecordCountWarn=100000
DBRecordSizeWarn=10000000
DBSizeWarn=100000000
PullDBPreallocation=10485760
LockProcessesPerDB=200
RecBufferSizeLimit=1000000
QueueBufferSize=1024
IPAllocAlgorithm=2
AllowMixedVersions=0
"

ok_tunable_defaults ()
{
	ok "$defaults"
}

# Set required output to a version of $defaults where values for
# tunables specified in $tfile replace the default values
ok_tunable ()
{
	# Construct a version of $defaults prepended with a lowercase
	# version of the tunable variable, to allow case-insensitive
	# matching.  This would be easier with the GNU sed
	# case-insensitivity flag, but that is less portable.  The $0
	# condition in awk causes empty lines to be skipped, in case
	# there are trailing empty lines in $defaults.
	_map=$(echo "$defaults" |
	       awk -F= '$0 { printf "%s:%s=%s\n", tolower($1), $1, $2 }')

	# Replace values for tunables set in $tfile
	while IFS='= 	' read -r _var _val ; do
		case "$_var" in
		\#* | "") continue ;;
		esac
		_decval=$((_val))
		_vl=$(echo "$_var" | tr '[:upper:]' '[:lower:]')
		_map=$(echo "$_map" |
		       sed -e "s|^\\(${_vl}:.*=\\).*\$|\\1${_decval}|")
	done <"$tfile"

	# Set result, stripping off lowercase tunable prefix
	ok "$(echo "$_map" | awk -F: '{ print $2 }')"
}

test_case "Unreadable file"
: >"$tfile"
chmod a-r "$tfile"
uid=$(id -u)
# root can read unreadable files
if [ "$uid" = 0 ]; then
	ok_tunable_defaults
else
	required_error EINVAL <<EOF
ctdb_tunable_load_file: Failed to open ${tfile}
EOF
fi
unit_test tunable_test "$tfile"
rm -f "$tfile"

test_case "Invalid file, contains 1 word"
echo "Hello" >"$tfile"
required_error EINVAL <<EOF
ctdb_tunable_load_file: Invalid line containing "Hello"
EOF
unit_test tunable_test "$tfile"

test_case "Invalid file, contains multiple words"
echo "Hello world!" >"$tfile"
required_error EINVAL <<EOF
ctdb_tunable_load_file: Invalid line containing "Hello world!"
EOF
unit_test tunable_test "$tfile"

test_case "Invalid file, missing value"
echo "EnableBans=" >"$tfile"
required_error EINVAL <<EOF
ctdb_tunable_load_file: Invalid line containing "EnableBans"
EOF
unit_test tunable_test "$tfile"

test_case "Invalid file, invalid value (not a number)"
echo "EnableBans=value" >"$tfile"
required_error EINVAL <<EOF
ctdb_tunable_load_file: Invalid value "value" for tunable "EnableBans"
EOF
unit_test tunable_test "$tfile"

test_case "Invalid file, missing key"
echo "=123" >"$tfile"
required_error EINVAL <<EOF
ctdb_tunable_load_file: Syntax error
EOF
unit_test tunable_test "$tfile"

test_case "Invalid file, missing key but space before ="
cat >"$tfile" <<EOF
 =0
EOF
required_error EINVAL <<EOF
ctdb_tunable_load_file: Syntax error
EOF
unit_test tunable_test "$tfile"

test_case "Invalid file, unknown tunable"
echo "HelloWorld=123" >"$tfile"
required_error EINVAL <<EOF
ctdb_tunable_load_file: Unknown tunable "HelloWorld"
EOF
unit_test tunable_test "$tfile"

test_case "Invalid file, obsolete tunable"
echo "MaxRedirectCount=123" >"$tfile"
required_error EINVAL <<EOF
ctdb_tunable_load_file: Obsolete tunable "MaxRedirectCount"
EOF
unit_test tunable_test "$tfile"

test_case "Invalid file, trailing non-whitespace garbage"
echo "EnableBans=0xgg" >"$tfile"
required_error EINVAL <<EOF
ctdb_tunable_load_file: Invalid value "0xgg" for tunable "EnableBans"
EOF
unit_test tunable_test "$tfile"

test_case "Invalid file, multiple errors"
cat >"$tfile" <<EOF
EnableBans=
EnableBans=value
=123
HelloWorld=123
MaxRedirectCount =123
EOF
required_error EINVAL <<EOF
ctdb_tunable_load_file: Invalid line containing "EnableBans"
ctdb_tunable_load_file: Invalid value "value" for tunable "EnableBans"
ctdb_tunable_load_file: Syntax error
EOF
unit_test tunable_test "$tfile"

test_case "Invalid file, errors followed by valid"
cat >"$tfile" <<EOF
HelloWorld=123
EnableBans=value
EnableBans=0
EOF
required_error EINVAL <<EOF
ctdb_tunable_load_file: Unknown tunable "HelloWorld"
ctdb_tunable_load_file: Invalid value "value" for tunable "EnableBans"
EOF
unit_test tunable_test "$tfile"

test_case "OK, missing file"
rm -f "$tfile"
ok_tunable_defaults
unit_test tunable_test "$tfile"

test_case "OK, empty file"
: >"$tfile"
ok_tunable_defaults
unit_test tunable_test "$tfile"

test_case "OK, comments and blanks only"
cat >"$tfile" <<EOF
# This is a comment

# There are also some blank lines


EOF
ok_tunable_defaults
unit_test tunable_test "$tfile"

test_case "OK, 1 tunable"
cat >"$tfile" <<EOF
EnableBans=0
EOF
ok_tunable
unit_test tunable_test "$tfile"

test_case "OK, 1 tunable, hex"
cat >"$tfile" <<EOF
EnableBans=0xf
EOF
ok_tunable
unit_test tunable_test "$tfile"

test_case "OK, 1 tunable, octal"
cat >"$tfile" <<EOF
EnableBans=072
EOF
ok_tunable
unit_test tunable_test "$tfile"

test_case "OK, 1 tunable, tab before ="
cat >"$tfile" <<EOF
EnableBans	=0
EOF
ok_tunable
unit_test tunable_test "$tfile"

test_case "OK, 1 tunable, space after ="
cat >"$tfile" <<EOF
EnableBans= 0
EOF
ok_tunable
unit_test tunable_test "$tfile"

test_case "OK, 2 tunables, multiple spaces around ="
cat >"$tfile" <<EOF
EnableBans      =  0
RecoverInterval = 10
EOF
ok_tunable
unit_test tunable_test "$tfile"

test_case "OK, 2 tunables, whitespace everywhere"
cat >"$tfile" <<EOF
	EnableBans      = 0  
	RecoverInterval = 10 
EOF
ok_tunable
unit_test tunable_test "$tfile"

test_case "OK, several tunables"
cat >"$tfile" <<EOF
EnableBans=0
RecoverInterval=10
ElectionTimeout=5
EOF
ok_tunable
unit_test tunable_test "$tfile"

test_case "OK, several tunables, varying case"
cat >"$tfile" <<EOF
enablebans=0
ReCoVerInTeRvAl=10
ELECTIONTIMEOUT=5
EOF
ok_tunable
unit_test tunable_test "$tfile"

test_case "OK, miscellaneous..."
cat >"$tfile" <<EOF
# Leading comment
enablebans=0
ReCoVerInTeRvAl	 =    10

# Intermediate comment after a blank line
  ELECTIONTIMEOUT=25   


# Final comment among blanks lines




EOF
ok_tunable
unit_test tunable_test "$tfile"