Merge lp:~dobey/ubuntu/precise/ubuntuone-dev-tools/release-2-99-2 into lp:ubuntu/precise/ubuntuone-dev-tools
- Precise (12.04)
- release-2-99-2
- Merge into precise
Proposed by
dobey
Status: | Merged |
---|---|
Merged at revision: | 8 |
Proposed branch: | lp:~dobey/ubuntu/precise/ubuntuone-dev-tools/release-2-99-2 |
Merge into: | lp:ubuntu/precise/ubuntuone-dev-tools |
Diff against target: |
698 lines (+514/-35) 13 files modified
PKG-INFO (+1/-1) data/squid.conf.in (+120/-0) debian/changelog (+9/-0) debian/copyright (+2/-2) debian/rules (+1/-1) debian/ubuntuone-dev-tools.install (+2/-1) run-tests (+1/-1) setup.py (+13/-5) ubuntuone/devtools/services/__init__.py (+53/-0) ubuntuone/devtools/services/dbus.py (+8/-23) ubuntuone/devtools/services/squid.py (+245/-0) ubuntuone/devtools/testcases/dbus.py (+1/-1) ubuntuone/devtools/testcases/squid.py (+58/-0) |
To merge this branch: | bzr merge lp:~dobey/ubuntu/precise/ubuntuone-dev-tools/release-2-99-2 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Martin Pitt | Approve | ||
Andrew Starr-Bochicchio (community) | Needs Fixing | ||
Review via email: mp+88959@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Charlie_Smotherman (cjsmo) wrote : | # |
Revision history for this message
dobey (dobey) wrote : | # |
Charlie, I have fixed these issues now. Thanks.
Revision history for this message
Andrew Starr-Bochicchio (andrewsomething) wrote : | # |
You introduced a typo in debian/rules:
dh #@ --with python2
Which of course comments out every thing after "dh" It should be:
dh $@ --with python2
review:
Needs Fixing
Revision history for this message
dobey (dobey) wrote : | # |
So I did. Sorry about that. Fixed now.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'PKG-INFO' |
2 | --- PKG-INFO 2012-01-04 17:55:14 +0000 |
3 | +++ PKG-INFO 2012-01-21 19:50:29 +0000 |
4 | @@ -1,6 +1,6 @@ |
5 | Metadata-Version: 1.0 |
6 | Name: ubuntuone-dev-tools |
7 | -Version: 2.99.1 |
8 | +Version: 2.99.2 |
9 | Summary: Ubuntu One development tools and utilities |
10 | Home-page: http://launchpad.net/ubuntuone-dev-tools |
11 | Author: UNKNOWN |
12 | |
13 | === added file 'data/squid.conf.in' |
14 | --- data/squid.conf.in 1970-01-01 00:00:00 +0000 |
15 | +++ data/squid.conf.in 2012-01-21 19:50:29 +0000 |
16 | @@ -0,0 +1,120 @@ |
17 | +auth_param basic casesensitive on |
18 | +# Use a default auth using ncsa and the passed generated file. |
19 | +auth_param basic program ${auth_process} ${auth_file} |
20 | +#Recommended minimum configuration: |
21 | +acl manager proto cache_object |
22 | +acl localhost src 127.0.0.1/32 |
23 | +acl to_localhost dst 127.0.0.0/32 |
24 | +# |
25 | +# Example rule allowing access from your local networks. |
26 | +# Adapt to list your (internal) IP networks from where browsing |
27 | +# should be allowed |
28 | +acl all src all |
29 | +acl localnet src 10.0.0.0/8 # RFC1918 possible internal network |
30 | +acl localnet src 172.16.0.0/12 # RFC1918 possible internal network |
31 | +acl localnet src 192.168.0.0/16 # RFC1918 possible internal network |
32 | +# |
33 | +acl SSL_ports port 443 # https |
34 | +acl SSL_ports port 563 # snews |
35 | +acl SSL_ports port 873 # rsync |
36 | +acl Safe_ports port 80 # http |
37 | +acl Safe_ports port 21 # ftp |
38 | +acl Safe_ports port 443 # https |
39 | +acl Safe_ports port 70 # gopher |
40 | +acl Safe_ports port 210 # wais |
41 | +acl Safe_ports port 1025-65535 # unregistered ports |
42 | +acl Safe_ports port 280 # http-mgmt |
43 | +acl Safe_ports port 488 # gss-http |
44 | +acl Safe_ports port 591 # filemaker |
45 | +acl Safe_ports port 777 # multiling http |
46 | +acl Safe_ports port 631 # cups |
47 | +acl Safe_ports port 873 # rsync |
48 | +acl Safe_ports port 901 # SWAT |
49 | +acl purge method PURGE |
50 | +acl CONNECT method CONNECT |
51 | + |
52 | +# make an acl for users that have auth |
53 | +acl password proxy_auth REQUIRED myportname ${auth_port_number} |
54 | +acl auth_port_connected myportname ${auth_port_number} |
55 | +acl nonauth_port_connected myportname ${noauth_port_number} |
56 | + |
57 | +# Settings used for the tests: |
58 | +# Allow users connected to the nonauth port |
59 | +# Allow users authenticated AND connected to the auth port |
60 | +http_access allow nonauth_port_connected |
61 | +http_access allow password |
62 | + |
63 | +#Recommended minimum configuration: |
64 | +# |
65 | +# Only allow cachemgr access from localhost |
66 | +http_access allow manager localhost |
67 | +http_access deny manager |
68 | +# Only allow purge requests from localhost |
69 | +http_access allow purge localhost |
70 | +http_access deny purge |
71 | +# Deny requests to unknown ports |
72 | +http_access deny !Safe_ports |
73 | +# Deny CONNECT to other than SSL ports |
74 | +http_access deny CONNECT !SSL_ports |
75 | +# Example rule allowing access from your local networks. |
76 | +# Adapt localnet in the ACL section to list your (internal) IP networks |
77 | +# from where browsing should be allowed |
78 | +#http_access allow localnet |
79 | +http_access allow localhost |
80 | + |
81 | +# And finally deny all other access to this proxy |
82 | +http_access deny all |
83 | + |
84 | +icp_access allow localnet |
85 | +icp_access deny all |
86 | + |
87 | +# Squid normally listens to port 3128 but we are going to listento two |
88 | +# different ports, one for auth one for nonauth. |
89 | +http_port ${noauth_port_number} |
90 | +http_port ${auth_port_number} |
91 | + |
92 | +#We recommend you to use at least the following line. |
93 | +hierarchy_stoplist cgi-bin ? |
94 | + |
95 | +# Default cache settings. |
96 | +cache_dir ufs ${spool_temp} 1000 16 256 |
97 | + |
98 | +# access log settings |
99 | +access_log ${squid_temp}/access.log squid |
100 | + |
101 | +# cache log settings |
102 | +cache_log ${squid_temp}/cache.log |
103 | + |
104 | +# cache store log settings |
105 | +cache_store_log ${squid_temp}/store.log |
106 | + |
107 | +# mime table conf |
108 | +# mime_table /usr/share/squid/mime.conf |
109 | + |
110 | +#Default pid file name |
111 | +pid_filename ${squid_temp}/squid.pid |
112 | + |
113 | +# debug options (Full debugging) |
114 | +debug_options ALL,1 |
115 | + |
116 | +#Default netdb_filename |
117 | + |
118 | +#Suggested default: |
119 | +refresh_pattern ^ftp: 1440 20% 10080 |
120 | +refresh_pattern ^gopher: 1440 0% 1440 |
121 | +refresh_pattern -i (/cgi-bin/|\?) 0 0% 0 |
122 | +refresh_pattern (Release|Packages(.gz)*)$ 0 20% 2880 |
123 | +# example line deb packages |
124 | +refresh_pattern . 0 20% 4320 |
125 | + |
126 | +# Don't upgrade ShoutCast responses to HTTP |
127 | +acl shoutcast rep_header X-HTTP09-First-Line ^ICY.[0-9] |
128 | + |
129 | +# Apache mod_gzip and mod_deflate known to be broken so don't trust |
130 | +# Apache to signal ETag correctly on such responses |
131 | +acl apache rep_header Server ^Apache |
132 | + |
133 | +hosts_file /etc/hosts |
134 | + |
135 | +# Leave coredumps in the first cache dir |
136 | +coredump_dir ${spool_temp}/squid |
137 | |
138 | === modified file 'debian/changelog' |
139 | --- debian/changelog 2012-01-04 20:59:13 +0000 |
140 | +++ debian/changelog 2012-01-21 19:50:29 +0000 |
141 | @@ -1,3 +1,12 @@ |
142 | +ubuntuone-dev-tools (2.99.2-0ubuntu1) precise; urgency=low |
143 | + |
144 | + * New upstream release. |
145 | + - Provide SquidTestCase for testing proxy support. (LP: #884963) |
146 | + - Provide batch scripts for u1trial and u1lint on Windows. (LP: #816020) |
147 | + * Fix a few lintian warnings and dh argument ordering. |
148 | + |
149 | + -- Rodney Dawes <rodney.dawes@ubuntu.com> Fri, 20 Jan 2012 17:02:51 -0500 |
150 | + |
151 | ubuntuone-dev-tools (2.99.1-0ubuntu1) precise; urgency=low |
152 | |
153 | * New upstream release. |
154 | |
155 | === modified file 'debian/copyright' |
156 | --- debian/copyright 2010-08-02 13:45:54 +0000 |
157 | +++ debian/copyright 2012-01-21 19:50:29 +0000 |
158 | @@ -1,7 +1,7 @@ |
159 | -Format-Specification: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn |
160 | +Format: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn |
161 | |
162 | Files: * |
163 | -Copyright: 2009-2010 Canonical Ltd. |
164 | +Copyright: 2009-2012 Canonical Ltd. |
165 | License: GPL-3 |
166 | This program is free software: you can redistribute it and/or modify it |
167 | under the terms of the GNU General Public License version 3, as published |
168 | |
169 | === modified file 'debian/rules' |
170 | --- debian/rules 2011-12-22 21:33:15 +0000 |
171 | +++ debian/rules 2012-01-21 19:50:29 +0000 |
172 | @@ -1,7 +1,7 @@ |
173 | #!/usr/bin/make -f |
174 | |
175 | %: |
176 | - dh --with python2 $@ |
177 | + dh $@ --with python2 |
178 | |
179 | override_dh_auto_test: |
180 | ./run-tests |
181 | |
182 | === modified file 'debian/ubuntuone-dev-tools.install' |
183 | --- debian/ubuntuone-dev-tools.install 2010-08-02 13:45:54 +0000 |
184 | +++ debian/ubuntuone-dev-tools.install 2012-01-21 19:50:29 +0000 |
185 | @@ -1,3 +1,4 @@ |
186 | usr/bin |
187 | usr/share/ubuntuone-dev-tools |
188 | -usr/share/man/man1/{u1lint,u1trial}.* |
189 | +usr/share/man |
190 | + |
191 | |
192 | === modified file 'run-tests' |
193 | --- run-tests 2011-12-22 21:20:09 +0000 |
194 | +++ run-tests 2012-01-21 19:50:29 +0000 |
195 | @@ -20,6 +20,6 @@ |
196 | bin/u1trial --reactor=twisted ubuntuone |
197 | echo "Running style checks..." |
198 | bin/u1lint |
199 | -pep8 --repeat . bin/* |
200 | +pep8 --repeat . bin/* --exclude=*.bat |
201 | rm -rf _trial_temp |
202 | rm -rf .coverage |
203 | |
204 | === modified file 'setup.py' |
205 | --- setup.py 2012-01-04 17:55:14 +0000 |
206 | +++ setup.py 2012-01-21 19:50:29 +0000 |
207 | @@ -21,7 +21,7 @@ |
208 | from distutils.core import setup, Command |
209 | |
210 | PACKAGE = 'ubuntuone-dev-tools' |
211 | -VERSION = '2.99.1' |
212 | +VERSION = '2.99.2' |
213 | |
214 | U1LINT = 'bin/u1lint' |
215 | |
216 | @@ -44,6 +44,15 @@ |
217 | if retcode != 0: |
218 | sys.exit(retcode) |
219 | |
220 | +# pylint: disable=C0103 |
221 | +scripts = ['bin/u1lint', |
222 | + 'bin/u1trial'] |
223 | +# pylint: enable=C0103 |
224 | + |
225 | +if sys.platform == 'win32': |
226 | + # lets add the .bat so that windows users are happy |
227 | + scripts.extend(['bin/u1lint.bat', 'bin/u1trial.bat']) |
228 | + |
229 | setup(name=PACKAGE, |
230 | version=VERSION, |
231 | description='Ubuntu One development tools and utilities', |
232 | @@ -55,12 +64,11 @@ |
233 | 'ubuntuone.devtools.testing', |
234 | 'ubuntuone.devtools.testcases'], |
235 | extra_path='ubuntuone-dev-tools', |
236 | - scripts=['bin/u1lint', |
237 | - 'bin/u1trial', |
238 | - ], |
239 | + scripts=scripts, |
240 | data_files=[('share/%s' % PACKAGE, |
241 | ['pylintrc', |
242 | - 'data/dbus-session.conf.in']), |
243 | + 'data/dbus-session.conf.in', |
244 | + 'data/squid.conf.in']), |
245 | ('share/man/man1', |
246 | ['man/u1lint.1', |
247 | 'man/u1trial.1']), |
248 | |
249 | === modified file 'ubuntuone/devtools/services/__init__.py' |
250 | --- ubuntuone/devtools/services/__init__.py 2010-11-29 18:43:05 +0000 |
251 | +++ ubuntuone/devtools/services/__init__.py 2012-01-21 19:50:29 +0000 |
252 | @@ -1,1 +1,54 @@ |
253 | +# |
254 | +# Copyright 2011 Canonical Ltd. |
255 | +# |
256 | +# This program is free software: you can redistribute it and/or modify it |
257 | +# under the terms of the GNU General Public License version 3, as published |
258 | +# by the Free Software Foundation. |
259 | +# |
260 | +# This program is distributed in the hope that it will be useful, but |
261 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
262 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
263 | +# PURPOSE. See the GNU General Public License for more details. |
264 | +# |
265 | +# You should have received a copy of the GNU General Public License along |
266 | +# with this program. If not, see <http://www.gnu.org/licenses/>. |
267 | """Service runners for testing.""" |
268 | + |
269 | +import os |
270 | +import socket |
271 | + |
272 | +from dirspec.basedir import load_data_paths |
273 | + |
274 | + |
275 | +def find_config_file(in_config_file): |
276 | + """Find the first appropriate conf to use.""" |
277 | + # In case we're running from within the source tree |
278 | + path = os.path.abspath(os.path.join(os.path.dirname(__file__), |
279 | + os.path.pardir, os.path.pardir, |
280 | + os.path.pardir, |
281 | + "data", in_config_file)) |
282 | + if not os.path.exists(path): |
283 | + # Use the installed file in $pkgdatadir as source |
284 | + for path in load_data_paths("ubuntuone-dev-tools", |
285 | + in_config_file): |
286 | + if os.path.exists(path): |
287 | + break |
288 | + |
289 | + # Check to make sure we didn't just fall out of the loop |
290 | + if not os.path.exists(path): |
291 | + raise IOError('Could not locate suitable %s' % in_config_file) |
292 | + return path |
293 | + |
294 | + |
295 | +def get_arbitrary_port(): |
296 | + """ |
297 | + Find an unused port, and return it. |
298 | + |
299 | + There might be a small race condition here, but we aren't |
300 | + worried about it. |
301 | + """ |
302 | + sock = socket.socket() |
303 | + sock.bind(('localhost', 0)) |
304 | + _, port = sock.getsockname() |
305 | + sock.close() |
306 | + return port |
307 | |
308 | === modified file 'ubuntuone/devtools/services/dbus.py' |
309 | --- ubuntuone/devtools/services/dbus.py 2011-12-22 21:20:09 +0000 |
310 | +++ ubuntuone/devtools/services/dbus.py 2012-01-21 19:50:29 +0000 |
311 | @@ -20,10 +20,12 @@ |
312 | import signal |
313 | import subprocess |
314 | |
315 | -from dirspec.basedir import load_data_paths |
316 | from distutils.spawn import find_executable |
317 | from urllib import quote |
318 | |
319 | +from ubuntuone.devtools.services import find_config_file |
320 | +DBUS_CONFIG_FILE = 'dbus-session.conf.in' |
321 | + |
322 | |
323 | class DBusLaunchError(Exception): |
324 | """Error while launching dbus-daemon""" |
325 | @@ -44,42 +46,25 @@ |
326 | self.running = False |
327 | self.config_file = None |
328 | |
329 | - def _find_config_file(self, tempdir=None): |
330 | + def _generate_config_file(self, tempdir=None): |
331 | """Find the first appropriate dbus-session.conf to use.""" |
332 | - # In case we're running from within the source tree |
333 | - path = os.path.abspath(os.path.join(os.path.dirname(__file__), |
334 | - os.path.pardir, os.path.pardir, |
335 | - os.path.pardir, |
336 | - "data", "dbus-session.conf.in")) |
337 | - if not os.path.exists(path): |
338 | - # Use the installed file in $pkgdatadir as source |
339 | - for path in load_data_paths("ubuntuone-dev-tools", |
340 | - "dbus-session.conf.in"): |
341 | - if os.path.exists(path): |
342 | - break |
343 | - |
344 | - # Check to make sure we didn't just fall out of the loop |
345 | - if not os.path.exists(path): |
346 | - raise IOError('Could not locate suitable dbus-session.conf.in') |
347 | - |
348 | + # load the config file |
349 | + path = find_config_file(DBUS_CONFIG_FILE) |
350 | + # replace config settings |
351 | self.config_file = os.path.join(tempdir, 'dbus-session.conf') |
352 | dbus_address = 'unix:tmpdir=%s' % quote(tempdir) |
353 | with open(path) as in_file: |
354 | content = in_file.read() |
355 | with open(self.config_file, 'w') as out_file: |
356 | out_file.write(content.replace('@ADDRESS@', dbus_address)) |
357 | - out_file.close() |
358 | - in_file.close() |
359 | |
360 | def start_service(self, tempdir=None): |
361 | """Start our own session bus daemon for testing.""" |
362 | - if not tempdir: |
363 | - tempdir = os.path.join(os.getcwd(), '_trial_temp') |
364 | dbus = find_executable("dbus-daemon") |
365 | if not dbus: |
366 | raise NotFoundError("dbus-daemon was not found.") |
367 | |
368 | - self._find_config_file(tempdir) |
369 | + self._generate_config_file(tempdir) |
370 | |
371 | dbus_args = ["--fork", |
372 | "--config-file=" + self.config_file, |
373 | |
374 | === added file 'ubuntuone/devtools/services/squid.py' |
375 | --- ubuntuone/devtools/services/squid.py 1970-01-01 00:00:00 +0000 |
376 | +++ ubuntuone/devtools/services/squid.py 2012-01-21 19:50:29 +0000 |
377 | @@ -0,0 +1,245 @@ |
378 | +# |
379 | +# Copyright 2011 Canonical Ltd. |
380 | +# |
381 | +# This program is free software: you can redistribute it and/or modify it |
382 | +# under the terms of the GNU General Public License version 3, as published |
383 | +# by the Free Software Foundation. |
384 | +# |
385 | +# This program is distributed in the hope that it will be useful, but |
386 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
387 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
388 | +# PURPOSE. See the GNU General Public License for more details. |
389 | +# |
390 | +# You should have received a copy of the GNU General Public License along |
391 | +# with this program. If not, see <http://www.gnu.org/licenses/>. |
392 | +"""Utilities for finding and running a squid proxy for testing.""" |
393 | + |
394 | +import random |
395 | +import signal |
396 | +# pylint:disable=W0402 |
397 | +import string |
398 | +# pylint:enable=W0402 |
399 | +import subprocess |
400 | +import time |
401 | + |
402 | +from json import dumps, loads |
403 | +from os import environ, makedirs, kill, unlink |
404 | +from os.path import abspath, exists, join |
405 | + |
406 | +from distutils.spawn import find_executable |
407 | + |
408 | +from ubuntuone.devtools.services import ( |
409 | + find_config_file, |
410 | + get_arbitrary_port, |
411 | +) |
412 | + |
413 | +SQUID_CONFIG_FILE = 'squid.conf.in' |
414 | +SQUID_DIR = 'squid' |
415 | +AUTH_PROCESS_PATH = '/usr/lib/%s/ncsa_auth' |
416 | +SPOOL_DIR = 'spool' |
417 | +AUTH_FILE = 'htpasswd' |
418 | +PROXY_ENV_VAR = 'SQUID_PROXY_SETTINGS' |
419 | + |
420 | + |
421 | +def get_squid_executable(): |
422 | + """Return the squid executable of the system.""" |
423 | + # try with squid and if not present try with squid3 for newer systems |
424 | + # (Ubuntu P). We also return the path to the auth process so that we can |
425 | + # point to the correct one. |
426 | + squid = find_executable('squid3') |
427 | + auth_process = AUTH_PROCESS_PATH % 'squid3' |
428 | + if squid is None: |
429 | + squid = find_executable('squid') |
430 | + auth_process = AUTH_PROCESS_PATH % 'squid' |
431 | + return squid, auth_process |
432 | + |
433 | + |
434 | +def get_htpasswd_executable(): |
435 | + """Return the htpasswd executable.""" |
436 | + return find_executable('htpasswd') |
437 | + |
438 | + |
439 | +def _make_random_string(count): |
440 | + """Make a random string of the given length.""" |
441 | + entropy = random.SystemRandom() |
442 | + return ''.join([entropy.choice(string.letters) for _ in |
443 | + range(count)]) |
444 | + |
445 | + |
446 | +def _get_basedir(tempdir): |
447 | + """Return the base squid config.""" |
448 | + basedir = join(tempdir, SQUID_DIR) |
449 | + basedir = abspath(basedir) |
450 | + if not exists(basedir): |
451 | + makedirs(basedir) |
452 | + return basedir |
453 | + |
454 | + |
455 | +def _get_spool_temp_path(tempdir=''): |
456 | + """Return the temp dir to be used for spool.""" |
457 | + basedir = _get_basedir(tempdir) |
458 | + path = join(basedir, SPOOL_DIR) |
459 | + path = abspath(path) |
460 | + if not exists(path): |
461 | + makedirs(path) |
462 | + return path |
463 | + |
464 | + |
465 | +def _get_squid_temp_path(tempdir=''): |
466 | + """Return the temp dir to be used by squid.""" |
467 | + basedir = _get_basedir(tempdir) |
468 | + path = join(basedir, SQUID_DIR) |
469 | + path = abspath(path) |
470 | + if not exists(path): |
471 | + makedirs(path) |
472 | + return path |
473 | + |
474 | + |
475 | +def _get_auth_temp_path(tempdir=''): |
476 | + """Return the path for the auth file.""" |
477 | + basedir = _get_basedir(tempdir) |
478 | + auth_file = join(basedir, AUTH_FILE) |
479 | + if not exists(basedir): |
480 | + makedirs(basedir) |
481 | + return auth_file |
482 | + |
483 | + |
484 | +def store_proxy_settings(settings): |
485 | + """Store the proxy setting in an env var.""" |
486 | + environ[PROXY_ENV_VAR] = dumps(settings) |
487 | + |
488 | + |
489 | +def retrieve_proxy_settings(): |
490 | + """Return the proxy settings of the env.""" |
491 | + if PROXY_ENV_VAR in environ: |
492 | + return loads(environ[PROXY_ENV_VAR]) |
493 | + return None |
494 | + |
495 | + |
496 | +def delete_proxy_settings(): |
497 | + """Delete the proxy env settings.""" |
498 | + if PROXY_ENV_VAR in environ: |
499 | + del environ[PROXY_ENV_VAR] |
500 | + |
501 | + |
502 | +class SquidLaunchError(Exception): |
503 | + """Error while launching squid.""" |
504 | + |
505 | + |
506 | +class SquidRunner(object): |
507 | + """Class for running a squid proxy with the local config.""" |
508 | + |
509 | + def __init__(self): |
510 | + """Create a new instance.""" |
511 | + self.squid, self.auth_process = get_squid_executable() |
512 | + if self.squid is None: |
513 | + raise SquidLaunchError('Could not locate "squid".') |
514 | + |
515 | + self.htpasswd = get_htpasswd_executable() |
516 | + if self.htpasswd is None: |
517 | + raise SquidLaunchError('Could not locate "htpasswd".') |
518 | + |
519 | + self.settings = dict(noauth_port=None, auth_port=None, |
520 | + username=None, password=None) |
521 | + self.squid_pid = None |
522 | + self.running = False |
523 | + self.config_file = None |
524 | + self.auth_file = None |
525 | + |
526 | + def _generate_config_file(self, tempdir=''): |
527 | + """Find the first appropiate squid.conf to use.""" |
528 | + # load the config file |
529 | + path = find_config_file(SQUID_CONFIG_FILE) |
530 | + # replace config settings |
531 | + basedir = join(tempdir, 'squid') |
532 | + basedir = abspath(basedir) |
533 | + if not exists(basedir): |
534 | + makedirs(basedir) |
535 | + self.config_file = join(basedir, 'squid.conf') |
536 | + with open(path) as in_file: |
537 | + template = string.Template(in_file.read()) |
538 | + |
539 | + self.settings['noauth_port'] = get_arbitrary_port() |
540 | + self.settings['auth_port'] = get_arbitrary_port() |
541 | + spool_path = _get_spool_temp_path(tempdir) |
542 | + squid_path = _get_squid_temp_path(tempdir) |
543 | + with open(self.config_file, 'w') as out_file: |
544 | + out_file.write(template.safe_substitute( |
545 | + auth_file=self.auth_file, |
546 | + auth_process=self.auth_process, |
547 | + noauth_port_number=self.settings['noauth_port'], |
548 | + auth_port_number=self.settings['auth_port'], |
549 | + spool_temp=spool_path, |
550 | + squid_temp=squid_path)) |
551 | + |
552 | + def _generate_swap(self, config_file): |
553 | + """Generate the squid swap files.""" |
554 | + squid_args = ['-z', '-f', config_file] |
555 | + sp = subprocess.Popen([self.squid] + squid_args, |
556 | + stdout=subprocess.PIPE, |
557 | + stderr=subprocess.PIPE) |
558 | + sp.wait() |
559 | + |
560 | + def _generate_auth_file(self, tempdir=''): |
561 | + """Generates a auth file using htpasswd.""" |
562 | + if self.settings['username'] is None: |
563 | + self.settings['username'] = _make_random_string(10) |
564 | + if self.settings['password'] is None: |
565 | + self.settings['password'] = _make_random_string(10) |
566 | + |
567 | + self.auth_file = _get_auth_temp_path(tempdir) |
568 | + # remove possible old auth file |
569 | + if exists(self.auth_file): |
570 | + unlink(self.auth_file) |
571 | + # create a new htpasswrd |
572 | + htpasswd_args = ['-bc', |
573 | + self.auth_file, |
574 | + self.settings['username'], |
575 | + self.settings['password']] |
576 | + sp = subprocess.Popen([self.htpasswd] + htpasswd_args, |
577 | + stdout=subprocess.PIPE, |
578 | + stderr=subprocess.PIPE) |
579 | + sp.wait() |
580 | + |
581 | + def _is_squid_running(self): |
582 | + """Return if squid is running.""" |
583 | + squid_args = ['-k', 'check', '-f', self.config_file] |
584 | + print 'Starting squid version...' |
585 | + message = 'Waiting for squid to start...' |
586 | + for timeout in (0.4, 0.1, 0.1, 0.2, 0.5, 1, 3, 5): |
587 | + try: |
588 | + # Do not use stdout=PIPE or stderr=PIPE with this function. |
589 | + subprocess.check_call([self.squid] + squid_args, |
590 | + stdout=subprocess.PIPE, |
591 | + stderr=subprocess.PIPE) |
592 | + return True |
593 | + except subprocess.CalledProcessError: |
594 | + message += '.' |
595 | + print message |
596 | + time.sleep(timeout) |
597 | + return False |
598 | + |
599 | + def start_service(self, tempdir=None): |
600 | + """Start our own proxy.""" |
601 | + # generate auth, config and swap dirs |
602 | + self._generate_auth_file(tempdir) |
603 | + self._generate_config_file(tempdir) |
604 | + self._generate_swap(self.config_file) |
605 | + squid_args = ['-N', '-X', '-f', self.config_file] |
606 | + sp = subprocess.Popen([self.squid] + squid_args, |
607 | + stdout=subprocess.PIPE, |
608 | + stderr=subprocess.PIPE) |
609 | + store_proxy_settings(self.settings) |
610 | + if not self._is_squid_running(): |
611 | + raise SquidLaunchError('Could not start squid.') |
612 | + self.squid_pid = sp.pid |
613 | + self.running = True |
614 | + |
615 | + def stop_service(self): |
616 | + """Stop our proxy,""" |
617 | + kill(self.squid_pid, signal.SIGKILL) |
618 | + delete_proxy_settings() |
619 | + self.running = False |
620 | + unlink(self.config_file) |
621 | + unlink(self.auth_file) |
622 | + self.config_file = None |
623 | |
624 | === modified file 'ubuntuone/devtools/testcases/dbus.py' |
625 | --- ubuntuone/devtools/testcases/dbus.py 2011-12-22 21:20:09 +0000 |
626 | +++ ubuntuone/devtools/testcases/dbus.py 2012-01-21 19:50:29 +0000 |
627 | @@ -14,7 +14,7 @@ |
628 | # You should have received a copy of the GNU General Public License along |
629 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
630 | |
631 | -"""Base tests cases and test utilities.""" |
632 | +"""Base dbus tests cases and test utilities.""" |
633 | |
634 | from __future__ import absolute_import, with_statement |
635 | |
636 | |
637 | === added file 'ubuntuone/devtools/testcases/squid.py' |
638 | --- ubuntuone/devtools/testcases/squid.py 1970-01-01 00:00:00 +0000 |
639 | +++ ubuntuone/devtools/testcases/squid.py 2012-01-21 19:50:29 +0000 |
640 | @@ -0,0 +1,58 @@ |
641 | +# -*- coding: utf-8 -*- |
642 | +# |
643 | +# Copyright 2011 Canonical Ltd. |
644 | +# |
645 | +# This program is free software: you can redistribute it and/or modify it |
646 | +# under the terms of the GNU General Public License version 3, as published |
647 | +# by the Free Software Foundation. |
648 | +# |
649 | +# This program is distributed in the hope that it will be useful, but |
650 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
651 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
652 | +# PURPOSE. See the GNU General Public License for more details. |
653 | +# |
654 | +# You should have received a copy of the GNU General Public License along |
655 | +# with this program. If not, see <http://www.gnu.org/licenses/>. |
656 | + |
657 | +"""Base squid tests cases and test utilities.""" |
658 | + |
659 | +from ubuntuone.devtools.testcase import BaseTestCase, skipIf |
660 | +from ubuntuone.devtools.services.squid import ( |
661 | + SquidRunner, |
662 | + SquidLaunchError, |
663 | + get_squid_executable, |
664 | + get_htpasswd_executable, |
665 | + retrieve_proxy_settings) |
666 | + |
667 | +# pylint: disable=C0103 |
668 | +squid, _ = get_squid_executable() |
669 | +htpasswd = get_htpasswd_executable() |
670 | +# pylint: enable=C0103 |
671 | + |
672 | + |
673 | +@skipIf(squid is None or htpasswd is None, |
674 | + 'The test requires squid and htpasswd.') |
675 | +class SquidTestCase(BaseTestCase): |
676 | + """Test that uses a proxy.""" |
677 | + |
678 | + def required_services(self): |
679 | + """Return the list of required services for DBusTestCase.""" |
680 | + services = super(SquidTestCase, self).required_services() |
681 | + services.extend([SquidRunner]) |
682 | + return services |
683 | + |
684 | + def get_nonauth_proxy_settings(self): |
685 | + """Return the settings of the noneauth proxy.""" |
686 | + settings = retrieve_proxy_settings() |
687 | + if settings is None: |
688 | + raise SquidLaunchError('Proxy is not running.') |
689 | + return dict(host='localhost', port=settings['noauth_port']) |
690 | + |
691 | + def get_auth_proxy_settings(self): |
692 | + """Return the settings of the auth proxy.""" |
693 | + settings = retrieve_proxy_settings() |
694 | + if settings is None: |
695 | + raise SquidLaunchError('Proxy is not running.') |
696 | + return dict(host='localhost', port=settings['auth_port'], |
697 | + username=settings['username'], |
698 | + password=settings['password']) |
Looks good except for a few nit pics.
in debian/rules "dh --with python2 $@" should be "dh $@ --with python2
And some lintian errors that need to be addressed
W: ubuntuone-dev-tools source: brace-expansion -in-debhelper- config- file debian/ ubuntuone- dev-tools. install field-in- dep5-copyright format- specification format Specification. Maintainer. dep.debian. net/deps/ dep5/ for details.
N:
N: This debhelper config file appears to use shell brace expansion (such as
N: {foo,bar}) to specify files. This happens to work due to an accident of
N: implementation but is not a supported feature. Only ?, *, and [...] are
N: supported.
N:
N: Refer to the debhelper(1) manual page for details.
N:
N: Severity: normal, Certainty: possible
N:
N: Check: debhelper, Type: source
N:
W: ubuntuone-dev-tools source: obsolete-
N:
N: The machine-readable copyright file uses a field, that used to be
N: defined by the specification, but has been renamed since then.
N:
N: Please use Format instead of Format-
N:
N: Please use Upstream-Contact instead of Contact, Maintainer or
N: Upstream-
N:
N: Please use Upstream-Name instead of Name.
N:
N: Refer to http://
N:
N: Severity: normal, Certainty: possible
N:
N: Check: source-copyright, Type: source
N: