Merge lp:~notmyname/swift/stats_fix into lp:~hudson-openstack/swift/trunk

Proposed by John Dickinson
Status: Merged
Approved by: gholt
Approved revision: 120
Merged at revision: 122
Proposed branch: lp:~notmyname/swift/stats_fix
Merge into: lp:~hudson-openstack/swift/trunk
Diff against target: 76 lines (+43/-2)
2 files modified
swift/stats/log_processor.py (+1/-2)
test/unit/stats/test_log_processor.py (+42/-0)
To merge this branch: bzr merge lp:~notmyname/swift/stats_fix
Reviewer Review Type Date Requested Status
clayg Approve
Review via email: mp+40145@code.launchpad.net

Commit message

fixed bug in internal proxy

Description of the change

fixed bug in internal proxy

To post a comment you must log in.
lp:~notmyname/swift/stats_fix updated
120. By John Dickinson

merged with clayg's branch

Revision history for this message
clayg (clay-gerrard) wrote :

this looks good, thanks for adding the test

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'swift/stats/log_processor.py'
2--- swift/stats/log_processor.py 2010-10-08 22:20:43 +0000
3+++ swift/stats/log_processor.py 2010-11-05 14:44:52 +0000
4@@ -73,8 +73,7 @@
5 self._internal_proxy = InternalProxy(proxy_server_conf,
6 self.logger,
7 retries=3)
8- else:
9- return self._internal_proxy
10+ return self._internal_proxy
11
12 def process_one_file(self, plugin_name, account, container, object_name):
13 self.logger.info('Processing %s/%s/%s with plugin "%s"' % (account,
14
15=== modified file 'test/unit/stats/test_log_processor.py'
16--- test/unit/stats/test_log_processor.py 2010-10-08 22:20:43 +0000
17+++ test/unit/stats/test_log_processor.py 2010-11-05 14:44:52 +0000
18@@ -14,9 +14,30 @@
19 # limitations under the License.
20
21 import unittest
22+import os
23+from contextlib import contextmanager
24+from tempfile import NamedTemporaryFile
25
26+from swift.common import internal_proxy
27 from swift.stats import log_processor
28
29+
30+@contextmanager
31+def tmpfile(content):
32+ with NamedTemporaryFile('w', delete=False) as f:
33+ file_name = f.name
34+ f.write(str(content))
35+ try:
36+ yield file_name
37+ finally:
38+ os.unlink(file_name)
39+
40+
41+class FakeUploadApp(object):
42+ def __init__(self, *args, **kwargs):
43+ pass
44+
45+
46 class DumbLogger(object):
47 def __getattr__(self, n):
48 return self.foo
49@@ -63,6 +84,27 @@
50 }
51 }
52
53+ def test_lazy_load_internal_proxy(self):
54+ # stub out internal_proxy's upload_app
55+ internal_proxy.BaseApplication = FakeUploadApp
56+ dummy_proxy_config = """[app:proxy-server]
57+use = egg:swift#proxy
58+"""
59+ with tmpfile(dummy_proxy_config) as proxy_config_file:
60+ conf = {'log-processor': {
61+ 'proxy_server_conf': proxy_config_file,
62+ }
63+ }
64+ p = log_processor.LogProcessor(conf, DumbLogger())
65+ self.assert_(isinstance(p._internal_proxy,
66+ None.__class__))
67+ self.assert_(isinstance(p.internal_proxy,
68+ log_processor.InternalProxy))
69+ self.assertEquals(p.internal_proxy, p._internal_proxy)
70+
71+ # reset FakeUploadApp
72+ reload(internal_proxy)
73+
74 def test_access_log_line_parser(self):
75 access_proxy_config = self.proxy_config.copy()
76 access_proxy_config.update({