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.py36
1 files changed, 19 insertions, 17 deletions
diff --git a/meta/lib/oeqa/runtime/cases/logrotate.py b/meta/lib/oeqa/runtime/cases/logrotate.py
index 6ad980cb6a..0d4b9ac60b 100644
--- a/meta/lib/oeqa/runtime/cases/logrotate.py
+++ b/meta/lib/oeqa/runtime/cases/logrotate.py
@@ -15,59 +15,61 @@ class LogrotateTest(OERuntimeTestCase):
15 15
16 @classmethod 16 @classmethod
17 def setUpClass(cls): 17 def setUpClass(cls):
18 cls.tc.target.run('cp /etc/logrotate.d/wtmp $HOME/wtmp.oeqabak') 18 cls.tc.target.run('cp /etc/logrotate.d/wtmp $HOME/wtmp.oeqabak',
19 ignore_ssh_fails=True)
19 20
20 @classmethod 21 @classmethod
21 def tearDownClass(cls): 22 def tearDownClass(cls):
22 cls.tc.target.run('mv -f $HOME/wtmp.oeqabak /etc/logrotate.d/wtmp && rm -rf /var/log//logrotate_dir') 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('rm -rf /var/log/logrotate_testfile && rm -rf /etc/logrotate.d/logrotate_testfile') 24 cls.tc.target.run('rm -rf /var/log/logrotate_testfile && rm -rf /etc/logrotate.d/logrotate_testfile', ignore_ssh_fails=True)
24 25
25 @OETestDepends(['ssh.SSHTest.test_ssh']) 26 @OETestDepends(['ssh.SSHTest.test_ssh'])
26 @OEHasPackage(['logrotate']) 27 @OEHasPackage(['logrotate'])
27 def test_logrotate_wtmp(self): 28 def test_logrotate_wtmp(self):
28
29 # /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
30 status, output = self.target.run('touch /var/log/wtmp') 30 status, output = self.target.run('touch /var/log/wtmp')
31 msg = ('Could not create/update /var/log/wtmp with touch') 31 msg = ('Could not create/update /var/log/wtmp with touch')
32 self.assertEqual(status, 0, msg = msg) 32 self.assertEqual(status, 0, msg = msg)
33 33
34 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')
35 msg = ('Could not create logrotate_dir. Output: %s' % output) 37 msg = ('Could not create logrotate_dir. Output: %s' % output)
36 self.assertEqual(status, 0, msg = msg) 38 self.assertEqual(status, 0, msg = msg)
37 39
38 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')
39 msg = ('Could not write to /tmp/logrotate-test.conf') 41 msg = ('Could not write to /tmp/logrotate-test.conf')
40 self.assertEqual(status, 0, msg = msg) 42 self.assertEqual(status, 0, msg = msg)
41 43
44 # Call logrotate -f to force the rotation immediately
42 # 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
43 _, logrotate_output = self.target.run('logrotate -vf /tmp/logrotate-test.conf') 46 _, logrotate_output = self.target.run('logrotate -vf /tmp/logrotate-test.conf')
44 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')
45 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))
46 self.assertEqual(status, 0, msg = msg) 49 self.assertEqual(status, 0, msg = msg)
47 50
48 @OETestDepends(['logrotate.LogrotateTest.test_logrotate_wtmp']) 51 @OETestDepends(['logrotate.LogrotateTest.test_logrotate_wtmp'])
49 def test_logrotate_newlog(self): 52 def test_logrotate_newlog(self):
50
51 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')
52 msg = ('Could not create logrotate test file in /var/log') 54 msg = ('Could not create logrotate test file in /var/log')
53 self.assertEqual(status, 0, msg = msg) 55 self.assertEqual(status, 0, msg = msg)
54 56
55 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')
56 msg = ('Could not write to /etc/logrotate.d/logrotate_testfile') 59 msg = ('Could not write to /etc/logrotate.d/logrotate_testfile')
57 self.assertEqual(status, 0, msg = msg) 60 self.assertEqual(status, 0, msg = msg)
58 61
59 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')
60 msg = ('Could not write to /tmp/logrotate_test2.conf') 63 msg = ('Could not write to /tmp/logrotate_test2.conf')
61 self.assertEqual(status, 0, msg = msg) 64 self.assertEqual(status, 0, msg = msg)
62 65
63 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')
64 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')
65 self.assertEqual(status, 1, msg = msg) 68 self.assertEqual(status, 1, msg = msg)
66 69
70 # Call logrotate -f to force the rotation immediately
67 # 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
68 _, logrotate_output = self.target.run('logrotate -vf /tmp/logrotate-test2.conf') 72 _, logrotate_output = self.target.run('logrotate -vf /tmp/logrotate-test2.conf')
69 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')
70 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))
71 self.assertEqual(status, 0, msg = msg) 75 self.assertEqual(status, 0, msg = msg)
72
73