diff options
-rw-r--r-- | meta/lib/oeqa/runtime/cases/oe_syslog.py | 68 |
1 files changed, 59 insertions, 9 deletions
diff --git a/meta/lib/oeqa/runtime/cases/oe_syslog.py b/meta/lib/oeqa/runtime/cases/oe_syslog.py index 0f5f9f43ca..0f79e5a0f3 100644 --- a/meta/lib/oeqa/runtime/cases/oe_syslog.py +++ b/meta/lib/oeqa/runtime/cases/oe_syslog.py | |||
@@ -6,6 +6,7 @@ from oeqa.runtime.case import OERuntimeTestCase | |||
6 | from oeqa.core.decorator.depends import OETestDepends | 6 | from oeqa.core.decorator.depends import OETestDepends |
7 | from oeqa.core.decorator.data import skipIfDataVar | 7 | from oeqa.core.decorator.data import skipIfDataVar |
8 | from oeqa.runtime.decorator.package import OEHasPackage | 8 | from oeqa.runtime.decorator.package import OEHasPackage |
9 | import time | ||
9 | 10 | ||
10 | class SyslogTest(OERuntimeTestCase): | 11 | class SyslogTest(OERuntimeTestCase): |
11 | 12 | ||
@@ -21,6 +22,53 @@ class SyslogTest(OERuntimeTestCase): | |||
21 | 22 | ||
22 | class SyslogTestConfig(OERuntimeTestCase): | 23 | class SyslogTestConfig(OERuntimeTestCase): |
23 | 24 | ||
25 | def verif_not_running(self, pids): | ||
26 | for pid in pids: | ||
27 | status, err_output = self.target.run('kill -0 %s' %pid) | ||
28 | if not status: | ||
29 | self.logger.debug("previous %s is still running" %pid) | ||
30 | return 1 | ||
31 | |||
32 | def verify_running(self, names): | ||
33 | pids = [] | ||
34 | for name in names: | ||
35 | status, pid = self.target.run('pidof %s' %name) | ||
36 | if status: | ||
37 | self.logger.debug("%s is not running" %name) | ||
38 | return 1, pids | ||
39 | pids.append(pid) | ||
40 | return 0, pids | ||
41 | |||
42 | |||
43 | def restart_sanity(self, names, restart_cmd): | ||
44 | status, original_pids = self.verify_running(names) | ||
45 | if status: | ||
46 | return 1 | ||
47 | |||
48 | status, output = self.target.run(restart_cmd) | ||
49 | |||
50 | # Always check for an error, most likely a race between shutting down and starting up | ||
51 | timeout = time.time() + 30 | ||
52 | |||
53 | while time.time() < timeout: | ||
54 | # Verify the previous ones are no longer running | ||
55 | status = self.verif_not_running(original_pids) | ||
56 | if status: | ||
57 | continue | ||
58 | |||
59 | status, pids = self.verify_running(names) | ||
60 | if status: | ||
61 | continue | ||
62 | |||
63 | # Everything is fine now, so exit to continue the test | ||
64 | status = 0 | ||
65 | break | ||
66 | |||
67 | msg = ('Could not restart %s service. Status and output: %s and %s' | ||
68 | %(names, status, output)) | ||
69 | self.assertEqual(status, 0, msg) | ||
70 | |||
71 | |||
24 | @OETestDepends(['oe_syslog.SyslogTest.test_syslog_running']) | 72 | @OETestDepends(['oe_syslog.SyslogTest.test_syslog_running']) |
25 | def test_syslog_logger(self): | 73 | def test_syslog_logger(self): |
26 | status, output = self.target.run('logger foobar') | 74 | status, output = self.target.run('logger foobar') |
@@ -37,12 +85,16 @@ class SyslogTestConfig(OERuntimeTestCase): | |||
37 | ' Output: %s ' % output) | 85 | ' Output: %s ' % output) |
38 | self.assertEqual(status, 0, msg=msg) | 86 | self.assertEqual(status, 0, msg=msg) |
39 | 87 | ||
88 | |||
40 | @OETestDepends(['oe_syslog.SyslogTest.test_syslog_running']) | 89 | @OETestDepends(['oe_syslog.SyslogTest.test_syslog_running']) |
41 | def test_syslog_restart(self): | 90 | def test_syslog_restart(self): |
42 | if "systemd" != self.tc.td.get("VIRTUAL-RUNTIME_init_manager", ""): | 91 | status = self.restart_sanity(['systemd-journald'], 'systemctl restart syslog.service') |
43 | (_, _) = self.target.run('/etc/init.d/syslog restart') | 92 | if status: |
44 | else: | 93 | status = self.restart_sanity(['rsyslogd'], '/etc/init.d/rsyslog restart') |
45 | (_, _) = self.target.run('systemctl restart syslog.service') | 94 | if status: |
95 | status = self.restart_sanity(['syslogd', 'klogd'], '/etc/init.d/syslog restart') | ||
96 | else: | ||
97 | self.logger.info("No syslog found to restart, ignoring") | ||
46 | 98 | ||
47 | 99 | ||
48 | @OETestDepends(['oe_syslog.SyslogTestConfig.test_syslog_logger']) | 100 | @OETestDepends(['oe_syslog.SyslogTestConfig.test_syslog_logger']) |
@@ -52,10 +104,8 @@ class SyslogTestConfig(OERuntimeTestCase): | |||
52 | def test_syslog_startup_config(self): | 104 | def test_syslog_startup_config(self): |
53 | cmd = 'echo "LOGFILE=/var/log/test" >> /etc/syslog-startup.conf' | 105 | cmd = 'echo "LOGFILE=/var/log/test" >> /etc/syslog-startup.conf' |
54 | self.target.run(cmd) | 106 | self.target.run(cmd) |
55 | status, output = self.target.run('/etc/init.d/syslog restart') | 107 | |
56 | msg = ('Could not restart syslog service. Status and output:' | 108 | self.test_syslog_restart() |
57 | ' %s and %s' % (status,output)) | ||
58 | self.assertEqual(status, 0, msg) | ||
59 | 109 | ||
60 | cmd = 'logger foobar && grep foobar /var/log/test' | 110 | cmd = 'logger foobar && grep foobar /var/log/test' |
61 | status,output = self.target.run(cmd) | 111 | status,output = self.target.run(cmd) |
@@ -64,4 +114,4 @@ class SyslogTestConfig(OERuntimeTestCase): | |||
64 | 114 | ||
65 | cmd = "sed -i 's#LOGFILE=/var/log/test##' /etc/syslog-startup.conf" | 115 | cmd = "sed -i 's#LOGFILE=/var/log/test##' /etc/syslog-startup.conf" |
66 | self.target.run(cmd) | 116 | self.target.run(cmd) |
67 | self.target.run('/etc/init.d/syslog restart') | 117 | self.test_syslog_restart() |