sendmail/Sanity/init-script-LSB/runtest.sh
František Hrdina 66b86fa382 Fix tests
2025-02-25 14:31:24 +01:00

131 lines
5.2 KiB
Bash
Executable file

#!/bin/bash
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/sendmail/Sanity/init-script-LSB
# Description: Test initscript sanity
# Author: Martin Cermak <mcermak@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2010 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="sendmail"
SERVICE=$PACKAGE
TESTER="testuserqa"
rlRunSleep() {
rlRun "$1" "$2" "$3"
sleep ${4:-5}
}
rlJournalStart
########## SETUP PHASE ##########
rlPhaseStartSetup
useradd $TESTER
rlAssertRpm $PACKAGE
rlRun "rpm -q --whatprovides MTA"
for i in $(rpm -q --whatprovides MTA --queryformat="%{name} "); do
rlServiceStop $i
done
rlRun "alternatives --set mta $(rpm --eval '%{_sbindir}')/sendmail.sendmail"
rlPhaseEnd
#################### TEST PHASE ####################
rlPhaseStartTest ">>>>>>>>> service start"
rlRunSleep "rlServiceStart $SERVICE" 0 "Service must start without problem"
rlRun "systemctl status --no-pager $SERVICE " 0
rlRunSleep "systemctl start $SERVICE" 0 "Already started service"
rlRun "systemctl status --no-pager $SERVICE" 0
rlPhaseEnd
#################### TEST PHASE ####################
rlPhaseStartTest ">>>>>>>>> service restart"
rlRunSleep "rlServiceStart $SERVICE" 0 "Restarting of service"
rlRun "systemctl status --no-pager $SERVICE " 0
rlPhaseEnd
#################### TEST PHASE ####################
rlPhaseStartTest ">>>>>>>>> service stop"
rlRunSleep "rlServiceStop $SERVICE" 0 "Stopping service"
rlRun "systemctl status --no-pager $SERVICE" 3
rlRunSleep "rlServiceStop $SERVICE" 0 "Stopping service again"
rlRun "systemctl status --no-pager $SERVICE" 3
rlPhaseEnd
#################### TEST PHASE ####################
rlPhaseStartTest ">>>>>>>>> pid file"
rlServiceStop $SERVICE
rm -fv /var/run/$SERVICE.pid
rlServiceStart $SERVICE
sleep 5
rlAssertExists "/var/run/$SERVICE.pid" "Pid file /var/run/$SERVICE.pid must exist"
rlServiceStop $SERVICE
sleep 5
rlRun "echo 666666 > /var/run/$SERVICE.pid"
rlRun "systemctl status --no-pager $SERVICE" 1,3 " Existing pid file, but service not started"
rlServiceStop $SERVICE
sleep 5
rlRun "rm -fv /var/run/$SERVICE.pid"
rlPhaseEnd
# don't use lockfile, change in autentication / may return 1
#################### TEST PHASE ####################
rlPhaseStartTest ">>>>>>>>> insufficient rights"
rlRunSleep "rlServiceStart $SERVICE" 0 " Starting service for restarting under nonpriv user"
rlRun "su $TESTER -c 'systemctl restart $SERVICE'" 4,1 "Insufficient rights, restarting resrvice under nonprivileged user must fail"
rlPhaseEnd
#################### TEST PHASE ####################
rlPhaseStartTest ">>>>>>>>> operations"
rlServiceStop $SERVICE
rlRunSleep "systemctl start $SERVICE " 0 "Service have to implement start function"
rlRunSleep "systemctl restart $SERVICE " 0 "Service have to implement restart function"
rlRunSleep "systemctl status --no-pager $SERVICE " 0 "Service have to implement status function"
rlRunSleep "systemctl condrestart $SERVICE " 0,3 "Service have to implement condrestart function"
rlRunSleep "systemctl try-restart $SERVICE " 0,3 "Service have to implement try-restart function"
rlRunSleep "systemctl reload $SERVICE " 0,3 "Service have to implement reload function"
rlRunSleep "systemctl force-reload $SERVICE " 0,3 "Service have to implement force-reload function"
rlPhaseEnd
#################### TEST PHASE ####################
rlPhaseStartTest ">>>>>>>>> invalid arguments"
rlRunSleep "systemctl $SERVICE" 1 " When no arguments added to service, it must fail with proper return code"
rlPhaseEnd
########## CLEANUP PHASE ##########
rlPhaseStartCleanup
rlRun "userdel -fr $TESTER"
rlRun "rlServiceStop $SERVICE"
rlRun "alternatives --auto mta"
for i in $(rpm -q --whatprovides MTA --queryformat="%{name} "); do
rlServiceRestore $i
sleep 5
done
rlPhaseEnd
rlJournalPrintText
rlJournalEnd