Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1 | # 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 | |
| 4 | from oeqa.runtime.case import OERuntimeTestCase |
| 5 | from oeqa.core.decorator.depends import OETestDepends |
| 6 | from oeqa.core.decorator.oeid import OETestID |
| 7 | from oeqa.runtime.decorator.package import OEHasPackage |
| 8 | |
| 9 | class LogrotateTest(OERuntimeTestCase): |
| 10 | |
| 11 | @classmethod |
| 12 | def tearDownClass(cls): |
| 13 | cls.tc.target.run('rm -rf $HOME/logrotate_dir') |
| 14 | |
| 15 | @OETestID(1544) |
| 16 | @OETestDepends(['ssh.SSHTest.test_ssh']) |
| 17 | @OEHasPackage(['logrotate']) |
| 18 | def test_1_logrotate_setup(self): |
| 19 | status, output = self.target.run('mkdir $HOME/logrotate_dir') |
| 20 | msg = 'Could not create logrotate_dir. Output: %s' % output |
| 21 | self.assertEqual(status, 0, msg = msg) |
| 22 | |
| 23 | cmd = ('sed -i "s#wtmp {#wtmp {\\n olddir $HOME/logrotate_dir#"' |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 24 | ' /etc/logrotate.d/wtmp') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 25 | status, output = self.target.run(cmd) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 26 | msg = ('Could not write to logrotate.d/wtmp file. Status and output: ' |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 27 | ' %s and %s' % (status, output)) |
| 28 | self.assertEqual(status, 0, msg = msg) |
| 29 | |
| 30 | @OETestID(1542) |
| 31 | @OETestDepends(['logrotate.LogrotateTest.test_1_logrotate_setup']) |
| 32 | def test_2_logrotate(self): |
| 33 | status, output = self.target.run('logrotate -f /etc/logrotate.conf') |
| 34 | msg = ('logrotate service could not be reloaded. Status and output: ' |
| 35 | '%s and %s' % (status, output)) |
| 36 | self.assertEqual(status, 0, msg = msg) |
| 37 | |
| 38 | _, output = self.target.run('ls -la $HOME/logrotate_dir/ | wc -l') |
| 39 | msg = ('new logfile could not be created. List of files within log ' |
| 40 | 'directory: %s' % ( |
| 41 | self.target.run('ls -la $HOME/logrotate_dir')[1])) |
| 42 | self.assertTrue(int(output)>=3, msg = msg) |