#!/bin/sh
# PCP QA Test No. 727
# Check that pmwebd advertises its presence using avahi
#
# Copyright (c) 2014-2016 Red Hat.
#

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

. ./common.avahi
. ./common.webapi

avahi_notrun_checks
[ -x $PCP_RC_DIR/pmwebd ] || _notrun "PCP web services not installed"
PCP_PMWEBDOPTIONS_PATH=$PCP_SYSCONF_DIR/pmwebd/pmwebd.options

_cleanup()
{
    # ensure we do not leave local-only settings enabled
    _restore_config $PCP_PMWEBDOPTIONS_PATH
    avahi_cleanup
}

status=1	# failure is the default!
$sudo rm -rf $tmp.* $seq.full
trap "_cleanup; exit \$status" 0 1 2 3 15

# real QA test starts here
service=pmwebd
_save_config $PCP_PMWEBDOPTIONS_PATH

avahi_service
_wait_for_pmwebd_logfile $PCP_LOG_DIR/pmwebd/pmwebd.log 44323
avahi_verify

# check -S (service discovery disabling) option works
cp $PCP_PMWEBDOPTIONS_PATH $tmp.conf
echo 'OPTIONS="$OPTIONS -S"' >> $tmp.conf
$sudo mv $tmp.conf $PCP_PMWEBDOPTIONS_PATH

avahi_service
_wait_for_pmwebd_logfile $PCP_LOG_DIR/pmwebd/pmwebd.log 44323
avahi_verify "Verify $service avahi discovery disabling option"

status=0
exit
