/var/lib/pcp/testsuite/1052 is in pcp-testsuite 4.0.1-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | #!/bin/bash
# PCP QA Test No. 1052
# Exercise the JSON PMDA.
#
# Copyright (c) 2015 Red Hat.
#
seq=`basename $0`
echo "QA output created by $seq"
. ./common.python
python_path=`which $python`
pmda_path="$PCP_PMDAS_DIR/json"
pmda_script="${pmda_path}/pmdajson.python"
pmda_config="${pmda_path}/config.json"
ceph_script="${pmda_path}/generate_ceph_metadata"
qa_dir=`pwd`
json_qa_dir="${qa_dir}/json"
pmda_config_dir="${PCP_VAR_DIR}/config/pmda"
pmda_saved_config_dir="${pmda_config_dir}/pmdajson.$seq"
test -f "$pmda_script" || _notrun "pmdajson not installed"
$python -c "from pcp import pmda" >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "python pcp pmda module not installed"
$python -c "import jsonpointer" >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "python jsonpointer module not installed"
$python -c "import six" >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "python six module not installed"
status=1 # failure is the default!
$sudo rm -rf $tmp.* $seq.full
mkdir $tmp
chmod ugo+rwx $tmp
cd $tmp
# We need a bit more interaction with dbpmda than other tests do, so
# create 2 named pipes (FIFOs). This allows us to send dbpmda some
# commands, do some shell commands, then send the same dbpmda session
# more commands.
fifo_in="${tmp}/fifo_in"
fifo_out="${tmp}/fifo_out"
$sudo mkfifo ${fifo_in} ${fifo_out}
$sudo chmod 666 ${fifo_in} ${fifo_out}
_needclean=true
trap "cleanup; exit \$status" 0 1 2 3 15
# Notice in _drain_output() we are reading from fd 4, which will be
# set up later to point one of the fifos we created above.
_drain_output()
{
quit=0
while [ $quit -eq 0 ]; do
# detect failure, but have a last round
read -u 4 -t 1 output || quit=1
echo "$output" | _filter
done
}
# We have to sort the output of certain commands (like "children"),
# since the order of the output depends on python internal ordering.
_drain_output_sorted()
{
_drain_output | LC_COLLATE=POSIX sort
}
_filter()
{
tee -a $here/$seq.full | \
sed \
-e "s;$PCP_PMDAS_DIR;\$PCP_PMDAS_DIR;" \
-e '/pmResult/s/ .* numpmid/ ... numpmid/' \
-e '/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/s/[^ ]*/TIMESTAMP/' \
-e "s;$python_path;\$PCP_PYTHON_PROG;" \
-e "s;$python;python;" \
-e 's;137.3.[0-9]\+;137.3.ID;' \
#end
}
_filter2()
{
tee -a $here/$seq.full | \
sed \
-e '2,$s/^\([0-9][0-9]*\) [0-9][0-9]* /\1 TIMESTAMP /'
}
cleanup()
{
cd $here
if $_needclean; then
_needclean=false
_restore_config $PCP_PMCDCONF_PATH
if [ -f ${pmda_config}.$seq ]; then
_restore_config ${pmda_config}
fi
# Remove the newly created indom cache files and restore any
# old indom cache files.
$sudo rm -f ${pmda_config_dir}/${domain}.*
if [ -d ${pmda_saved_config_dir} ]; then
$sudo mv ${pmda_saved_config_dir}/* ${pmda_config_dir}/
$sudo rm -rf ${pmda_saved_config_dir}
fi
fi
$sudo rm -rf $tmp $tmp.* json.log
}
domain=137
test="$here/json"
# Copy the pmcd config file to restore state later.
_save_config $PCP_PMCDCONF_PATH
# Ditto for JSON pmda config.
if [ -f ${pmda_config} ]; then
_save_config ${pmda_config}
fi
# We want to get any JSON pmda indom cache files out of the way, so we
# start with a clean slate. We'll restore these at the end.
if [ -f "${pmda_config_dir}/${domain}.0" ]; then
$sudo rm -rf ${pmda_saved_config_dir}
$sudo mkdir ${pmda_saved_config_dir}
$sudo mv ${pmda_config_dir}/${domain}.* ${pmda_saved_config_dir}/
fi
# Create a new JSOM pmda config file and install it
cat > ${tmp}/config.json << EOF
{
"directory_list" : [
"${tmp}"
]
}
EOF
$sudo cp ${tmp}/config.json ${pmda_config}
# Create some JSON data/metadata files.
#
# SRC1 is a basic JSON data/metadata files.
SRC1_METADATA="${tmp}/s1_metadata.json"
SRC1_DATA1="${tmp}/s1_data1.json"
SRC1_DATA2="${tmp}/s1_data2.json"
cat > ${SRC1_METADATA} <<EOF
{
"metrics": [
{
"name": "string",
"pointer": "/string",
"type": "string",
"description": "Test string"
},
{
"name": "value",
"pointer": "/value",
"type": "integer",
"description": "Integer value",
"semantics": "instantaneous"
},
{
"name": "counter",
"pointer": "/counter",
"type": "double",
"description": "double counter",
"semantics": "counter"
},
{
"name": "discrete",
"pointer": "/discrete",
"type": "integer",
"description": "discrete integer",
"semantics": "discrete"
}
]
}
EOF
cat > ${SRC1_DATA1} <<EOF
{
"string": "original value",
"value": 0,
"counter": 5,
"discrete": 7
}
EOF
cat > ${SRC1_DATA2} <<EOF
{
"string": "new value",
"value": 99,
"counter": 10,
"discrete": 14
}
EOF
# SRC2 is more complicated, and has an array.
SRC2_METADATA="${tmp}/s2_metadata.json"
SRC2_DATA1="${tmp}/s2_data1.json"
SRC2_DATA2="${tmp}/s2_data2.json"
SRC2_DATA3="${tmp}/s2_data3.json"
SRC2_DATA4="${tmp}/s2_data4.json"
cat > ${SRC2_METADATA} <<EOF
{
"metrics": [
{
"name": "array_data",
"pointer": "/array_data",
"type": "array",
"index": "/__id",
"metrics": [
{
"name": "count",
"pointer": "/count",
"type": "integer"
},
{
"name": "value",
"pointer": "/value",
"type": "integer"
},
{
"name": "counter",
"pointer": "/counter",
"type": "double",
"semantics": "counter"
}
]
}
]
}
EOF
cat > ${SRC2_DATA1} <<EOF
{
"array_data": [
{
"__id": "first",
"count": 0,
"value": 1024,
"counter": 3
},
{
"__id": "second",
"count": 99,
"value": 2048,
"counter": 5
}
]
}
EOF
cat > ${SRC2_DATA2} <<EOF
{
"array_data": [
{
"__id": "third",
"count": 3,
"value": 3072,
"counter": 7
},
{
"__id": "second",
"count": 100,
"value": 2049,
"counter": 10
}
]
}
EOF
cat > ${SRC2_DATA3} <<EOF
{
"array_data": [
{
"__id": "first",
"count": 1,
"value": 1025,
"counter": 6
},
{
"__id": "fourth",
"count": 4,
"value": 999,
"counter": 13
}
]
}
EOF
cat > ${SRC2_DATA4} <<EOF
{
"array_data": [
{
"__id": "first",
"count": 2,
"value": 1026,
"counter": 9
}
]
}
EOF
#
# real QA test starts here
#
pmns_root="${tmp}/json.root"
PCP_PYTHON_PMNS=root $python "$pmda_script" > ${pmns_root}
# Start dbpmda in the background, redirecting its stdin/stdout to the
# fifos.
cd $here # create pmda log file somewhere safe (for debugging)
$sudo dbpmda -n ${pmns_root} -e <${fifo_in} >${fifo_out} 2>&1 &
# Open fd 3 for write and fd 4 for read. Note that we need to avoid
# closing either fifo below, so we have to be careful with redirects.
exec 3>${fifo_in} 4<${fifo_out}
# Check to see if the 'nsources' static metric is present.
cat >&3 <<EOF
open pipe $python_path $pmda_script
getdesc on
desc json.nsources
fetch json.nsources
EOF
_drain_output
cat >&3 <<EOF
children json
EOF
_drain_output_sorted
# Now, let's add a JSON data source.
mkdir ${tmp}/s1
cp $SRC1_METADATA ${tmp}/s1/metadata.json
cp $SRC1_DATA1 ${tmp}/s1/data.json
# On this fetch, the 'nsources' static metric should be increased and
# the new data source should be present.
cat >&3 <<EOF
fetch json.nsources
EOF
cat >&3 <<EOF
children json
children json.s1
EOF
_drain_output_sorted
cat >&3 <<EOF
desc json.s1.counter
desc json.s1.discrete
fetch json.s1.string
fetch json.s1.value
fetch json.s1.counter
fetch json.s1.discrete
EOF
_drain_output
# Now update the JSON data for the source.
cp $SRC1_DATA2 ${tmp}/s1/data.json
# On this fetch, the data source variables should have their new values.
cat >&3 <<EOF
fetch json.nsources
fetch json.s1.string
fetch json.s1.value
fetch json.s1.counter
fetch json.s1.discrete
EOF
_drain_output
# Add the 2nd JSON data source.
mkdir ${tmp}/s2
cp $SRC2_METADATA ${tmp}/s2/metadata.json
cp $SRC2_DATA1 ${tmp}/s2/data.json
# On this fetch, the 'nsources' static metric should be increased and
# the new data source should be present.
cat >&3 <<EOF
fetch json.nsources
EOF
_drain_output
cat >&3 <<EOF
children json
children json.s1
children json.s2
EOF
_drain_output_sorted
cat >&3 <<EOF
instance $domain.0
desc json.s2.array_data.counter
fetch json.s2.array_data.count
fetch json.s2.array_data.value
fetch json.s2.array_data.counter
EOF
_drain_output
# Let's test proper indom support with the 2nd source. First, find out
# what the current indom state looks like.
cat ${pmda_config_dir}/${domain}.4 | _filter2
cat >&3 <<EOF
instance $domain.4
EOF
_drain_output
# Copy a new data file in and see how the instance values change. The
# instance command just returns "active" instances, not all instances.
cp $SRC2_DATA2 ${tmp}/s2/data.json
cat >&3 <<EOF
fetch json.s2.array_data.count
fetch json.s2.array_data.value
fetch json.s2.array_data.counter
instance $domain.4
EOF
_drain_output
# We should see all instances by looking at the indom cache file.
cat ${pmda_config_dir}/${domain}.4 | _filter2
# Let's try another indom test. This data file reuses an inactive
# instance and adds a new one.
cp $SRC2_DATA3 ${tmp}/s2/data.json
cat >&3 <<EOF
fetch json.s2.array_data.count
fetch json.s2.array_data.value
fetch json.s2.array_data.counter
instance $domain.4
EOF
_drain_output
# We should see all instances by looking at the indom cache file.
cat ${pmda_config_dir}/${domain}.4 | _filter2
# Let's try another indom test. This data file just reuses an
# instance.
cp $SRC2_DATA4 ${tmp}/s2/data.json
cat >&3 <<EOF
fetch json.s2.array_data.count
fetch json.s2.array_data.value
fetch json.s2.array_data.counter
instance $domain.4
EOF
_drain_output
# We should see all instances by looking at the indom cache file.
cat ${pmda_config_dir}/${domain}.4 | _filter2
# Let's test the ceph support by running the 'generate_ceph_metadata'
# script on some canned data.
mkdir -p ${tmp}/ceph
cp ${json_qa_dir}/ceph_data1.json ${tmp}/ceph/data.json
# Use the generate_ceph_metadata script to convert the ceph schema
# into metadata.
$python ${ceph_script} -o ${tmp}/ceph/metadata.json -t ${json_qa_dir}/ceph_schema1.json
# On this fetch, the 'nsources' static metric should be increased and
# the new data source should be present. Notice we aren't grabbing all
# the metrics from the ceph source, just a couple.
cat >&3 <<EOF
fetch json.nsources
EOF
_drain_output
cat >&3 <<EOF
children json
children json.s1
children json.s2
children json.ceph
EOF
_drain_output_sorted
cat >&3 <<EOF
instance $domain.0
fetch json.ceph.filestore.journal_wr_bytes.sum
fetch json.ceph.osd.stat_bytes
EOF
_drain_output
# Other things to test:
# - 'prefix' directive
# - 'data-exec' directive
# Tell dbpmda to quit.
cat >&3 <<EOF
quit
EOF
_drain_output
# Wait for dbpmda to quit.
wait
cat json.log >>$here/$seq.full
status=0
exit
|