blob: d2666444e96c748dc75b19d7457c0256ebd5d435 [file] [log] [blame]
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001# This test should cover https://bugzilla.yoctoproject.org/tr_show_case.cgi?case_id=289 testcase
2# Note that the image under test must have logrotate installed
3
4from oeqa.runtime.case import OERuntimeTestCase
5from oeqa.core.decorator.depends import OETestDepends
6from oeqa.core.decorator.oeid import OETestID
7from oeqa.runtime.decorator.package import OEHasPackage
8
9class LogrotateTest(OERuntimeTestCase):
10
11 @classmethod
Andrew Geissler99467da2019-02-25 18:54:23 -060012 def setUpClass(cls):
13 cls.tc.target.run('cp /etc/logrotate.d/wtmp $HOME/wtmp.oeqabak')
14
15 @classmethod
Brad Bishop6e60e8b2018-02-01 10:27:11 -050016 def tearDownClass(cls):
Andrew Geissler99467da2019-02-25 18:54:23 -060017 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 -050018
19 @OETestID(1544)
20 @OETestDepends(['ssh.SSHTest.test_ssh'])
21 @OEHasPackage(['logrotate'])
22 def test_1_logrotate_setup(self):
23 status, output = self.target.run('mkdir $HOME/logrotate_dir')
24 msg = 'Could not create logrotate_dir. Output: %s' % output
25 self.assertEqual(status, 0, msg = msg)
26
27 cmd = ('sed -i "s#wtmp {#wtmp {\\n olddir $HOME/logrotate_dir#"'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080028 ' /etc/logrotate.d/wtmp')
Brad Bishop6e60e8b2018-02-01 10:27:11 -050029 status, output = self.target.run(cmd)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080030 msg = ('Could not write to logrotate.d/wtmp file. Status and output: '
Brad Bishop6e60e8b2018-02-01 10:27:11 -050031 ' %s and %s' % (status, output))
32 self.assertEqual(status, 0, msg = msg)
33
34 @OETestID(1542)
35 @OETestDepends(['logrotate.LogrotateTest.test_1_logrotate_setup'])
36 def test_2_logrotate(self):
37 status, output = self.target.run('logrotate -f /etc/logrotate.conf')
38 msg = ('logrotate service could not be reloaded. Status and output: '
39 '%s and %s' % (status, output))
40 self.assertEqual(status, 0, msg = msg)
41
42 _, output = self.target.run('ls -la $HOME/logrotate_dir/ | wc -l')
43 msg = ('new logfile could not be created. List of files within log '
44 'directory: %s' % (
45 self.target.run('ls -la $HOME/logrotate_dir')[1]))
46 self.assertTrue(int(output)>=3, msg = msg)