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
|
#!/bin/sh
# PCP QA Test No. 1041
# Exercise the libvirt PMDA - install, remove and values.
#
# Copyright (c) 2016 Red Hat.
#
# Expectations:
# 1) libvirtd installed and running
# - typically from libvirt package
# 2) libvirt Python API available
# - typically from libvirt-python
# 3) optionally one or more VMs up
# 4) libvirt.hv.* metrics always expected
# 5) with VMs available at least:
# - libvirt.dominfo.uuid
# - libvirt.dominfo.name
# - libvirt.dominfo.memory.{boot,current}
# - libvirt.dominfo.vcpu.*
# - libvirt.dominfo.type
# - libvirt.dominfo.os.type
# - libvirt.domstats.mem.*
#
seq=`basename $0`
echo "QA output created by $seq"
. ./common.python
[ -d $PCP_PMDAS_DIR/libvirt ] || _notrun "libvirt PMDA directory is not installed"
$python -c "from pcp import pmda" >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "python pcp pmda module not installed"
$python -c "import libvirt" >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "python libvirt module not installed"
$python -c "import lxml" >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "python lxml module not installed"
# start libvirtd
#
if ! _service libvirtd start >$seq_full 2>&1; then _exit 1; fi
[ -e /var/run/libvirt/libvirt-sock-ro ] || _notrun "no socket, libvirtd not running?"
status=1 # failure is the default!
pmdalibvirt_remove()
{
echo
echo "=== remove libvirt agent ==="
$sudo ./Remove >$tmp.out 2>&1
_filter_pmda_remove <$tmp.out
}
pmdalibvirt_install()
{
# start from known starting points
cd $PCP_PMDAS_DIR/libvirt
$sudo ./Remove >/dev/null 2>&1
cat <<EOF >$tmp.config
[pmda]
user = root
uri = qemu:///system
EOF
echo "pmdalibvirt config:" >> $seq_full
cat $tmp.config >> $seq_full
[ -f $PCP_PMDAS_DIR/libvirt/libvirt.conf ] && \
$sudo cp $PCP_PMDAS_DIR/libvirt/libvirt.conf $tmp.backup
$sudo cp $tmp.config $PCP_PMDAS_DIR/libvirt/libvirt.conf
echo
echo "=== libvirt agent installation ==="
PCPQA_CHECK_DELAY=10; export PCPQA_CHECK_DELAY
$sudo ./Install </dev/null >$tmp.out 2>&1
cat $tmp.out >>$seq_full
# Check metrics have appeared ... X metrics and Y values
# skip lines like ...
# [Fri Mar 29 21:09:33] pmdalibvirt(21564) Error: pmdaCacheOp: $PCP_VAR_DIR/config/pmda/140.0: empty file?
_filter_pmda_install <$tmp.out \
| sed \
-e '/^Waiting for pmcd/s/\.\.\.[. ]*$/DOTS/' \
-e "\\;Error: pmdaCacheOp: \$PCP_VAR_DIR/config/pmda/.*: empty file?;d" \
| tee $tmp.tmp \
| $PCP_AWK_PROG '
/warnings,/ { print; next }
/Check libvirt metrics have appeared/ { if ($7 >= 120) $7 = "X"
if ($10 >= 4) $10 = "Y"
}
{ print }'
# the PMDA install sometimes reports all the metrics as warnings
# and/or no values ... dig a bit deeper when this happens
#
if grep -E 'warnings,|and 0 values' $tmp.tmp >/dev/null
then
echo "Arrgh: Install failed, see $seq_full"
pminfo -f pmcd.agent.status >>$seq_full
pminfo -f libvirt >>$seq_full
echo "--- pmcd.log ---" >>$seq_full
cat $PCP_LOG_DIR/pmcd/pmcd.log >>$seq_full
echo "--- libvirt.log ---" >>$seq_full
cat $PCP_LOG_DIR/pmcd/libvirt.log >>$seq_full
fi
}
pmdalibvirt_cleanup()
{
if [ -f $tmp.backup ]; then
$sudo cp $tmp.backup $PCP_PMDAS_DIR/libvirt/libvirt.conf
$sudo rm $tmp.backup
else
$sudo rm -f $PCP_PMDAS_DIR/libvirt/libvirt.conf
fi
# note: _restore_auto_restart pmcd done in _cleanup_pmda()
_cleanup_pmda libvirt
[ -n "$timeout" ] && pmstore pmcd.control.timeout $timeout >>$seq_full 2>&1
}
_prepare_pmda libvirt
trap "pmdalibvirt_cleanup; exit \$status" 0 1 2 3 15
_stop_auto_restart pmcd
_filter()
{
sed \
-e '/No value(s) available/d' \
#end
}
# increase pmcd-PMDA timeout because this one is sometimes slow to
# get going
#
timeout=`pmprobe -v pmcd.control.timeout | $PCP_AWK_PROG '{ print $3 }'`
pmstore pmcd.control.timeout 20 >>$seq_full 2>&1
# real QA test starts here
pmdalibvirt_install
echo
echo "=== verify metric values ==="
echo "from pminfo:" >>$seq_full
pminfo -v libvirt 2>&1 \
| tee -a $seq_full \
| _filter
pmdalibvirt_remove 2>&1 \
| sed \
-e '/pmdalibvirt([0-9]*) Error: pmdaCacheOp: .* empty file?/d' \
# end
status=0
exit
|