ppp/Sanity/logrotate-script-functionality/runtest.sh
2023-03-22 12:20:10 +01:00

69 lines
2.5 KiB
Bash
Executable file

#!/bin/bash
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/ppp/Sanity/logrotate-script-functionality
# Description: rotates /var/log/ppp/connect-errors using /etc/logrotate.d/ppp
# Author: Jiri Jaburek <jjaburek@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2014 Red Hat, Inc.
#
# 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 Beaker environment
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="ppp"
ROTATE_CONF="/etc/logrotate.d/ppp"
rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE
rlFileBackup --clean /var/log/ppp
rlServiceStart crond
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "pushd $TmpDir"
rlPhaseEnd
rlPhaseStartTest
testfile="/var/log/ppp/connect-errors"
# missingok test
rlRun "rm -f \"$testfile\"*" # wildcard intentional - remove rotates
rlRun "logrotate -f \"$ROTATE_CONF\"" 0
rlRun "ls \"$testfile\"* &>/dev/null" 2 "$testfile (or rotated variant) doesn't exist"
# correct rotate
rlRun "echo CONTENT > \"$testfile\""
rlRun "logrotate -f \"$ROTATE_CONF\""
[ -e "$testfile" ] && rlAssertNotGrep "CONTENT" "$testfile" # must be rotated
rlRun "ls \"$testfile\"[.-]* | xargs cat | zgrep CONTENT"
#
# TODO: test for pppd reload after rotate
# (jj: no known simple way to emulate a modem device,
# perhaps pptpd could be used as sub-daemon)
#
rlPhaseEnd
rlPhaseStartCleanup
rlFileRestore
rlServiceRestore crond
rlPhaseEnd
rlJournalPrintText
rlJournalEnd