mirror of
git://git.yoctoproject.org/poky.git
synced 2025-07-19 12:59:02 +02:00

During the test logrotate.LogrotateTest.test_1_logrotate_setup, there is below logic: # mkdir $HOME/logrotate_dir # sed -i "s#wtmp {#wtmp {\n olddir $HOME/logrotate_dir#" /etc/logrotate.d/wtmp After all logrotate.LogrotateTest finished, only cleanup $HOME/logrotate_dir as below, but don't restore the config file /etc/logrotate.d/wtmp. [snip] def tearDownClass(cls): cls.tc.target.run('rm -rf $HOME/logrotate_dir') [snip] That's to say, there is one additional line added to /etc/logrotate.d/wtmp and will make the logrotate service start failed when run systemd.SystemdBasicTests.test_systemd_failed Take an example as below when run test as root: # cat /etc/logrotate.d/wtmp # no packages own wtmp -- we'll rotate it here /var/log/wtmp { olddir /root/logrotate_dir missingok monthly create 0664 root utmp minsize 1M rotate 1 } # ls /root/logrotate_dir ls: cannot access '/root/logrotate_dir': No such file or directory # systemctl start logrotate Job for logrotate.service failed because the control process exited with error code. See "systemctl status logrotate.service" and "journalctl -xe" for details. # systemctl status logrotate logrotate.service - Rotate log files Loaded: loaded (/lib/systemd/system/logrotate.service; static; vendor preset> Active: failed (Result: exit-code) since Wed 2019-02-13 03:35:19 UTC; 7s ago Docs: man:logrotate(8) man:logrotate.conf(5) Process: 540 ExecStart=/usr/sbin/logrotate /etc/logrotate.conf (code=exited, status=1/FAILURE) Main PID: 540 (code=exited, status=1/FAILURE) Feb 13 03:35:18 qemumips systemd[1]: Starting Rotate log files... Feb 13 03:35:19 qemumips logrotate[540]: error: wtmp:9 error verifying olddir path /root/logrotate_dir: No such file or directory Feb 13 03:35:19 qemumips logrotate[540]: error: found error in file wtmp, skipping Feb 13 03:35:19 qemumips systemd[1]: logrotate.service: Main process exited, code=exited, status=1/FAILURE Feb 13 03:35:19 qemumips systemd[1]: logrotate.service: Failed with result 'exit-code'. Feb 13 03:35:19 qemumips systemd[1]: Failed to start Rotate log files. Add the logic to restore /etc/logrotate.d/wtmp to make the cleanup complete to fix the above issue. (From OE-Core rev: a2db9320d97d12d87524ff16a329f9c38a8da33f) Signed-off-by: Mingli Yu <Mingli.Yu@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
47 lines
2.0 KiB
Python
47 lines
2.0 KiB
Python
# This test should cover https://bugzilla.yoctoproject.org/tr_show_case.cgi?case_id=289 testcase
|
|
# Note that the image under test must have logrotate installed
|
|
|
|
from oeqa.runtime.case import OERuntimeTestCase
|
|
from oeqa.core.decorator.depends import OETestDepends
|
|
from oeqa.core.decorator.oeid import OETestID
|
|
from oeqa.runtime.decorator.package import OEHasPackage
|
|
|
|
class LogrotateTest(OERuntimeTestCase):
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.tc.target.run('cp /etc/logrotate.d/wtmp $HOME/wtmp.oeqabak')
|
|
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
cls.tc.target.run('mv -f $HOME/wtmp.oeqabak /etc/logrotate.d/wtmp && rm -rf $HOME/logrotate_dir')
|
|
|
|
@OETestID(1544)
|
|
@OETestDepends(['ssh.SSHTest.test_ssh'])
|
|
@OEHasPackage(['logrotate'])
|
|
def test_1_logrotate_setup(self):
|
|
status, output = self.target.run('mkdir $HOME/logrotate_dir')
|
|
msg = 'Could not create logrotate_dir. Output: %s' % output
|
|
self.assertEqual(status, 0, msg = msg)
|
|
|
|
cmd = ('sed -i "s#wtmp {#wtmp {\\n olddir $HOME/logrotate_dir#"'
|
|
' /etc/logrotate.d/wtmp')
|
|
status, output = self.target.run(cmd)
|
|
msg = ('Could not write to logrotate.d/wtmp file. Status and output: '
|
|
' %s and %s' % (status, output))
|
|
self.assertEqual(status, 0, msg = msg)
|
|
|
|
@OETestID(1542)
|
|
@OETestDepends(['logrotate.LogrotateTest.test_1_logrotate_setup'])
|
|
def test_2_logrotate(self):
|
|
status, output = self.target.run('logrotate -f /etc/logrotate.conf')
|
|
msg = ('logrotate service could not be reloaded. Status and output: '
|
|
'%s and %s' % (status, output))
|
|
self.assertEqual(status, 0, msg = msg)
|
|
|
|
_, output = self.target.run('ls -la $HOME/logrotate_dir/ | wc -l')
|
|
msg = ('new logfile could not be created. List of files within log '
|
|
'directory: %s' % (
|
|
self.target.run('ls -la $HOME/logrotate_dir')[1]))
|
|
self.assertTrue(int(output)>=3, msg = msg)
|