3 # Exercise the JSON PMDA.
5 # Copyright (c) 2015 Red Hat.
9 echo "QA output created by $seq"
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"
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
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
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}
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.
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
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
69 tee -a $here/$seq.full | \
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;' \
82 tee -a $here/$seq.full | \
84 -e '2,$s/^\([0-9][0-9]*\) [0-9][0-9]* /\1 TIMESTAMP /'
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.
*
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
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
148 "pointer": "/string",
150 "description": "Test string"
156 "description": "Integer value",
157 "semanatics": "instantaneous"
161 "pointer": "/counter",
163 "description": "double counter",
164 "semantics": "counter"
168 "pointer": "/discrete",
170 "description": "discrete integer",
171 "semantics": "discrete"
176 cat > ${SRC1_DATA1} <<EOF
178 "string": "original value",
184 cat > ${SRC1_DATA2} <<EOF
186 "string": "new value",
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
203 "name": "array_data",
204 "pointer": "/array_data",
220 "pointer": "/counter",
222 "semantics": "counter"
229 cat > ${SRC2_DATA1} <<EOF
247 cat > ${SRC2_DATA2} <<EOF
265 cat > ${SRC2_DATA3} <<EOF
283 cat > ${SRC2_DATA4} <<EOF
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
305 cd $here # create pmda log file somewhere safe (for debugging)
306 $sudo dbpmda
-n ${pmns_root} -e <${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.
314 open pipe $python_path $pmda_script
326 # Now, let's add a JSON data source.
328 cp $SRC1_METADATA ${tmp}/s
1/metadata.json
329 cp $SRC1_DATA1 ${tmp}/s
1/data.json
331 # On this fetch, the 'nsources' static metric should be increased and
332 # the new data source should be present.
345 desc json.s1.discrete
348 fetch json.s1.counter
349 fetch json.s1.discrete
353 # Now update the JSON data for the source.
354 cp $SRC1_DATA2 ${tmp}/s
1/data.json
356 # On this fetch, the data source variables should have their new values.
361 fetch json.s1.counter
362 fetch json.s1.discrete
366 # Add the 2nd JSON data source.
368 cp $SRC2_METADATA ${tmp}/s
2/metadata.json
369 cp $SRC2_DATA1 ${tmp}/s
2/data.json
371 # On this fetch, the 'nsources' static metric should be increased and
372 # the new data source should be present.
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
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
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}/s
2/data.json
406 fetch json.s2.array_data.count
407 fetch json.s2.array_data.value
408 fetch json.s2.array_data.counter
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}/s
2/data.json
419 fetch json.s2.array_data.count
420 fetch json.s2.array_data.value
421 fetch json.s2.array_data.counter
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
430 cp $SRC2_DATA4 ${tmp}/s
2/data.json
432 fetch json.s2.array_data.count
433 fetch json.s2.array_data.value
434 fetch json.s2.array_data.counter
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.
444 cp ${json_qa_dir}/ceph_data1.json
${tmp}/ceph
/data.json
445 # Use the generate_ceph_metadata script to convert the ceph schema
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.
467 fetch json.ceph.filestore.journal_wr_bytes.sum
468 fetch json.ceph.osd.stat_bytes
472 # Other things to test:
473 # - 'prefix' directive
474 # - 'data-exec' directive
476 # Tell dbpmda to quit.
482 # Wait for dbpmda to quit.