Merge lp:~nuclearbob/utah/consolidate-scripts into lp:utah
- consolidate-scripts
- Merge into dev
Status: | Superseded | ||||||||
---|---|---|---|---|---|---|---|---|---|
Proposed branch: | lp:~nuclearbob/utah/consolidate-scripts | ||||||||
Merge into: | lp:utah | ||||||||
Diff against target: |
1260 lines (+180/-797) 15 files modified
debian/changelog (+5/-1) docs/source/conf.py (+1/-9) docs/source/man/run_install_test.py.rst (+0/-26) docs/source/man/run_test_cobbler.py.rst (+0/-26) docs/source/man/run_test_vm.py.rst (+0/-26) examples/run_install_test.py (+0/-114) examples/run_test_bamboo_feeder.py (+0/-119) examples/run_test_cobbler.py (+0/-127) examples/run_test_vm.py (+0/-115) examples/run_utah_tests.py (+126/-53) utah/config.py (+7/-1) utah/provisioning/baremetal/power.py (+1/-2) utah/provisioning/provisioning.py (+17/-37) utah/provisioning/vm/vm.py (+8/-22) utah/run.py (+15/-119) |
||||||||
To merge this branch: | bzr merge lp:~nuclearbob/utah/consolidate-scripts | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Javier Collado (community) | Needs Fixing | ||
Review via email: mp+159895@code.launchpad.net |
This proposal has been superseded by a proposal from 2013-04-25.
Commit message
Description of the change
This branch removes the scripts other than run_utah_tests.py and consolidates their functionality into run_utah_tests.py
I tried to minimize changes to the actual functionality here. I think we should work on testing and landing lp:~doanac/utah/run-cleanups and then look into improving the integration between the two, cleaning things up, moving things around, reworking input methods, etc.
Andy Doan (doanac) wrote : | # |
should we keep the original scripts and just print an error, so people don't think dpkg failed or something?
Andy Doan (doanac) wrote : | # |
i agree about breaking out the if/else stuff.
Also it might be worth using context managers for the machine/inventory API's now that its in one spot. It could get rid of the destroy/del stuff?
- 872. By Javier Collado
-
Merged changes to verify UTAHTimeout exceptions in rsyslog module
Source branch: lp:~javier.collado/utah/bug1169846-test-case
Max Brustkern (nuclearbob) wrote : | # |
I'd like to see different provisioning methods, whether those are functions or not, that basically only consist of getting the inventory and machine objects. Everything else I'd like to see handled the same way, either in run_utah_test.py or run.py. I'll work on cleaning up the documentation, and I think if we can land this proposal:
https:/
That'll put me in better shape to make the changes we've talked about in this branch.
Max Brustkern (nuclearbob) wrote : | # |
The documentation should be updated now. I'm pondering the best place for machine getting functions. Right now, each machine type only works with a single inventory type. Would it make sense to provide functions at the level of a Machine subclass or at an Inventory level that would parse some arguments and request a machine? Or maybe we should be pulling the Machine-specific stuff out of args to pass that in? I'm not sure.
- 873. By Javier Collado
-
Merged chnages to cleanup server code
Source branch: lp:~doanac/utah/server-cleanups
- 874. By Javier Collado
-
Merged changes to cleanup utah.run code
Source branch: lp:~doanac/utah/run-cleanups
Javier Collado (javier.collado) wrote : | # |
There still a few .rst files under docs/source/man that should be removed.
If you try to build the documentation you'll see some error messages because
those .rst files include the .txt file that was generated from the script help
output to generate the man page.
Regarding what should be the way to get a machine, I think a function or a
class method in the inventory module would be a good fit with how the code
works now.
- 875. By Max Brustkern
-
Merged reduced exception catching
- 876. By Andy Doan
-
uuid_check requires ssh so "self.provisioned" must be True
This call was moved into provisioning.py where its a litle
easier to manage it in conjunction with the state the machine
is in. This now means vm's will do the check as well, but that
should be harmless. - 877. By Javier Collado
-
Merged changes to fix help output to use just one runlist (LP: #1112597)
Source branch: lp:~nuclearbob/utah/bug1112597
- 878. By Javier Collado
-
Merged changes to fix DefaultValidator and updated schemas to draftv4 (LP: #1165175)
Source branch: lp:~javier.collado/utah/bug1165175
- 879. By Javier Collado
-
Merged changes to refactor cleanup for the machine class
Source branch: lp:~nuclearbob/utah/cleanup-cleanup
- 882. By Max Brustkern
-
Removed other scripts from documentation configuration
- 883. By Max Brustkern
-
Removed old rst files
- 884. By Max Brustkern
-
Fixed permissions after rebasing
- 885. By Max Brustkern
-
Cleaned up argument handling for machine object stuff
- 886. By Max Brustkern
-
Removed old destruction handler
- 887. By Max Brustkern
-
Simplified main function
- 888. By Max Brustkern
-
Moved command line handling back into the script since it's just one script now
- 889. By Max Brustkern
-
Fixed pep257 warning
- 890. By Max Brustkern
-
Added TODO
- 891. By Max Brustkern
-
Changed to activecheck for compatibility with potential future non-ssh Machines
- 892. By Max Brustkern
-
Changed preseed copier to check for finalpreseed attribute instead of machine type. This should improve compatibility with future machine types.
- 893. By Max Brustkern
-
Cleaned up try block behavior now that cleanup works differently
- 894. By Max Brustkern
-
Fixed pep8 warning
- 895. By Max Brustkern
-
Cleaned up run_utah_tests function a bit
- 896. By Max Brustkern
-
Using standard config interface for dlpercentincrement and making the value we always use anyway into the default
- 897. By Max Brustkern
-
Alphabetized imports
- 898. By Max Brustkern
-
Fixed LP#1130901
- 899. By Max Brustkern
-
Updated changelog
- 900. By Max Brustkern
-
Added selectable arm arch
- 901. By Max Brustkern
-
Request->request
- 902. By Max Brustkern
-
Correctly named disksizes parameter
- 903. By Max Brustkern
-
Fixed dlpercentincrement setting
- 904. By Max Brustkern
-
Only VMs are automatically named, so only they need a prefix
- 905. By Max Brustkern
-
Overhauled handling of default args and config values, and added a config for power, which fixes LP #1153735
- 906. By Max Brustkern
-
Alphabetized config options
- 907. By Max Brustkern
-
Simplified outdir setting
- 908. By Max Brustkern
-
Set argument defaults from config
- 909. By Max Brustkern
-
Removed unneeded default sets
- 910. By Max Brustkern
-
Persistent directory is only used by VMs and wasn't even being used in the main constructor
- 911. By Max Brustkern
-
Updated default setting in Machine classes
- 912. By Max Brustkern
-
Made jobtimeout a default config option
- 913. By Max Brustkern
-
Made get machine function
- 914. By Max Brustkern
-
Implemented explicit argument stuff because everybody else thinks it's great :p
- 915. By Max Brustkern
-
Fixed typo
- 916. By Max Brustkern
-
Fixed changelog
- 917. By Max Brustkern
-
Removed extra man pages
- 918. By Max Brustkern
-
Moved cleanup before exception handling
- 919. By Max Brustkern
-
Updated help strings
- 920. By Max Brustkern
-
Fixed image handling typos
- 921. By Max Brustkern
-
Fixed machineid not being set
- 922. By Max Brustkern
-
Fixed failure to chmod preseed when it doesn't exist, and fixed self tests
Unmerged revisions
Preview Diff
1 | === modified file 'debian/changelog' |
2 | --- debian/changelog 2013-04-19 19:08:00 +0000 |
3 | +++ debian/changelog 2013-04-25 15:05:30 +0000 |
4 | @@ -12,8 +12,12 @@ |
5 | * Added syslog output (including real time test output) to client |
6 | * Make rsyslog timeout error message clearer (LP: #1169846) |
7 | * Write to log UTAH version as soon as possible (LP: #1152216) |
8 | + * Combined current provisioning functions into one script and removed |
9 | + old scripts |
10 | + * Fixed LP #1130901 |
11 | + * Fixed LP #1153735 |
12 | |
13 | - -- Max Brustkern <max@canonical.com> Tue, 16 Apr 2013 09:21:19 -0400 |
14 | + -- Max Brustkern <max@canonical.com> Thu, 25 Apr 2013 11:02:23 -0400 |
15 | |
16 | utah (0.10ubuntu1) UNRELEASED; urgency=low |
17 | |
18 | |
19 | === modified file 'docs/source/conf.py' |
20 | --- docs/source/conf.py 2013-04-18 10:46:00 +0000 |
21 | +++ docs/source/conf.py 2013-04-25 15:05:30 +0000 |
22 | @@ -148,8 +148,7 @@ |
23 | |
24 | return description, options, epilog |
25 | |
26 | -module_names = ('client', 'run_install_test', 'run_test_cobbler', |
27 | - 'run_test_vm', 'run_utah_tests') |
28 | +module_names = ('client', 'run_utah_tests') |
29 | for module_name in module_names: |
30 | module = __import__(module_name) |
31 | parser = module.get_parser() |
32 | @@ -367,13 +366,6 @@ |
33 | man_pages = [ |
34 | ('man/utah', 'utah', u'UTAH client test runner', |
35 | [u'Canonical Ltd'], 1), |
36 | - ('man/run_install_test.py', 'run_install_test.py', |
37 | - u'UTAH server test runner (provisioning)', [u'Canonical Ltd'], 1), |
38 | - ('man/run_test_cobbler.py', 'run_test_cobbler.py', |
39 | - u'UTAH server test runner (physical hardware)', [u'Canonical Ltd'], 1), |
40 | - ('man/run_test_vm.py', 'run_test_vm.py', |
41 | - u'UTAH server test runner (virtual hardware)', |
42 | - [u'Canonical Ltd'], 1), |
43 | ('man/run_utah_tests.py', 'run_utah_tests.py', |
44 | u'UTAH server test runner (any hardware)', [u'Canonical Ltd'], 1), |
45 | ] |
46 | |
47 | === removed file 'docs/source/man/run_install_test.py.rst' |
48 | --- docs/source/man/run_install_test.py.rst 2012-09-05 11:30:16 +0000 |
49 | +++ docs/source/man/run_install_test.py.rst 1970-01-01 00:00:00 +0000 |
50 | @@ -1,26 +0,0 @@ |
51 | -:orphan: |
52 | - |
53 | -run_install_test.py manual page |
54 | -=============================== |
55 | - |
56 | -Synopsis |
57 | --------- |
58 | -**run_install_test.py** [options] [runlist ...] |
59 | - |
60 | -Description |
61 | ------------ |
62 | -.. include:: run_install_test_description.txt |
63 | - |
64 | -Options |
65 | -------- |
66 | -.. include:: run_install_test_options.txt |
67 | - |
68 | -Examples |
69 | --------- |
70 | -.. include:: run_install_test_epilog.txt |
71 | - |
72 | -See also |
73 | --------- |
74 | -:manpage:`run_test_cobbler.py(1)` |
75 | -:manpage:`run_test_vm.py(1)` |
76 | -:manpage:`run_utah_tests.py(1)` |
77 | |
78 | === removed file 'docs/source/man/run_test_cobbler.py.rst' |
79 | --- docs/source/man/run_test_cobbler.py.rst 2012-09-05 11:30:16 +0000 |
80 | +++ docs/source/man/run_test_cobbler.py.rst 1970-01-01 00:00:00 +0000 |
81 | @@ -1,26 +0,0 @@ |
82 | -:orphan: |
83 | - |
84 | -run_test_cobbler.py manual page |
85 | -=============================== |
86 | - |
87 | -Synopsis |
88 | --------- |
89 | -**run_test_cobbler.py** [options] [runlist ...] |
90 | - |
91 | -Description |
92 | ------------ |
93 | -.. include:: run_test_cobbler_description.txt |
94 | - |
95 | -Options |
96 | -------- |
97 | -.. include:: run_test_cobbler_options.txt |
98 | - |
99 | -Examples |
100 | --------- |
101 | -.. include:: run_test_cobbler_epilog.txt |
102 | - |
103 | -See also |
104 | --------- |
105 | -:manpage:`run_install_test.py(1)` |
106 | -:manpage:`run_test_vm.py(1)` |
107 | -:manpage:`run_utah_tests.py(1)` |
108 | |
109 | === removed file 'docs/source/man/run_test_vm.py.rst' |
110 | --- docs/source/man/run_test_vm.py.rst 2012-09-05 11:30:16 +0000 |
111 | +++ docs/source/man/run_test_vm.py.rst 1970-01-01 00:00:00 +0000 |
112 | @@ -1,26 +0,0 @@ |
113 | -:orphan: |
114 | - |
115 | -run_test_vm.py manual page |
116 | -========================== |
117 | - |
118 | -Synopsis |
119 | --------- |
120 | -**run_test_vm.py** [options] [runlist ...] |
121 | - |
122 | -Description |
123 | ------------ |
124 | -.. include:: run_test_vm_description.txt |
125 | - |
126 | -Options |
127 | -------- |
128 | -.. include:: run_test_vm_options.txt |
129 | - |
130 | -Examples |
131 | --------- |
132 | -.. include:: run_test_vm_epilog.txt |
133 | - |
134 | -See also |
135 | --------- |
136 | -:manpage:`run_install_test.py(1)` |
137 | -:manpage:`run_test_cobbler.py(1)` |
138 | -:manpage:`run_utah_tests.py(1)` |
139 | |
140 | === removed file 'examples/run_install_test.py' |
141 | --- examples/run_install_test.py 2013-04-18 14:15:12 +0000 |
142 | +++ examples/run_install_test.py 1970-01-01 00:00:00 +0000 |
143 | @@ -1,114 +0,0 @@ |
144 | -#!/usr/bin/env python |
145 | - |
146 | -# Ubuntu Testing Automation Harness |
147 | -# Copyright 2012 Canonical Ltd. |
148 | - |
149 | -# This program is free software: you can redistribute it and/or modify it |
150 | -# under the terms of the GNU General Public License version 3, as published |
151 | -# by the Free Software Foundation. |
152 | - |
153 | -# This program is distributed in the hope that it will be useful, but |
154 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
155 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
156 | -# PURPOSE. See the GNU General Public License for more details. |
157 | - |
158 | -# You should have received a copy of the GNU General Public License along |
159 | -# with this program. If not, see <http://www.gnu.org/licenses/>. |
160 | - |
161 | -"""Create a VM and run a test.""" |
162 | - |
163 | - |
164 | -import argparse |
165 | -import logging |
166 | -import sys |
167 | - |
168 | -from utah.cleanup import cleanup |
169 | -from utah.exceptions import UTAHException |
170 | -from utah.group import check_user_group, print_group_error_message |
171 | -from utah.provisioning.vm.vm import CustomVM, TinySQLiteInventory |
172 | -from utah.run import ( |
173 | - common_arguments, |
174 | - custom_arguments, |
175 | - file_arguments, |
176 | - run_tests, |
177 | - virtual_arguments, |
178 | - configure_logging, |
179 | - ReturnCodes, |
180 | -) |
181 | - |
182 | - |
183 | -def get_parser(): |
184 | - parser = argparse.ArgumentParser( |
185 | - description=('Provision a machine ' |
186 | - 'and run one or more UTAH runlists there.'), |
187 | - epilog=("For example:\n" |
188 | - "Provision a VM using a precise server image " |
189 | - "with i386 architecture and run the two given runlists\n" |
190 | - "\t%(prog)s -s precise -t server -a i386 \\\n" |
191 | - "\t\t/usr/share/utah/client/examples/master.run \\\n" |
192 | - "\t\t'http://people.canonical.com/~max/max_test.run'"), |
193 | - formatter_class=argparse.RawDescriptionHelpFormatter) |
194 | - parser = common_arguments(parser) |
195 | - parser = custom_arguments(parser) |
196 | - parser = file_arguments(parser) |
197 | - parser = virtual_arguments(parser) |
198 | - return parser |
199 | - |
200 | - |
201 | -def run_install_test(args=None): |
202 | - if args is None: |
203 | - args = get_parser().parse_args() |
204 | - |
205 | - if not check_user_group(): |
206 | - print_group_error_message(__file__) |
207 | - sys.exit(ReturnCodes.GROUP_ERROR) |
208 | - |
209 | - locallogs = [] |
210 | - exitstatus = ReturnCodes.SUCCESS |
211 | - machine = None |
212 | - |
213 | - configure_logging(args.debug) |
214 | - |
215 | - try: |
216 | - inventory = TinySQLiteInventory() |
217 | - machine = inventory.request( |
218 | - CustomVM, |
219 | - arch=args.arch, boot=args.boot, clean=(not args.no_destroy), |
220 | - debug=args.debug, diskbus=args.diskbus, |
221 | - disksizes=args.gigabytes, dlpercentincrement=10, |
222 | - emulator=args.emulator, image=args.image, initrd=args.initrd, |
223 | - installtype=args.type, kernel=args.kernel, new=True, |
224 | - preseed=args.preseed, rewrite=args.rewrite, |
225 | - series=args.series, xml=args.xml) |
226 | - exitstatus, locallogs = run_tests(args, machine) |
227 | - finally: |
228 | - if not args.no_destroy and machine is not None: |
229 | - try: |
230 | - machine.destroy() |
231 | - except UTAHException as error: |
232 | - sys.stderr.write('Failed to destroy machine: ' + str(error)) |
233 | - finally: |
234 | - try: |
235 | - inventory.destroy(machine.machineid) |
236 | - except UTAHException as error: |
237 | - sys.stderr.write('Failed to update inventory: ' |
238 | - + str(error)) |
239 | - finally: |
240 | - del machine |
241 | - if len(locallogs) != 0: |
242 | - print('Test logs copied to the following files:') |
243 | - print("\t" + "\n\t".join(locallogs)) |
244 | - |
245 | - sys.exit(exitstatus) |
246 | - |
247 | - |
248 | -if __name__ == '__main__': |
249 | - logging.warning('This script is deprecated; please use run_utah_tests.py') |
250 | - logging.warning('The same command line arguments should work there, i.e.:') |
251 | - argv = list(sys.argv) |
252 | - argv[0] = 'run_utah_tests.py' |
253 | - logging.warning(' '.join(argv)) |
254 | - try: |
255 | - run_install_test() |
256 | - finally: |
257 | - cleanup.run() |
258 | |
259 | === removed file 'examples/run_test_bamboo_feeder.py' |
260 | --- examples/run_test_bamboo_feeder.py 2013-04-10 15:34:49 +0000 |
261 | +++ examples/run_test_bamboo_feeder.py 1970-01-01 00:00:00 +0000 |
262 | @@ -1,119 +0,0 @@ |
263 | -#!/usr/bin/env python |
264 | - |
265 | -# Ubuntu Testing Automation Harness |
266 | -# Copyright 2012 Canonical Ltd. |
267 | - |
268 | -# This program is free software: you can redistribute it and/or modify it |
269 | -# under the terms of the GNU General Public License version 3, as published |
270 | -# by the Free Software Foundation. |
271 | - |
272 | -# This program is distributed in the hope that it will be useful, but |
273 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
274 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
275 | -# PURPOSE. See the GNU General Public License for more details. |
276 | - |
277 | -# You should have received a copy of the GNU General Public License along |
278 | -# with this program. If not, see <http://www.gnu.org/licenses/>. |
279 | - |
280 | -"""Provision a panda board in a bamboo-feeder setup and run a test.""" |
281 | - |
282 | - |
283 | -import argparse |
284 | -import os |
285 | -import sys |
286 | -import logging |
287 | - |
288 | -from utah.cleanup import cleanup |
289 | -from utah.exceptions import UTAHException |
290 | -from utah.group import check_user_group, print_group_error_message |
291 | -from utah.provisioning.baremetal.bamboofeeder import BambooFeederMachine |
292 | -from utah.provisioning.baremetal.inventory import \ |
293 | - ManualBaremetalSQLiteInventory |
294 | -from utah.run import ( |
295 | - common_arguments, |
296 | - custom_arguments, |
297 | - name_argument, |
298 | - run_tests, |
299 | - configure_logging, |
300 | - ReturnCodes, |
301 | -) |
302 | - |
303 | - |
304 | -def get_parser(): |
305 | - parser = argparse.ArgumentParser( |
306 | - description=('Provision a pandaboard in a bamboo-feeder setup ' |
307 | - 'and run one or more UTAH runlists there.'), |
308 | - epilog=("For example:\n" |
309 | - "Provision a machine using a precise server image " |
310 | - "with i386 architecture and run the two given runlists\n" |
311 | - "\t%(prog)s -s precise -t server -a i386 \\\n" |
312 | - "\t\t/usr/share/utah/client/examples/master.run \\\n" |
313 | - "\t\t'http://people.canonical.com/~max/max_test.run'"), |
314 | - formatter_class=argparse.RawDescriptionHelpFormatter) |
315 | - parser = common_arguments(parser) |
316 | - parser = custom_arguments(parser) |
317 | - parser = name_argument(parser) |
318 | - return parser |
319 | - |
320 | - |
321 | -def run_test_bamboo_feeder(args=None): |
322 | - if args is None: |
323 | - args = get_parser().parse_args() |
324 | - |
325 | - if not check_user_group(): |
326 | - print_group_error_message(__file__) |
327 | - sys.exit(ReturnCodes.GROUP_ERROR) |
328 | - |
329 | - locallogs = [] |
330 | - exitstatus = ReturnCodes.SUCCESS |
331 | - machine = None |
332 | - |
333 | - configure_logging(args.debug) |
334 | - |
335 | - try: |
336 | - inventory = ManualBaremetalSQLiteInventory( |
337 | - db=os.path.join('~', '.utah-bamboofeeder-inventory'), |
338 | - lockfile=os.path.join('~', '.utah-bamboofeeder-lock')) |
339 | - kw = {} |
340 | - for arg in ['boot', 'image', 'preseed']: |
341 | - value = getattr(args, arg) |
342 | - if value is not None: |
343 | - kw[arg] = value |
344 | - machine = inventory.request(machinetype=BambooFeederMachine, |
345 | - clean=(not args.no_destroy), |
346 | - debug=args.debug, new=True, |
347 | - dlpercentincrement=10, **kw) |
348 | - exitstatus, locallogs = run_tests(args, machine) |
349 | - |
350 | - except UTAHException as error: |
351 | - mesg = 'Exception: ' + str(error) |
352 | - try: |
353 | - logging.error(mesg) |
354 | - except (AttributeError, NameError): |
355 | - sys.stderr.write(mesg) |
356 | - exitstatus = ReturnCodes.UTAH_EXCEPTION_ERROR |
357 | - except Exception: |
358 | - logging.exception('Unhandled error in UTAH') |
359 | - exitstatus = ReturnCodes.UNHANDLED_ERROR |
360 | - finally: |
361 | - if machine is not None: |
362 | - try: |
363 | - machine.destroy() |
364 | - except UTAHException as error: |
365 | - sys.stderr.write('Failed to destroy machine: ' + str(error)) |
366 | - |
367 | - if len(locallogs) != 0: |
368 | - print('Test logs copied to the following files:') |
369 | - print("\t" + "\n\t".join(locallogs)) |
370 | - |
371 | - sys.exit(exitstatus) |
372 | - |
373 | - |
374 | -if __name__ == '__main__': |
375 | - logging.warning('This script is thought to be broken') |
376 | - logging.warning('If it is working, please report it to the UTAH team via ' |
377 | - 'ubuntu-utah-devel@lists.ubuntu.com') |
378 | - try: |
379 | - run_test_bamboo_feeder() |
380 | - finally: |
381 | - cleanup.run() |
382 | |
383 | === removed file 'examples/run_test_cobbler.py' |
384 | --- examples/run_test_cobbler.py 2013-04-10 15:34:49 +0000 |
385 | +++ examples/run_test_cobbler.py 1970-01-01 00:00:00 +0000 |
386 | @@ -1,127 +0,0 @@ |
387 | -#!/usr/bin/env python |
388 | - |
389 | -# Ubuntu Testing Automation Harness |
390 | -# Copyright 2012 Canonical Ltd. |
391 | - |
392 | -# This program is free software: you can redistribute it and/or modify it |
393 | -# under the terms of the GNU General Public License version 3, as published |
394 | -# by the Free Software Foundation. |
395 | - |
396 | -# This program is distributed in the hope that it will be useful, but |
397 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
398 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
399 | -# PURPOSE. See the GNU General Public License for more details. |
400 | - |
401 | -# You should have received a copy of the GNU General Public License along |
402 | -# with this program. If not, see <http://www.gnu.org/licenses/>. |
403 | - |
404 | -"""Provision a machine with cobbler and run a test.""" |
405 | - |
406 | - |
407 | -import argparse |
408 | -import sys |
409 | -import logging |
410 | - |
411 | -from utah.cleanup import cleanup |
412 | -from utah.exceptions import UTAHException |
413 | -from utah.group import check_user_group, print_group_error_message |
414 | -from utah.provisioning.baremetal.cobbler import CobblerMachine |
415 | -from utah.provisioning.baremetal.inventory import \ |
416 | - ManualBaremetalSQLiteInventory |
417 | -from utah.run import ( |
418 | - common_arguments, |
419 | - custom_arguments, |
420 | - name_argument, |
421 | - run_tests, |
422 | - configure_logging, |
423 | - ReturnCodes, |
424 | -) |
425 | - |
426 | - |
427 | -def get_parser(): |
428 | - parser = argparse.ArgumentParser( |
429 | - description=('Provision a machine using cobbler ' |
430 | - 'and run one or more UTAH runlists there.'), |
431 | - epilog=("For example:\n" |
432 | - "Provision a machine using a precise server image " |
433 | - "with i386 architecture and run the two given runlists\n" |
434 | - "\t%(prog)s -s precise -t server -a i386 \\\n" |
435 | - "\t\t/usr/share/utah/client/examples/master.run \\\n" |
436 | - "\t\t'http://people.canonical.com/~max/max_test.run'"), |
437 | - formatter_class=argparse.RawDescriptionHelpFormatter) |
438 | - parser = common_arguments(parser) |
439 | - parser = custom_arguments(parser) |
440 | - parser = name_argument(parser) |
441 | - return parser |
442 | - |
443 | - |
444 | -def run_test_cobbler(args=None): |
445 | - if args is None: |
446 | - args = get_parser().parse_args() |
447 | - |
448 | - if not check_user_group(): |
449 | - print_group_error_message(__file__) |
450 | - sys.exit(ReturnCodes.GROUP_ERROR) |
451 | - |
452 | - locallogs = [] |
453 | - exitstatus = ReturnCodes.SUCCESS |
454 | - machine = None |
455 | - |
456 | - configure_logging(args.debug) |
457 | - |
458 | - try: |
459 | - inventory = ManualBaremetalSQLiteInventory() |
460 | - kw = {} |
461 | - for arg in ['arch', |
462 | - 'boot', |
463 | - 'image', |
464 | - 'preseed', |
465 | - 'rewrite', |
466 | - 'series', |
467 | - ]: |
468 | - value = getattr(args, arg) |
469 | - if value is not None: |
470 | - kw[arg] = value |
471 | - if getattr(args, 'type') is not None: |
472 | - kw['installtype'] = args.type |
473 | - machine = inventory.request(CobblerMachine, |
474 | - clean=(not args.no_destroy), |
475 | - debug=args.debug, dlpercentincrement=10, |
476 | - name=args.name, new=True, **kw) |
477 | - exitstatus, locallogs = run_tests(args, machine) |
478 | - |
479 | - except UTAHException as error: |
480 | - mesg = 'Exception: ' + str(error) |
481 | - try: |
482 | - logging.error(mesg) |
483 | - except (AttributeError, NameError): |
484 | - sys.stderr.write(mesg) |
485 | - exitstatus = ReturnCodes.UTAH_EXCEPTION_ERROR |
486 | - except Exception: |
487 | - logging.exception('Unhandled error in UTAH') |
488 | - exitstatus = ReturnCodes.UNHANDLED_ERROR |
489 | - finally: |
490 | - if machine is not None: |
491 | - try: |
492 | - machine.destroy() |
493 | - except UTAHException as error: |
494 | - sys.stderr.write('Failed to destroy machine: ' + str(error)) |
495 | - |
496 | - if len(locallogs) != 0: |
497 | - print('Test logs copied to the following files:') |
498 | - print("\t" + "\n\t".join(locallogs)) |
499 | - |
500 | - sys.exit(exitstatus) |
501 | - |
502 | - |
503 | -if __name__ == '__main__': |
504 | - logging.warning('This script is deprecated; please use run_utah_tests.py') |
505 | - logging.warning('Add the -m physical argument to your existing list, i.e.:') |
506 | - argv = list(sys.argv) |
507 | - argv[0] = 'run_utah_tests.py' |
508 | - argv.extend(['-m', 'physical']) |
509 | - logging.warning(' '.join(argv)) |
510 | - try: |
511 | - run_test_cobbler() |
512 | - finally: |
513 | - cleanup.run() |
514 | |
515 | === removed file 'examples/run_test_vm.py' |
516 | --- examples/run_test_vm.py 2013-04-10 15:34:49 +0000 |
517 | +++ examples/run_test_vm.py 1970-01-01 00:00:00 +0000 |
518 | @@ -1,115 +0,0 @@ |
519 | -#!/usr/bin/env python |
520 | - |
521 | -# Ubuntu Testing Automation Harness |
522 | -# Copyright 2012 Canonical Ltd. |
523 | - |
524 | -# This program is free software: you can redistribute it and/or modify it |
525 | -# under the terms of the GNU General Public License version 3, as published |
526 | -# by the Free Software Foundation. |
527 | - |
528 | -# This program is distributed in the hope that it will be useful, but |
529 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
530 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
531 | -# PURPOSE. See the GNU General Public License for more details. |
532 | - |
533 | -# You should have received a copy of the GNU General Public License along |
534 | -# with this program. If not, see <http://www.gnu.org/licenses/>. |
535 | - |
536 | -"""Create a VM and run a test.""" |
537 | - |
538 | - |
539 | -import argparse |
540 | -import logging |
541 | -import sys |
542 | - |
543 | -from utah.cleanup import cleanup |
544 | -from utah.exceptions import UTAHException |
545 | -from utah.group import check_user_group, print_group_error_message |
546 | -from utah.provisioning.vm.vm import TinySQLiteInventory |
547 | -from utah.run import ( |
548 | - common_arguments, |
549 | - run_tests, |
550 | - configure_logging, |
551 | - ReturnCodes, |
552 | -) |
553 | - |
554 | - |
555 | -def get_parser(): |
556 | - parser = argparse.ArgumentParser( |
557 | - description=('Create a virtual machine ' |
558 | - 'and run a UTAH runlist there.'), |
559 | - epilog=("For example:\n" |
560 | - "Provision a VM using a precise server image " |
561 | - "with i386 architecture and run the two given runlists\n" |
562 | - "\t%(prog)s -s precise -t server -a i386 \\\n" |
563 | - "\t\t/usr/share/utah/client/examples/master.run \\\n" |
564 | - "\t\t'http://people.canonical.com/~max/max_test.run'"), |
565 | - formatter_class=argparse.RawDescriptionHelpFormatter) |
566 | - return common_arguments(parser) |
567 | - |
568 | - |
569 | -def run_test_vm(args=None): |
570 | - if args is None: |
571 | - args = get_parser().parse_args() |
572 | - |
573 | - if not check_user_group(): |
574 | - print_group_error_message(__file__) |
575 | - sys.exit(ReturnCodes.GROUP_ERROR) |
576 | - |
577 | - locallogs = [] |
578 | - exitstatus = ReturnCodes.SUCCESS |
579 | - machine = None |
580 | - |
581 | - configure_logging(args.debug) |
582 | - |
583 | - try: |
584 | - inventory = TinySQLiteInventory() |
585 | - kw = {} |
586 | - for arg in ['arch', 'series']: |
587 | - value = getattr(args, arg) |
588 | - if value is not None: |
589 | - kw[arg] = value |
590 | - if args.type is not None: |
591 | - kw.update([('installtype', args.type)]) |
592 | - machine = inventory.request(clean=(not args.no_destroy), |
593 | - debug=args.debug, new=True, |
594 | - dlpercentincrement=10, **kw) |
595 | - exitstatus, locallogs = run_tests(args, machine) |
596 | - |
597 | - except UTAHException as error: |
598 | - sys.stderr.write('Exception: ' + str(error)) |
599 | - exitstatus = ReturnCodes.UTAH_EXCEPTION_ERROR |
600 | - except Exception: |
601 | - logging.exception('Unhandled error in UTAH') |
602 | - exitstatus = ReturnCodes.UNHANDLED_ERROR |
603 | - finally: |
604 | - if not args.no_destroy and machine is not None: |
605 | - try: |
606 | - machine.destroy() |
607 | - except UTAHException as error: |
608 | - sys.stderr.write('Failed to destroy machine: ' + str(error)) |
609 | - finally: |
610 | - try: |
611 | - inventory.destroy(machine.machineid) |
612 | - except UTAHException as error: |
613 | - sys.stderr.write('Failed to update inventory: ' |
614 | - + str(error)) |
615 | - finally: |
616 | - del machine |
617 | - if len(locallogs) != 0: |
618 | - print('Test logs copied to the following files:') |
619 | - print("\t" + "\n\t".join(locallogs)) |
620 | - |
621 | - sys.exit(exitstatus) |
622 | - |
623 | - |
624 | -if __name__ == '__main__': |
625 | - logging.warning('This script is deprecated; please use run_utah_tests.py') |
626 | - logging.warning('The same command line arguments should work there, i.e.:') |
627 | - argv = list(sys.argv) |
628 | - argv[0] = 'run_utah_tests.py' |
629 | - logging.warning(' '.join(argv)) |
630 | - try: |
631 | - run_test_vm() |
632 | - finally: |
633 | - cleanup.run() |
634 | |
635 | === modified file 'examples/run_utah_tests.py' |
636 | --- examples/run_utah_tests.py 2013-04-24 11:37:21 +0000 |
637 | +++ examples/run_utah_tests.py 2013-04-25 15:05:30 +0000 |
638 | @@ -20,27 +20,31 @@ |
639 | |
640 | import argparse |
641 | import logging |
642 | +import os |
643 | import sys |
644 | + |
645 | from traceback import format_exception |
646 | |
647 | import utah |
648 | + |
649 | from utah import config |
650 | from utah.cleanup import cleanup |
651 | +from utah.exceptions import UTAHException |
652 | from utah.group import check_user_group, print_group_error_message |
653 | +from utah.provisioning.baremetal.bamboofeeder import BambooFeederMachine |
654 | +from utah.provisioning.baremetal.cobbler import CobblerMachine |
655 | +from utah.provisioning.baremetal.inventory import \ |
656 | + ManualBaremetalSQLiteInventory |
657 | +from utah.provisioning.ssh import ProvisionedMachine |
658 | +from utah.provisioning.vm.vm import TinySQLiteInventory |
659 | from utah.run import ( |
660 | - common_arguments, |
661 | - custom_arguments, |
662 | - file_arguments, |
663 | - name_argument, |
664 | - virtual_arguments, |
665 | configure_logging, |
666 | + master_runlist_argument, |
667 | run_tests, |
668 | ReturnCodes, |
669 | ) |
670 | from utah.timeout import timeout, UTAHTimeout |
671 | -from run_install_test import run_install_test |
672 | -from utah.provisioning.ssh import ProvisionedMachine |
673 | -from utah.exceptions import UTAHException |
674 | +from utah.url import url_argument |
675 | |
676 | |
677 | def get_parser(): |
678 | @@ -64,11 +68,63 @@ |
679 | parser.add_argument('--skip-provisioning', action='store_true', |
680 | help=('Reuse a system that is already provisioned ' |
681 | '(name argument must be passed)')) |
682 | - parser = common_arguments(parser) |
683 | - parser = custom_arguments(parser) |
684 | - parser = file_arguments(parser) |
685 | - parser = name_argument(parser) |
686 | - parser = virtual_arguments(parser) |
687 | + parser.add_argument('runlist', metavar='runlist', |
688 | + type=master_runlist_argument, |
689 | + help='URLs of runlist files to run') |
690 | + parser.add_argument('-s', '--series', metavar='SERIES', |
691 | + choices=config.serieschoices, |
692 | + help='Series to use for VM creation (%(choices)s)') |
693 | + parser.add_argument('-t', '--type', metavar='TYPE', |
694 | + choices=('desktop', 'server', 'mini', 'alternate'), |
695 | + help=('Install type to use for VM creation ' |
696 | + '(%(choices)s)')) |
697 | + parser.add_argument('-a', '--arch', metavar='ARCH', |
698 | + choices=('i386', 'amd64', 'arm'), |
699 | + help=('Architecture to use for VM creation ' |
700 | + '(%(choices)s)')) |
701 | + parser.add_argument('-n', '--no-destroy', action='store_true', |
702 | + help='Preserve VM after tests have run') |
703 | + parser.add_argument('-d', '--debug', action='store_true', |
704 | + help='Enable debug logging') |
705 | + parser.add_argument('-j', '--json', action='store_true', |
706 | + help='Enable json logging (default is YAML)') |
707 | + parser.add_argument('-f', '--files', action='append', |
708 | + help='File or directory to copy from test system ') |
709 | + parser.add_argument('-o', '--outdir', |
710 | + help=('Directory to store locally copied files ' |
711 | + '(Default is {}/machine-name)' |
712 | + .format(config.logpath))) |
713 | + parser.add_argument('--dumplogs', action='store_true', |
714 | + help='Write client output logs to standard out') |
715 | + parser.add_argument('--outputpreseed', action='store_true', |
716 | + help='Copy preseed to logs directory and list as ' |
717 | + 'log file in output') |
718 | + parser.add_argument('-i', '--image', type=url_argument, |
719 | + help='Image/ISO file to use for installation') |
720 | + parser.add_argument('-p', '--preseed', type=url_argument, |
721 | + help='Preseed file to use for installation') |
722 | + parser.add_argument('-b', '--boot', |
723 | + help='Boot arguments for initial installation') |
724 | + parser.add_argument('--rewrite', choices=('all', 'minimal', 'casperonly', |
725 | + 'none'), help='Enable or disable automatic ' |
726 | + 'configuration rewriting') |
727 | + parser.add_argument('-k', '--kernel', type=url_argument, |
728 | + help='Kernel file to use for installation') |
729 | + parser.add_argument('-r', '--initrd', type=url_argument, |
730 | + help='InitRD file to use for installation') |
731 | + parser.add_argument('--name', help='Name of machine to provision') |
732 | + parser.add_argument('-e', '--emulator', |
733 | + help=('Emulator to use (kvm and qemu are supported, ' |
734 | + 'kvm will be favored if available)')) |
735 | + parser.add_argument('-x', '--xml', type=url_argument, |
736 | + help='XML VM definition file') |
737 | + parser.add_argument('-g', '--gigabytes', action='append', |
738 | + help=('Size in gigabytes of virtual disk, ' |
739 | + 'specify more than once for multiple disks')) |
740 | + parser.add_argument('--diskbus', metavar='DISKBUS', |
741 | + choices=('virtio', 'sata', 'ide'), |
742 | + help=('Disk bus to use for customvm installation ' |
743 | + '(%(choices)s)')) |
744 | return parser |
745 | |
746 | |
747 | @@ -78,57 +134,71 @@ |
748 | |
749 | if not check_user_group(): |
750 | print_group_error_message(__file__) |
751 | - sys.exit(ReturnCodes.GROUP_ERROR) |
752 | + return ReturnCodes.GROUP_ERROR |
753 | |
754 | - if args.machinetype is None: |
755 | + if args.arch: |
756 | + arch = args.arch |
757 | + else: |
758 | + arch = config.arch |
759 | + if args.machinetype: |
760 | + machinetype = args.machinetype |
761 | + else: |
762 | machinetype = config.machinetype |
763 | - else: |
764 | - machinetype = args.machinetype |
765 | |
766 | configure_logging(args.debug) |
767 | logging.info('UTAH version: %s', utah.__version__) |
768 | |
769 | - # Default is now CustomVM |
770 | - function = run_install_test |
771 | + exitstatus = ReturnCodes.SUCCESS |
772 | + locallogs = [] |
773 | |
774 | if args.skip_provisioning: |
775 | - def run_provisioned_tests(args): |
776 | - """Run test cases in a provisioned machine.""" |
777 | - locallogs = [] |
778 | - try: |
779 | - # TBD: Inventory should be used to verify machine |
780 | - # is not running other tests |
781 | - machine = ProvisionedMachine(name=args.name) |
782 | - exitstatus, locallogs = run_tests(args, machine) |
783 | - finally: |
784 | - if len(locallogs) != 0: |
785 | - print('Test logs copied to the following files:') |
786 | - print("\t" + "\n\t".join(locallogs)) |
787 | - sys.exit(ReturnCodes.SUCCESS) |
788 | - |
789 | - function = run_provisioned_tests |
790 | - if args.arch is not None and 'arm' in args.arch: |
791 | - # If arch is arm, use BambooFeederMachine |
792 | - from run_test_bamboo_feeder import run_test_bamboo_feeder |
793 | - function = run_test_bamboo_feeder |
794 | - elif machinetype == 'physical': |
795 | - # If machinetype is physical but arch isn't arm, use CobblerMachine |
796 | - from run_test_cobbler import run_test_cobbler |
797 | - function = run_test_cobbler |
798 | - |
799 | - function(args=args) |
800 | + # TBD: Inventory should be used to verify machine |
801 | + # is not running other tests |
802 | + machine = ProvisionedMachine(name=args.name) |
803 | + else: |
804 | + kw = {'clean': (not args.no_destroy), |
805 | + 'new': True, |
806 | + } |
807 | + for arg in ['arch', |
808 | + 'boot', |
809 | + 'debug', |
810 | + 'image', |
811 | + 'initrd', |
812 | + 'kernel', |
813 | + 'name', |
814 | + 'preseed', |
815 | + 'rewrite', |
816 | + 'series', |
817 | + ]: |
818 | + kw[arg] = getattr(args, arg) |
819 | + kw['installtype'] = args.type |
820 | + if machinetype == 'physical': |
821 | + if arch and 'arm' in arch: |
822 | + inventory = ManualBaremetalSQLiteInventory( |
823 | + db=os.path.join('~', '.utah-bamboofeeder-inventory'), |
824 | + lockfile=os.path.join('~', '.utah-bamboofeeder-lock')) |
825 | + kw['machinetype'] = BambooFeederMachine |
826 | + else: |
827 | + inventory = ManualBaremetalSQLiteInventory() |
828 | + kw['machinetype'] = CobblerMachine |
829 | + else: |
830 | + inventory = TinySQLiteInventory() |
831 | + for arg in ['diskbus', 'emulator', 'xml']: |
832 | + kw[arg] = getattr(args, arg) |
833 | + kw['disksizes'] = args.gigabytes |
834 | + machine = inventory.request(**kw) |
835 | + exitstatus, locallogs = run_tests(args, machine) |
836 | + if len(locallogs) > 0: |
837 | + print('Test logs copied to the following files:') |
838 | + print("\t" + "\n\t".join(locallogs)) |
839 | + |
840 | + return(exitstatus) |
841 | + |
842 | |
843 | if __name__ == '__main__': |
844 | try: |
845 | - try: |
846 | - if isinstance(config.jobtimeout, int): |
847 | - timeout(config.jobtimeout, run_utah_tests) |
848 | - else: |
849 | - run_utah_tests() |
850 | - except AttributeError: |
851 | - run_utah_tests() |
852 | - finally: |
853 | - cleanup.run() |
854 | + exitstatus = timeout(getattr(config, 'jobtimeout', None), |
855 | + run_utah_tests) |
856 | except UTAHTimeout as exception: |
857 | sys.stderr.write('UTAH timeout: {}\n'.format(exception.message)) |
858 | sys.exit(ReturnCodes.TIMEOUT_ERROR) |
859 | @@ -139,3 +209,6 @@ |
860 | sys.stderr.write('Unhandled error in UTAH:\n{}\n' |
861 | .format(''.join(format_exception(*sys.exc_info())))) |
862 | sys.exit(ReturnCodes.UNHANDLED_ERROR) |
863 | + finally: |
864 | + cleanup.run() |
865 | + sys.exit(exitstatus) |
866 | |
867 | === modified file 'utah/config.py' |
868 | --- utah/config.py 2013-04-04 14:55:25 +0000 |
869 | +++ utah/config.py 2013-04-25 15:05:30 +0000 |
870 | @@ -60,6 +60,8 @@ |
871 | boottimeout=90, |
872 | # Time to wait between checking if system is available over ssh |
873 | checktimeout=15, |
874 | + # Default setting for whether to clean up after a test run |
875 | + clean=True, |
876 | # Default log level to print to the console |
877 | consoleloglevel=logging.WARNING, |
878 | # Default debug setting |
879 | @@ -67,7 +69,7 @@ |
880 | # Command to download test images |
881 | dlcommand='dl-ubuntu-test-iso', |
882 | # Percentage increment at which to report download updates |
883 | - dlpercentincrement=1, |
884 | + dlpercentincrement=10, |
885 | # Number of times to retry image download |
886 | dlretries=10, |
887 | # Default diskbus for VMs |
888 | @@ -117,8 +119,12 @@ |
889 | outputpreseed=False, |
890 | # Directory where utah client and other needed packages reside |
891 | packagedir=os.path.join('/', 'usr', 'share', 'utah'), |
892 | + # Command to use to power cycle machine |
893 | + powercmd=None, |
894 | # Time to wait between power off and power on for physical systems |
895 | powertimeout=15, |
896 | + # Prefix for machine names |
897 | + prefix='utah', |
898 | # Default preseed |
899 | preseed=os.path.join('/', 'etc', 'utah', 'default-preseed.cfg'), |
900 | # Location of PXE configuration files |
901 | |
902 | === modified file 'utah/provisioning/baremetal/power.py' |
903 | --- utah/provisioning/baremetal/power.py 2013-04-04 13:19:16 +0000 |
904 | +++ utah/provisioning/baremetal/power.py 2013-04-25 15:05:30 +0000 |
905 | @@ -40,8 +40,7 @@ |
906 | for item in machineinfo: |
907 | if 'power' in item: |
908 | self.power[item] = machineinfo[item] |
909 | - if powercmd is not None: |
910 | - self.powercmd = powercmd |
911 | + self.powercmd = (powercmd or config.powercmd) |
912 | super(PowerMixin, self).__init__(*args, **kw) |
913 | |
914 | def powercommand(self): |
915 | |
916 | === modified file 'utah/provisioning/provisioning.py' |
917 | --- utah/provisioning/provisioning.py 2013-04-24 11:37:21 +0000 |
918 | +++ utah/provisioning/provisioning.py 2013-04-25 15:05:30 +0000 |
919 | @@ -65,11 +65,10 @@ |
920 | """ |
921 | |
922 | def __init__(self, arch=None, boot=None, clean=True, debug=False, |
923 | - directory=None, image=None, dlpercentincrement=1, |
924 | + directory=None, image=None, dlpercentincrement=None, |
925 | initrd=None, installtype=None, kernel=None, machineid=None, |
926 | - machineuuid=None, name=None, new=False, prefix='utah', |
927 | - preseed=None, rewrite=None, series=None, template=None, |
928 | - xml=None): |
929 | + machineuuid=None, name=None, new=False, preseed=None, |
930 | + rewrite=None, series=None, template=None, xml=None): |
931 | """Initialize the object representing the machine. |
932 | |
933 | One of these groups of arguments should be included: |
934 | @@ -96,7 +95,6 @@ |
935 | supplied. |
936 | new: Request a new machine (or a reinstall if a specific machine |
937 | was requested.) |
938 | - prefix: prefix for automatically named machines. |
939 | rewrite: How much to alter supplied preseed and xml files. |
940 | all: everything we need for an automated install |
941 | minimal: insert latecommand into preseed |
942 | @@ -115,44 +113,26 @@ |
943 | """ |
944 | # TODO: Make this work right with super at some point. |
945 | # TODO: Consider a global temp file creator, maybe as part of install. |
946 | - self.debug = debug |
947 | - self.dlpercentincrement = dlpercentincrement |
948 | - self.machineid = machineid |
949 | - self.new = new |
950 | - self.prefix = prefix |
951 | - self.template = template |
952 | + args = ['arch', |
953 | + 'boot', |
954 | + 'clean', |
955 | + 'debug', |
956 | + 'dlpercentincrement', |
957 | + 'installtype', |
958 | + 'new', |
959 | + 'rewrite', |
960 | + 'series', |
961 | + 'template', |
962 | + 'uuid', |
963 | + ] |
964 | + for arg in args: |
965 | + setattr(self, arg, (locals()[arg] or getattr(config, arg))) |
966 | |
967 | self.boottimeout = config.boottimeout |
968 | |
969 | - if clean is None: |
970 | - self.clean = True |
971 | - else: |
972 | - self.clean = clean |
973 | - |
974 | # TODO: Move namesetup into vm |
975 | self._namesetup(name) |
976 | |
977 | - if arch is None: |
978 | - self.arch = config.arch |
979 | - else: |
980 | - self.arch = arch |
981 | - if boot is None: |
982 | - self.boot = config.boot |
983 | - else: |
984 | - self.boot = boot |
985 | - if installtype is None: |
986 | - self.installtype = config.installtype |
987 | - else: |
988 | - self.installtype = installtype |
989 | - if rewrite is None: |
990 | - self.rewrite = config.rewrite |
991 | - else: |
992 | - self.rewrite = rewrite |
993 | - if series is None: |
994 | - self.series = config.series |
995 | - else: |
996 | - self.series = series |
997 | - |
998 | if machineuuid is None: |
999 | self.uuid = str(uuid.uuid4()) |
1000 | else: |
1001 | |
1002 | === modified file 'utah/provisioning/vm/vm.py' |
1003 | --- utah/provisioning/vm/vm.py 2013-04-18 17:17:45 +0000 |
1004 | +++ utah/provisioning/vm/vm.py 2013-04-25 15:05:30 +0000 |
1005 | @@ -135,7 +135,7 @@ |
1006 | # TODO: probably remove parameters from the private methods |
1007 | def __init__(self, directory=None, diskbus=None, disksizes=None, |
1008 | emulator=None, machineid=None, macs=None, name=None, |
1009 | - prefix='utah', *args, **kw): |
1010 | + prefix=None, *args, **kw): |
1011 | # Make sure that no other virtualization solutions are running |
1012 | # TODO: see if this is needed for qemu or just kvm |
1013 | process_checker = ProcessChecker() |
1014 | @@ -145,16 +145,9 @@ |
1015 | message = process_checker.get_error_message(app) |
1016 | raise UTAHVMProvisioningException(message) |
1017 | |
1018 | - if diskbus is None: |
1019 | - self.diskbus = config.diskbus |
1020 | - else: |
1021 | - self.diskbus = diskbus |
1022 | - if disksizes is None: |
1023 | - disksizes = config.disksizes |
1024 | - if disksizes is None: |
1025 | - self.disksizes = [8] |
1026 | - else: |
1027 | - self.disksizes = disksizes |
1028 | + args = ['diskbus', 'disksizes', 'emulator', 'prefix'] |
1029 | + for arg in args: |
1030 | + setattr(self, arg, (locals()[arg] or getattr(config, arg))) |
1031 | self.disks = [] |
1032 | if name is None: |
1033 | autoname = True |
1034 | @@ -174,27 +167,20 @@ |
1035 | self._loggerunsetup() |
1036 | self._loggersetup() |
1037 | self._cmdlinesetup() |
1038 | - if emulator is None: |
1039 | - emulator = config.emulator |
1040 | - if emulator is None: |
1041 | + if self.emulator is None: |
1042 | if self._supportsdomaintype('kvm'): |
1043 | self.logger.info( |
1044 | 'Setting type to kvm since it is in libvirt capabilities') |
1045 | - self.domaintype = 'kvm' |
1046 | + self.emulator = 'kvm' |
1047 | elif self._supportsdomaintype('qemu'): |
1048 | self.logger.info( |
1049 | 'Setting type to qemu since it is in libvirt capabilities') |
1050 | - self.domaintype = 'qemu' |
1051 | + self.emulator = 'qemu' |
1052 | else: |
1053 | raise UTAHVMProvisioningException( |
1054 | 'kvm and qemu not supported in libvirt capabilities; ' |
1055 | 'please make sure qemu and/or kvm are installed ' |
1056 | 'and libvirt is configured correctly') |
1057 | - else: |
1058 | - self.domaintype = emulator |
1059 | - if self.domaintype == 'qemu': |
1060 | - self.logger.debug('Raising boot timeout for qemu domain') |
1061 | - self.boottimeout *= 4 |
1062 | if macs is None: |
1063 | macs = [] |
1064 | self.macs = macs |
1065 | @@ -292,7 +278,7 @@ |
1066 | xmlt.find('uuid').text = self.uuid |
1067 | self.logger.debug( |
1068 | 'Setting type to qemu in case no hardware virtualization present') |
1069 | - xmlt.getroot().set('type', self.domaintype) |
1070 | + xmlt.getroot().set('type', self.emulator) |
1071 | ose = xmlt.find('os') |
1072 | if self.arch == ('i386'): |
1073 | ose.find('type').set('arch', 'i686') |
1074 | |
1075 | === modified file 'utah/run.py' |
1076 | --- utah/run.py 2013-04-19 19:27:58 +0000 |
1077 | +++ utah/run.py 2013-04-25 15:05:30 +0000 |
1078 | @@ -33,22 +33,21 @@ |
1079 | parse_yaml_file, |
1080 | ReturnCodes as ClientReturnCodes, |
1081 | ) |
1082 | -from utah.client.runner import Runner |
1083 | from utah.client.exceptions import ( |
1084 | YAMLEmptyFile, |
1085 | YAMLParsingError, |
1086 | ) |
1087 | +from utah.client.runner import Runner |
1088 | from utah.exceptions import UTAHException |
1089 | from utah.retry import retry |
1090 | from utah.timeout import timeout |
1091 | from utah.url import url_argument |
1092 | -from utah.provisioning.ssh import ProvisionedMachine |
1093 | |
1094 | |
1095 | # Return codes for the server |
1096 | class ReturnCodes: |
1097 | |
1098 | - """Provide standard return codes for run\_ scripts.""" |
1099 | + r"""Provide standard return codes for run\_ scripts.""" |
1100 | |
1101 | SUCCESS = 0 # No problems found |
1102 | UTAH_EXCEPTION_ERROR = 1 # UTAH exception caught |
1103 | @@ -131,114 +130,8 @@ |
1104 | return filename |
1105 | |
1106 | |
1107 | -def common_arguments(parser): |
1108 | - """Centralize command line arguments for all run\_ scripts. |
1109 | - |
1110 | - :returns: argparse parser with arguments added |
1111 | - :rtype: obj |
1112 | - |
1113 | - """ |
1114 | - parser.add_argument('runlist', metavar='runlist', |
1115 | - type=master_runlist_argument, |
1116 | - help='URLs of runlist files to run') |
1117 | - parser.add_argument('-s', '--series', metavar='SERIES', |
1118 | - choices=config.serieschoices, |
1119 | - help='Series to use for VM creation (%(choices)s)') |
1120 | - parser.add_argument('-t', '--type', metavar='TYPE', |
1121 | - choices=('desktop', 'server', 'mini', 'alternate'), |
1122 | - help=('Install type to use for VM creation ' |
1123 | - '(%(choices)s)')) |
1124 | - parser.add_argument('-a', '--arch', metavar='ARCH', |
1125 | - choices=('i386', 'amd64'), |
1126 | - help=('Architecture to use for VM creation ' |
1127 | - '(%(choices)s)')) |
1128 | - parser.add_argument('-n', '--no-destroy', action='store_true', |
1129 | - help='Preserve VM after tests have run') |
1130 | - parser.add_argument('-d', '--debug', action='store_true', |
1131 | - help='Enable debug logging') |
1132 | - parser.add_argument('-j', '--json', action='store_true', |
1133 | - help='Enable json logging (default is YAML)') |
1134 | - parser.add_argument('-f', '--files', action='append', |
1135 | - help='File or directory to copy from test system ') |
1136 | - parser.add_argument('-o', '--outdir', |
1137 | - help=('Directory to store locally copied files ' |
1138 | - '(Default is {}/machine-name)' |
1139 | - .format(config.logpath))) |
1140 | - parser.add_argument('--dumplogs', action='store_true', |
1141 | - help='Write client output logs to standard out') |
1142 | - parser.add_argument('--outputpreseed', action='store_true', |
1143 | - help='Copy preseed to logs directory and list as ' |
1144 | - 'log file in output') |
1145 | - return parser |
1146 | - |
1147 | - |
1148 | -def custom_arguments(parser): |
1149 | - """Centralize arguments for installing from an image. |
1150 | - |
1151 | - :returns: argparse parser with arguments added |
1152 | - :rtype: obj |
1153 | - |
1154 | - """ |
1155 | - parser.add_argument('-i', '--image', type=url_argument, |
1156 | - help='Image/ISO file to use for installation') |
1157 | - parser.add_argument('-p', '--preseed', type=url_argument, |
1158 | - help='Preseed file to use for installation') |
1159 | - parser.add_argument('-b', '--boot', |
1160 | - help='Boot arguments for initial installation') |
1161 | - parser.add_argument('--rewrite', choices=('all', 'minimal', 'casperonly', |
1162 | - 'none'), help='Enable or disable automatic ' |
1163 | - 'configuration rewriting') |
1164 | - return parser |
1165 | - |
1166 | - |
1167 | -def file_arguments(parser): |
1168 | - """Centralize arguments for custom kernel and initrd support. |
1169 | - |
1170 | - :returns: argparse parser with arguments added |
1171 | - :rtype: obj |
1172 | - |
1173 | - """ |
1174 | - parser.add_argument('-k', '--kernel', type=url_argument, |
1175 | - help='Kernel file to use for installation') |
1176 | - parser.add_argument('-r', '--initrd', type=url_argument, |
1177 | - help='InitRD file to use for installation') |
1178 | - return parser |
1179 | - |
1180 | - |
1181 | -def name_argument(parser): |
1182 | - """Centralize arguments for named machines. |
1183 | - |
1184 | - :returns: argparse parser with arguments added |
1185 | - :rtype: obj |
1186 | - |
1187 | - """ |
1188 | - parser.add_argument('--name', help='Name of machine to provision') |
1189 | - return parser |
1190 | - |
1191 | - |
1192 | -def virtual_arguments(parser): |
1193 | - """Centralize arguments for virtual machines. |
1194 | - |
1195 | - :returns: argparse parser with arguments added |
1196 | - :rtype: obj |
1197 | - |
1198 | - """ |
1199 | - parser.add_argument('-e', '--emulator', |
1200 | - help=('Emulator to use (kvm and qemu are supported, ' |
1201 | - 'kvm will be favored if available)')) |
1202 | - parser.add_argument('-x', '--xml', type=url_argument, |
1203 | - help='XML VM definition file') |
1204 | - parser.add_argument('-g', '--gigabytes', action='append', |
1205 | - help=('Size in gigabytes of virtual disk, ' |
1206 | - 'specify more than once for multiple disks')) |
1207 | - parser.add_argument('--diskbus', metavar='DISKBUS', |
1208 | - choices=('virtio', 'sata', 'ide'), |
1209 | - help=('Disk bus to use for customvm installation ' |
1210 | - '(%(choices)s)')) |
1211 | - return parser |
1212 | - |
1213 | - |
1214 | def _get_runlist(url): |
1215 | + # TODO: Make something that this and utah.iso._get_resource can both use |
1216 | try: |
1217 | return urllib.urlretrieve(url)[0] |
1218 | except urllib.ContentTooShortError as e: |
1219 | @@ -329,21 +222,24 @@ |
1220 | """Copy preseed to locallogs. |
1221 | |
1222 | If we are provisioning a system, we can optionally copy its preseed along |
1223 | - with other locallogs from the job. Systems already provisioned will not |
1224 | + with other locallogs from the job. |
1225 | |
1226 | """ |
1227 | - if (not isinstance(machine, ProvisionedMachine) and |
1228 | - (args.outputpreseed or config.outputpreseed)): |
1229 | + if args.outputpreseed or config.outputpreseed: |
1230 | if args.outputpreseed: |
1231 | logging.debug('Capturing preseed due to command line option') |
1232 | |
1233 | p = os.path.join(config.logpath, '{}-preseed.cfg'.format(machine.name)) |
1234 | - try: |
1235 | - shutil.copyfile(machine.finalpreseed, p) |
1236 | - except (IOError, shutil.Error) as err: |
1237 | - logging.warning('Failed to copy preseed file: %s', err) |
1238 | + if machine.hasattr('finalpreseed'): |
1239 | + try: |
1240 | + os.chmod(p, 0664) |
1241 | + shutil.copyfile(machine.finalpreseed, p) |
1242 | + except (IOError, OSError, shutil.Error) as err: |
1243 | + logging.warning('Failed to copy preseed file: %s', err) |
1244 | + else: |
1245 | + locallogs.append(p) |
1246 | else: |
1247 | - locallogs.append(p) |
1248 | + logging.debug('Machine has no preseed to capture') |
1249 | |
1250 | |
1251 | def run_tests(args, machine): |
1252 | @@ -507,7 +403,7 @@ |
1253 | |
1254 | """ |
1255 | logging.info('Checking if UTAH client is finished') |
1256 | - machine.sshcheck() |
1257 | + machine.activecheck() |
1258 | try: |
1259 | exitstatus = machine.run('/usr/share/utah/client/utah-done.py', |
1260 | quiet=True)[0] |
Documentation needs to be updated. In particular, the part in conf.py` that takes care of the manpage generation of the scripts
`docs/source/
that are now gone.
Aside from that, I think it would be a good idea to refactor the code in the
big if/elif/else to still have a function for each different provisioning case.