#!/bin/bash
# vim: dict=/usr/share/rhts-library/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/frr/Sanity/initscript
# Description: Basic initscript test for frr
# Author: Daniel Rusek <drusek@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2019 Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing
# to use, modify, copy, or redistribute it subject to the terms
# and conditions of the GNU General Public License version 2.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include rhts environment
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="frr"
CONF_EXISTS=0
SAMPLE_EXISTS=0
rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE
rlRun "useradd testuserqa" 0 "Add test user"
rlRun "rlFileBackup --clean /etc/frr/" 0 "Backup of original config files"
rlPhaseEnd
rlPhaseStartSetup "Prepare"
rlServiceStop frr
rlRun "systemctl start frr" 0 "Starting frr without config"
rlRun "systemctl --no-pager status frr" 0
rlRun "systemctl stop frr" 0
for SERVICE in bgpd ospf6d ospfd ripd ripngd zebra; do
CONF="/etc/frr/$SERVICE.conf"
SAMPLE="/usr/share/doc/frr/$SERVICE.conf.sample"
if [ -e $CONF ]; then
rlRun "rm $CONF"
fi
if [ -e $SAMPLE ]; then
rlRun "cp $SAMPLE $CONF" 0
fi
rlRun "cp daemons /etc/frr/" 0
done
rlPhaseEnd
rlPhaseStartTest "Mandatory actions"
rlLog ">>>>>>>>> service start"
rlRun "systemctl start frr" 0 "Service must start without problem"
rlRun "systemctl --no-pager status frr" 0 "Then Status command"
rlRun "systemctl start frr" 0 "Already started service"
rlRun "systemctl --no-pager status frr" 0 "Again status command"
rlLog ">>>>>>>>> service restart"
rlRun "systemctl restart frr" 0 "Restarting of service"
rlRun "systemctl --no-pager status frr" 0 "Status command"
rlLog ">>>>>>>>> service stop"
rlRun "systemctl stop frr" 0 "Stopping service"
rlRun "systemctl --no-pager status frr" 3 "Status of stopped service"
rlRun "systemctl stop frr" 0 "Stopping service again"
rlRun "systemctl --no-pager status frr" 3 "Status of stopped service"
rlLog ">>>>>>>>> insufficient rights"
# Polkit rpm installed is causing that running with insufficient rights returns 1 instead of 4
if (rlIsRHEL '>=9' || rlIsFedora || rlIsCentOS '>=9') && ! rlCheckRpm 'polkit'; then
ACCESS_DENIED_EXIT_STATUS=4
else
ACCESS_DENIED_EXIT_STATUS=1
fi
rlRun "systemctl start frr " 0 " Starting service for restarting under nonpriv user "
rlRun "su testuserqa -c 'systemctl restart frr'" $ACCESS_DENIED_EXIT_STATUS "Insufficient rights, restarting service under nonprivileged user must fail"
rlRun "systemctl stop frr " 0
rlLog ">>>>>>>>> operations"
rlRun "systemctl condrestart frr" 0 " Service have to implement condrestart function "
rlRun "systemctl try-restart frr" 0 " Service have to implement condrestart function "
rlRun "systemctl force-reload frr" 0 " Service have to implement force-reload function "
rlPhaseEnd
rlPhaseStartCleanup
rlServiceRestore frr
rlRun "rlFileRestore" 0 "Restoring original config files"
rlRun "userdel -fr testuserqa" 0 "Remove test user"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd