Merge lp:~bigkevmcd/landscape-client/517454-incorrect-log-file-location into lp:~landscape/landscape-client/trunk

Proposed by Kevin McDermott
Status: Merged
Approved by: Kevin McDermott
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~bigkevmcd/landscape-client/517454-incorrect-log-file-location
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 183 lines (+68/-14)
4 files modified
landscape/sysinfo/deployment.py (+10/-3)
landscape/sysinfo/sysinfo.py (+4/-1)
landscape/sysinfo/tests/test_deployment.py (+21/-1)
landscape/sysinfo/tests/test_sysinfo.py (+33/-9)
To merge this branch: bzr merge lp:~bigkevmcd/landscape-client/517454-incorrect-log-file-location
Reviewer Review Type Date Requested Status
Free Ekanayaka (community) Approve
Thomas Herve (community) Approve
Review via email: mp+18704@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Thomas Herve (therve) wrote :
Download full text (3.9 KiB)

[1] Pep8:
landscape/sysinfo/tests/test_deployment.py:20:5: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_deployment.py:22:9: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_deployment.py:63:5: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_deployment.py:67:5: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_deployment.py:69:5: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_deployment.py:71:5: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_deployment.py:73:5: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_deployment.py:144:9: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_deployment.py:261:1: W291 trailing whitespace
landscape/sysinfo/tests/test_deployment.py:263:5: E301 expected 1 blank line, found 2
landscape/sysinfo/sysinfo.py:18:1: W291 trailing whitespace
landscape/sysinfo/sysinfo.py:92:1: W291 trailing whitespace
landscape/sysinfo/sysinfo.py:236:22: E111 indentation is not a multiple of four
landscape/sysinfo/tests/test_sysinfo.py:80:9: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_sysinfo.py:81:13: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_sysinfo.py:83:13: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_sysinfo.py:85:13: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_sysinfo.py:120:9: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_sysinfo.py:121:13: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_sysinfo.py:123:13: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_sysinfo.py:126:9: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_sysinfo.py:127:13: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_sysinfo.py:129:13: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_sysinfo.py:151:9: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_sysinfo.py:152:13: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_sysinfo.py:154:13: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_sysinfo.py:170:9: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_sysinfo.py:171:13: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_sysinfo.py:173:13: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_sysinfo.py:177:13: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_sysinfo.py:179:13: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_sysinfo.py:199:9: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_sysinfo.py:200:13: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_sysinfo.py:202:13: E301 expected 1 blank line, found 0
landscape/sysinfo/tests/test_sysinfo.py:214:1: E302 expected 2 blank lines, found 1
landscape/sysinfo/tests/test_sysinfo.py:300:31: W291 trailing whitespace
landscape/sysinfo/tests/test_sysinfo.py:329:37: E202 whitespace before ')'
landscape/sysinfo/tests/test_sysinfo.py:338:31: W291 trailing whitespace
landscape/sysinfo/tests/test_sysinfo.py:341:37: E202 whitespace before ')'
landscape/sysi...

Read more...

review: Approve
Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

Nice fix and tests! +1

[1]

+ def test_exception_running_as_privileged_user(self):

This test is missing a docstring.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/sysinfo/deployment.py'
2--- landscape/sysinfo/deployment.py 2008-09-18 18:42:22 +0000
3+++ landscape/sysinfo/deployment.py 2010-02-05 15:57:13 +0000
4@@ -60,14 +60,21 @@
5 % (plugin_name.lower(), plugin_name))()
6 for plugin_name in plugins]
7
8-
9-def setup_logging(landscape_dir=None):
10+def get_landscape_log_directory(landscape_dir=None):
11+ """
12+ Work out the correct path to store logs in depending on the effective
13+ user id of the current process.
14+ """
15 if landscape_dir is None:
16 if os.getuid() == 0:
17 landscape_dir = "/var/log/landscape"
18 else:
19 landscape_dir = os.path.expanduser("~/.landscape")
20-
21+ return landscape_dir
22+
23+
24+def setup_logging(landscape_dir=None):
25+ landscape_dir = get_landscape_log_directory(landscape_dir)
26 logger = getLogger("landscape-sysinfo")
27 logger.propagate = False
28 if not os.path.isdir(landscape_dir):
29
30=== modified file 'landscape/sysinfo/sysinfo.py'
31--- landscape/sysinfo/sysinfo.py 2008-09-03 16:59:55 +0000
32+++ landscape/sysinfo/sysinfo.py 2010-02-05 15:57:13 +0000
33@@ -1,6 +1,7 @@
34 import textwrap
35 from logging import getLogger
36 import math
37+import os
38
39 from twisted.python.failure import Failure
40
41@@ -110,10 +111,12 @@
42 log_failure(failure, message, logger=logger)
43
44 def _report_error_note(self, result):
45+ from landscape.sysinfo.deployment import get_landscape_log_directory
46+ path = os.path.join(get_landscape_log_directory(), "sysinfo.log")
47 if self._plugin_error:
48 self.add_note(
49 "There were exceptions while processing one or more plugins. "
50- "See ~/.landscape/sysinfo.log for more information.")
51+ "See %s for more information." % path)
52 return result
53
54
55
56=== modified file 'landscape/sysinfo/tests/test_deployment.py'
57--- landscape/sysinfo/tests/test_deployment.py 2009-08-07 22:36:33 +0000
58+++ landscape/sysinfo/tests/test_deployment.py 2010-02-05 15:57:13 +0000
59@@ -6,7 +6,8 @@
60 from twisted.internet.defer import Deferred
61
62 from landscape.sysinfo.deployment import (
63- SysInfoConfiguration, ALL_PLUGINS, run, setup_logging)
64+ SysInfoConfiguration, ALL_PLUGINS, run, setup_logging,
65+ get_landscape_log_directory)
66 from landscape.sysinfo.testplugin import TestPlugin
67 from landscape.sysinfo.sysinfo import SysInfoPluginRegistry
68 from landscape.sysinfo.load import Load
69@@ -192,6 +193,25 @@
70 self.assertEquals(reactor.scheduled_calls, [(0, reactor.stop, (), {})])
71 return self.assertFailure(d, ZeroDivisionError)
72
73+ def test_get_landscape_log_directory_unprivileged(self):
74+ """
75+ If landscape-sysinfo is running as a non-privileged user the
76+ log directory is stored in their home directory.
77+ """
78+ self.assertEquals(get_landscape_log_directory(),
79+ os.path.expanduser("~/.landscape"))
80+
81+ def test_get_landscape_log_directory_privileged(self):
82+ """
83+ If landscape-sysinfo is running as a privileged user, then the logs
84+ should be stored in the system-wide log directory.
85+ """
86+ uid_mock = self.mocker.replace("os.getuid")
87+ uid_mock()
88+ self.mocker.result(0)
89+ self.mocker.replay()
90+ self.assertEquals(get_landscape_log_directory(), "/var/log/landscape")
91+
92 def test_wb_logging_setup(self):
93 """
94 setup_logging sets up a "landscape-sysinfo" logger which rotates every
95
96=== modified file 'landscape/sysinfo/tests/test_sysinfo.py'
97--- landscape/sysinfo/tests/test_sysinfo.py 2008-09-03 16:59:55 +0000
98+++ landscape/sysinfo/tests/test_sysinfo.py 2010-02-05 15:57:13 +0000
99@@ -1,5 +1,6 @@
100 from cStringIO import StringIO
101 from logging import getLogger, StreamHandler
102+import os
103
104 from twisted.internet.defer import Deferred, succeed, fail
105
106@@ -107,7 +108,7 @@
107
108 plugin_exception_message = (
109 "There were exceptions while processing one or more plugins. "
110- "See ~/.landscape/sysinfo.log for more information.")
111+ "See %s/sysinfo.log for more information.")
112
113 def test_plugins_run_after_synchronous_error(self):
114 """
115@@ -139,9 +140,11 @@
116 self.assertIn(message, log)
117 self.assertIn("1/0", log)
118 self.assertIn("ZeroDivisionError", log)
119+
120+ path = os.path.expanduser("~/.landscape")
121 self.assertEquals(
122 self.sysinfo.get_notes(),
123- [self.plugin_exception_message])
124+ [self.plugin_exception_message % path])
125
126 def test_asynchronous_errors_logged(self):
127 self.log_helper.ignore_errors(ZeroDivisionError)
128@@ -157,9 +160,10 @@
129 message = "BadPlugin plugin raised an exception."
130 self.assertIn(message, log)
131 self.assertIn("ZeroDivisionError: yay", log)
132+ path = os.path.expanduser("~/.landscape")
133 self.assertEquals(
134 self.sysinfo.get_notes(),
135- [self.plugin_exception_message])
136+ [self.plugin_exception_message % path])
137
138 def test_multiple_exceptions_get_one_note(self):
139 self.log_helper.ignore_errors(ZeroDivisionError)
140@@ -181,11 +185,31 @@
141 self.sysinfo.add(plugin2)
142 self.sysinfo.run()
143
144- self.assertEquals(
145- self.sysinfo.get_notes(),
146- [self.plugin_exception_message])
147-
148-
149+ path = os.path.expanduser("~/.landscape")
150+ self.assertEquals(
151+ self.sysinfo.get_notes(),
152+ [self.plugin_exception_message % path])
153+
154+ def test_exception_running_as_privileged_user(self):
155+ uid_mock = self.mocker.replace("os.getuid")
156+ uid_mock()
157+ self.mocker.result(0)
158+ self.mocker.replay()
159+ self.log_helper.ignore_errors(ZeroDivisionError)
160+ class AsyncBadPlugin(object):
161+ def register(self, registry):
162+ pass
163+ def run(self):
164+ return fail(ZeroDivisionError("Hi"))
165+
166+ plugin = AsyncBadPlugin()
167+ self.sysinfo.add(plugin)
168+ self.sysinfo.run()
169+
170+ path = "/var/log/landscape"
171+ self.assertEquals(
172+ self.sysinfo.get_notes(),
173+ [self.plugin_exception_message % path])
174
175 class FormatTest(LandscapeTest):
176
177@@ -345,4 +369,4 @@
178 """\
179 Z=> I do believe that a very long note, such as
180 one that is longer than about 50 characters,
181- should wrap at the specified width.""")
182\ No newline at end of file
183+ should wrap at the specified width.""")

Subscribers

People subscribed via source and target branches

to all changes: