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
|
#!/bin/sh
# PCP QA Test No. 1491
# Basic pmcheck exercising
#
# Copyright (c) 2024 Ken McDonell. All Rights Reserved.
#
if [ $# -eq 0 ]
then
seq=`basename $0`
echo "QA output created by $seq"
else
# use $seq from caller, unless not set
[ -n "$seq" ] || seq=`basename $0`
echo "QA output created by `basename $0` $*"
fi
# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check
_cleanup()
{
cd $here
$sudo rm -rf $tmp $tmp.*
# make sure pmcd is really running ...
#
if [ ! -f $PCP_RUN_DIR/pmcd.pid ]
then
$sudo _service pmcd restart >>$seq_full
_wait_for_pmcd
fi
# and primary pmlogger is back in the land of the living
#
_wait_for_pmlogger
}
status=0 # success is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15
_filter()
{
sed \
-e "s@$tmp@TMP@g" \
-e "s@`basename $tmp`@TMP@g" \
# end
}
_filter_states()
{
sed \
-e 's/ *$//' \
-e 's/ active$/ OK/' \
-e '/^pmproxy /{
s/inactive/OK/
s/could be activated/OK/
}' \
-e '/^pmie /{
s/inactive/OK/
s/could be activated/OK/
}' \
-e '/^pmda-overhead /{
s/inactive/OK/
s/could be activated/OK/
s/cannot be activated/OK/
s/measure overhead of PCP components/.../
s/not currently available for .*/.../
}' \
-e '/^pmda-postgresql /{
s/PostgreSQL/postgresql/g
s/inactive/OK/
s/could be activated/OK/
s/cannot be activated/OK/
s/ No systemd unit file installed//
s/ systemd.s postgresql.service unit is not installed//
s@ /etc/init.d/postgresql is not installed@@
s/not currently available .*/metrics from postgresql/
}' \
-e '/^pmda-redis /{
s/Redis/redis/g
s/inactive/OK/
s/could be activated/OK/
s/cannot be activated/OK/
s/ systemd.s redis.service unit is not installed//
s/ systemd.s redis.service unit has failed//
s/ systemd.s redis-server.service unit is not installed//
s/ systemd.s redis-server.service unit has failed//
s@ /etc/init.d/redis-server is not installed@@
s/not currently available .*/metrics from redis-server(1)/
}' \
-e '/^pmda-uwsgi /{
s/uWSGI/uwsgi/g
s/inactive/OK/
s/could be activated/OK/
s/cannot be activated/OK/
s/not currently available .*/metrics from uwsgi servers/
}' \
-e '/^zeroconf /{
s/inactive/OK/
s/could be activated/OK/
s/cannot be activated/OK/
s/Package$/& .../
s/Package - not currently available for .*/Package .../
}' \
#end
}
# real QA test starts here
echo "basic stuff ..."
# expect most things to be active, but some are optional ...
#
# some services need to run as root, even for "status"
# requests, e.g. redis-server without systemd
#
echo '-- no args --'
$sudo $PCP_BINADM_DIR/pmcheck 2>&1 | _filter_states
echo '-- -l --'
$PCP_BINADM_DIR/pmcheck -l
echo '-- -lv --'
$PCP_BINADM_DIR/pmcheck -lv | _filter_states
echo '-- -s --'
$sudo $PCP_BINADM_DIR/pmcheck -s 2>&1 | _filter_states
touch $tmp.pmcheck
echo
echo "=== usage ==="
echo '-- --help --'
$PCP_BINADM_DIR/pmcheck --help
echo '-- -l + -c --'
$PCP_BINADM_DIR/pmcheck -l -c /bin/echo
echo '-- -l + component arg --'
$PCP_BINADM_DIR/pmcheck -l pmcd
echo '-- -c does not exist --'
$PCP_BINADM_DIR/pmcheck -c /no.such.file -s
echo '-- -c not executable --'
$PCP_BINADM_DIR/pmcheck -c $tmp.pmcheck -s 2>&1 | _filter
echo '-- -c + component arg --'
$PCP_BINADM_DIR/pmcheck -c /bin/echo -s pmcd
echo '-- component arg + no action opt --'
$PCP_BINADM_DIR/pmcheck pmcd
echo '-- -n without -a or -d --'
$PCP_BINADM_DIR/pmcheck -n -s pmcd
echo '-- -c + no action opt --'
$PCP_BINADM_DIR/pmcheck -c /bin/echo
echo '-- multiple actions --'
$PCP_BINADM_DIR/pmcheck -a -d pmcd
$PCP_BINADM_DIR/pmcheck -l -s
echo '-- bad option --'
$PCP_BINADM_DIR/pmcheck -f -o -o
$PCP_BINADM_DIR/pmcheck -foo
echo
echo "=== parsing and arg hand-off to component script ==="
cat <<'End-of-File' >$tmp.pmcheck
#!/bin/sh
echo "component called, $# args: $*"
exit 0
End-of-File
chmod 755 $tmp.pmcheck
echo '-- -c ... -s --'
$PCP_BINADM_DIR/pmcheck -c $tmp.pmcheck -s 2>&1 | _filter
# no action/state output for this one
echo '-- -c ... -nav --'
$PCP_BINADM_DIR/pmcheck -c $tmp.pmcheck -nav 2>&1 | _filter
cat <<'End-of-File' >$tmp.pmcheck
#!/bin/sh
. $PCP_DIR/etc/pcp.env || exit 1
. $PCP_SHARE_DIR/lib/checkproc.sh
_do_args "$@"
if $lflag
then
[ $verbose -gt 0 ] && echo I am here for QA 1491
elif $sflag
then
[ $verbose -gt 0 ] && echo some state explanation
status=$RC
elif $aflag
then
if $show_me
then
echo "# some-magic-activation-command $component"
else
: some-magic-activation-command
fi
[ $verbose -gt 0 ] && echo some activation explanation
status=$RC
elif $dflag
then
if $show_me
then
echo "# some-magic-deactivation-command $component"
else
: some-magic-deactivation-command
fi
[ $verbose -gt 0 ] && echo some deactivation explanation
status=$RC
fi
End-of-File
echo "-- -c ... -lv --"
$PCP_BINADM_DIR/pmcheck -c $tmp.pmcheck -lv 2>&1 | _filter
for rc in 0 1 2
do
echo "-- RC=$rc -c ... -s --"
RC=$rc $PCP_BINADM_DIR/pmcheck -c $tmp.pmcheck -s 2>&1 | _filter
done
for rc in 0 1
do
for opt in '-a' '-av' '-an' '-anv' '-d' '-dv' '-dn' '-dnv'
do
echo "-- RC=$rc -c ... $opt --"
RC=$rc $PCP_BINADM_DIR/pmcheck -c $tmp.pmcheck $opt 2>&1 | _filter
done
done
echo
echo "=== glob expansion ==="
echo '-- -s pm[cl]* --'
$PCP_BINADM_DIR/pmcheck -s 'pm[cl]*'
echo
echo "=== actions ==="
echo '-- -d --'
$sudo $PCP_BINADM_DIR/pmcheck -d pmcd
_wait_for_pmcd_stop || _exit 1
if [ -f $PCP_RUN_DIR/pmcd.pid ]
then
echo "$seq: Botch: $PCP_RUN_DIR/pmcd.pid => `cat $PCP_RUN_DIR/pmcd.pid`"
else
echo "$seq: pmcd stopped"
fi
$PCP_BINADM_DIR/pmcheck -s pmcd
echo '-- and -d again with -v --'
$sudo $PCP_BINADM_DIR/pmcheck -v -d pmcd 2>&1 \
| sed \
-e '/^ *already /d' \
-e 's/ stopped via .*/ STOPPED via .../' \
-e 's/ disabled via .*/ STOPPED via .../' \
# end
echo '-- -a --'
$sudo $PCP_BINADM_DIR/pmcheck -a pmcd
_wait_for_pmcd || _exit 1
if [ -f $PCP_RUN_DIR/pmcd.pid ]
then
echo "$seq: pmcd started"
else
echo "$seq: Botch: $PCP_RUN_DIR/pmcd.pid missing"
fi
$PCP_BINADM_DIR/pmcheck -s pmcd
echo '-- and -a again with -v --'
$PCP_BINADM_DIR/pmcheck -v -a pmcd 2>&1 \
| sed \
-e '/^ *already /d' \
-e 's/ enabled via .*/ STARTED via .../' \
-e 's/ started via .*/ STARTED via .../' \
# end
# success, all done
exit
|