Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1 | from oeqa.runtime.case import OERuntimeTestCase |
| 2 | from oeqa.core.decorator.depends import OETestDepends |
| 3 | from oeqa.core.decorator.oeid import OETestID |
| 4 | from oeqa.core.decorator.data import skipIfDataVar |
| 5 | from oeqa.runtime.decorator.package import OEHasPackage |
| 6 | |
| 7 | class SyslogTest(OERuntimeTestCase): |
| 8 | |
| 9 | @OETestID(201) |
| 10 | @OETestDepends(['ssh.SSHTest.test_ssh']) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 11 | @OEHasPackage(["busybox-syslog", "sysklogd", "rsyslog", "syslog-ng"]) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 12 | def test_syslog_running(self): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 13 | status, output = self.target.run(self.tc.target_cmds['ps']) |
| 14 | msg = "Failed to execute %s" % self.tc.target_cmds['ps'] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 15 | self.assertEqual(status, 0, msg=msg) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 16 | 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 19 | |
| 20 | class 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 Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 50 | @OEHasPackage(["busybox-syslog"]) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 51 | @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') |