Merge lp:~mandel/ubuntuone-dev-tools/fix-squid-tests into lp:ubuntuone-dev-tools
- fix-squid-tests
- Merge into trunk
Status: | Merged | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Approved by: | Manuel de la Peña | ||||||||||||||||
Approved revision: | 76 | ||||||||||||||||
Merged at revision: | 70 | ||||||||||||||||
Proposed branch: | lp:~mandel/ubuntuone-dev-tools/fix-squid-tests | ||||||||||||||||
Merge into: | lp:ubuntuone-dev-tools | ||||||||||||||||
Diff against target: |
509 lines (+266/-33) 9 files modified
data/squid.conf.in (+5/-5) run-tests (+2/-2) run-tests.bat (+3/-1) setup.py (+17/-9) ubuntuone/devtools/services/squid.py (+54/-9) ubuntuone/devtools/services/tests/test_squid.py (+9/-6) ubuntuone/devtools/services/tests/test_squid_linux.py (+67/-0) ubuntuone/devtools/services/tests/test_squid_windows.py (+108/-0) ubuntuone/devtools/testcases/tests/test_squid_testcase.py (+1/-1) |
||||||||||||||||
To merge this branch: | bzr merge lp:~mandel/ubuntuone-dev-tools/fix-squid-tests | ||||||||||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
dobey (community) | Approve | ||
Eric Casteleijn (community) | Approve | ||
Review via email: mp+103325@code.launchpad.net |
Commit message
Description of the change
- Ensured that the ncsa_auth.exe can be found on windows (LP: #987213).
- Formatted the path correctly so that the squid config can read them (LP: #987225).
- Use win32api to kill the squid process (LP: #987256)
- Use dirspec to place the data files correctly on windows (LP: #988228).
In order to tests the branch you have to follow these steps:
1- Download and copy to C:\squid the windows squid binaries from here: http://
2- Downlaod the apacache msi and install it: http://
3- Ensure the following is in your path: C:\squid\
All the above will allow you to run the proxy tests on windows.
Note: The path to the apache bins might differ depending on your system.
Eric Casteleijn (thisfred) wrote : | # |
Eric Casteleijn (thisfred) wrote : | # |
Also, what does "source" mean in this context?
Eric Casteleijn (thisfred) wrote : | # |
I would suggest something like "squid_util" or "squid_helpers" instead of source.
Eric Casteleijn (thisfred) wrote : | # |
Looks good otherwise, use your own judgement on the above...
dobey (dobey) wrote : | # |
+# Do use doble \ because squids config needs \ to be escaped
+ """Return the path for the formated for the config."""
Some spelling and grammar fixes need to happen. :)
Also, why do we need to split the Linux and Windows pieces up like this? We need to find a way to run all the tests on all platforms, and just skip the ones that are platform-specific on other platforms.
Manuel de la Peña (mandel) wrote : | # |
> +# Do use doble \ because squids config needs \ to be escaped
> + """Return the path for the formated for the config."""
>
> Some spelling and grammar fixes need to happen. :)
Fixing!
>
> Also, why do we need to split the Linux and Windows pieces up like this? We
> need to find a way to run all the tests on all platforms, and just skip the
> ones that are platform-specific on other platforms.
Well this is not splitting the tests according to the platform but working around the fact that squid on windows is not a good citizen. The following is a list of the workarounds we have to do to ensure that we can run all squid tests on windows:
* os.kill does not work on windows, we need to use the win api or we will leave the proxy running.
* The squid config is stupid, it needs paths to be C:\\path\\to\\cache rather than C:\path\to\cache, if you don't do that squid wont start.
* The location of the ncsa_auth is diff.
With that fixed we are able to run all tests as long as squid and htpasswd are present in the path.
Manuel de la Peña (mandel) wrote : | # |
> I would suggest something like "squid_util" or "squid_helpers" instead of
> source.
Fixing!
dobey (dobey) : | # |
Ubuntu One Auto Pilot (otto-pilot) wrote : | # |
Attempt to merge into lp:ubuntuone-dev-tools failed due to conflicts:
text conflict in run-tests.bat
- 76. By Manuel de la Peña
-
Fixed conflicts issues with trunk.
Preview Diff
1 | === modified file 'data/squid.conf.in' | |||
2 | --- data/squid.conf.in 2012-01-05 16:42:37 +0000 | |||
3 | +++ data/squid.conf.in 2012-04-30 11:07:20 +0000 | |||
4 | @@ -80,19 +80,19 @@ | |||
5 | 80 | cache_dir ufs ${spool_temp} 1000 16 256 | 80 | cache_dir ufs ${spool_temp} 1000 16 256 |
6 | 81 | 81 | ||
7 | 82 | # access log settings | 82 | # access log settings |
9 | 83 | access_log ${squid_temp}/access.log squid | 83 | access_log ${squid_temp}access.log squid |
10 | 84 | 84 | ||
11 | 85 | # cache log settings | 85 | # cache log settings |
13 | 86 | cache_log ${squid_temp}/cache.log | 86 | cache_log ${squid_temp}cache.log |
14 | 87 | 87 | ||
15 | 88 | # cache store log settings | 88 | # cache store log settings |
17 | 89 | cache_store_log ${squid_temp}/store.log | 89 | cache_store_log ${squid_temp}store.log |
18 | 90 | 90 | ||
19 | 91 | # mime table conf | 91 | # mime table conf |
20 | 92 | # mime_table /usr/share/squid/mime.conf | 92 | # mime_table /usr/share/squid/mime.conf |
21 | 93 | 93 | ||
22 | 94 | #Default pid file name | 94 | #Default pid file name |
24 | 95 | pid_filename ${squid_temp}/squid.pid | 95 | pid_filename ${squid_temp}squid.pid |
25 | 96 | 96 | ||
26 | 97 | # debug options (Full debugging) | 97 | # debug options (Full debugging) |
27 | 98 | debug_options ALL,1 | 98 | debug_options ALL,1 |
28 | @@ -117,4 +117,4 @@ | |||
29 | 117 | hosts_file /etc/hosts | 117 | hosts_file /etc/hosts |
30 | 118 | 118 | ||
31 | 119 | # Leave coredumps in the first cache dir | 119 | # Leave coredumps in the first cache dir |
33 | 120 | coredump_dir ${spool_temp}/squid | 120 | coredump_dir ${spool_temp}squid |
34 | 121 | 121 | ||
35 | === modified file 'run-tests' | |||
36 | --- run-tests 2012-01-12 12:08:22 +0000 | |||
37 | +++ run-tests 2012-04-30 11:07:20 +0000 | |||
38 | @@ -16,8 +16,8 @@ | |||
39 | 16 | # with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
40 | 17 | set -e | 17 | set -e |
41 | 18 | 18 | ||
44 | 19 | bin/u1trial -c ubuntuone | 19 | bin/u1trial -i "test_squid_windows.py" -c ubuntuone |
45 | 20 | bin/u1trial --reactor=twisted ubuntuone | 20 | bin/u1trial --reactor=twisted -i "test_squid_windows.py" ubuntuone |
46 | 21 | echo "Running style checks..." | 21 | echo "Running style checks..." |
47 | 22 | bin/u1lint | 22 | bin/u1lint |
48 | 23 | pep8 --repeat . bin/* --exclude=*.bat | 23 | pep8 --repeat . bin/* --exclude=*.bat |
49 | 24 | 24 | ||
50 | === modified file 'run-tests.bat' | |||
51 | --- run-tests.bat 2012-04-25 12:33:48 +0000 | |||
52 | +++ run-tests.bat 2012-04-30 11:07:20 +0000 | |||
53 | @@ -28,6 +28,8 @@ | |||
54 | 28 | :: files in the program, then also delete it here. | 28 | :: files in the program, then also delete it here. |
55 | 29 | @ECHO off | 29 | @ECHO off |
56 | 30 | 30 | ||
57 | 31 | SET IGNORED="test_squid_linux.py" | ||
58 | 32 | |||
59 | 31 | ECHO Checking for Python on the path | 33 | ECHO Checking for Python on the path |
60 | 32 | :: Look for Python from buildout | 34 | :: Look for Python from buildout |
61 | 33 | FOR %%A in (python.exe) do (SET PYTHONEXEPATH=%%~$PATH:A) | 35 | FOR %%A in (python.exe) do (SET PYTHONEXEPATH=%%~$PATH:A) |
62 | @@ -67,7 +69,7 @@ | |||
63 | 67 | 69 | ||
64 | 68 | ECHO Python found at %PYTHONEXEPATH%, executing the tests... | 70 | ECHO Python found at %PYTHONEXEPATH%, executing the tests... |
65 | 69 | :: execute the tests with a number of ignored linux only modules | 71 | :: execute the tests with a number of ignored linux only modules |
67 | 70 | "%PYTHONEXEPATH%" "%TRIALPATH%" --reactor=twisted -c %PARAMS% ubuntuone | 72 | "%PYTHONEXEPATH%" bin/u1trial --reactor=twisted -i %IGNORED% -c %PARAMS% ubuntuone |
68 | 71 | 73 | ||
69 | 72 | IF %SKIPLINT% == 1 ( | 74 | IF %SKIPLINT% == 1 ( |
70 | 73 | ECHO Skipping style checks | 75 | ECHO Skipping style checks |
71 | 74 | 76 | ||
72 | === modified file 'setup.py' | |||
73 | --- setup.py 2012-03-30 17:44:03 +0000 | |||
74 | +++ setup.py 2012-04-30 11:07:20 +0000 | |||
75 | @@ -28,10 +28,12 @@ | |||
76 | 28 | # files in the program, then also delete it here. | 28 | # files in the program, then also delete it here. |
77 | 29 | """setup.py""" | 29 | """setup.py""" |
78 | 30 | 30 | ||
79 | 31 | import os | ||
80 | 31 | import subprocess | 32 | import subprocess |
81 | 32 | import sys | 33 | import sys |
82 | 33 | 34 | ||
83 | 34 | from distutils.core import setup, Command | 35 | from distutils.core import setup, Command |
84 | 36 | from dirspec import basedir | ||
85 | 35 | 37 | ||
86 | 36 | PACKAGE = 'ubuntuone-dev-tools' | 38 | PACKAGE = 'ubuntuone-dev-tools' |
87 | 37 | VERSION = '3.1' | 39 | VERSION = '3.1' |
88 | @@ -65,6 +67,20 @@ | |||
89 | 65 | if sys.platform == 'win32': | 67 | if sys.platform == 'win32': |
90 | 66 | # lets add the .bat so that windows users are happy | 68 | # lets add the .bat so that windows users are happy |
91 | 67 | scripts.extend(['bin/u1lint.bat', 'bin/u1trial.bat']) | 69 | scripts.extend(['bin/u1lint.bat', 'bin/u1trial.bat']) |
92 | 70 | DATA_FILES = [(os.path.join(basedir.default_data_path, PACKAGE), | ||
93 | 71 | ['pylintrc', | ||
94 | 72 | 'data/dbus-session.conf.in', | ||
95 | 73 | 'data/squid.conf.in']), | ||
96 | 74 | ] | ||
97 | 75 | else: | ||
98 | 76 | DATA_FILES = [('share/%s' % PACKAGE, | ||
99 | 77 | ['pylintrc', | ||
100 | 78 | 'data/dbus-session.conf.in', | ||
101 | 79 | 'data/squid.conf.in']), | ||
102 | 80 | ('share/man/man1', | ||
103 | 81 | ['man/u1lint.1', | ||
104 | 82 | 'man/u1trial.1']), | ||
105 | 83 | ] | ||
106 | 68 | 84 | ||
107 | 69 | setup(name=PACKAGE, | 85 | setup(name=PACKAGE, |
108 | 70 | version=VERSION, | 86 | version=VERSION, |
109 | @@ -78,15 +94,7 @@ | |||
110 | 78 | 'ubuntuone.devtools.testcases'], | 94 | 'ubuntuone.devtools.testcases'], |
111 | 79 | extra_path='ubuntuone-dev-tools', | 95 | extra_path='ubuntuone-dev-tools', |
112 | 80 | scripts=scripts, | 96 | scripts=scripts, |
122 | 81 | data_files=[('share/%s' % PACKAGE, | 97 | data_files=DATA_FILES, |
114 | 82 | ['pylintrc', | ||
115 | 83 | 'data/dbus-session.conf.in', | ||
116 | 84 | 'data/squid.conf.in']), | ||
117 | 85 | ('share/man/man1', | ||
118 | 86 | ['man/u1lint.1', | ||
119 | 87 | 'man/u1trial.1']), | ||
120 | 88 | ], | ||
121 | 89 | |||
123 | 90 | cmdclass={ | 98 | cmdclass={ |
124 | 91 | 'lint': Lint, | 99 | 'lint': Lint, |
125 | 92 | }, | 100 | }, |
126 | 93 | 101 | ||
127 | === modified file 'ubuntuone/devtools/services/squid.py' | |||
128 | --- ubuntuone/devtools/services/squid.py 2012-04-20 17:00:51 +0000 | |||
129 | +++ ubuntuone/devtools/services/squid.py 2012-04-30 11:07:20 +0000 | |||
130 | @@ -33,10 +33,11 @@ | |||
131 | 33 | import string | 33 | import string |
132 | 34 | # pylint:enable=W0402 | 34 | # pylint:enable=W0402 |
133 | 35 | import subprocess | 35 | import subprocess |
134 | 36 | import sys | ||
135 | 36 | import time | 37 | import time |
136 | 37 | 38 | ||
137 | 38 | from json import dumps, loads | 39 | from json import dumps, loads |
139 | 39 | from os import environ, makedirs, kill, unlink | 40 | from os import environ, kill, makedirs, unlink |
140 | 40 | from os.path import abspath, exists, join | 41 | from os.path import abspath, exists, join |
141 | 41 | 42 | ||
142 | 42 | from distutils.spawn import find_executable | 43 | from distutils.spawn import find_executable |
143 | @@ -46,24 +47,52 @@ | |||
144 | 46 | get_arbitrary_port, | 47 | get_arbitrary_port, |
145 | 47 | ) | 48 | ) |
146 | 48 | 49 | ||
147 | 50 | # pylint: disable=C0103 | ||
148 | 51 | if sys.platform == 'win32': | ||
149 | 52 | AUTH_PROCESS_PATH = r'C:\squid\libexec\ncsa_auth.exe' | ||
150 | 53 | SQUID_START_ARGS = ['-f'] | ||
151 | 54 | else: | ||
152 | 55 | AUTH_PROCESS_PATH = '/usr/lib/%s/ncsa_auth' | ||
153 | 56 | SQUID_START_ARGS = ['-N', '-X', '-f'] | ||
154 | 57 | # pylint: enable=C0103 | ||
155 | 58 | |||
156 | 49 | SQUID_CONFIG_FILE = 'squid.conf.in' | 59 | SQUID_CONFIG_FILE = 'squid.conf.in' |
157 | 50 | SQUID_DIR = 'squid' | 60 | SQUID_DIR = 'squid' |
158 | 51 | AUTH_PROCESS_PATH = '/usr/lib/%s/ncsa_auth' | ||
159 | 52 | SPOOL_DIR = 'spool' | 61 | SPOOL_DIR = 'spool' |
160 | 53 | AUTH_FILE = 'htpasswd' | 62 | AUTH_FILE = 'htpasswd' |
161 | 54 | PROXY_ENV_VAR = 'SQUID_PROXY_SETTINGS' | 63 | PROXY_ENV_VAR = 'SQUID_PROXY_SETTINGS' |
162 | 55 | 64 | ||
163 | 56 | 65 | ||
164 | 66 | def format_config_path(path): | ||
165 | 67 | """Return the path correctly formatted for the config file.""" | ||
166 | 68 | # squid cannot handle correctly paths with a single \ | ||
167 | 69 | return path.replace('\\', '\\\\') | ||
168 | 70 | |||
169 | 71 | |||
170 | 72 | def get_auth_process_path(squid_version): | ||
171 | 73 | """Return the path to the auth executable.""" | ||
172 | 74 | if sys.platform == 'win32': | ||
173 | 75 | path = find_executable('ncsa_auth') | ||
174 | 76 | if path is None: | ||
175 | 77 | path = AUTH_PROCESS_PATH | ||
176 | 78 | return format_config_path(path) | ||
177 | 79 | else: | ||
178 | 80 | squid = 'squid3' if squid_version == 3 else 'squid' | ||
179 | 81 | path = AUTH_PROCESS_PATH % squid | ||
180 | 82 | return path | ||
181 | 83 | |||
182 | 84 | |||
183 | 57 | def get_squid_executable(): | 85 | def get_squid_executable(): |
184 | 58 | """Return the squid executable of the system.""" | 86 | """Return the squid executable of the system.""" |
185 | 59 | # try with squid and if not present try with squid3 for newer systems | 87 | # try with squid and if not present try with squid3 for newer systems |
186 | 60 | # (Ubuntu P). We also return the path to the auth process so that we can | 88 | # (Ubuntu P). We also return the path to the auth process so that we can |
187 | 61 | # point to the correct one. | 89 | # point to the correct one. |
188 | 62 | squid = find_executable('squid3') | 90 | squid = find_executable('squid3') |
190 | 63 | auth_process = AUTH_PROCESS_PATH % 'squid3' | 91 | version = 3 |
191 | 64 | if squid is None: | 92 | if squid is None: |
192 | 93 | version = 2 | ||
193 | 65 | squid = find_executable('squid') | 94 | squid = find_executable('squid') |
195 | 66 | auth_process = AUTH_PROCESS_PATH % 'squid' | 95 | auth_process = get_auth_process_path(version) |
196 | 67 | return squid, auth_process | 96 | return squid, auth_process |
197 | 68 | 97 | ||
198 | 69 | 98 | ||
199 | @@ -72,6 +101,21 @@ | |||
200 | 72 | return find_executable('htpasswd') | 101 | return find_executable('htpasswd') |
201 | 73 | 102 | ||
202 | 74 | 103 | ||
203 | 104 | def kill_squid(squid_pid): | ||
204 | 105 | """Kill the squid process.""" | ||
205 | 106 | if sys.platform == 'win32': | ||
206 | 107 | # pylint: disable=F0401 | ||
207 | 108 | import win32api | ||
208 | 109 | import win32con | ||
209 | 110 | # pylint: enable=F0401 | ||
210 | 111 | |||
211 | 112 | handle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, 0, squid_pid) | ||
212 | 113 | win32api.TerminateProcess(handle, 0) | ||
213 | 114 | win32api.CloseHandle(handle) | ||
214 | 115 | else: | ||
215 | 116 | kill(squid_pid, signal.SIGKILL) | ||
216 | 117 | |||
217 | 118 | |||
218 | 75 | def _make_random_string(count): | 119 | def _make_random_string(count): |
219 | 76 | """Make a random string of the given length.""" | 120 | """Make a random string of the given length.""" |
220 | 77 | entropy = random.SystemRandom() | 121 | entropy = random.SystemRandom() |
221 | @@ -95,7 +139,7 @@ | |||
222 | 95 | path = abspath(path) | 139 | path = abspath(path) |
223 | 96 | if not exists(path): | 140 | if not exists(path): |
224 | 97 | makedirs(path) | 141 | makedirs(path) |
226 | 98 | return path | 142 | return format_config_path(path) |
227 | 99 | 143 | ||
228 | 100 | 144 | ||
229 | 101 | def _get_squid_temp_path(tempdir=''): | 145 | def _get_squid_temp_path(tempdir=''): |
230 | @@ -105,7 +149,7 @@ | |||
231 | 105 | path = abspath(path) | 149 | path = abspath(path) |
232 | 106 | if not exists(path): | 150 | if not exists(path): |
233 | 107 | makedirs(path) | 151 | makedirs(path) |
235 | 108 | return path | 152 | return format_config_path(join(path, '')) |
236 | 109 | 153 | ||
237 | 110 | 154 | ||
238 | 111 | def _get_auth_temp_path(tempdir=''): | 155 | def _get_auth_temp_path(tempdir=''): |
239 | @@ -114,7 +158,7 @@ | |||
240 | 114 | auth_file = join(basedir, AUTH_FILE) | 158 | auth_file = join(basedir, AUTH_FILE) |
241 | 115 | if not exists(basedir): | 159 | if not exists(basedir): |
242 | 116 | makedirs(basedir) | 160 | makedirs(basedir) |
244 | 117 | return auth_file | 161 | return format_config_path(auth_file) |
245 | 118 | 162 | ||
246 | 119 | 163 | ||
247 | 120 | def store_proxy_settings(settings): | 164 | def store_proxy_settings(settings): |
248 | @@ -238,7 +282,8 @@ | |||
249 | 238 | self._generate_auth_file(tempdir) | 282 | self._generate_auth_file(tempdir) |
250 | 239 | self._generate_config_file(tempdir) | 283 | self._generate_config_file(tempdir) |
251 | 240 | self._generate_swap(self.config_file) | 284 | self._generate_swap(self.config_file) |
253 | 241 | squid_args = ['-N', '-X', '-f', self.config_file] | 285 | squid_args = SQUID_START_ARGS |
254 | 286 | squid_args.append(self.config_file) | ||
255 | 242 | sp = subprocess.Popen([self.squid] + squid_args, | 287 | sp = subprocess.Popen([self.squid] + squid_args, |
256 | 243 | stdout=subprocess.PIPE, | 288 | stdout=subprocess.PIPE, |
257 | 244 | stderr=subprocess.PIPE) | 289 | stderr=subprocess.PIPE) |
258 | @@ -255,7 +300,7 @@ | |||
259 | 255 | 300 | ||
260 | 256 | def stop_service(self): | 301 | def stop_service(self): |
261 | 257 | """Stop our proxy,""" | 302 | """Stop our proxy,""" |
263 | 258 | kill(self.squid_pid, signal.SIGKILL) | 303 | kill_squid(self.squid_pid) |
264 | 259 | delete_proxy_settings() | 304 | delete_proxy_settings() |
265 | 260 | self.running = False | 305 | self.running = False |
266 | 261 | unlink(self.config_file) | 306 | unlink(self.config_file) |
267 | 262 | 307 | ||
268 | === modified file 'ubuntuone/devtools/services/tests/test_squid.py' | |||
269 | --- ubuntuone/devtools/services/tests/test_squid.py 2012-04-20 16:42:54 +0000 | |||
270 | +++ ubuntuone/devtools/services/tests/test_squid.py 2012-04-30 11:07:20 +0000 | |||
271 | @@ -72,6 +72,7 @@ | |||
272 | 72 | self.patch(squid, '_get_basedir', fake_basedir_fn) | 72 | self.patch(squid, '_get_basedir', fake_basedir_fn) |
273 | 73 | self.patch(squid, 'makedirs', fake_makedirs) | 73 | self.patch(squid, 'makedirs', fake_makedirs) |
274 | 74 | self.patch(squid, 'exists', fake_exists) | 74 | self.patch(squid, 'exists', fake_exists) |
275 | 75 | self.patch(squid, 'format_config_path', lambda path: path) | ||
276 | 75 | 76 | ||
277 | 76 | def test_get_basedir_missing(self): | 77 | def test_get_basedir_missing(self): |
278 | 77 | """Test the base dir creation.""" | 78 | """Test the base dir creation.""" |
279 | @@ -116,24 +117,26 @@ | |||
280 | 116 | 117 | ||
281 | 117 | def test_get_squid_temp_path_missing(self): | 118 | def test_get_squid_temp_path_missing(self): |
282 | 118 | """Test the squid path creation.""" | 119 | """Test the squid path creation.""" |
284 | 119 | expected_path = os.path.join(self.basedir, squid.SQUID_DIR) | 120 | expected_path = os.path.join(self.basedir, squid.SQUID_DIR, '') |
285 | 121 | abspath = os.path.abspath(expected_path) | ||
286 | 120 | result = squid._get_squid_temp_path() | 122 | result = squid._get_squid_temp_path() |
287 | 121 | self.assertEqual(expected_path, result) | 123 | self.assertEqual(expected_path, result) |
288 | 122 | self.assertTrue(('fake_basedir_fn', '') in self.called) | 124 | self.assertTrue(('fake_basedir_fn', '') in self.called) |
292 | 123 | self.assertTrue(('fake_makedirs', expected_path) in self.called) | 125 | self.assertTrue(('fake_makedirs', abspath) in self.called) |
293 | 124 | self.assertTrue(expected_path in self.created_paths) | 126 | self.assertTrue(abspath in self.created_paths) |
294 | 125 | self.assertTrue(('fake_exists', expected_path) in self.called) | 127 | self.assertTrue(('fake_exists', abspath) in self.called) |
295 | 126 | 128 | ||
296 | 127 | def test_get_squid_temp_path_present(self): | 129 | def test_get_squid_temp_path_present(self): |
297 | 128 | """Test the squid path creation.""" | 130 | """Test the squid path creation.""" |
298 | 129 | self.path_exists = True | 131 | self.path_exists = True |
300 | 130 | expected_path = os.path.join(self.basedir, squid.SQUID_DIR) | 132 | expected_path = os.path.join(self.basedir, squid.SQUID_DIR, '') |
301 | 131 | result = squid._get_squid_temp_path() | 133 | result = squid._get_squid_temp_path() |
302 | 132 | self.assertEqual(expected_path, result) | 134 | self.assertEqual(expected_path, result) |
303 | 133 | self.assertTrue(('fake_basedir_fn', '') in self.called) | 135 | self.assertTrue(('fake_basedir_fn', '') in self.called) |
304 | 134 | self.assertTrue(('fake_makedirs', expected_path) not in self.called) | 136 | self.assertTrue(('fake_makedirs', expected_path) not in self.called) |
305 | 135 | self.assertTrue(expected_path not in self.created_paths) | 137 | self.assertTrue(expected_path not in self.created_paths) |
307 | 136 | self.assertTrue(('fake_exists', expected_path) in self.called) | 138 | self.assertTrue(('fake_exists', |
308 | 139 | os.path.abspath(expected_path)) in self.called) | ||
309 | 137 | 140 | ||
310 | 138 | def test_get_auth_temp_path(self): | 141 | def test_get_auth_temp_path(self): |
311 | 139 | """Test the creation of the auth path.""" | 142 | """Test the creation of the auth path.""" |
312 | 140 | 143 | ||
313 | === added file 'ubuntuone/devtools/services/tests/test_squid_linux.py' | |||
314 | --- ubuntuone/devtools/services/tests/test_squid_linux.py 1970-01-01 00:00:00 +0000 | |||
315 | +++ ubuntuone/devtools/services/tests/test_squid_linux.py 2012-04-30 11:07:20 +0000 | |||
316 | @@ -0,0 +1,67 @@ | |||
317 | 1 | # | ||
318 | 2 | # Copyright 2012 Canonical Ltd. | ||
319 | 3 | # | ||
320 | 4 | # This program is free software: you can redistribute it and/or modify it | ||
321 | 5 | # under the terms of the GNU General Public License version 3, as published | ||
322 | 6 | # by the Free Software Foundation. | ||
323 | 7 | # | ||
324 | 8 | # This program is distributed in the hope that it will be useful, but | ||
325 | 9 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
326 | 10 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
327 | 11 | # PURPOSE. See the GNU General Public License for more details. | ||
328 | 12 | # | ||
329 | 13 | # You should have received a copy of the GNU General Public License along | ||
330 | 14 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
331 | 15 | # | ||
332 | 16 | # In addition, as a special exception, the copyright holders give | ||
333 | 17 | # permission to link the code of portions of this program with the | ||
334 | 18 | # OpenSSL library under certain conditions as described in each | ||
335 | 19 | # individual source file, and distribute linked combinations | ||
336 | 20 | # including the two. | ||
337 | 21 | # You must obey the GNU General Public License in all respects | ||
338 | 22 | # for all of the code used other than OpenSSL. If you modify | ||
339 | 23 | # file(s) with this exception, you may extend this exception to your | ||
340 | 24 | # version of the file(s), but you are not obligated to do so. If you | ||
341 | 25 | # do not wish to do so, delete this exception statement from your | ||
342 | 26 | # version. If you delete this exception statement from all source | ||
343 | 27 | # files in the program, then also delete it here. | ||
344 | 28 | """Tests for the linux squid bits.""" | ||
345 | 29 | |||
346 | 30 | import signal | ||
347 | 31 | |||
348 | 32 | from twisted.trial.unittest import TestCase | ||
349 | 33 | |||
350 | 34 | from ubuntuone.devtools.services import squid | ||
351 | 35 | |||
352 | 36 | |||
353 | 37 | class SquidLinuxTestCase(TestCase): | ||
354 | 38 | """"Test the different linux bits.""" | ||
355 | 39 | |||
356 | 40 | def test_get_auth_process_3(self): | ||
357 | 41 | """Test getting the auth process for squid3.""" | ||
358 | 42 | expected = squid.AUTH_PROCESS_PATH % 'squid3' | ||
359 | 43 | self.assertEqual(expected, squid.get_auth_process_path(3)) | ||
360 | 44 | |||
361 | 45 | def test_get_auth_process(self): | ||
362 | 46 | """Test getting the auth process.""" | ||
363 | 47 | expected = squid.AUTH_PROCESS_PATH % 'squid' | ||
364 | 48 | self.assertEqual(expected, squid.get_auth_process_path(2)) | ||
365 | 49 | |||
366 | 50 | def test_format_config_path(self): | ||
367 | 51 | """Test formating a config path.""" | ||
368 | 52 | path = '/a/config/path' | ||
369 | 53 | self.assertEqual(path, squid.format_config_path(path)) | ||
370 | 54 | |||
371 | 55 | def test_kill_squid(self): | ||
372 | 56 | """Test killing squid.""" | ||
373 | 57 | called = [] | ||
374 | 58 | |||
375 | 59 | def fake_kill(pid, kill_signal): | ||
376 | 60 | """Fake os.kill.""" | ||
377 | 61 | called.append(('kill', pid, kill_signal)) | ||
378 | 62 | |||
379 | 63 | self.patch(squid, 'kill', fake_kill) | ||
380 | 64 | |||
381 | 65 | squid_pid = 4 | ||
382 | 66 | squid.kill_squid(squid_pid) | ||
383 | 67 | self.assertIn(('kill', squid_pid, signal.SIGKILL), called) | ||
384 | 0 | 68 | ||
385 | === added file 'ubuntuone/devtools/services/tests/test_squid_windows.py' | |||
386 | --- ubuntuone/devtools/services/tests/test_squid_windows.py 1970-01-01 00:00:00 +0000 | |||
387 | +++ ubuntuone/devtools/services/tests/test_squid_windows.py 2012-04-30 11:07:20 +0000 | |||
388 | @@ -0,0 +1,108 @@ | |||
389 | 1 | # | ||
390 | 2 | # Copyright 2012 Canonical Ltd. | ||
391 | 3 | # | ||
392 | 4 | # This program is free software: you can redistribute it and/or modify it | ||
393 | 5 | # under the terms of the GNU General Public License version 3, as published | ||
394 | 6 | # by the Free Software Foundation. | ||
395 | 7 | # | ||
396 | 8 | # This program is distributed in the hope that it will be useful, but | ||
397 | 9 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
398 | 10 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
399 | 11 | # PURPOSE. See the GNU General Public License for more details. | ||
400 | 12 | # | ||
401 | 13 | # You should have received a copy of the GNU General Public License along | ||
402 | 14 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
403 | 15 | # | ||
404 | 16 | # In addition, as a special exception, the copyright holders give | ||
405 | 17 | # permission to link the code of portions of this program with the | ||
406 | 18 | # OpenSSL library under certain conditions as described in each | ||
407 | 19 | # individual source file, and distribute linked combinations | ||
408 | 20 | # including the two. | ||
409 | 21 | # You must obey the GNU General Public License in all respects | ||
410 | 22 | # for all of the code used other than OpenSSL. If you modify | ||
411 | 23 | # file(s) with this exception, you may extend this exception to your | ||
412 | 24 | # version of the file(s), but you are not obligated to do so. If you | ||
413 | 25 | # do not wish to do so, delete this exception statement from your | ||
414 | 26 | # version. If you delete this exception statement from all source | ||
415 | 27 | # files in the program, then also delete it here. | ||
416 | 28 | """Tests for the windows squid bits.""" | ||
417 | 29 | |||
418 | 30 | # pylint: disable=F0401 | ||
419 | 31 | import win32api | ||
420 | 32 | import win32con | ||
421 | 33 | # pylint: enable=F0401 | ||
422 | 34 | |||
423 | 35 | from twisted.trial.unittest import TestCase | ||
424 | 36 | |||
425 | 37 | from ubuntuone.devtools.services import squid | ||
426 | 38 | |||
427 | 39 | |||
428 | 40 | class SquidWindowsTestCase(TestCase): | ||
429 | 41 | """"Test the different windows bits.""" | ||
430 | 42 | |||
431 | 43 | def test_get_auth_process(self): | ||
432 | 44 | """Test getting the auth process for squid3.""" | ||
433 | 45 | called = [] | ||
434 | 46 | |||
435 | 47 | self.patch(squid, 'find_executable', lambda _: None) | ||
436 | 48 | |||
437 | 49 | def fake_format(path): | ||
438 | 50 | """Fake format of a config path.""" | ||
439 | 51 | called.append(('format', path)) | ||
440 | 52 | return path | ||
441 | 53 | |||
442 | 54 | self.patch(squid, 'format_config_path', fake_format) | ||
443 | 55 | self.assertEqual(squid.AUTH_PROCESS_PATH, | ||
444 | 56 | squid.get_auth_process_path(3)) | ||
445 | 57 | self.assertIn(('format', squid.AUTH_PROCESS_PATH), called) | ||
446 | 58 | |||
447 | 59 | def test_get_auth_process_path(self): | ||
448 | 60 | """Test getting the auth process.""" | ||
449 | 61 | called = [] | ||
450 | 62 | |||
451 | 63 | exec_path = '/path/to/exec' | ||
452 | 64 | self.patch(squid, 'find_executable', lambda _: exec_path) | ||
453 | 65 | |||
454 | 66 | def fake_format(path): | ||
455 | 67 | """Fake format of a config path.""" | ||
456 | 68 | called.append(('format', path)) | ||
457 | 69 | return path | ||
458 | 70 | |||
459 | 71 | self.patch(squid, 'format_config_path', fake_format) | ||
460 | 72 | self.assertEqual(exec_path, squid.get_auth_process_path(3)) | ||
461 | 73 | self.assertIn(('format', exec_path), called) | ||
462 | 74 | |||
463 | 75 | def test_format_config_path(self): | ||
464 | 76 | """Test formating a config path.""" | ||
465 | 77 | path = '\\a\\config\\path' | ||
466 | 78 | expected = path.replace('\\', '\\\\') | ||
467 | 79 | self.assertEqual(expected, squid.format_config_path(path)) | ||
468 | 80 | |||
469 | 81 | def test_kill_squid(self): | ||
470 | 82 | """Test killing squid.""" | ||
471 | 83 | called = [] | ||
472 | 84 | |||
473 | 85 | def fake_open_process(access, inherit, pid): | ||
474 | 86 | """A fake open process.""" | ||
475 | 87 | called.append(('OpenProcess', access, inherit, pid)) | ||
476 | 88 | return pid | ||
477 | 89 | |||
478 | 90 | self.patch(win32api, 'OpenProcess', fake_open_process) | ||
479 | 91 | |||
480 | 92 | def fake_terminate(handle, exit_code): | ||
481 | 93 | """Fake terminate the process.""" | ||
482 | 94 | called.append(('TerminateProcess', handle, exit_code)) | ||
483 | 95 | |||
484 | 96 | self.patch(win32api, 'TerminateProcess', fake_terminate) | ||
485 | 97 | |||
486 | 98 | def fake_close_handle(handle): | ||
487 | 99 | """Fale closing a handle.""" | ||
488 | 100 | called.append(('CloseHandle', handle)) | ||
489 | 101 | |||
490 | 102 | self.patch(win32api, 'CloseHandle', fake_close_handle) | ||
491 | 103 | squid_pid = 4 | ||
492 | 104 | squid.kill_squid(squid_pid) | ||
493 | 105 | self.assertIn(('OpenProcess', win32con.PROCESS_TERMINATE, 0, | ||
494 | 106 | squid_pid), called) | ||
495 | 107 | self.assertIn(('TerminateProcess', squid_pid, 0), called) | ||
496 | 108 | self.assertIn(('CloseHandle', squid_pid), called) | ||
497 | 0 | 109 | ||
498 | === modified file 'ubuntuone/devtools/testcases/tests/test_squid_testcase.py' | |||
499 | --- ubuntuone/devtools/testcases/tests/test_squid_testcase.py 2012-03-30 17:44:03 +0000 | |||
500 | +++ ubuntuone/devtools/testcases/tests/test_squid_testcase.py 2012-04-30 11:07:20 +0000 | |||
501 | @@ -192,7 +192,7 @@ | |||
502 | 192 | """Build the url for this mock server.""" | 192 | """Build the url for this mock server.""" |
503 | 193 | #pylint: disable=W0212 | 193 | #pylint: disable=W0212 |
504 | 194 | port_num = self.tcpserver._port.getHost().port | 194 | port_num = self.tcpserver._port.getHost().port |
506 | 195 | return "http://localhost:%d/" % port_num | 195 | return "http://127.0.0.1:%d/" % port_num |
507 | 196 | 196 | ||
508 | 197 | @defer.inlineCallbacks | 197 | @defer.inlineCallbacks |
509 | 198 | def stop(self): | 198 | def stop(self): |
98 +if sys.platform == 'win32': devtools. services. squid import windows devtools. services. squid import linux
99 + from ubuntuone.
100 + source = windows
101 +else:
102 + from ubuntuone.
103 + source = linux
why not import windows as source, and import linux as source?