logrotate.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #
  2. # SPDX-License-Identifier: MIT
  3. #
  4. # This test should cover https://bugzilla.yoctoproject.org/tr_show_case.cgi?case_id=289 testcase
  5. # Note that the image under test must have logrotate installed
  6. from oeqa.runtime.case import OERuntimeTestCase
  7. from oeqa.core.decorator.depends import OETestDepends
  8. from oeqa.runtime.decorator.package import OEHasPackage
  9. class LogrotateTest(OERuntimeTestCase):
  10. @classmethod
  11. def setUpClass(cls):
  12. cls.tc.target.run('cp /etc/logrotate.d/wtmp $HOME/wtmp.oeqabak')
  13. @classmethod
  14. def tearDownClass(cls):
  15. cls.tc.target.run('mv -f $HOME/wtmp.oeqabak /etc/logrotate.d/wtmp && rm -rf $HOME/logrotate_dir')
  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. cmd = ('sed -i "s#wtmp {#wtmp {\\n olddir $HOME/logrotate_dir#"'
  23. ' /etc/logrotate.d/wtmp')
  24. status, output = self.target.run(cmd)
  25. msg = ('Could not write to logrotate.d/wtmp file. Status and output: '
  26. ' %s and %s' % (status, output))
  27. self.assertEqual(status, 0, msg = msg)
  28. @OETestDepends(['logrotate.LogrotateTest.test_1_logrotate_setup'])
  29. def test_2_logrotate(self):
  30. status, output = self.target.run('logrotate -f /etc/logrotate.conf')
  31. msg = ('logrotate service could not be reloaded. Status and output: '
  32. '%s and %s' % (status, output))
  33. self.assertEqual(status, 0, msg = msg)
  34. _, output = self.target.run('ls -la $HOME/logrotate_dir/ | wc -l')
  35. msg = ('new logfile could not be created. List of files within log '
  36. 'directory: %s' % (
  37. self.target.run('ls -la $HOME/logrotate_dir')[1]))
  38. self.assertTrue(int(output)>=3, msg = msg)