summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/runtime/cases/logrotate.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/runtime/cases/logrotate.py')
-rw-r--r--meta/lib/oeqa/runtime/cases/logrotate.py31
1 files changed, 16 insertions, 15 deletions
diff --git a/meta/lib/oeqa/runtime/cases/logrotate.py b/meta/lib/oeqa/runtime/cases/logrotate.py
index 7cb43d98c5..0d4b9ac60b 100644
--- a/meta/lib/oeqa/runtime/cases/logrotate.py
+++ b/meta/lib/oeqa/runtime/cases/logrotate.py
@@ -20,55 +20,56 @@ class LogrotateTest(OERuntimeTestCase):
20 20
21 @classmethod 21 @classmethod
22 def tearDownClass(cls): 22 def tearDownClass(cls):
23 cls.tc.target.run('mv -f $HOME/wtmp.oeqabak /etc/logrotate.d/wtmp && rm -rf /var/log//logrotate_dir', ignore_ssh_fails=True) 23 cls.tc.target.run('mv -f $HOME/wtmp.oeqabak /etc/logrotate.d/wtmp && rm -rf /var/log/logrotate_dir', ignore_ssh_fails=True)
24 cls.tc.target.run('rm -rf /var/log/logrotate_testfile && rm -rf /etc/logrotate.d/logrotate_testfile', ignore_ssh_fails=True) 24 cls.tc.target.run('rm -rf /var/log/logrotate_testfile && rm -rf /etc/logrotate.d/logrotate_testfile', ignore_ssh_fails=True)
25 25
26 @OETestDepends(['ssh.SSHTest.test_ssh']) 26 @OETestDepends(['ssh.SSHTest.test_ssh'])
27 @OEHasPackage(['logrotate']) 27 @OEHasPackage(['logrotate'])
28 def test_logrotate_wtmp(self): 28 def test_logrotate_wtmp(self):
29
30 # /var/log/wtmp may not always exist initially, so use touch to ensure it is present 29 # /var/log/wtmp may not always exist initially, so use touch to ensure it is present
31 status, output = self.target.run('touch /var/log/wtmp') 30 status, output = self.target.run('touch /var/log/wtmp')
32 msg = ('Could not create/update /var/log/wtmp with touch') 31 msg = ('Could not create/update /var/log/wtmp with touch')
33 self.assertEqual(status, 0, msg = msg) 32 self.assertEqual(status, 0, msg = msg)
34 33
35 status, output = self.target.run('mkdir /var/log//logrotate_dir') 34 # Create a folder to store rotated file and add the corresponding
35 # configuration option
36 status, output = self.target.run('mkdir /var/log/logrotate_dir')
36 msg = ('Could not create logrotate_dir. Output: %s' % output) 37 msg = ('Could not create logrotate_dir. Output: %s' % output)
37 self.assertEqual(status, 0, msg = msg) 38 self.assertEqual(status, 0, msg = msg)
38 39
39 status, output = self.target.run('echo "create \n olddir /var/log//logrotate_dir \n include /etc/logrotate.d/wtmp" > /tmp/logrotate-test.conf') 40 status, output = self.target.run('echo "create \n olddir /var/log/logrotate_dir \n include /etc/logrotate.d/wtmp" > /tmp/logrotate-test.conf')
40 msg = ('Could not write to /tmp/logrotate-test.conf') 41 msg = ('Could not write to /tmp/logrotate-test.conf')
41 self.assertEqual(status, 0, msg = msg) 42 self.assertEqual(status, 0, msg = msg)
42 43
44 # Call logrotate -f to force the rotation immediately
43 # If logrotate fails to rotate the log, view the verbose output of logrotate to see what prevented it 45 # If logrotate fails to rotate the log, view the verbose output of logrotate to see what prevented it
44 _, logrotate_output = self.target.run('logrotate -vf /tmp/logrotate-test.conf') 46 _, logrotate_output = self.target.run('logrotate -vf /tmp/logrotate-test.conf')
45 status, _ = self.target.run('find /var/log//logrotate_dir -type f | grep wtmp.1') 47 status, _ = self.target.run('find /var/log/logrotate_dir -type f | grep wtmp.1')
46 msg = ("logrotate did not successfully rotate the wtmp log. Output from logrotate -vf: \n%s" % (logrotate_output)) 48 msg = ("logrotate did not successfully rotate the wtmp log. Output from logrotate -vf: \n%s" % (logrotate_output))
47 self.assertEqual(status, 0, msg = msg) 49 self.assertEqual(status, 0, msg = msg)
48 50
49 @OETestDepends(['logrotate.LogrotateTest.test_logrotate_wtmp']) 51 @OETestDepends(['logrotate.LogrotateTest.test_logrotate_wtmp'])
50 def test_logrotate_newlog(self): 52 def test_logrotate_newlog(self):
51
52 status, output = self.target.run('echo "oeqa logrotate test file" > /var/log/logrotate_testfile') 53 status, output = self.target.run('echo "oeqa logrotate test file" > /var/log/logrotate_testfile')
53 msg = ('Could not create logrotate test file in /var/log') 54 msg = ('Could not create logrotate test file in /var/log')
54 self.assertEqual(status, 0, msg = msg) 55 self.assertEqual(status, 0, msg = msg)
55 56
56 status, output = self.target.run('echo "/var/log/logrotate_testfile {\n missingok \n monthly \n rotate 1" > /etc/logrotate.d/logrotate_testfile') 57 # Create a new configuration file dedicated to a /var/log/logrotate_testfile
58 status, output = self.target.run('echo "/var/log/logrotate_testfile {\n missingok \n monthly \n rotate 1}" > /etc/logrotate.d/logrotate_testfile')
57 msg = ('Could not write to /etc/logrotate.d/logrotate_testfile') 59 msg = ('Could not write to /etc/logrotate.d/logrotate_testfile')
58 self.assertEqual(status, 0, msg = msg) 60 self.assertEqual(status, 0, msg = msg)
59 61
60 status, output = self.target.run('echo "create \n olddir /var/log//logrotate_dir \n include /etc/logrotate.d/logrotate_testfile" > /tmp/logrotate-test2.conf') 62 status, output = self.target.run('echo "create \n olddir /var/log/logrotate_dir \n include /etc/logrotate.d/logrotate_testfile" > /tmp/logrotate-test2.conf')
61 msg = ('Could not write to /tmp/logrotate_test2.conf') 63 msg = ('Could not write to /tmp/logrotate_test2.conf')
62 self.assertEqual(status, 0, msg = msg) 64 self.assertEqual(status, 0, msg = msg)
63 65
64 status, output = self.target.run('find /var/log//logrotate_dir -type f | grep logrotate_testfile.1') 66 status, output = self.target.run('find /var/log/logrotate_dir -type f | grep logrotate_testfile.1')
65 msg = ('A rotated log for logrotate_testfile is already present in logrotate_dir') 67 msg = ('A rotated log for logrotate_testfile is already present in logrotate_dir')
66 self.assertEqual(status, 1, msg = msg) 68 self.assertEqual(status, 1, msg = msg)
67 69
70 # Call logrotate -f to force the rotation immediately
68 # If logrotate fails to rotate the log, view the verbose output of logrotate instead of just listing the files in olddir 71 # If logrotate fails to rotate the log, view the verbose output of logrotate instead of just listing the files in olddir
69 _, logrotate_output = self.target.run('logrotate -vf /tmp/logrotate-test2.conf') 72 _, logrotate_output = self.target.run('logrotate -vf /tmp/logrotate-test2.conf')
70 status, _ = self.target.run('find /var/log//logrotate_dir -type f | grep logrotate_testfile.1') 73 status, _ = self.target.run('find /var/log/logrotate_dir -type f | grep logrotate_testfile.1')
71 msg = ('logrotate did not successfully rotate the logrotate_test log. Output from logrotate -vf: \n%s' % (logrotate_output)) 74 msg = ('logrotate did not successfully rotate the logrotate_test log. Output from logrotate -vf: \n%s' % (logrotate_output))
72 self.assertEqual(status, 0, msg = msg) 75 self.assertEqual(status, 0, msg = msg)
73
74