logrotate.py 1.9 KB

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