#! /bin/sh
#
# RETIRED 22 Nov 2017
#
# PCP QA Test No. 162
# namespace only Install/Remove for pmdas
#
# this is less important for PCP 2.0 than it was for PCP 1.x, but we
# need to make sure the functionality still works, e.g. upgrade a
# collector to PCP 2.0, but want to monitor from a PCP 1.x system
#
# Note: expect some "Cannot create" errors from the installation
#	of the pmchart view(s) ... we do not run Install/Remove as root
#	in this test
#
# See also 600.  This version is for the PMDAs in pcp_opensrc.
#
# Copyright (c) 1995-2002 Silicon Graphics, Inc.  All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard filters
. ./common.product
. ./common.filter
. ./common.check

perl -e "use PCP::PMDA" >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "perl PCP::PMDA module not installed"

trap "rm -rf $tmp; exit" 0 1 2 3 15

#
# Get rid of some new sample metrics which
# would make the test vary.
#
_filter()
{
    sed \
	-e '/sample\.dynamic\.meta/d' \
	-e '/sample\.datasize/d' \
	-e '/sample\.darkness/d' \

}


_filter_ins()
{
    sed \
	-e 's/.* \(hash table entries\)/  NNN \1/' \
	-e 's/.* \(non-leaf nodes\)/  NNN \1/' \
	-e 's/.* \(leaf nodes\)/  NNN \1/' \
	-e 's/.* \(bytes of symbol table\)/  NNN \1/' \
	-e 's/ *- Permission denied/\
Permission denied/'
}


# all of the ones we ship as part of the PCP product
#
PMDALIST='
cisco
mailq
news
sample
sendmail
simple
summary
trace
trivial
txmon'

# real QA test starts here
unset ROOT MAKEFLAGS
mkdir $tmp

cat >>$tmp/root.orig <<End-of-File
root {
}
End-of-File
cp $tmp/root.orig $tmp/root

for pmda in $PMDALIST
do
    instdir=$PCP_PMDAS_DIR/$pmda
    echo
    echo "=== Install -n for $pmda ==="
    if [ -f $instdir/Install ] 
    then
	cd $instdir
	# used to be -N here
	$sudo ./Install -e -n $tmp/root </dev/null 2>&1 | _filter_ins
	pminfo -n $tmp/root $pmda | _filter | LC_COLLATE=POSIX sort
    else
	echo "Error: $instdir/Install does not exist"
    fi
done

echo
echo 'Removals ... expect "Unknown metric name" errors at the end of each'
echo 'operation as the PMNS should have been culled'
for pmda in $PMDALIST
do
    instdir=$PCP_PMDAS_DIR/$pmda
    echo
    echo "=== Remove -n for $pmda ==="
    if [ -f $instdir/Remove ]
    then
	cd $instdir
	# used to be -N here
	$sudo ./Remove -n $tmp/root
	pminfo -n $tmp/root $pmda
    else
	echo "Error: $instdir/Install does not exist"
    fi

done

echo
echo "=== Check final state of root ==="
echo "(expect no diffs between the initial and final PMNS)"
diff -c $tmp/root.orig $tmp/root

exit 0
