Ticket #1389: 1389-refactored.patch

File 1389-refactored.patch, 11.1 KB (added by davidsarah, at 2011-04-10T16:00:02Z)

refactored version of the same patches

Line 
12 patches for repository davidsarah@dev.allmydata.org:/home/darcs/tahoe/trunk:
2
3Sun Apr 10 16:57:05 BST 2011  david-sarah@jacaranda.org
4  * allmydata/__init__.py: preserve the message and last traceback entry (file, line number, function, and source line) of ImportErrors in the package versions string. fixes #1389
5
6Sun Apr 10 16:58:44 BST 2011  david-sarah@jacaranda.org
7  * tests: add test for including the ImportError message and traceback entry in the summary of errors from importing dependencies. refs #1389
8
9New patches:
10
11[allmydata/__init__.py: preserve the message and last traceback entry (file, line number, function, and source line) of ImportErrors in the package versions string. fixes #1389
12david-sarah@jacaranda.org**20110410155705
13 Ignore-this: 2f87b8b327906cf8bfca9440a0904900
14] {
15hunk ./src/allmydata/__init__.py 35
16 # http://allmydata.org/trac/tahoe/wiki/Versioning
17 __full_version__ = __appname__ + '/' + str(__version__)
18 
19-import os, platform, re, subprocess, sys
20+import os, platform, re, subprocess, sys, traceback
21 _distributor_id_cmdline_re = re.compile("(?:Distributor ID:)\s*(.*)", re.I)
22 _release_cmdline_re = re.compile("(?:Release:)\s*(.*)", re.I)
23 
24hunk ./src/allmydata/__init__.py 140
25     try:
26         return verlib.NormalizedVersion(verlib.suggest_normalized_version(verstr))
27     except (StandardError, verlib.IrrationalVersionError):
28-        cls, value, traceback = sys.exc_info()
29+        cls, value, trace = sys.exc_info()
30         raise PackagingError, ("could not parse %s due to %s: %s"
31hunk ./src/allmydata/__init__.py 142
32-                               % (what or repr(verstr), cls.__name__, value)), traceback
33+                               % (what or repr(verstr), cls.__name__, value)), trace
34 
35 
36 def get_package_versions_and_locations():
37hunk ./src/allmydata/__init__.py 190
38                 __import__(modulename)
39                 module = sys.modules[modulename]
40             except ImportError:
41-                packages.append( (pkgname, (None, None, modulename)) )
42+                etype, emsg, etrace = sys.exc_info()
43+                trace_info = (emsg, ([None] + traceback.extract_tb(etrace))[-1])
44+                packages.append( (pkgname, (None, None, trace_info)) )
45             else:
46                 if 'sqlite' in pkgname:
47                     packages.append( (pkgname, (get_version(module, 'version'), package_dir(module.__file__),
48hunk ./src/allmydata/__init__.py 223
49         return
50     (actual, location, comment) = vers_and_locs[name]
51     if actual is None:
52-        # comment is the module name
53-        raise ImportError("could not import %r for requirement %r" % (comment, req))
54+        # comment is (message, (filename, line number, function name, text)) for the original ImportError
55+        raise ImportError("for requirement %r: %s" % (req, comment))
56     if actual == 'unknown':
57         return
58     actualver = normalized_version(actual, what="actual version %r of %s from %r" % (actual, name, location))
59}
60[tests: add test for including the ImportError message and traceback entry in the summary of errors from importing dependencies. refs #1389
61david-sarah@jacaranda.org**20110410155844
62 Ignore-this: fbecdbeb0d06a0f875fe8d4030aabafa
63] {
64addfile ./src/allmydata/test/test_package_initialization.py
65hunk ./src/allmydata/test/test_package_initialization.py 1
66+
67+from twisted.trial import unittest
68+
69+import allmydata
70+import mock
71+
72+real_import_func = __import__
73+
74+class T(unittest.TestCase):
75+    @mock.patch('__builtin__.__import__')
76+    def test_report_import_error(self, mockimport):
77+        def raiseIE_from_this_particular_func(name, *args):
78+            if name == "foolscap":
79+                marker = "wheeeyo"
80+                raise ImportError(marker + " foolscap cant be imported")
81+            else:
82+                return real_import_func(name, *args)
83+
84+        mockimport.side_effect = raiseIE_from_this_particular_func
85+
86+        vers_and_locs =  allmydata.get_package_versions_and_locations()
87+        for (pkgname, stuff) in vers_and_locs:
88+            if pkgname == 'foolscap':
89+                self.failUnless('wheeeyo' in str(stuff[2]), stuff)
90+                self.failUnless('raiseIE_from_this_particular_func' in str(stuff[2]), stuff)
91}
92
93Context:
94
95[remove unused variable detected by pyflakes
96zooko@zooko.com**20110407172231
97 Ignore-this: 7344652d5e0720af822070d91f03daf9
98]
99[allmydata/__init__.py: Nicer reporting of unparseable version numbers in dependencies. fixes #1388
100david-sarah@jacaranda.org**20110401202750
101 Ignore-this: 9c6bd599259d2405e1caadbb3e0d8c7f
102]
103[update FTP-and-SFTP.rst: the necessary patch is included in Twisted-10.1
104Brian Warner <warner@lothar.com>**20110325232511
105 Ignore-this: d5307faa6900f143193bfbe14e0f01a
106]
107[control.py: remove all uses of s.get_serverid()
108warner@lothar.com**20110227011203
109 Ignore-this: f80a787953bd7fa3d40e828bde00e855
110]
111[web: remove some uses of s.get_serverid(), not all
112warner@lothar.com**20110227011159
113 Ignore-this: a9347d9cf6436537a47edc6efde9f8be
114]
115[immutable/downloader/fetcher.py: remove all get_serverid() calls
116warner@lothar.com**20110227011156
117 Ignore-this: fb5ef018ade1749348b546ec24f7f09a
118]
119[immutable/downloader/fetcher.py: fix diversity bug in server-response handling
120warner@lothar.com**20110227011153
121 Ignore-this: bcd62232c9159371ae8a16ff63d22c1b
122 
123 When blocks terminate (either COMPLETE or CORRUPT/DEAD/BADSEGNUM), the
124 _shares_from_server dict was being popped incorrectly (using shnum as the
125 index instead of serverid). I'm still thinking through the consequences of
126 this bug. It was probably benign and really hard to detect. I think it would
127 cause us to incorrectly believe that we're pulling too many shares from a
128 server, and thus prefer a different server rather than asking for a second
129 share from the first server. The diversity code is intended to spread out the
130 number of shares simultaneously being requested from each server, but with
131 this bug, it might be spreading out the total number of shares requested at
132 all, not just simultaneously. (note that SegmentFetcher is scoped to a single
133 segment, so the effect doesn't last very long).
134]
135[immutable/downloader/share.py: reduce get_serverid(), one left, update ext deps
136warner@lothar.com**20110227011150
137 Ignore-this: d8d56dd8e7b280792b40105e13664554
138 
139 test_download.py: create+check MyShare instances better, make sure they share
140 Server objects, now that finder.py cares
141]
142[immutable/downloader/finder.py: reduce use of get_serverid(), one left
143warner@lothar.com**20110227011146
144 Ignore-this: 5785be173b491ae8a78faf5142892020
145]
146[immutable/offloaded.py: reduce use of get_serverid() a bit more
147warner@lothar.com**20110227011142
148 Ignore-this: b48acc1b2ae1b311da7f3ba4ffba38f
149]
150[immutable/upload.py: reduce use of get_serverid()
151warner@lothar.com**20110227011138
152 Ignore-this: ffdd7ff32bca890782119a6e9f1495f6
153]
154[immutable/checker.py: remove some uses of s.get_serverid(), not all
155warner@lothar.com**20110227011134
156 Ignore-this: e480a37efa9e94e8016d826c492f626e
157]
158[add remaining get_* methods to storage_client.Server, NoNetworkServer, and
159warner@lothar.com**20110227011132
160 Ignore-this: 6078279ddf42b179996a4b53bee8c421
161 MockIServer stubs
162]
163[upload.py: rearrange _make_trackers a bit, no behavior changes
164warner@lothar.com**20110227011128
165 Ignore-this: 296d4819e2af452b107177aef6ebb40f
166]
167[happinessutil.py: finally rename merge_peers to merge_servers
168warner@lothar.com**20110227011124
169 Ignore-this: c8cd381fea1dd888899cb71e4f86de6e
170]
171[test_upload.py: factor out FakeServerTracker
172warner@lothar.com**20110227011120
173 Ignore-this: 6c182cba90e908221099472cc159325b
174]
175[test_upload.py: server-vs-tracker cleanup
176warner@lothar.com**20110227011115
177 Ignore-this: 2915133be1a3ba456e8603885437e03
178]
179[happinessutil.py: server-vs-tracker cleanup
180warner@lothar.com**20110227011111
181 Ignore-this: b856c84033562d7d718cae7cb01085a9
182]
183[upload.py: more tracker-vs-server cleanup
184warner@lothar.com**20110227011107
185 Ignore-this: bb75ed2afef55e47c085b35def2de315
186]
187[upload.py: fix var names to avoid confusion between 'trackers' and 'servers'
188warner@lothar.com**20110227011103
189 Ignore-this: 5d5e3415b7d2732d92f42413c25d205d
190]
191[refactor: s/peer/server/ in immutable/upload, happinessutil.py, test_upload
192warner@lothar.com**20110227011100
193 Ignore-this: 7ea858755cbe5896ac212a925840fe68
194 
195 No behavioral changes, just updating variable/method names and log messages.
196 The effects outside these three files should be minimal: some exception
197 messages changed (to say "server" instead of "peer"), and some internal class
198 names were changed. A few things still use "peer" to minimize external
199 changes, like UploadResults.timings["peer_selection"] and
200 happinessutil.merge_peers, which can be changed later.
201]
202[storage_client.py: clean up test_add_server/test_add_descriptor, remove .test_servers
203warner@lothar.com**20110227011056
204 Ignore-this: efad933e78179d3d5fdcd6d1ef2b19cc
205]
206[test_client.py, upload.py:: remove KiB/MiB/etc constants, and other dead code
207warner@lothar.com**20110227011051
208 Ignore-this: dc83c5794c2afc4f81e592f689c0dc2d
209]
210[test: increase timeout on a network test because Francois's ARM machine hit that timeout
211zooko@zooko.com**20110317165909
212 Ignore-this: 380c345cdcbd196268ca5b65664ac85b
213 I'm skeptical that the test was proceeding correctly but ran out of time. It seems more likely that it had gotten hung. But if we raise the timeout to an even more extravagant number then we can be even more certain that the test was never going to finish.
214]
215[docs/configuration.rst: add a "Frontend Configuration" section
216Brian Warner <warner@lothar.com>**20110222014323
217 Ignore-this: 657018aa501fe4f0efef9851628444ca
218 
219 this points to docs/frontends/*.rst, which were previously underlinked
220]
221[web/filenode.py: avoid calling req.finish() on closed HTTP connections. Closes #1366
222"Brian Warner <warner@lothar.com>"**20110221061544
223 Ignore-this: 799d4de19933f2309b3c0c19a63bb888
224]
225[Add unit tests for cross_check_pkg_resources_versus_import, and a regression test for ref #1355. This requires a little refactoring to make it testable.
226david-sarah@jacaranda.org**20110221015817
227 Ignore-this: 51d181698f8c20d3aca58b057e9c475a
228]
229[allmydata/__init__.py: .name was used in place of the correct .__name__ when printing an exception. Also, robustify string formatting by using %r instead of %s in some places. fixes #1355.
230david-sarah@jacaranda.org**20110221020125
231 Ignore-this: b0744ed58f161bf188e037bad077fc48
232]
233[Refactor StorageFarmBroker handling of servers
234Brian Warner <warner@lothar.com>**20110221015804
235 Ignore-this: 842144ed92f5717699b8f580eab32a51
236 
237 Pass around IServer instance instead of (peerid, rref) tuple. Replace
238 "descriptor" with "server". Other replacements:
239 
240  get_all_servers -> get_connected_servers/get_known_servers
241  get_servers_for_index -> get_servers_for_psi (now returns IServers)
242 
243 This change still needs to be pushed further down: lots of code is now
244 getting the IServer and then distributing (peerid, rref) internally.
245 Instead, it ought to distribute the IServer internally and delay
246 extracting a serverid or rref until the last moment.
247 
248 no_network.py was updated to retain parallelism.
249]
250[TAG allmydata-tahoe-1.8.2
251warner@lothar.com**20110131020101]
252Patch bundle hash:
253265085ccd8e83abeece5024a05a2384aaf84935c