Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | # |
| 4 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 5 | # 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 | |
| 8 | from oeqa.runtime.case import OERuntimeTestCase |
| 9 | from oeqa.core.decorator.depends import OETestDepends |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 10 | from oeqa.runtime.decorator.package import OEHasPackage |
| 11 | |
| 12 | class LogrotateTest(OERuntimeTestCase): |
| 13 | |
| 14 | @classmethod |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame] | 15 | def setUpClass(cls): |
| 16 | cls.tc.target.run('cp /etc/logrotate.d/wtmp $HOME/wtmp.oeqabak') |
| 17 | |
| 18 | @classmethod |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 19 | def tearDownClass(cls): |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame] | 20 | cls.tc.target.run('mv -f $HOME/wtmp.oeqabak /etc/logrotate.d/wtmp && rm -rf $HOME/logrotate_dir') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 21 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 22 | @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 Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 30 | ' /etc/logrotate.d/wtmp') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 31 | status, output = self.target.run(cmd) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 32 | msg = ('Could not write to logrotate.d/wtmp file. Status and output: ' |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 33 | ' %s and %s' % (status, output)) |
| 34 | self.assertEqual(status, 0, msg = msg) |
| 35 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 36 | @OETestDepends(['logrotate.LogrotateTest.test_1_logrotate_setup']) |
| 37 | def test_2_logrotate(self): |
Brad Bishop | f3fd288 | 2019-06-21 08:06:37 -0400 | [diff] [blame] | 38 | 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 41 | 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) |