blob: 0f5f9f43ca4b13f5fe39025f26d60cf6757ec87f [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
4
Brad Bishop6e60e8b2018-02-01 10:27:11 -05005from oeqa.runtime.case import OERuntimeTestCase
6from oeqa.core.decorator.depends import OETestDepends
Brad Bishop6e60e8b2018-02-01 10:27:11 -05007from oeqa.core.decorator.data import skipIfDataVar
8from oeqa.runtime.decorator.package import OEHasPackage
9
10class SyslogTest(OERuntimeTestCase):
11
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012 @OETestDepends(['ssh.SSHTest.test_ssh'])
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080013 @OEHasPackage(["busybox-syslog", "sysklogd", "rsyslog", "syslog-ng"])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050014 def test_syslog_running(self):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080015 status, output = self.target.run(self.tc.target_cmds['ps'])
16 msg = "Failed to execute %s" % self.tc.target_cmds['ps']
Brad Bishop6e60e8b2018-02-01 10:27:11 -050017 self.assertEqual(status, 0, msg=msg)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080018 msg = "No syslog daemon process; %s output:\n%s" % (self.tc.target_cmds['ps'], output)
19 hasdaemon = "syslogd" in output or "syslog-ng" in output
20 self.assertTrue(hasdaemon, msg=msg)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050021
22class SyslogTestConfig(OERuntimeTestCase):
23
Brad Bishop6e60e8b2018-02-01 10:27:11 -050024 @OETestDepends(['oe_syslog.SyslogTest.test_syslog_running'])
25 def test_syslog_logger(self):
26 status, output = self.target.run('logger foobar')
27 msg = "Can't log into syslog. Output: %s " % output
28 self.assertEqual(status, 0, msg=msg)
29
30 status, output = self.target.run('grep foobar /var/log/messages')
31 if status != 0:
32 if self.tc.td.get("VIRTUAL-RUNTIME_init_manager") == "systemd":
33 status, output = self.target.run('journalctl -o cat | grep foobar')
34 else:
35 status, output = self.target.run('logread | grep foobar')
36 msg = ('Test log string not found in /var/log/messages or logread.'
37 ' Output: %s ' % output)
38 self.assertEqual(status, 0, msg=msg)
39
Brad Bishop6e60e8b2018-02-01 10:27:11 -050040 @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
Brad Bishop6e60e8b2018-02-01 10:27:11 -050048 @OETestDepends(['oe_syslog.SyslogTestConfig.test_syslog_logger'])
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080049 @OEHasPackage(["busybox-syslog"])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050050 @skipIfDataVar('VIRTUAL-RUNTIME_init_manager', 'systemd',
51 'Not appropiate for systemd image')
52 def test_syslog_startup_config(self):
53 cmd = 'echo "LOGFILE=/var/log/test" >> /etc/syslog-startup.conf'
54 self.target.run(cmd)
55 status, output = self.target.run('/etc/init.d/syslog restart')
56 msg = ('Could not restart syslog service. Status and output:'
57 ' %s and %s' % (status,output))
58 self.assertEqual(status, 0, msg)
59
60 cmd = 'logger foobar && grep foobar /var/log/test'
61 status,output = self.target.run(cmd)
62 msg = 'Test log string not found. Output: %s ' % output
63 self.assertEqual(status, 0, msg=msg)
64
65 cmd = "sed -i 's#LOGFILE=/var/log/test##' /etc/syslog-startup.conf"
66 self.target.run(cmd)
67 self.target.run('/etc/init.d/syslog restart')