#!/bin/sh

set -e

ulimit -H -l unlimited 2>/dev/null || {
    # https://bugs.launchpad.net/bugs/1828228
    echo "test disabled for unprivileged namespaces"
    exit 77
}

OUTPUT=$AUTOPKGTEST_TMP/walk.out

cleanup () {
  service pacemaker stop
  service corosync stop
  rm -f $OUTPUT
}

trap "cleanup" 0 2 3 15

service corosync start
service pacemaker start

# enable localhost access to full snmp data
sed -i '/^rocommunity\s\+public/ i\
rocommunity public localhost' /etc/snmp/snmpd.conf
service snmpd restart
service pcs_snmp_agent restart

sleep 60

pcs property set stonith-enabled=false
pcs property set no-quorum-policy=ignore
pcs resource create dummy1 ocf:heartbeat:Dummy
pcs resource create dummy2 ocf:heartbeat:Dummy

sleep 60

snmpwalk -m PACEMAKER-PCS-V1-MIB -v 2c -c public localhost 1.3.6.1.4.1.32723.100.1 | tee $OUTPUT

grep -q 'RunningResourcesNum.0 = INTEGER: 2$' $OUTPUT
