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
|
#!/bin/sh
# PCP QA Test No. 1243
# Exercise shell mechanism in pmDiscoverServices(3).
#
# Copyright (c) 2018 Red Hat.
#
seq=`basename $0`
echo "QA output created by $seq"
# get standard environment, filters and checks
. ./common.discovery
_check_valgrind
_check_helgrind
_get_libpcp_config
$service_discovery || _notrun "No support for service discovery"
case `admin/whatami`
in
*Fedora\ 32\ *)
_notrun "helgrind broken for this test on Fedora 32"
;;
*openSUSE\ Leap\ 15.5\ *)
_notrun "helgrind broken for this test on openSUSE Leap 15.?"
;;
esac
if sed -e 's/$/ /' /etc/hosts | grep '::1[ ].*localhost ' >/dev/null
then
:
else
# need something like this in /etc/hosts
# ::1 localhost.localdomain localhost localhost6.localdomain6 localhost6
#
echo "Warning: no IPv6 localhost (not localhost6) entry in /etc/hosts, so only"
echo "IPv4 localhost will be discovered below"
fi
_cleanup()
{
cd $here
$sudo rm -rf $tmp $tmp.*
}
status=1 # failure is the default!
hostname=`hostname`
hostip=`_host_to_ipaddr $hostname`
localip=`_host_to_ipaddr localhost`
trap "_cleanup; exit \$status" 0 1 2 3 15
_filter()
{
tee -a $seq_full \
| sed \
-e "s,$tmp.discover,DISCOVER_DIR,g" \
-e "s,\[::1\],IP_ADDRESS,g" \
-e "s,$localip,IP_ADDRESS,g" \
-e "s,$hostip,IP_ADDRESS,g" \
#end
}
# expect at least 2 pmcd servers on <realip_addr> and 127.0.0.1
# but there may be others ...
# === std out ===
# Discovered pmcd servers:
# pcp://IP_ADDRESS:44321
# pcp://IP_ADDRESS:44321
# pcp://IP_ADDRESS:44321
# === std err ===
#
_fix_pmcds_found()
{
$PCP_AWK_PROG '
/^Discovered pmcd servers:/ { print; n = 0; inblock = 1; next }
inblock == 1 && /pcp:/ { n++; next }
inblock == 1 && $1 == "===" { if (n >= 2)
print " >= 2 pcp://IP_ADDRESS:44321 lines"
else
print " " n " pcp://IP_ADDRESS:44321 lines"
inblock = 0
}
{ print }'
}
# real QA test starts here
mkdir -p $tmp.discover
# test script with local addresses
cat >$tmp.discover/localhost.sh <<EOF
#!/bin/sh
echo localhost
echo 127.0.0.1
EOF
chmod 755 $tmp.discover/localhost.sh
# test script with a mix of hostnames
cat >$tmp.discover/hostnames.sh <<EOF
#!/bin/sh
echo $hostname
echo no.such.host
EOF
chmod 755 $tmp.discover/hostnames.sh
# drop-in kubectl so we can see args
cat >$tmp.kubectl.sh <<EOF
#!/bin/sh
echo "\$@" > $tmp.kubectl.args
EOF
chmod 755 $tmp.kubectl.sh
PCP_KUBECTL_PROG=$tmp.kubectl.sh; export PCP_KUBECTL_PROG
echo "== discovery directory" >> $seq_full
find $tmp.discover >> $seq_full
echo "== localhost.sh" >> $seq_full
$tmp.discover/localhost.sh >> $seq_full
echo "== hostnames.sh" >> $seq_full
$tmp.discover/hostnames.sh >> $seq_full
echo "== checking pcp-kube-pods argument handling" | tee -a $seq_full
$PCP_BINADM_DIR/discover/pcp-kube-pods
cat $tmp.kubectl.args | tee -a $seq_full
# handy pmfind debugging option: -Ddiscovery
echo "== checking pmfind results and memory access" | tee -a $seq_full
_run_valgrind pmfind -m shell,path=$tmp.discover,maxThreads=1 -s pmcd \
| _filter \
| _fix_pmcds_found
echo "== checking pmfind results and thread locks" | tee -a $seq_full
_run_helgrind pmfind -m shell,path=$tmp.discover,maxThreads=4 -s pmcd \
| _filter
# success, all done
status=0
exit
|