pmrep: fix archive end time reporting
[pcp.git] / qa / 1052
blob84b7246dfcf7ea2ae77cb913b22835ec460222a3
1 #!/bin/bash
2 # PCP QA Test No. 1052
3 # Exercise the JSON PMDA.
5 # Copyright (c) 2015 Red Hat.
8 seq=`basename $0`
9 echo "QA output created by $seq"
11 . ./common.python
13 python_path=`which $python`
14 pmda_path="$PCP_PMDAS_DIR/json"
15 pmda_script="${pmda_path}/pmdajson.python"
16 pmda_config="${pmda_path}/config.json"
17 ceph_script="${pmda_path}/generate_ceph_metadata"
18 qa_dir=`pwd`
19 json_qa_dir="${qa_dir}/json"
20 pmda_config_dir="${PCP_VAR_DIR}/config/pmda"
21 pmda_saved_config_dir="${pmda_config_dir}/pmdajson.$seq"
22 test -f "$pmda_script" || _notrun "pmdajson not installed"
23 $python -c "from pcp import pmda" >/dev/null 2>&1
24 [ $? -eq 0 ] || _notrun "python pcp pmda module not installed"
25 $python -c "import jsonpointer" >/dev/null 2>&1
26 [ $? -eq 0 ] || _notrun "python jsonpointer module not installed"
27 $python -c "import six" >/dev/null 2>&1
28 [ $? -eq 0 ] || _notrun "python six module not installed"
30 status=1 # failure is the default!
31 $sudo rm -rf $tmp.* $seq.full
32 mkdir $tmp
33 chmod ugo+rwx $tmp
34 cd $tmp
36 # We need a bit more interaction with dbpmda than other tests do, so
37 # create 2 named pipes (FIFOs). This allows us to send dbpmda some
38 # commands, do some shell commands, then send the same dbpmda session
39 # more commands.
40 fifo_in="${tmp}/fifo_in"
41 fifo_out="${tmp}/fifo_out"
42 $sudo mkfifo ${fifo_in} ${fifo_out}
43 $sudo chmod 666 ${fifo_in} ${fifo_out}
45 _needclean=true
46 trap "cleanup; exit \$status" 0 1 2 3 15
48 # Notice in _drain_output() we are reading from fd 4, which will be
49 # set up later to point one of the fifos we created above.
50 _drain_output()
52 quit=0
53 while [ $quit -eq 0 ]; do
54 # detect failure, but have a last round
55 read -u 4 -t 1 output || quit=1
56 echo "$output" | _filter
57 done
60 # We have to sort the output of certain commands (like "children"),
61 # since the order of the output depends on python internal ordering.
62 _drain_output_sorted()
64 _drain_output | LC_COLLATE=POSIX sort
67 _filter()
69 tee -a $here/$seq.full | \
70 sed \
71 -e "s;$PCP_PMDAS_DIR;\$PCP_PMDAS_DIR;" \
72 -e '/pmResult/s/ .* numpmid/ ... numpmid/' \
73 -e '/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/s/[^ ]*/TIMESTAMP/' \
74 -e "s;$python_path;\$PCP_PYTHON_PROG;" \
75 -e "s;$python;python;" \
76 -e 's;137.3.[0-9]\+;137.3.ID;' \
77 #end
80 _filter2()
82 tee -a $here/$seq.full | \
83 sed \
84 -e '2,$s/^\([0-9][0-9]*\) [0-9][0-9]* /\1 TIMESTAMP /'
87 cleanup()
89 cd $here
90 if $_needclean; then
91 _needclean=false
92 _restore_config $PCP_PMCDCONF_PATH
93 if [ -f ${pmda_config}.$seq ]; then
94 _restore_config ${pmda_config}
97 # Remove the newly created indom cache files and restore any
98 # old indom cache files.
99 $sudo rm -f ${pmda_config_dir}/${domain}.*
100 if [ -d ${pmda_saved_config_dir} ]; then
101 $sudo mv ${pmda_saved_config_dir}/* ${pmda_config_dir}/
102 $sudo rm -rf ${pmda_saved_config_dir}
105 $sudo rm -rf $tmp $tmp.*
108 domain=137
109 test="$here/json"
111 # Copy the pmcd config file to restore state later.
112 _save_config $PCP_PMCDCONF_PATH
114 # Ditto for JSON pmda config.
115 if [ -f ${pmda_config} ]; then
116 _save_config ${pmda_config}
119 # We want to get any JSON pmda indom cache files out of the way, so we
120 # start with a clean slate. We'll restore these at the end.
121 if [ -f "${pmda_config_dir}/${domain}.0" ]; then
122 $sudo rm -rf ${pmda_saved_config_dir}
123 $sudo mkdir ${pmda_saved_config_dir}
124 $sudo mv ${pmda_config_dir}/${domain}.* ${pmda_saved_config_dir}/
127 # Create a new JSOM pmda config file and install it
128 cat > ${tmp}/config.json << EOF
130 "directory_list" : [
131 "${tmp}"
135 $sudo cp ${tmp}/config.json ${pmda_config}
137 # Create some JSON data/metadata files.
139 # SRC1 is a basic JSON data/metadata files.
140 SRC1_METADATA="${tmp}/s1_metadata.json"
141 SRC1_DATA1="${tmp}/s1_data1.json"
142 SRC1_DATA2="${tmp}/s1_data2.json"
143 cat > ${SRC1_METADATA} <<EOF
145 "metrics": [
147 "name": "string",
148 "pointer": "/string",
149 "type": "string",
150 "description": "Test string"
153 "name": "value",
154 "pointer": "/value",
155 "type": "integer",
156 "description": "Integer value",
157 "semanatics": "instantaneous"
160 "name": "counter",
161 "pointer": "/counter",
162 "type": "double",
163 "description": "double counter",
164 "semantics": "counter"
167 "name": "discrete",
168 "pointer": "/discrete",
169 "type": "integer",
170 "description": "discrete integer",
171 "semantics": "discrete"
176 cat > ${SRC1_DATA1} <<EOF
178 "string": "original value",
179 "value": 0,
180 "counter": 5,
181 "discrete": 7
184 cat > ${SRC1_DATA2} <<EOF
186 "string": "new value",
187 "value": 99,
188 "counter": 10,
189 "discrete": 14
193 # SRC2 is more complicated, and has an array.
194 SRC2_METADATA="${tmp}/s2_metadata.json"
195 SRC2_DATA1="${tmp}/s2_data1.json"
196 SRC2_DATA2="${tmp}/s2_data2.json"
197 SRC2_DATA3="${tmp}/s2_data3.json"
198 SRC2_DATA4="${tmp}/s2_data4.json"
199 cat > ${SRC2_METADATA} <<EOF
201 "metrics": [
203 "name": "array_data",
204 "pointer": "/array_data",
205 "type": "array",
206 "index": "/__id",
207 "metrics": [
209 "name": "count",
210 "pointer": "/count",
211 "type": "integer"
214 "name": "value",
215 "pointer": "/value",
216 "type": "integer"
219 "name": "counter",
220 "pointer": "/counter",
221 "type": "double",
222 "semantics": "counter"
229 cat > ${SRC2_DATA1} <<EOF
231 "array_data": [
233 "__id": "first",
234 "count": 0,
235 "value": 1024,
236 "counter": 3
239 "__id": "second",
240 "count": 99,
241 "value": 2048,
242 "counter": 5
247 cat > ${SRC2_DATA2} <<EOF
249 "array_data": [
251 "__id": "third",
252 "count": 3,
253 "value": 3072,
254 "counter": 7
257 "__id": "second",
258 "count": 100,
259 "value": 2049,
260 "counter": 10
265 cat > ${SRC2_DATA3} <<EOF
267 "array_data": [
269 "__id": "first",
270 "count": 1,
271 "value": 1025,
272 "counter": 6
275 "__id": "fourth",
276 "count": 4,
277 "value": 999,
278 "counter": 13
283 cat > ${SRC2_DATA4} <<EOF
285 "array_data": [
287 "__id": "first",
288 "count": 2,
289 "value": 1026,
290 "counter": 9
297 # real QA test starts here
300 pmns_root="${tmp}/json.root"
301 PCP_PYTHON_PMNS=root $python "$pmda_script" > ${pmns_root}
303 # Start dbpmda in the background, redirecting its stdin/stdout to the
304 # fifos.
305 cd $here # create pmda log file somewhere safe (for debugging)
306 $sudo dbpmda -n ${pmns_root} -ie <${fifo_in} >${fifo_out} 2>&1 &
308 # Open fd 3 for write and fd 4 for read. Note that we need to avoid
309 # closing either fifo below, so we have to be careful with redirects.
310 exec 3>${fifo_in} 4<${fifo_out}
312 # Check to see if the 'nsources' static metric is present.
313 cat >&3 <<EOF
314 open pipe $python_path $pmda_script
315 getdesc on
316 desc json.nsources
317 fetch json.nsources
319 _drain_output
321 cat >&3 <<EOF
322 children json
324 _drain_output_sorted
326 # Now, let's add a JSON data source.
327 mkdir ${tmp}/s1
328 cp $SRC1_METADATA ${tmp}/s1/metadata.json
329 cp $SRC1_DATA1 ${tmp}/s1/data.json
331 # On this fetch, the 'nsources' static metric should be increased and
332 # the new data source should be present.
333 cat >&3 <<EOF
334 fetch json.nsources
337 cat >&3 <<EOF
338 children json
339 children json.s1
341 _drain_output_sorted
343 cat >&3 <<EOF
344 desc json.s1.counter
345 desc json.s1.discrete
346 fetch json.s1.string
347 fetch json.s1.value
348 fetch json.s1.counter
349 fetch json.s1.discrete
351 _drain_output
353 # Now update the JSON data for the source.
354 cp $SRC1_DATA2 ${tmp}/s1/data.json
356 # On this fetch, the data source variables should have their new values.
357 cat >&3 <<EOF
358 fetch json.nsources
359 fetch json.s1.string
360 fetch json.s1.value
361 fetch json.s1.counter
362 fetch json.s1.discrete
364 _drain_output
366 # Add the 2nd JSON data source.
367 mkdir ${tmp}/s2
368 cp $SRC2_METADATA ${tmp}/s2/metadata.json
369 cp $SRC2_DATA1 ${tmp}/s2/data.json
371 # On this fetch, the 'nsources' static metric should be increased and
372 # the new data source should be present.
373 cat >&3 <<EOF
374 fetch json.nsources
376 _drain_output
378 cat >&3 <<EOF
379 children json
380 children json.s1
381 children json.s2
383 _drain_output_sorted
385 cat >&3 <<EOF
386 instance $domain.0
387 desc json.s2.array_data.counter
388 fetch json.s2.array_data.count
389 fetch json.s2.array_data.value
390 fetch json.s2.array_data.counter
392 _drain_output
394 # Let's test proper indom support with the 2nd source. First, find out
395 # what the current indom state looks like.
396 cat ${pmda_config_dir}/${domain}.4 | _filter2
397 cat >&3 <<EOF
398 instance $domain.4
400 _drain_output
402 # Copy a new data file in and see how the instance values change. The
403 # instance command just returns "active" instances, not all instances.
404 cp $SRC2_DATA2 ${tmp}/s2/data.json
405 cat >&3 <<EOF
406 fetch json.s2.array_data.count
407 fetch json.s2.array_data.value
408 fetch json.s2.array_data.counter
409 instance $domain.4
411 _drain_output
412 # We should see all instances by looking at the indom cache file.
413 cat ${pmda_config_dir}/${domain}.4 | _filter2
415 # Let's try another indom test. This data file reuses an inactive
416 # instance and adds a new one.
417 cp $SRC2_DATA3 ${tmp}/s2/data.json
418 cat >&3 <<EOF
419 fetch json.s2.array_data.count
420 fetch json.s2.array_data.value
421 fetch json.s2.array_data.counter
422 instance $domain.4
424 _drain_output
425 # We should see all instances by looking at the indom cache file.
426 cat ${pmda_config_dir}/${domain}.4 | _filter2
428 # Let's try another indom test. This data file just reuses an
429 # instance.
430 cp $SRC2_DATA4 ${tmp}/s2/data.json
431 cat >&3 <<EOF
432 fetch json.s2.array_data.count
433 fetch json.s2.array_data.value
434 fetch json.s2.array_data.counter
435 instance $domain.4
437 _drain_output
438 # We should see all instances by looking at the indom cache file.
439 cat ${pmda_config_dir}/${domain}.4 | _filter2
441 # Let's test the ceph support by running the 'generate_ceph_metadata'
442 # script on some canned data.
443 mkdir -p ${tmp}/ceph
444 cp ${json_qa_dir}/ceph_data1.json ${tmp}/ceph/data.json
445 # Use the generate_ceph_metadata script to convert the ceph schema
446 # into metadata.
447 $python ${ceph_script} -o ${tmp}/ceph/metadata.json -t ${json_qa_dir}/ceph_schema1.json
449 # On this fetch, the 'nsources' static metric should be increased and
450 # the new data source should be present. Notice we aren't grabbing all
451 # the metrics from the ceph source, just a couple.
452 cat >&3 <<EOF
453 fetch json.nsources
455 _drain_output
457 cat >&3 <<EOF
458 children json
459 children json.s1
460 children json.s2
461 children json.ceph
463 _drain_output_sorted
465 cat >&3 <<EOF
466 instance $domain.0
467 fetch json.ceph.filestore.journal_wr_bytes.sum
468 fetch json.ceph.osd.stat_bytes
470 _drain_output
472 # Other things to test:
473 # - 'prefix' directive
474 # - 'data-exec' directive
476 # Tell dbpmda to quit.
477 cat >&3 <<EOF
478 quit
480 _drain_output
482 # Wait for dbpmda to quit.
483 wait
485 status=0
486 exit