Yevhenii Shapovalov dbe331
#!/bin/bash
Yevhenii Shapovalov dbe331
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
Yevhenii Shapovalov dbe331
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Yevhenii Shapovalov dbe331
#
Yevhenii Shapovalov dbe331
#   runtest.sh of /CoreOS/bind/Sanity/Master-server-not-chrooted
Yevhenii Shapovalov dbe331
#   Description: Set up master nameserver, test it.
Yevhenii Shapovalov dbe331
#   Author: Martin Cermak <mcermak@redhat.com>
Yevhenii Shapovalov dbe331
#
Yevhenii Shapovalov dbe331
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Yevhenii Shapovalov dbe331
#
Yevhenii Shapovalov dbe331
#   Copyright (c) 2009 Red Hat, Inc. All rights reserved.
Yevhenii Shapovalov dbe331
#
Yevhenii Shapovalov dbe331
#   This copyrighted material is made available to anyone wishing
Yevhenii Shapovalov dbe331
#   to use, modify, copy, or redistribute it subject to the terms
Yevhenii Shapovalov dbe331
#   and conditions of the GNU General Public License version 2.
Yevhenii Shapovalov dbe331
#
Yevhenii Shapovalov dbe331
#   This program is distributed in the hope that it will be
Yevhenii Shapovalov dbe331
#   useful, but WITHOUT ANY WARRANTY; without even the implied
Yevhenii Shapovalov dbe331
#   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
Yevhenii Shapovalov dbe331
#   PURPOSE. See the GNU General Public License for more details.
Yevhenii Shapovalov dbe331
#
Yevhenii Shapovalov dbe331
#   You should have received a copy of the GNU General Public
Yevhenii Shapovalov dbe331
#   License along with this program; if not, write to the Free
Yevhenii Shapovalov dbe331
#   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Yevhenii Shapovalov dbe331
#   Boston, MA 02110-1301, USA.
Yevhenii Shapovalov dbe331
#
Yevhenii Shapovalov dbe331
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Yevhenii Shapovalov dbe331
Yevhenii Shapovalov dbe331
# Include rhts environment
Yevhenii Shapovalov dbe331
#set -x
Yevhenii Shapovalov dbe331
. /usr/bin/rhts-environment.sh
Yevhenii Shapovalov dbe331
. /usr/lib/beakerlib/beakerlib.sh
Yevhenii Shapovalov dbe331
Yevhenii Shapovalov dbe331
# Some heplful functions
Yevhenii Shapovalov dbe331
randomString () {
Yevhenii Shapovalov dbe331
    TEMPSTR=`date +%c%N | md5sum | awk '{print $1}'`
Yevhenii Shapovalov dbe331
    echo ${TEMPSTR:0:8}
Yevhenii Shapovalov dbe331
    unset TEMPSTR
Yevhenii Shapovalov dbe331
}
Yevhenii Shapovalov dbe331
Yevhenii Shapovalov dbe331
randomIp () {
Yevhenii Shapovalov dbe331
    echo "192.168.1.`echo $[ $RANDOM / 256 + 1 ]`"
Yevhenii Shapovalov dbe331
}
Yevhenii Shapovalov dbe331
Yevhenii Shapovalov dbe331
randomSerial () {
Yevhenii Shapovalov dbe331
    date +%N
Yevhenii Shapovalov dbe331
}
Yevhenii Shapovalov dbe331
Yevhenii Shapovalov dbe331
# Variable declarations
Yevhenii Shapovalov dbe331
CONF="/etc/named.conf"
Yevhenii Shapovalov dbe331
IP1=`randomIp`
Yevhenii Shapovalov dbe331
IP2=`randomIp`
Yevhenii Shapovalov dbe331
IP3=`randomIp`
Yevhenii Shapovalov dbe331
IP4=`randomIp`
Yevhenii Shapovalov dbe331
IP5=`randomIp`
Yevhenii Shapovalov dbe331
SERIAL=`randomSerial`
Yevhenii Shapovalov dbe331
ORIGPWD=`pwd`
Yevhenii Shapovalov dbe331
Yevhenii Shapovalov dbe331
# The test
Yevhenii Shapovalov dbe331
rlJournalStart
Yevhenii Shapovalov dbe331
    rlPhaseStartSetup
Yevhenii Shapovalov dbe331
        rlRun "TmpDir=\`mktemp -d\`" 0 "Creating tmp directory"
Yevhenii Shapovalov dbe331
        rlRun "pushd $TmpDir"
Yevhenii Shapovalov dbe331
Yevhenii Shapovalov dbe331
        rlRun "rlImport bind/bind-setup"
