Merge lp:~vila/u1-test-utils/pep8 into lp:u1-test-utils
- pep8
- Merge into trunk
Proposed by
Vincent Ladeuil
Status: | Merged |
---|---|
Approved by: | Vincent Ladeuil |
Approved revision: | 95 |
Merged at revision: | 92 |
Proposed branch: | lp:~vila/u1-test-utils/pep8 |
Merge into: | lp:u1-test-utils |
Diff against target: |
801 lines (+187/-182) 8 files modified
setup_vm/bin/setup_vm.py (+108/-145) setup_vm/tests/__init__.py (+5/-3) setup_vm/tests/test_code_conformance.py (+30/-0) setup_vm/tests/test_setup_vm.py (+31/-31) setup_vm/tests/test_test.py (+2/-3) u1testutils/static/__init__.py (+6/-0) u1testutils/static/test_pep8_conformance.py (+3/-0) u1testutils/static/test_pyflakes_analysis.py (+2/-0) |
To merge this branch: | bzr merge lp:~vila/u1-test-utils/pep8 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Leo Arias (community) | code review | Approve | |
Review via email: mp+179147@code.launchpad.net |
Commit message
Add pep8/pyflakes for setup_vm.
Description of the change
Add code conformance tests for setup_vm.
Explain why the test_pyflakes_
always succeed.
Fix all pep8 and pyflakes issues which reminds me that I'd really want my
editor to agree with pep8 about continuation lines :-/
To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote : | # |
Revision history for this message
Leo Arias (elopio) wrote : | # |
More pretty code :)
Thanks!
review:
Approve
(code review)
lp:~vila/u1-test-utils/pep8
updated
- 95. By Vincent Ladeuil
-
The classes under u1testutils/static are not meant to be loaded.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'setup_vm/bin/setup_vm.py' |
2 | --- setup_vm/bin/setup_vm.py 2013-08-07 18:21:45 +0000 |
3 | +++ setup_vm/bin/setup_vm.py 2013-08-08 16:32:55 +0000 |
4 | @@ -7,14 +7,11 @@ |
5 | |
6 | """ |
7 | import argparse |
8 | -import base64 |
9 | from cStringIO import StringIO |
10 | import errno |
11 | import os |
12 | import subprocess |
13 | import sys |
14 | -import tempfile |
15 | -import time |
16 | |
17 | |
18 | import bzrlib |
19 | @@ -87,7 +84,7 @@ |
20 | ], |
21 | user_store, mutable_section_id=name) |
22 | |
23 | - if bzrlib.version_info < (2,6): |
24 | + if bzrlib.version_info < (2, 6): |
25 | def get(self, name, expand=True): |
26 | """Override base class to expand by default.""" |
27 | return super(VmStack, self).get(name, expand) |
28 | @@ -114,9 +111,8 @@ |
29 | config.option_registry.register(option) |
30 | |
31 | |
32 | -register(config.Option( |
33 | - 'vm', default=None, |
34 | - help='''The name space defining a virtual machine. |
35 | +register(config.Option('vm', default=None, |
36 | + help='''The name space defining a virtual machine. |
37 | |
38 | This option is a place holder to document the options that defines a virtual |
39 | machine and the options defining the infrastructure used to manage them all. |
40 | @@ -147,9 +143,8 @@ |
41 | |
42 | # The directory where we store vm files related to their configuration with |
43 | # cloud-init (user-data, meta-data, ssh keys). |
44 | -register(config.Option( |
45 | - 'vm.vms_dir', default='~/.config/setup_vm', |
46 | - help='''Where vm related config files are stored. |
47 | +register(config.Option('vm.vms_dir', default='~/.config/setup_vm', |
48 | + help='''Where vm related config files are stored. |
49 | |
50 | This includes user-data and meta-data for cloud-init and ssh server keys. |
51 | |
52 | @@ -159,59 +154,43 @@ |
53 | name. |
54 | ''')) |
55 | # The base directories where vms are stored for kvm |
56 | -register(PathOption( |
57 | - 'vm.images_dir', default='/var/lib/libvirt/images', |
58 | - help="Where vm disk images are stored.", |
59 | - )) |
60 | -register(config.Option( |
61 | - 'vm.qemu_etc_dir', |
62 | - default='/etc/libvirt/qemu', |
63 | - help="Where libvirt (qemu) stores the vms config files." |
64 | - )) |
65 | +register(PathOption('vm.images_dir', default='/var/lib/libvirt/images', |
66 | + help='''Where vm disk images are stored.''',)) |
67 | +register(config.Option('vm.qemu_etc_dir', default='/etc/libvirt/qemu', |
68 | + help='''\ |
69 | +Where libvirt (qemu) stores the vms config files.''')) |
70 | |
71 | # Isos and images download handling |
72 | -register(config.Option( |
73 | - 'vm.iso_url', |
74 | - default='http://cdimage.ubuntu.com/daily-live/current/' , |
75 | - help="Where an iso can be downloaded from." |
76 | - )) |
77 | -register(config.Option( |
78 | - 'vm.iso_name', |
79 | - default='{vm.release}-desktop-{vm.cpu_model}.iso', |
80 | - help="The name of the iso." |
81 | - )) |
82 | -register(config.Option( |
83 | - 'vm.cloud_image_url', |
84 | - default='http://cloud-images.ubuntu.com/{vm.release}/current/', |
85 | - help="Where a cloud image can be downloaded from." |
86 | - )) |
87 | -register(config.Option( |
88 | - 'vm.cloud_image_name', |
89 | - default='{vm.release}-server-cloudimg-{vm.cpu_model}-disk1.img', |
90 | - help="The name of the cloud image." |
91 | - )) |
92 | -register(PathOption( |
93 | - 'vm.download_cache', |
94 | - default='{vm.images_dir}', |
95 | - help="Where downloads end up.", |
96 | - )) |
97 | +register(config.Option('vm.iso_url', |
98 | + default='http://cdimage.ubuntu.com/daily-live/current/', |
99 | + help='''Where an iso can be downloaded from.''')) |
100 | +register(config.Option('vm.iso_name', |
101 | + default='{vm.release}-desktop-{vm.cpu_model}.iso', |
102 | + help='''The name of the iso.''')) |
103 | +register(config.Option('vm.cloud_image_url', |
104 | + default='''\ |
105 | +http://cloud-images.ubuntu.com/{vm.release}/current/''', |
106 | + help='''Where a cloud image can be downloaded from.''')) |
107 | +register(config.Option('vm.cloud_image_name', |
108 | + default='''\ |
109 | +{vm.release}-server-cloudimg-{vm.cpu_model}-disk1.img''', |
110 | + help='''The name of the cloud image.''')) |
111 | +register(PathOption('vm.download_cache', default='{vm.images_dir}', |
112 | + help='''Where downloads end up.''')) |
113 | |
114 | # The ubiquitous vm name |
115 | -register(config.Option( |
116 | - 'vm.name', default=None, invalid='error', |
117 | - help="The vm name, used as a prefix for related files." |
118 | - )) |
119 | +register(config.Option('vm.name', default=None, invalid='error', |
120 | + help='''\ |
121 | +The vm name, used as a prefix for related files.''')) |
122 | # The second most important bit to define a vm: which ubuntu release ? |
123 | -register(config.Option( |
124 | - 'vm.release', default=None, invalid='error', |
125 | - help="The ubuntu release name." |
126 | - )) |
127 | +register(config.Option('vm.release', default=None, invalid='error', |
128 | + help='''The ubuntu release name.''')) |
129 | # The third important piece to define a vm: where to store files like the |
130 | # console, the user-data and meta-data files, the ssh server keys, etc. |
131 | -register(config.Option( |
132 | - 'vm.config_dir', default='{vm.vms_dir}/{vm.name}', |
133 | - invalid='error', |
134 | - help='''The directory where files specific to a vm are stored. |
135 | +register(config.Option('vm.config_dir', default='{vm.vms_dir}/{vm.name}', |
136 | + invalid='error', |
137 | + help='''\ |
138 | +The directory where files specific to a vm are stored. |
139 | |
140 | This includes the user-data and meta-data files used at install time (for |
141 | reference and easier debug) as well as the optional ssh server keys. |
142 | @@ -220,118 +199,101 @@ |
143 | redifining it as long as it ends up being unique for the vm. |
144 | |
145 | {vm.vms_dir}/{vm.release}/{vm.name} may better suit your taste for example. |
146 | -''' |
147 | - )) |
148 | +''')) |
149 | # The options defining the vm physical characteristics |
150 | -register(config.Option( |
151 | - 'vm.ram_size', default='1024', |
152 | - help="The ram size in megabytes." |
153 | - )) |
154 | -register(config.Option( |
155 | - 'vm.disk_size', default='8G', |
156 | - help='''The disk image size in bytes. |
157 | +register(config.Option('vm.ram_size', default='1024', |
158 | + help='''The ram size in megabytes.''')) |
159 | +register(config.Option('vm.disk_size', default='8G', |
160 | + help='''The disk image size in bytes. |
161 | |
162 | Optional suffixes "k" or "K" (kilobyte, 1024) "M" (megabyte, 1024k) "G" |
163 | (gigabyte, 1024M) and T (terabyte, 1024G) are supported. |
164 | ''')) |
165 | -register(config.Option( |
166 | - 'vm.cpus', default='1', |
167 | - help="The number of cpus." |
168 | - )) |
169 | -register(config.Option( |
170 | - 'vm.cpu_model', default=None, invalid='error', |
171 | - help="The number of cpus.")) |
172 | -register(config.Option( |
173 | - 'vm.network', default='network=default', invalid='error', |
174 | - help="""The --network parameter for virt-install. |
175 | +register(config.Option('vm.cpus', default='1', help='''The number of cpus.''')) |
176 | +register(config.Option('vm.cpu_model', default=None, invalid='error', |
177 | + help='''The number of cpus.''')) |
178 | +register(config.Option('vm.network', default='network=default', |
179 | + invalid='error', help='''\ |
180 | +The --network parameter for virt-install. |
181 | |
182 | This can be specialized for each machine but the default should work in most |
183 | setups. Watch for your DHCP server exhausting its address space if you create a |
184 | lot of vms with random MAC addresses. |
185 | -""")) |
186 | +''')) |
187 | |
188 | -register(config.Option( |
189 | - 'vm.meta_data', default='''\ |
190 | +register(config.Option('vm.meta_data', default='''\ |
191 | instance-id: {vm.name} |
192 | local-hostname: {vm.name} |
193 | ''', |
194 | - invalid='error', |
195 | - help="The meta data for cloud-init to put in the seed." |
196 | - )) |
197 | + invalid='error', |
198 | + help='''\ |
199 | +The meta data for cloud-init to put in the seed.''')) |
200 | |
201 | # Some bits that may added to user-data but are optional |
202 | |
203 | -register(config.ListOption( |
204 | - 'vm.packages', default=None, |
205 | - help='''A list of package names to be installed. |
206 | -''')) |
207 | -register(config.Option( |
208 | - 'vm.apt_proxy', default=None, invalid='error', |
209 | - help='''A local proxy for apt to avoid repeated .deb downloads. |
210 | +register(config.ListOption('vm.packages', default=None, |
211 | + help='''\ |
212 | +A list of package names to be installed.''')) |
213 | +register(config.Option('vm.apt_proxy', default=None, invalid='error', |
214 | + help='''\ |
215 | +A local proxy for apt to avoid repeated .deb downloads. |
216 | |
217 | Example: |
218 | |
219 | vm.apt_proxy = http://192.168.0.42:8000 |
220 | - |
221 | ''')) |
222 | -register(config.ListOption( |
223 | - 'vm.apt_sources', default=None, |
224 | - help='''A list of apt sources entries to be added to the default ones. |
225 | +register(config.ListOption('vm.apt_sources', default=None, |
226 | + help='''\ |
227 | +A list of apt sources entries to be added to the default ones. |
228 | |
229 | Cloud-init already setup /etc/apt/sources.list with appropriate entries. Only |
230 | additional entries need to be specified here. |
231 | ''')) |
232 | -register(config.ListOption( |
233 | - 'vm.ssh_authorized_keys', default=None, |
234 | - help='A list of paths to public ssh keys to be authorized for' |
235 | - ' the default user.')) |
236 | -register(config.ListOption( |
237 | - 'vm.ssh_keys', default=None, |
238 | - help='''A list of paths to server ssh keys. |
239 | +register(config.ListOption('vm.ssh_authorized_keys', default=None, |
240 | + help='''\ |
241 | +A list of paths to public ssh keys to be authorized for the default user.''')) |
242 | +register(config.ListOption('vm.ssh_keys', default=None, |
243 | + help='''A list of paths to server ssh keys. |
244 | |
245 | Both public and private keys can be provided. Accepted ssh key types are rsa, |
246 | dsa and ecdsa. The file names should match <type>.*[.pub]. |
247 | ''')) |
248 | -register(config.Option( |
249 | - 'vm.update', default=False, |
250 | - from_unicode=config.bool_from_store, |
251 | - help='''Whether or not the vm should be updated. |
252 | +register(config.Option('vm.update', default=False, |
253 | + from_unicode=config.bool_from_store, |
254 | + help='''Whether or not the vm should be updated. |
255 | + |
256 | Both apt-get update and apt-get upgrade are called if this option is set. |
257 | ''')) |
258 | -register(config.Option( |
259 | - 'vm.password', default='ubuntu', invalid='error', |
260 | - help="The ubuntu user password." |
261 | - )) |
262 | -register(config.Option( |
263 | - 'vm.launchpad_id', |
264 | - help="The launchpad login used for launchpad ssh access from the guest." |
265 | - )) |
266 | +register(config.Option('vm.password', default='ubuntu', invalid='error', |
267 | + help='''The ubuntu user password.''')) |
268 | +register(config.Option('vm.launchpad_id', |
269 | + help='''\ |
270 | +The launchpad login used for launchpad ssh access from the guest.''')) |
271 | # The scripts that are executed before powering off |
272 | -register(PathOption( |
273 | - 'vm.root_script', default=None, |
274 | - help='''The path to a script executed as root before powering off. |
275 | +register(PathOption('vm.root_script', default=None, |
276 | + help='''\ |
277 | +The path to a script executed as root before powering off. |
278 | |
279 | This script is executed before {vm.ubuntu_script}. |
280 | -''' |
281 | - )) |
282 | -register(PathOption( |
283 | - 'vm.ubuntu_script', default=None, |
284 | - help='''The path to a script executed as ubuntu before powering off. |
285 | +''')) |
286 | +register(PathOption('vm.ubuntu_script', default=None, |
287 | + help='''\ |
288 | +The path to a script executed as ubuntu before powering off. |
289 | |
290 | This script is excuted after {vm.root_script}. |
291 | ''')) |
292 | -register(config.ListOption( |
293 | - 'vm.uploaded_scripts', default=None, |
294 | - help='''A list of scripts to be uploaded to the guest. |
295 | +register(config.ListOption('vm.uploaded_scripts', default=None, |
296 | + help='''\ |
297 | +A list of scripts to be uploaded to the guest. |
298 | |
299 | Scripts can use config options from their vm, they will be expanded before |
300 | upload. All scripts are uploaded into {vm.uploaded_scripts.guest_dir} under |
301 | their base name. |
302 | ''')) |
303 | -register(config.Option( |
304 | - 'vm.uploaded_scripts.guest_dir', default='~ubuntu/bin', |
305 | - help='''Where {vm.uploaded_scripts} are uploaded on the guest.''' |
306 | - )) |
307 | +register(config.Option('vm.uploaded_scripts.guest_dir', |
308 | + default='~ubuntu/bin', |
309 | + help='''\ |
310 | +Where {vm.uploaded_scripts} are uploaded on the guest.''')) |
311 | |
312 | |
313 | class SetupVmError(Exception): |
314 | @@ -363,6 +325,7 @@ |
315 | super(CommandError, self).__init__(joined_cmd=' '.join(cmd), |
316 | retcode=retcode, err=err, out=out) |
317 | |
318 | + |
319 | class ConfigValueError(SetupVmError): |
320 | |
321 | msg = 'Bad value "{value}" for option "{name}".' |
322 | @@ -395,6 +358,7 @@ |
323 | stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
324 | return proc |
325 | |
326 | + |
327 | def ssh_infos_from_path(key_path): |
328 | """Analyze path to find ssh key type and kind. |
329 | |
330 | @@ -443,7 +407,6 @@ |
331 | super(ConsoleMonitor, self).__init__() |
332 | self.stream = stream |
333 | |
334 | - |
335 | def parse(self): |
336 | while True: |
337 | line = self.stream.readline() |
338 | @@ -614,9 +577,9 @@ |
339 | # FIXME: This may be worth fixing if we provide a more generic way to |
340 | # create a remote tree. -- vila 2013-03-10 |
341 | hook_content = '''#!/bin/sh |
342 | -cat >{__guest_path} <<'EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN' |
343 | +cat >{__guest_path} <<'EOSETUPVMUNIQUECONTENTDONTBREAKFORFUN' |
344 | {__fcontent} |
345 | -EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN |
346 | +EOSETUPVMUNIQUECONTENTDONTBREAKFORFUN |
347 | chown {__user}:{__user} {__guest_path} |
348 | chmod {__mode} {__guest_path} |
349 | ''' |
350 | @@ -676,9 +639,9 @@ |
351 | chmod {dir_mode} ~ubuntu |
352 | chown {user}:{user} {dir_path} |
353 | chmod {dir_mode} {dir_path} |
354 | -cat >{guest_path} <<'EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN' |
355 | +cat >{guest_path} <<'EOSETUPVMUNIQUECONTENTDONTBREAKFORFUN' |
356 | {fcontent} |
357 | -EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN |
358 | +EOSETUPVMUNIQUECONTENTDONTBREAKFORFUN |
359 | chown {user}:{user} {guest_path} |
360 | chmod {file_mode} {guest_path} |
361 | ''' |
362 | @@ -698,7 +661,7 @@ |
363 | bindir = self.conf.get('vm.uploaded_scripts.guest_dir') |
364 | out = StringIO() |
365 | out.write('''#!/bin/sh |
366 | -cat >{hook_path} <<'EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN' |
367 | +cat >{hook_path} <<'EOSETUPVMUNIQUECONTENTDONTBREAKFORFUN' |
368 | mkdir -p {bindir} |
369 | cd {bindir} |
370 | '''.format(**locals())) |
371 | @@ -713,10 +676,10 @@ |
372 | chmod 0755 {base} |
373 | '''.format(**locals())) |
374 | |
375 | - out.write('''EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN |
376 | + out.write('''EOSETUPVMUNIQUECONTENTDONTBREAKFORFUN |
377 | chown {user}:{user} {hook_path} |
378 | chmod 0700 {hook_path} |
379 | -'''.format(user='ubuntu',**locals())) |
380 | +'''.format(user='ubuntu', **locals())) |
381 | self.uploaded_scripts_hook = out.getvalue() |
382 | self.append_cmd(['su', '-l', '-c', hook_path, 'ubuntu']) |
383 | |
384 | @@ -763,7 +726,7 @@ |
385 | |
386 | def add_boot_hook(self, parts, hook): |
387 | if hook is not None: |
388 | - parts.append({'content': '#cloud-boothook\n' + hook}) |
389 | + parts.append({'content': '#cloud-boothook\n' + hook}) |
390 | |
391 | def dump(self): |
392 | parts = [{'content': '#cloud-config\n' |
393 | @@ -818,8 +781,8 @@ |
394 | |
395 | def _ssh_keygen(self, key_path): |
396 | ssh_type, kind = ssh_infos_from_path(key_path) |
397 | - path = os.path.expanduser(key_path) # Just in case |
398 | - if kind == 'private': # public will be generated at the same time |
399 | + path = os.path.expanduser(key_path) # Just in case |
400 | + if kind == 'private': # public will be generated at the same time |
401 | run_subprocess( |
402 | ['ssh-keygen', '-f', path, '-N', '', '-t', ssh_type, |
403 | '-C', self.conf.get('vm.name')]) |
404 | @@ -871,7 +834,7 @@ |
405 | # FIXME: We do ask for a progress bar but it's not displayed |
406 | # (run_subprocess capture both stdout and stderr) ! At least while |
407 | # used interactively, it should. -- vila 2013-02-06 |
408 | - run_subprocess(['sudo', 'wget', '--progress=dot:mega','-O', |
409 | + run_subprocess(['sudo', 'wget', '--progress=dot:mega', '-O', |
410 | target, source]) |
411 | return True |
412 | else: |
413 | @@ -935,9 +898,9 @@ |
414 | raise NotImplementedError(self.create_disk_image) |
415 | |
416 | def _wait_for_install_with_seed(self): |
417 | - # The console is created by virt-install which requires sudo but creates |
418 | - # the file 0600 for libvirt-qemu. We give read access to all otherwise |
419 | - # 'tail -f' requires sudo and can't be killed anymore. |
420 | + # The console is created by virt-install which requires sudo but |
421 | + # creates the file 0600 for libvirt-qemu. We give read access to all |
422 | + # otherwise 'tail -f' requires sudo and can't be killed anymore. |
423 | run_subprocess(['sudo', 'chmod', '0644', self._console_path]) |
424 | # While `virt-install` is running, let's connect to the console |
425 | console = FileMonitor(self._console_path) |
426 | @@ -947,7 +910,7 @@ |
427 | # env var OR cmdline parameter ? -- vila 2013-02-11 |
428 | # print "read: [%s]" % (line,) # so useful for debug... |
429 | pass |
430 | - except (ConsoleEOFError, CloudInitError), e: |
431 | + except (ConsoleEOFError, CloudInitError): |
432 | # FIXME: No test covers this path -- vila 2013-02-15 |
433 | err_lines = ['Suspicious line from cloud-init.\n', |
434 | '\t' + console.lines[-1], |
435 | @@ -964,11 +927,11 @@ |
436 | |
437 | def install(self): |
438 | # Create a kvm, relying on cloud-init to customize the base image. |
439 | - # |
440 | + # |
441 | # There are two processes involvded here: |
442 | # - virt-install creates the vm and boots it. |
443 | # - progress is monitored via the console to detect cloud-final. |
444 | - # |
445 | + # |
446 | # Once cloud-init has finished, the vm can be powered off. |
447 | |
448 | # FIXME: If the install doesn't finish after $time, emit a warning and |
449 | @@ -1133,9 +1096,9 @@ |
450 | sys.stderr = err_orig |
451 | |
452 | |
453 | - |
454 | arg_parser = ArgParser() |
455 | |
456 | + |
457 | class Command(object): |
458 | |
459 | def __init__(self, vm): |
460 | |
461 | === modified file 'setup_vm/tests/__init__.py' |
462 | --- setup_vm/tests/__init__.py 2013-08-08 07:55:06 +0000 |
463 | +++ setup_vm/tests/__init__.py 2013-08-08 16:32:55 +0000 |
464 | @@ -1,3 +1,4 @@ |
465 | +import errno |
466 | import os |
467 | import shutil |
468 | import subprocess |
469 | @@ -33,8 +34,8 @@ |
470 | |
471 | :param name: The environment variable name. |
472 | |
473 | - :param new: The value to set the variable to. If None, the |
474 | - variable is deleted from the environment. |
475 | + :param new: The value to set the variable to. If None, the variable is |
476 | + deleted from the environment. |
477 | |
478 | :returns: The actual variable value. |
479 | """ |
480 | @@ -147,7 +148,8 @@ |
481 | """ |
482 | |
483 | def _probe(self): |
484 | - return os.path.exists(os.path.expanduser('~/.sudo_as_admin_successful')) |
485 | + path = os.path.expanduser('~/.sudo_as_admin_successful') |
486 | + return os.path.exists(path) |
487 | |
488 | def feature_name(self): |
489 | return 'sudo access' |
490 | |
491 | === added file 'setup_vm/tests/test_code_conformance.py' |
492 | --- setup_vm/tests/test_code_conformance.py 1970-01-01 00:00:00 +0000 |
493 | +++ setup_vm/tests/test_code_conformance.py 2013-08-08 16:32:55 +0000 |
494 | @@ -0,0 +1,30 @@ |
495 | +# Copyright 2013 Canonical Ltd. |
496 | +# |
497 | +# This program is free software: you can redistribute it and/or modify it |
498 | +# under the terms of the GNU Lesser General Public License version 3, as |
499 | +# published by the Free Software Foundation. |
500 | +# |
501 | +# This program is distributed in the hope that it will be useful, but |
502 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
503 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
504 | +# PURPOSE. See the GNU Lesser General Public License for more details. |
505 | +# |
506 | +# You should have received a copy of the GNU General Public License along |
507 | +# with this program. If not, see <http://www.gnu.org/licenses/>. |
508 | + |
509 | +import setup_vm |
510 | + |
511 | +from u1testutils.static import ( |
512 | + test_pep8_conformance as pep8, |
513 | + test_pyflakes_analysis as pyflakes, |
514 | +) |
515 | + |
516 | + |
517 | +class Pep8ConformanceTestCase(pep8.Pep8ConformanceTestCase): |
518 | + |
519 | + packages = [setup_vm] |
520 | + |
521 | + |
522 | +class PyflakesAnalysisTestCase(pyflakes.PyflakesAnalysisTestCase): |
523 | + |
524 | + packages = [setup_vm] |
525 | |
526 | === modified file 'setup_vm/tests/test_setup_vm.py' |
527 | --- setup_vm/tests/test_setup_vm.py 2013-08-08 07:55:06 +0000 |
528 | +++ setup_vm/tests/test_setup_vm.py 2013-08-08 16:32:55 +0000 |
529 | @@ -77,11 +77,9 @@ |
530 | super(TestVmStores, self).setUp() |
531 | self.conf = sm.VmStack('foo') |
532 | |
533 | - |
534 | def test_default_in_empty_stack(self): |
535 | self.assertEqual('1024', self.conf.get('vm.ram_size')) |
536 | |
537 | - |
538 | def test_system_overrides_internal(self): |
539 | self.conf.system_store._load_from_string('vm.ram_size = 42') |
540 | self.assertEqual('42', self.conf.get('vm.ram_size')) |
541 | @@ -113,10 +111,10 @@ |
542 | |
543 | def test_raring_iso_url(self): |
544 | self.assertValue('http://cdimage.ubuntu.com/daily-live/current/', |
545 | - 'vm.iso_url' ) |
546 | + 'vm.iso_url') |
547 | |
548 | def test_raring_iso_name(self): |
549 | - self.assertValue( 'raring-desktop-amd64.iso', 'vm.iso_name') |
550 | + self.assertValue('raring-desktop-amd64.iso', 'vm.iso_name') |
551 | |
552 | def test_raring_cloud_image_url(self): |
553 | self.assertValue('http://cloud-images.ubuntu.com/raring/current/', |
554 | @@ -256,7 +254,8 @@ |
555 | return sm.yaml.safe_dump(*args, **kwargs) |
556 | |
557 | def test_load_scalar(self): |
558 | - self.assertEqual({'foo': 'bar'}, self.yaml_load(StringIO('{foo: bar}'))) |
559 | + self.assertEqual( |
560 | + {'foo': 'bar'}, self.yaml_load(StringIO('{foo: bar}'))) |
561 | # Surprisingly the enclosing braces are not needed, probably a special |
562 | # case for the highest level |
563 | self.assertEqual({'foo': 'bar'}, self.yaml_load(StringIO('foo: bar'))) |
564 | @@ -276,19 +275,19 @@ |
565 | |
566 | def test_dump_list(self): |
567 | # No more enclosing braces... yeah for consistency :-/ |
568 | - self.assertEqual('foo: [a, b, c]\n', |
569 | - self.yaml_dump(dict(foo=['a', 'b', 'c']))) |
570 | + self.assertEqual( |
571 | + 'foo: [a, b, c]\n', self.yaml_dump(dict(foo=['a', 'b', 'c']))) |
572 | |
573 | def test_load_dict(self): |
574 | self.assertEqual({'foo': {'bar': 'baz'}}, |
575 | - self.yaml_load(StringIO('{foo: {bar: baz}}'))) |
576 | + self.yaml_load(StringIO('{foo: {bar: baz}}'))) |
577 | multiple_lines = '''\ |
578 | foo: {bar: multiple |
579 | lines} |
580 | ''' |
581 | - self.assertEqual({'foo': {'bar': 'multiple lines'}}, |
582 | - self.yaml_load(StringIO(multiple_lines))) |
583 | - |
584 | + self.assertEqual( |
585 | + {'foo': {'bar': 'multiple lines'}}, |
586 | + self.yaml_load(StringIO(multiple_lines))) |
587 | |
588 | |
589 | class TestLaunchpadAccess(TestCaseWithHome): |
590 | @@ -305,8 +304,8 @@ |
591 | self.ci_data.set_launchpad_access) |
592 | key_path = '~/.ssh/I-dont-exist@setup_vm' |
593 | self.assertEqual(key_path, e.path) |
594 | - self.assertTrue(unicode(e).startswith( |
595 | - 'You need to create the {p} keypair'.format(p=key_path))) |
596 | + msg_prefix = 'You need to create the {p} keypair'.format(p=key_path) |
597 | + self.assertTrue(unicode(e).startswith(msg_prefix)) |
598 | |
599 | def test_id_with_key(self): |
600 | ssh_dir = os.path.join(self.home_dir, '.ssh') |
601 | @@ -324,9 +323,9 @@ |
602 | chmod 0700 ~ubuntu |
603 | chown ubuntu:ubuntu /home/ubuntu/.ssh |
604 | chmod 0700 /home/ubuntu/.ssh |
605 | -cat >/home/ubuntu/.ssh/id_rsa <<'EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN' |
606 | +cat >/home/ubuntu/.ssh/id_rsa <<'EOSETUPVMUNIQUECONTENTDONTBREAKFORFUN' |
607 | key content |
608 | -EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN |
609 | +EOSETUPVMUNIQUECONTENTDONTBREAKFORFUN |
610 | chown ubuntu:ubuntu /home/ubuntu/.ssh/id_rsa |
611 | chmod 0400 /home/ubuntu/.ssh/id_rsa |
612 | ''', |
613 | @@ -388,8 +387,8 @@ |
614 | def test_poweroff_other(self): |
615 | self.conf.store._load_from_string('vm.release = raring') |
616 | self.ci_data.populate() |
617 | - self.assertEqual({'mode': 'poweroff'}, |
618 | - self.ci_data.cloud_config['power_state']) |
619 | + self.assertEqual( |
620 | + {'mode': 'poweroff'}, self.ci_data.cloud_config['power_state']) |
621 | self.assertIs(None, self.ci_data.cloud_config.get('runcmd')) |
622 | |
623 | def test_update_true(self): |
624 | @@ -420,7 +419,7 @@ |
625 | [{'source': 'deb http://archive.ubuntu.com/ubuntu raring partner'}, |
626 | {'source': 'deb http://archive.ubuntu.com/ubuntu raring main'}, |
627 | {'source': |
628 | - 'deb https://u:p@ppa.lp.net/user/ppa/ubuntu raring main', |
629 | + 'deb https://u:p@ppa.lp.net/user/ppa/ubuntu raring main', |
630 | 'keyid': 'ABCDEF'}], |
631 | self.ci_data.cloud_config['apt_sources']) |
632 | |
633 | @@ -492,7 +491,7 @@ |
634 | self.conf.store._load_from_string( |
635 | '''vm.uploaded_scripts = I-dont-exist ''') |
636 | self.assertRaises(sm.ConfigPathNotFound, |
637 | - self.ci_data.populate) |
638 | + self.ci_data.populate) |
639 | |
640 | def test_root_script(self): |
641 | with open('root_script.sh', 'w') as f: |
642 | @@ -507,11 +506,11 @@ |
643 | # The additional newline after the script is expected |
644 | self.assertEqual('''\ |
645 | #!/bin/sh |
646 | -cat >~root/setup_vm_post_install <<'EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN' |
647 | +cat >~root/setup_vm_post_install <<'EOSETUPVMUNIQUECONTENTDONTBREAKFORFUN' |
648 | #!/bin/sh |
649 | echo Hello root |
650 | |
651 | -EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN |
652 | +EOSETUPVMUNIQUECONTENTDONTBREAKFORFUN |
653 | chown root:root ~root/setup_vm_post_install |
654 | chmod 0700 ~root/setup_vm_post_install |
655 | ''', self.ci_data.root_hook) |
656 | @@ -531,11 +530,11 @@ |
657 | # The additional newline after the script is expected |
658 | self.assertEqual('''\ |
659 | #!/bin/sh |
660 | -cat >~ubuntu/setup_vm_post_install <<'EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN' |
661 | +cat >~ubuntu/setup_vm_post_install <<'EOSETUPVMUNIQUECONTENTDONTBREAKFORFUN' |
662 | #!/bin/sh |
663 | echo Hello ubuntu |
664 | |
665 | -EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN |
666 | +EOSETUPVMUNIQUECONTENTDONTBREAKFORFUN |
667 | chown ubuntu:ubuntu ~ubuntu/setup_vm_post_install |
668 | chmod 0700 ~ubuntu/setup_vm_post_install |
669 | ''', self.ci_data.ubuntu_hook) |
670 | @@ -555,7 +554,7 @@ |
671 | self.ci_data.populate() |
672 | self.assertEqual('''\ |
673 | #!/bin/sh |
674 | -cat >~ubuntu/setup_vm_uploads <<'EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN' |
675 | +cat >~ubuntu/setup_vm_uploads <<'EOSETUPVMUNIQUECONTENTDONTBREAKFORFUN' |
676 | mkdir -p ~ubuntu/bin |
677 | cd ~ubuntu/bin |
678 | cat >foo <<'EOFfoo' |
679 | @@ -570,7 +569,7 @@ |
680 | |
681 | EOFbar |
682 | chmod 0755 bar |
683 | -EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN |
684 | +EOSETUPVMUNIQUECONTENTDONTBREAKFORFUN |
685 | chown ubuntu:ubuntu ~ubuntu/setup_vm_uploads |
686 | chmod 0700 ~ubuntu/setup_vm_uploads |
687 | ''', |
688 | @@ -717,7 +716,7 @@ |
689 | self.assertEqual(expected, sm.vm_states(lines)) |
690 | |
691 | def test_empty(self): |
692 | - self.assertStates({},[]) |
693 | + self.assertStates({}, []) |
694 | |
695 | def test_garbage(self): |
696 | self.assertRaises(ValueError, self.assertStates, None, ['']) |
697 | @@ -941,10 +940,11 @@ |
698 | self.assertTrue(os.path.exists(public_path)) |
699 | public = file(public_path).read() |
700 | private = file(private_path).read() |
701 | - self.assertTrue(private.startswith( |
702 | - '-----BEGIN %s PRIVATE KEY-----\n' % (upper_type,))) |
703 | - self.assertTrue(private.endswith( |
704 | - '-----END %s PRIVATE KEY-----\n' % (upper_type,))) |
705 | + self.assertTrue( |
706 | + private.startswith('-----BEGIN %s PRIVATE KEY-----\n' |
707 | + % (upper_type,))) |
708 | + self.assertTrue( |
709 | + private.endswith('-----END %s PRIVATE KEY-----\n' % (upper_type,))) |
710 | return private, public |
711 | |
712 | def test_dsa(self): |
713 | @@ -990,6 +990,7 @@ |
714 | self.assertFalse(ns.install) |
715 | self.assertTrue(ns.download) |
716 | |
717 | + |
718 | class TestBuildCommands(testtools.TestCase): |
719 | |
720 | def setUp(self): |
721 | @@ -1061,7 +1062,6 @@ |
722 | def install(self): |
723 | self.install_called = True |
724 | |
725 | - |
726 | self.vm = FakeKvm(self.conf) |
727 | cmd = sm.Install(self.vm) |
728 | cmd.run() |
729 | |
730 | === modified file 'setup_vm/tests/test_test.py' |
731 | --- setup_vm/tests/test_test.py 2013-08-05 13:27:56 +0000 |
732 | +++ setup_vm/tests/test_test.py 2013-08-08 16:32:55 +0000 |
733 | @@ -16,13 +16,12 @@ |
734 | |
735 | class TestEnv(testtools.TestCase): |
736 | |
737 | - |
738 | def test_env_preserved(self): |
739 | os.environ['NOBODY_USES_THIS'] = 'foo' |
740 | |
741 | class Inner(testtools.TestCase): |
742 | |
743 | - def test_overridden(self): |
744 | + def test_overridden(self): |
745 | tests.isolate_env(self, {'NOBODY_USES_THIS': 'bar'}) |
746 | self.assertEqual('bar', os.environ['NOBODY_USES_THIS']) |
747 | |
748 | @@ -34,7 +33,7 @@ |
749 | |
750 | class Inner(testtools.TestCase): |
751 | |
752 | - def test_deleted(self): |
753 | + def test_deleted(self): |
754 | tests.isolate_env(self, {'NOBODY_USES_THIS': None}) |
755 | self.assertIs('deleted', |
756 | os.environ.get('NOBODY_USES_THIS', 'deleted')) |
757 | |
758 | === modified file 'u1testutils/static/__init__.py' |
759 | --- u1testutils/static/__init__.py 2012-12-03 17:52:45 +0000 |
760 | +++ u1testutils/static/__init__.py 2013-08-08 16:32:55 +0000 |
761 | @@ -0,0 +1,6 @@ |
762 | +# No tests to load here |
763 | + |
764 | +from sst import loaders |
765 | + |
766 | + |
767 | +discover = loaders.discoverNoTests |
768 | |
769 | === modified file 'u1testutils/static/test_pep8_conformance.py' |
770 | --- u1testutils/static/test_pep8_conformance.py 2013-04-24 13:06:11 +0000 |
771 | +++ u1testutils/static/test_pep8_conformance.py 2013-08-08 16:32:55 +0000 |
772 | @@ -26,6 +26,7 @@ |
773 | exclude = [] |
774 | |
775 | def setUp(self): |
776 | + super(Pep8ConformanceTestCase, self).setUp() |
777 | self.pep8style = pep8.StyleGuide( |
778 | counters=defaultdict(int), |
779 | doctest='', |
780 | @@ -44,6 +45,8 @@ |
781 | ) |
782 | |
783 | def test_pep8_conformance(self): |
784 | + self.assertNotEqual([], self.packages, |
785 | + 'You should define some packages to check') |
786 | for package in self.packages: |
787 | self.pep8style.input_dir(os.path.dirname(package.__file__)) |
788 | self.assertEqual(self.pep8style.options.report.total_errors, 0) |
789 | |
790 | === modified file 'u1testutils/static/test_pyflakes_analysis.py' |
791 | --- u1testutils/static/test_pyflakes_analysis.py 2012-12-04 20:05:13 +0000 |
792 | +++ u1testutils/static/test_pyflakes_analysis.py 2013-08-08 16:32:55 +0000 |
793 | @@ -28,6 +28,8 @@ |
794 | exclude_file = None |
795 | |
796 | def test_pyflakes_analysis(self): |
797 | + self.assertNotEqual([], self.packages, |
798 | + 'You should define some packages to check') |
799 | string_out = cStringIO.StringIO() |
800 | with patch('sys.stdout', string_out): |
801 | for package in self.packages: |
@Leo: Be fore you ask ;)
511 +from u1testutils.static import ( conformance as pep8, analysis as pyflakes, TestCase( pep8.Pep8Confor manceTestCase) : sTestCase( pyflakes. PyflakesAnalysi sTestCase) :
512 + test_pep8_
513 + test_pyflakes_
514 +)
515 +
516 +
517 +class Pep8Conformance
518 +
519 + packages = [setup_vm]
520 +
521 +
522 +class PyflakesAnalysi
That last line was too long with test_pyflakes_ analysis so I added the pyflakes alias in anger.
The whole file is short enough (and will remain that way in the foreseeable future) so there is no risk of collision.