blob: bfa57c534a929ef16dca25372f37c742311c4c0e [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
4
Brad Bishop6e60e8b2018-02-01 10:27:11 -05005# This test should cover https://bugzilla.yoctoproject.org/tr_show_case.cgi?case_id=289 testcase
6# Note that the image under test must have logrotate installed
7
8from oeqa.runtime.case import OERuntimeTestCase
9from oeqa.core.decorator.depends import OETestDepends
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010from oeqa.runtime.decorator.package import OEHasPackage
11
12class LogrotateTest(OERuntimeTestCase):
13
14 @classmethod
Andrew Geissler99467da2019-02-25 18:54:23 -060015 def setUpClass(cls):
16 cls.tc.target.run('cp /etc/logrotate.d/wtmp $HOME/wtmp.oeqabak')
17
18 @classmethod
Brad Bishop6e60e8b2018-02-01 10:27:11 -050019 def tearDownClass(cls):
Andrew Geissler99467da2019-02-25 18:54:23 -060020 cls.tc.target.run('mv -f $HOME/wtmp.oeqabak /etc/logrotate.d/wtmp && rm -rf $HOME/logrotate_dir')
Brad Bishop6e60e8b2018-02-01 10:27:11 -050021
Brad Bishop6e60e8b2018-02-01 10:27:11 -050022 @OETestDepends(['ssh.SSHTest.test_ssh'])
23 @OEHasPackage(['logrotate'])
24 def test_1_logrotate_setup(self):
25 status, output = self.target.run('mkdir $HOME/logrotate_dir')
26 msg = 'Could not create logrotate_dir. Output: %s' % output
27 self.assertEqual(status, 0, msg = msg)
28
29 cmd = ('sed -i "s#wtmp {#wtmp {\\n olddir $HOME/logrotate_dir#"'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080030 ' /etc/logrotate.d/wtmp')
Brad Bishop6e60e8b2018-02-01 10:27:11 -050031 status, output = self.target.run(cmd)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080032 msg = ('Could not write to logrotate.d/wtmp file. Status and output: '
Brad Bishop6e60e8b2018-02-01 10:27:11 -050033 ' %s and %s' % (status, output))
34 self.assertEqual(status, 0, msg = msg)
35
Brad Bishop6e60e8b2018-02-01 10:27:11 -050036 @OETestDepends(['logrotate.LogrotateTest.test_1_logrotate_setup'])
37 def test_2_logrotate(self):
Brad Bishopf3fd2882019-06-21 08:06:37 -040038 status, output = self.target.run('echo "create \n include /etc/logrotate.d" > /tmp/logrotate-test.conf')
39 status, output = self.target.run('logrotate -f /tmp/logrotate-test.conf')
40
Brad Bishop6e60e8b2018-02-01 10:27:11 -050041 msg = ('logrotate service could not be reloaded. Status and output: '
42 '%s and %s' % (status, output))
43 self.assertEqual(status, 0, msg = msg)
44
45 _, output = self.target.run('ls -la $HOME/logrotate_dir/ | wc -l')
46 msg = ('new logfile could not be created. List of files within log '
47 'directory: %s' % (
48 self.target.run('ls -la $HOME/logrotate_dir')[1]))
49 self.assertTrue(int(output)>=3, msg = msg)