1# 2# SPDX-License-Identifier: MIT 3# 4 5from oeqa.runtime.case import OERuntimeTestCase 6from oeqa.core.decorator.depends import OETestDepends 7from oeqa.core.decorator.data import skipIfDataVar 8from oeqa.runtime.decorator.package import OEHasPackage 9 10class SyslogTest(OERuntimeTestCase): 11 12 @OETestDepends(['ssh.SSHTest.test_ssh']) 13 @OEHasPackage(["busybox-syslog", "sysklogd", "rsyslog", "syslog-ng"]) 14 def test_syslog_running(self): 15 status, output = self.target.run(self.tc.target_cmds['ps']) 16 msg = "Failed to execute %s" % self.tc.target_cmds['ps'] 17 self.assertEqual(status, 0, msg=msg) 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) 21 22class SyslogTestConfig(OERuntimeTestCase): 23 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 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 @OETestDepends(['oe_syslog.SyslogTestConfig.test_syslog_logger']) 49 @OEHasPackage(["busybox-syslog"]) 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') 68