Yevhenii Shapovalov dbe331
Yevhenii Shapovalov dbe331
        bsBindSetupStart "$ORIGPWD/named.conf" "off"
Yevhenii Shapovalov dbe331
Yevhenii Shapovalov dbe331
        rlRun "TDOMAIN=`randomString`.cz"
Yevhenii Shapovalov dbe331
        rlRun "TZONEFILE=$ROOTDIR/var/named/$TDOMAIN.zone"
Yevhenii Shapovalov dbe331
Yevhenii Shapovalov dbe331
        # set up /etc/named.conf
Yevhenii Shapovalov dbe331
        rlRun "sed -i \"s/<DOMAIN>/$TDOMAIN/g\" $CONF"
Yevhenii Shapovalov dbe331
Yevhenii Shapovalov dbe331
        # set up zonefile
Yevhenii Shapovalov dbe331
        rlRun "cp $ORIGPWD/zonefile $TZONEFILE"
Yevhenii Shapovalov dbe331
        rlRun "chmod a+r $TZONEFILE"
Yevhenii Shapovalov dbe331
        rlRun "sed -i \"s/<DOMAIN>/$TDOMAIN/g\" $TZONEFILE"
Yevhenii Shapovalov dbe331
        rlRun "sed -i \"s/<IP1>/$IP1/g\" $TZONEFILE"
Yevhenii Shapovalov dbe331
        rlRun "sed -i \"s/<IP2>/$IP2/g\" $TZONEFILE"
Yevhenii Shapovalov dbe331
        rlRun "sed -i \"s/<IP3>/$IP3/g\" $TZONEFILE"
Yevhenii Shapovalov dbe331
        rlRun "sed -i \"s/<IP4>/$IP4/g\" $TZONEFILE"
Yevhenii Shapovalov dbe331
        rlRun "sed -i \"s/<IP5>/$IP5/g\" $TZONEFILE"
Yevhenii Shapovalov dbe331
        rlRun "sed -i \"s/<SERIAL>/$SERIAL/g\" $TZONEFILE"
Yevhenii Shapovalov dbe331
Yevhenii Shapovalov dbe331
        bsBindSetupDone
Yevhenii Shapovalov dbe331
    rlPhaseEnd
Yevhenii Shapovalov dbe331
Yevhenii Shapovalov dbe331
    rlPhaseStartTest
Yevhenii Shapovalov dbe331
        # perform tests
Yevhenii Shapovalov dbe331
        rlRun "dig @localhost $TDOMAIN | grep \"^$TDOMAIN\" | head -n 1 | grep \"$IP1\""
Yevhenii Shapovalov dbe331
        rlRun "dig @localhost server1.$TDOMAIN | grep \"^server1.$TDOMAIN\" | grep \"$IP2\""
Yevhenii Shapovalov dbe331
        rlRun "dig @localhost server2.$TDOMAIN | grep \"^server2.$TDOMAIN\" | grep \"$IP3\""
Yevhenii Shapovalov dbe331
        rlRun "dig @localhost dns1.$TDOMAIN | grep \"^dns1.$TDOMAIN\" | grep \"$IP4\""
Yevhenii Shapovalov dbe331
        rlRun "dig @localhost dns2.$TDOMAIN | grep \"^dns2.$TDOMAIN\" | grep \"$IP5\""
Yevhenii Shapovalov dbe331
        rlRun "dig @localhost ftp.$TDOMAIN | grep \"^ftp.$TDOMAIN\" | grep \"server1.$TDOMAIN\""
Yevhenii Shapovalov dbe331
        rlRun "dig @localhost mail.$TDOMAIN | grep \"^mail.$TDOMAIN\" | grep \"server1.$TDOMAIN\""
Yevhenii Shapovalov dbe331
        rlRun "dig @localhost mail2.$TDOMAIN | grep \"^mail2.$TDOMAIN\" | grep \"server2.$TDOMAIN\""
Yevhenii Shapovalov dbe331
        rlRun "dig @localhost www.$TDOMAIN | grep \"^www.$TDOMAIN\" | grep \"server2.$TDOMAIN\""
Yevhenii Shapovalov dbe331
Yevhenii Shapovalov dbe331
    rlPhaseEnd
Yevhenii Shapovalov dbe331
Yevhenii Shapovalov dbe331
    rlPhaseStartCleanup
Yevhenii Shapovalov dbe331
        bsBindSetupCleanup
Yevhenii Shapovalov dbe331
        rlRun "popd"
Yevhenii Shapovalov dbe331
        rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
Yevhenii Shapovalov dbe331
        rlRun "rm -rf $TZONEFILE"
Yevhenii Shapovalov dbe331
    rlPhaseEnd
Yevhenii Shapovalov dbe331
rlJournalEnd