Merge lp:~fourdollars/ubuntu/vivid/python-debianbts/1512200 into lp:ubuntu/vivid/python-debianbts

Proposed by Shih-Yuan Lee on 2015-11-02
Status: Merged
Merge reported by: Sebastien Bacher
Merged at revision: not available
Proposed branch: lp:~fourdollars/ubuntu/vivid/python-debianbts/1512200
Merge into: lp:ubuntu/vivid/python-debianbts
Diff against target: 132 lines (+50/-14)
4 files modified
debian/changelog (+6/-0)
debian/control (+3/-2)
src/debianbts.py (+27/-12)
test/test_debianbts.py (+14/-0)
To merge this branch: bzr merge lp:~fourdollars/ubuntu/vivid/python-debianbts/1512200
Reviewer Review Type Date Requested Status
Sebastien Bacher 2015-11-02 Approve on 2015-11-10
Review via email: mp+276359@code.launchpad.net

Description of the change

This patch is from https://github.com/venthur/python-debianbts/pull/5/files.
Please help to sponsor this patch.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2014-07-07 14:50:29 +0000
3+++ debian/changelog 2015-11-02 06:35:16 +0000
4@@ -1,3 +1,9 @@
5+python-debianbts (1.12ubuntu0.1) vivid-proposed; urgency=medium
6+
7+ * Fix the crashes on BTS query. (LP: #1512200)
8+
9+ -- Shih-Yuan Lee (FourDollars) <sylee@canonical.com> Mon, 02 Nov 2015 13:27:45 +0800
10+
11 python-debianbts (1.12) unstable; urgency=medium
12
13 * Added HTTP_PROXY support by applying the patch from Raphael Kubo da Costa,
14
15=== modified file 'debian/control'
16--- debian/control 2012-04-16 10:40:08 +0000
17+++ debian/control 2015-11-02 06:35:16 +0000
18@@ -1,8 +1,9 @@
19 Source: python-debianbts
20 Section: python
21 Priority: optional
22-Maintainer: Bastian Venthur <venthur@debian.org>
23-Build-Depends: debhelper (>= 9), python-support (>= 0.6), python
24+Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
25+XSBC-Original-Maintainer: Bastian Venthur <venthur@debian.org>
26+Build-Depends: debhelper (>= 9), python-support (>= 0.6), python, python-mock
27 Standards-Version: 3.9.3.1
28 Vcs-Git: git://github.com/venthur/python-debianbts.git
29 Vcs-Browser: http://github.com/venthur/python-debianbts
30
31=== modified file 'src/debianbts.py'
32--- src/debianbts.py 2014-07-07 14:50:29 +0000
33+++ src/debianbts.py 2015-11-02 06:35:16 +0000
34@@ -27,17 +27,24 @@
35
36
37 from datetime import datetime
38+import os
39 import urllib
40 import urlparse
41
42 import SOAPpy
43
44+# Support running from Debian infrastructure
45+ca_path = '/etc/ssl/ca-debian'
46+if os.path.isdir(ca_path):
47+ os.environ['SSL_CERT_DIR'] = ca_path
48
49 # Setup the soap server
50 # Default values
51-URL = 'http://bugs.debian.org/cgi-bin/soap.cgi'
52+URL = 'https://bugs.debian.org/cgi-bin/soap.cgi'
53 NS = 'Debbugs/SOAP/V1'
54-BTS_URL = 'http://bugs.debian.org/'
55+BTS_URL = 'https://bugs.debian.org/'
56+# Max number of bugs to send in a single get_status request
57+BATCH_SIZE = 500
58
59
60 def _get_http_proxy():
61@@ -174,20 +181,28 @@
62 return val
63
64
65-def get_status(*nr):
66+def get_status(*nrs):
67 """Returns a list of Bugreport objects."""
68- reply = server.get_status(*nr)
69 # If we called get_status with one single bug, we get a single bug,
70 # if we called it with a list of bugs, we get a list,
71- # No available bugreports returns an enmpy list
72+ # No available bugreports returns an empty list
73 bugs = []
74- if not reply:
75- pass
76- elif type(reply[0]) == type([]):
77- for elem in reply[0]:
78- bugs.append(_parse_status(elem))
79- else:
80- bugs.append(_parse_status(reply[0]))
81+ def parse(n):
82+ if not n:
83+ return []
84+ elif type(reply[0]) == type([]):
85+ return [_parse_status(elem) for elem in reply[0]]
86+ else:
87+ return [_parse_status(reply[0])]
88+ # Process the input in batches to avoid hitting resource limits on the BTS
89+ for nr in nrs:
90+ if isinstance(nr, list):
91+ for i in range(0, len(nr), BATCH_SIZE):
92+ reply = server.get_status(nr[i:i+BATCH_SIZE])
93+ bugs.extend(parse(reply))
94+ else:
95+ reply = server.get_status(nr)
96+ bugs.extend(parse(reply))
97 return bugs
98
99
100
101=== modified file 'test/test_debianbts.py'
102--- test/test_debianbts.py 2014-07-07 14:50:29 +0000
103+++ test/test_debianbts.py 2015-11-02 06:35:16 +0000
104@@ -18,7 +18,12 @@
105 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
106
107
108+import math
109 import unittest
110+try:
111+ import unittest.mock as mock
112+except ImportError:
113+ import mock
114
115 import debianbts as bts
116
117@@ -83,6 +88,15 @@
118 self.assertEqual(type(i["header"]), type(unicode()))
119 self.assertTrue(i.has_key("msg_num"))
120 self.assertEqual(type(i["msg_num"]), type(int()))
121+
122+ def testStatusBatchesLargeBugCounts(self):
123+ """get_status should perform requests in batches to reduce server load."""
124+ with mock.patch.object(bts.server, 'get_status') as MockStatus:
125+ MockStatus.return_value = None
126+ nr = bts.BATCH_SIZE + 10.0
127+ calls = int(math.ceil(nr / bts.BATCH_SIZE))
128+ bts.get_status([722226] * int(nr))
129+ self.assertEqual(MockStatus.call_count, calls)
130
131 def testComparison(self):
132 self.b1.archived = True

Subscribers

People subscribed via source and target branches

to all changes: