blob: a92a1f2bcb3369baed55006e7cf2115f891f3127 [file] [log] [blame]
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001from oeqa.runtime.case import OERuntimeTestCase
2from oeqa.core.decorator.depends import OETestDepends
3from oeqa.core.decorator.oeid import OETestID
4from oeqa.core.decorator.data import skipIfDataVar
5from oeqa.runtime.decorator.package import OEHasPackage
6
7class SyslogTest(OERuntimeTestCase):
8
9 @OETestID(201)
10 @OETestDepends(['ssh.SSHTest.test_ssh'])
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011 @OEHasPackage(["busybox-syslog", "sysklogd", "rsyslog", "syslog-ng"])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012 def test_syslog_running(self):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080013 status, output = self.target.run(self.tc.target_cmds['ps'])
14 msg = "Failed to execute %s" % self.tc.target_cmds['ps']
Brad Bishop6e60e8b2018-02-01 10:27:11 -050015 self.assertEqual(status, 0, msg=msg)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080016 msg = "No syslog daemon process; %s output:\n%s" % (self.tc.target_cmds['ps'], output)
17 hasdaemon = "syslogd" in output or "syslog-ng" in output
18 self.assertTrue(hasdaemon, msg=msg)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050019
20class SyslogTestConfig(OERuntimeTestCase):
21
22 @OETestID(1149)
23 @OETestDepends(['oe_syslog.SyslogTest.test_syslog_running'])
24 def test_syslog_logger(self):
25 status, output = self.target.run('logger foobar')
26 msg = "Can't log into syslog. Output: %s " % output
27 self.assertEqual(status, 0, msg=msg)
28
29 status, output = self.target.run('grep foobar /var/log/messages')
30 if status != 0:
31 if self.tc.td.get("VIRTUAL-RUNTIME_init_manager") == "systemd":
32 status, output = self.target.run('journalctl -o cat | grep foobar')
33 else:
34 status, output = self.target.run('logread | grep foobar')
35 msg = ('Test log string not found in /var/log/messages or logread.'
36 ' Output: %s ' % output)
37 self.assertEqual(status, 0, msg=msg)
38
39 @OETestID(1150)
40 @OETestDepends(['oe_syslog.SyslogTest.test_syslog_running'])
41 def test_syslog_restart(self):
42 if "systemd" != self.tc.td.get("VIRTUAL-RUNTIME_init_manager", ""):
43 (_, _) = self.target.run('/etc/init.d/syslog restart')
44 else:
45 (_, _) = self.target.run('systemctl restart syslog.service')
46
47
48 @OETestID(202)
49 @OETestDepends(['oe_syslog.SyslogTestConfig.test_syslog_logger'])
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080050 @OEHasPackage(["busybox-syslog"])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050051 @skipIfDataVar('VIRTUAL-RUNTIME_init_manager', 'systemd',
52 'Not appropiate for systemd image')
53 def test_syslog_startup_config(self):
54 cmd = 'echo "LOGFILE=/var/log/test" >> /etc/syslog-startup.conf'
55 self.target.run(cmd)
56 status, output = self.target.run('/etc/init.d/syslog restart')
57 msg = ('Could not restart syslog service. Status and output:'
58 ' %s and %s' % (status,output))
59 self.assertEqual(status, 0, msg)
60
61 cmd = 'logger foobar && grep foobar /var/log/test'
62 status,output = self.target.run(cmd)
63 msg = 'Test log string not found. Output: %s ' % output
64 self.assertEqual(status, 0, msg=msg)
65
66 cmd = "sed -i 's#LOGFILE=/var/log/test##' /etc/syslog-startup.conf"
67 self.target.run(cmd)
68 self.target.run('/etc/init.d/syslog restart')