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']) |
| 11 | @OEHasPackage(["busybox-syslog", "sysklogd"]) |
| 12 | def test_syslog_running(self): |
| 13 | cmd = '%s | grep -i [s]yslogd' % self.tc.target_cmds['ps'] |
| 14 | status, output = self.target.run(cmd) |
| 15 | msg = "No syslogd process; ps output: %s" % output |
| 16 | self.assertEqual(status, 0, msg=msg) |
| 17 | |
| 18 | class SyslogTestConfig(OERuntimeTestCase): |
| 19 | |
| 20 | @OETestID(1149) |
| 21 | @OETestDepends(['oe_syslog.SyslogTest.test_syslog_running']) |
| 22 | def test_syslog_logger(self): |
| 23 | status, output = self.target.run('logger foobar') |
| 24 | msg = "Can't log into syslog. Output: %s " % output |
| 25 | self.assertEqual(status, 0, msg=msg) |
| 26 | |
| 27 | status, output = self.target.run('grep foobar /var/log/messages') |
| 28 | if status != 0: |
| 29 | if self.tc.td.get("VIRTUAL-RUNTIME_init_manager") == "systemd": |
| 30 | status, output = self.target.run('journalctl -o cat | grep foobar') |
| 31 | else: |
| 32 | status, output = self.target.run('logread | grep foobar') |
| 33 | msg = ('Test log string not found in /var/log/messages or logread.' |
| 34 | ' Output: %s ' % output) |
| 35 | self.assertEqual(status, 0, msg=msg) |
| 36 | |
| 37 | @OETestID(1150) |
| 38 | @OETestDepends(['oe_syslog.SyslogTest.test_syslog_running']) |
| 39 | def test_syslog_restart(self): |
| 40 | if "systemd" != self.tc.td.get("VIRTUAL-RUNTIME_init_manager", ""): |
| 41 | (_, _) = self.target.run('/etc/init.d/syslog restart') |
| 42 | else: |
| 43 | (_, _) = self.target.run('systemctl restart syslog.service') |
| 44 | |
| 45 | |
| 46 | @OETestID(202) |
| 47 | @OETestDepends(['oe_syslog.SyslogTestConfig.test_syslog_logger']) |
| 48 | @OEHasPackage(["!sysklogd", "busybox"]) |
| 49 | @skipIfDataVar('VIRTUAL-RUNTIME_init_manager', 'systemd', |
| 50 | 'Not appropiate for systemd image') |
| 51 | def test_syslog_startup_config(self): |
| 52 | cmd = 'echo "LOGFILE=/var/log/test" >> /etc/syslog-startup.conf' |
| 53 | self.target.run(cmd) |
| 54 | status, output = self.target.run('/etc/init.d/syslog restart') |
| 55 | msg = ('Could not restart syslog service. Status and output:' |
| 56 | ' %s and %s' % (status,output)) |
| 57 | self.assertEqual(status, 0, msg) |
| 58 | |
| 59 | cmd = 'logger foobar && grep foobar /var/log/test' |
| 60 | status,output = self.target.run(cmd) |
| 61 | msg = 'Test log string not found. Output: %s ' % output |
| 62 | self.assertEqual(status, 0, msg=msg) |
| 63 | |
| 64 | cmd = "sed -i 's#LOGFILE=/var/log/test##' /etc/syslog-startup.conf" |
| 65 | self.target.run(cmd) |
| 66 | self.target.run('/etc/init.d/syslog restart') |