I am currently using this regression script for basic ifstated sanity testing.

Still a work in progress. Requesting commit for safe keeping.

Regards,

Rob

Index: usr.sbin/ifstated/ifstated.sh
===================================================================
RCS file: usr.sbin/ifstated/ifstated.sh
diff -N usr.sbin/ifstated/ifstated.sh
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ usr.sbin/ifstated/ifstated.sh       2 Jul 2017 16:01:29 -0000
@@ -0,0 +1,156 @@
+# $OpenBSD$
+
+# basic ifstated regression test script
+
+# Modify variables as required
+NIC=em0
+VHID=254
+PREFIX=172.16.0
+PING=8.8.8.8
+DEMOTE=ifconfig
+PROMOTE=ifconfig
+EVERY=3
+SLEEP=6
+
+if [ "$(pgrep ifstated)" ]
+then
+       echo "The ifstated daemon is already running."
+       echo "Please stop ifstated before commencing regression testing."
+       exit 1
+fi
+
+if [ -n "$(grep ifstated_test_host /etc/hosts)" ]
+then
+       echo "ifstated_test_host is already present in /etc/hosts."
+       echo "Please remove before commencing regression testing."
+       exit 1
+fi
+
+if [ -n "$(grep 1.2.3.4 /etc/hosts)" ]
+then
+       echo "1.2.3.4 is already present in /etc/hosts."
+       echo "Please remove before commencing regression testing."
+       exit 1
+fi
+
+if [ -f /etc/hostname.carp${VHID} ]
+then
+       echo "/etc/hostname.carp${VHID} already exists."
+       echo "Please remove before commencing regression testing."
+       exit 1
+else
+       echo "inet ${PREFIX}.${VHID} 255.255.255.0 ${PREFIX}.255 vhid ${VHID} 
carpdev ${NIC}" > hostname.carp${VHID}
+       cp hostname.carp${VHID} /etc
+       chmod 0640 /etc/hostname.carp${VHID}
+fi
+
+mkdir -p working
+cd working
+
+cat > output.test <<EOF
+changing state to primary
+changing state to demoted
+changing state to primary
+changing state to demoted
+changing state to primary
+changing state to demoted
+changing state to primary
+changing state to primary
+changing state to demoted
+changing state to primary
+EOF
+
+cp -p /etc/hosts .
+
+cat >> /etc/hosts <<EOF
+# temporary entry for ifstated regression testing
+${PING} ifstated_test_host
+EOF
+
+cat > ifstated.conf <<EOF
+# This is a config template for ifstated regression testing
+carp = "carp${VHID}.link.up"
+init-state primary
+net = '( "ping -q -c 1 -w 1 ifstated_test_host > /dev/null" every ${EVERY})'
+state primary {
+       init {
+               run "ifconfig"
+       }
+       if ! \$net
+               set-state demoted
+       if ! \$carp
+               set-state demoted
+}
+state demoted {
+       init {
+               run "ifconfig"
+       }
+       if \$net && \$carp
+               set-state primary
+}
+EOF
+
+echo -n "Configuring temporary carp interface..."
+sh /etc/netstart carp${VHID}
+echo
+
+echo -n "Waiting for carp interface to initialize..."
+# give the carp interface time to come up as MASTER
+# assume a single instance (i.e. we are not testing a pair of carp firewalls)
+sleep 5
+echo
+
+echo -n "Starting ifstated with test configuration..."
+nohup ifstated -dvf ./ifstated.conf > ifstated.log &
+echo
+
+echo -n "Performing ifstated regression testing..."
+sleep ${SLEEP}
+ifconfig ${NIC} down
+sleep ${SLEEP}
+sh /etc/netstart ${NIC} >/dev/null 2>&1
+sleep ${SLEEP}
+ifconfig carp${VHID} down
+sleep ${SLEEP}
+sh /etc/netstart carp${VHID}
+sleep ${SLEEP}
+ifconfig ${NIC} down
+ifconfig carp${VHID} down
+sleep ${SLEEP}
+sh /etc/netstart ${NIC} >/dev/null 2>&1
+sleep ${SLEEP}
+sh /etc/netstart carp${VHID}
+sleep ${SLEEP}
+kill -HUP $(pgrep ifstated)
+sleep ${SLEEP}
+cat /etc/hosts | sed "s/.* ifstated_test_host/1.2.3.4 ifstated_test_host/" > 
/etc/hosts
+sleep ${SLEEP}
+cat /etc/hosts | sed "s/.* ifstated_test_host/${PING} ifstated_test_host/" > 
/etc/hosts
+sleep ${SLEEP}
+echo
+
+grep ^changing ifstated.log > output.new
+
+echo -n "Stopping ifstated..."
+kill $(pgrep ifstated)
+echo
+
+diff output.test output.new
+case $? in
+0)     echo Test Passed.
+       echo -n "Cleaning up..."
+       ifconfig carp${VHID} down
+       ifconfig carp${VHID} delete
+       ifconfig carp${VHID} destroy
+       rm /etc/hostname.carp${VHID}
+       cp ./hosts /etc
+       echo
+       echo Done.
+       exit 0
+       ;;
+1)     echo Test Failed.
+       echo Please examine the interfaces and review files in the working 
directory.
+       echo You will need to manually delete the carp interface and remove 
residual files.
+       exit 1
+       ;;
+esac

Reply via email to