Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 1 | # |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | # |
| 4 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 5 | from oeqa.runtime.case import OERuntimeTestCase |
| 6 | from oeqa.core.decorator.depends import OETestDepends |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7 | from oeqa.core.decorator.data import skipIfDataVar |
| 8 | from oeqa.runtime.decorator.package import OEHasPackage |
| 9 | |
| 10 | class SyslogTest(OERuntimeTestCase): |
| 11 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 12 | @OETestDepends(['ssh.SSHTest.test_ssh']) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 13 | @OEHasPackage(["busybox-syslog", "sysklogd", "rsyslog", "syslog-ng"]) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 14 | def test_syslog_running(self): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 15 | status, output = self.target.run(self.tc.target_cmds['ps']) |
| 16 | msg = "Failed to execute %s" % self.tc.target_cmds['ps'] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 17 | self.assertEqual(status, 0, msg=msg) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 18 | 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 21 | |
| 22 | class SyslogTestConfig(OERuntimeTestCase): |
| 23 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 24 | @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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 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 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 48 | @OETestDepends(['oe_syslog.SyslogTestConfig.test_syslog_logger']) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 49 | @OEHasPackage(["busybox-syslog"]) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 50 | @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') |