Merge lp:~nuclearbob/utah/consolidate-scripts into lp:utah

Proposed by Max Brustkern
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
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.

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.

To post a comment you must log in.
Revision history for this message
Javier Collado (javier.collado) wrote :

Documentation needs to be updated. In particular, the part in
`docs/source/conf.py` that takes care of the manpage generation of the scripts
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.

review: Needs Fixing
Revision history for this message
Andy Doan (doanac) wrote :

should we keep the original scripts and just print an error, so people don't think dpkg failed or something?

Revision history for this message
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

Revision history for this message
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://code.launchpad.net/~doanac/utah/run-cleanups/+merge/159879
That'll put me in better shape to make the changes we've talked about in this branch.

Revision history for this message
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

Revision history for this message
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.

review: Needs Fixing
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

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/changelog'
--- debian/changelog 2013-04-19 19:08:00 +0000
+++ debian/changelog 2013-04-25 15:05:30 +0000
@@ -12,8 +12,12 @@
12 * Added syslog output (including real time test output) to client12 * Added syslog output (including real time test output) to client
13 * Make rsyslog timeout error message clearer (LP: #1169846)13 * Make rsyslog timeout error message clearer (LP: #1169846)
14 * Write to log UTAH version as soon as possible (LP: #1152216)14 * Write to log UTAH version as soon as possible (LP: #1152216)
15 * Combined current provisioning functions into one script and removed
16 old scripts
17 * Fixed LP #1130901
18 * Fixed LP #1153735
1519
16 -- Max Brustkern <max@canonical.com> Tue, 16 Apr 2013 09:21:19 -040020 -- Max Brustkern <max@canonical.com> Thu, 25 Apr 2013 11:02:23 -0400
1721
18utah (0.10ubuntu1) UNRELEASED; urgency=low22utah (0.10ubuntu1) UNRELEASED; urgency=low
1923
2024
=== modified file 'docs/source/conf.py'
--- docs/source/conf.py 2013-04-18 10:46:00 +0000
+++ docs/source/conf.py 2013-04-25 15:05:30 +0000
@@ -148,8 +148,7 @@
148148
149 return description, options, epilog149 return description, options, epilog
150150
151module_names = ('client', 'run_install_test', 'run_test_cobbler',151module_names = ('client', 'run_utah_tests')
152 'run_test_vm', 'run_utah_tests')
153for module_name in module_names:152for module_name in module_names:
154 module = __import__(module_name)153 module = __import__(module_name)
155 parser = module.get_parser()154 parser = module.get_parser()
@@ -367,13 +366,6 @@
367man_pages = [366man_pages = [
368 ('man/utah', 'utah', u'UTAH client test runner',367 ('man/utah', 'utah', u'UTAH client test runner',
369 [u'Canonical Ltd'], 1),368 [u'Canonical Ltd'], 1),
370 ('man/run_install_test.py', 'run_install_test.py',
371 u'UTAH server test runner (provisioning)', [u'Canonical Ltd'], 1),
372 ('man/run_test_cobbler.py', 'run_test_cobbler.py',
373 u'UTAH server test runner (physical hardware)', [u'Canonical Ltd'], 1),
374 ('man/run_test_vm.py', 'run_test_vm.py',
375 u'UTAH server test runner (virtual hardware)',
376 [u'Canonical Ltd'], 1),
377 ('man/run_utah_tests.py', 'run_utah_tests.py',369 ('man/run_utah_tests.py', 'run_utah_tests.py',
378 u'UTAH server test runner (any hardware)', [u'Canonical Ltd'], 1),370 u'UTAH server test runner (any hardware)', [u'Canonical Ltd'], 1),
379]371]
380372
=== removed file 'docs/source/man/run_install_test.py.rst'
--- docs/source/man/run_install_test.py.rst 2012-09-05 11:30:16 +0000
+++ docs/source/man/run_install_test.py.rst 1970-01-01 00:00:00 +0000
@@ -1,26 +0,0 @@
1:orphan:
2
3run_install_test.py manual page
4===============================
5
6Synopsis
7--------
8**run_install_test.py** [options] [runlist ...]
9
10Description
11-----------
12.. include:: run_install_test_description.txt
13
14Options
15-------
16.. include:: run_install_test_options.txt
17
18Examples
19--------
20.. include:: run_install_test_epilog.txt
21
22See also
23--------
24:manpage:`run_test_cobbler.py(1)`
25:manpage:`run_test_vm.py(1)`
26:manpage:`run_utah_tests.py(1)`
270
=== removed file 'docs/source/man/run_test_cobbler.py.rst'
--- docs/source/man/run_test_cobbler.py.rst 2012-09-05 11:30:16 +0000
+++ docs/source/man/run_test_cobbler.py.rst 1970-01-01 00:00:00 +0000
@@ -1,26 +0,0 @@
1:orphan:
2
3run_test_cobbler.py manual page
4===============================
5
6Synopsis
7--------
8**run_test_cobbler.py** [options] [runlist ...]
9
10Description
11-----------
12.. include:: run_test_cobbler_description.txt
13
14Options
15-------
16.. include:: run_test_cobbler_options.txt
17
18Examples
19--------
20.. include:: run_test_cobbler_epilog.txt
21
22See also
23--------
24:manpage:`run_install_test.py(1)`
25:manpage:`run_test_vm.py(1)`
26:manpage:`run_utah_tests.py(1)`
270
=== removed file 'docs/source/man/run_test_vm.py.rst'
--- docs/source/man/run_test_vm.py.rst 2012-09-05 11:30:16 +0000
+++ docs/source/man/run_test_vm.py.rst 1970-01-01 00:00:00 +0000
@@ -1,26 +0,0 @@
1:orphan:
2
3run_test_vm.py manual page
4==========================
5
6Synopsis
7--------
8**run_test_vm.py** [options] [runlist ...]
9
10Description
11-----------
12.. include:: run_test_vm_description.txt
13
14Options
15-------
16.. include:: run_test_vm_options.txt
17
18Examples
19--------
20.. include:: run_test_vm_epilog.txt
21
22See also
23--------
24:manpage:`run_install_test.py(1)`
25:manpage:`run_test_cobbler.py(1)`
26:manpage:`run_utah_tests.py(1)`
270
=== removed file 'examples/run_install_test.py'
--- examples/run_install_test.py 2013-04-18 14:15:12 +0000
+++ examples/run_install_test.py 1970-01-01 00:00:00 +0000
@@ -1,114 +0,0 @@
1#!/usr/bin/env python
2
3# Ubuntu Testing Automation Harness
4# Copyright 2012 Canonical Ltd.
5
6# This program is free software: you can redistribute it and/or modify it
7# under the terms of the GNU General Public License version 3, as published
8# by the Free Software Foundation.
9
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranties of
12# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13# PURPOSE. See the GNU General Public License for more details.
14
15# You should have received a copy of the GNU General Public License along
16# with this program. If not, see <http://www.gnu.org/licenses/>.
17
18"""Create a VM and run a test."""
19
20
21import argparse
22import logging
23import sys
24
25from utah.cleanup import cleanup
26from utah.exceptions import UTAHException
27from utah.group import check_user_group, print_group_error_message
28from utah.provisioning.vm.vm import CustomVM, TinySQLiteInventory
29from utah.run import (
30 common_arguments,
31 custom_arguments,
32 file_arguments,
33 run_tests,
34 virtual_arguments,
35 configure_logging,
36 ReturnCodes,
37)
38
39
40def get_parser():
41 parser = argparse.ArgumentParser(
42 description=('Provision a machine '
43 'and run one or more UTAH runlists there.'),
44 epilog=("For example:\n"
45 "Provision a VM using a precise server image "
46 "with i386 architecture and run the two given runlists\n"
47 "\t%(prog)s -s precise -t server -a i386 \\\n"
48 "\t\t/usr/share/utah/client/examples/master.run \\\n"
49 "\t\t'http://people.canonical.com/~max/max_test.run'"),
50 formatter_class=argparse.RawDescriptionHelpFormatter)
51 parser = common_arguments(parser)
52 parser = custom_arguments(parser)
53 parser = file_arguments(parser)
54 parser = virtual_arguments(parser)
55 return parser
56
57
58def run_install_test(args=None):
59 if args is None:
60 args = get_parser().parse_args()
61
62 if not check_user_group():
63 print_group_error_message(__file__)
64 sys.exit(ReturnCodes.GROUP_ERROR)
65
66 locallogs = []
67 exitstatus = ReturnCodes.SUCCESS
68 machine = None
69
70 configure_logging(args.debug)
71
72 try:
73 inventory = TinySQLiteInventory()
74 machine = inventory.request(
75 CustomVM,
76 arch=args.arch, boot=args.boot, clean=(not args.no_destroy),
77 debug=args.debug, diskbus=args.diskbus,
78 disksizes=args.gigabytes, dlpercentincrement=10,
79 emulator=args.emulator, image=args.image, initrd=args.initrd,
80 installtype=args.type, kernel=args.kernel, new=True,
81 preseed=args.preseed, rewrite=args.rewrite,
82 series=args.series, xml=args.xml)
83 exitstatus, locallogs = run_tests(args, machine)
84 finally:
85 if not args.no_destroy and machine is not None:
86 try:
87 machine.destroy()
88 except UTAHException as error:
89 sys.stderr.write('Failed to destroy machine: ' + str(error))
90 finally:
91 try:
92 inventory.destroy(machine.machineid)
93 except UTAHException as error:
94 sys.stderr.write('Failed to update inventory: '
95 + str(error))
96 finally:
97 del machine
98 if len(locallogs) != 0:
99 print('Test logs copied to the following files:')
100 print("\t" + "\n\t".join(locallogs))
101
102 sys.exit(exitstatus)
103
104
105if __name__ == '__main__':
106 logging.warning('This script is deprecated; please use run_utah_tests.py')
107 logging.warning('The same command line arguments should work there, i.e.:')
108 argv = list(sys.argv)
109 argv[0] = 'run_utah_tests.py'
110 logging.warning(' '.join(argv))
111 try:
112 run_install_test()
113 finally:
114 cleanup.run()
1150
=== removed file 'examples/run_test_bamboo_feeder.py'
--- examples/run_test_bamboo_feeder.py 2013-04-10 15:34:49 +0000
+++ examples/run_test_bamboo_feeder.py 1970-01-01 00:00:00 +0000
@@ -1,119 +0,0 @@
1#!/usr/bin/env python
2
3# Ubuntu Testing Automation Harness
4# Copyright 2012 Canonical Ltd.
5
6# This program is free software: you can redistribute it and/or modify it
7# under the terms of the GNU General Public License version 3, as published
8# by the Free Software Foundation.
9
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranties of
12# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13# PURPOSE. See the GNU General Public License for more details.
14
15# You should have received a copy of the GNU General Public License along
16# with this program. If not, see <http://www.gnu.org/licenses/>.
17
18"""Provision a panda board in a bamboo-feeder setup and run a test."""
19
20
21import argparse
22import os
23import sys
24import logging
25
26from utah.cleanup import cleanup
27from utah.exceptions import UTAHException
28from utah.group import check_user_group, print_group_error_message
29from utah.provisioning.baremetal.bamboofeeder import BambooFeederMachine
30from utah.provisioning.baremetal.inventory import \
31 ManualBaremetalSQLiteInventory
32from utah.run import (
33 common_arguments,
34 custom_arguments,
35 name_argument,
36 run_tests,
37 configure_logging,
38 ReturnCodes,
39)
40
41
42def get_parser():
43 parser = argparse.ArgumentParser(
44 description=('Provision a pandaboard in a bamboo-feeder setup '
45 'and run one or more UTAH runlists there.'),
46 epilog=("For example:\n"
47 "Provision a machine using a precise server image "
48 "with i386 architecture and run the two given runlists\n"
49 "\t%(prog)s -s precise -t server -a i386 \\\n"
50 "\t\t/usr/share/utah/client/examples/master.run \\\n"
51 "\t\t'http://people.canonical.com/~max/max_test.run'"),
52 formatter_class=argparse.RawDescriptionHelpFormatter)
53 parser = common_arguments(parser)
54 parser = custom_arguments(parser)
55 parser = name_argument(parser)
56 return parser
57
58
59def run_test_bamboo_feeder(args=None):
60 if args is None:
61 args = get_parser().parse_args()
62
63 if not check_user_group():
64 print_group_error_message(__file__)
65 sys.exit(ReturnCodes.GROUP_ERROR)
66
67 locallogs = []
68 exitstatus = ReturnCodes.SUCCESS
69 machine = None
70
71 configure_logging(args.debug)
72
73 try:
74 inventory = ManualBaremetalSQLiteInventory(
75 db=os.path.join('~', '.utah-bamboofeeder-inventory'),
76 lockfile=os.path.join('~', '.utah-bamboofeeder-lock'))
77 kw = {}
78 for arg in ['boot', 'image', 'preseed']:
79 value = getattr(args, arg)
80 if value is not None:
81 kw[arg] = value
82 machine = inventory.request(machinetype=BambooFeederMachine,
83 clean=(not args.no_destroy),
84 debug=args.debug, new=True,
85 dlpercentincrement=10, **kw)
86 exitstatus, locallogs = run_tests(args, machine)
87
88 except UTAHException as error:
89 mesg = 'Exception: ' + str(error)
90 try:
91 logging.error(mesg)
92 except (AttributeError, NameError):
93 sys.stderr.write(mesg)
94 exitstatus = ReturnCodes.UTAH_EXCEPTION_ERROR
95 except Exception:
96 logging.exception('Unhandled error in UTAH')
97 exitstatus = ReturnCodes.UNHANDLED_ERROR
98 finally:
99 if machine is not None:
100 try:
101 machine.destroy()
102 except UTAHException as error:
103 sys.stderr.write('Failed to destroy machine: ' + str(error))
104
105 if len(locallogs) != 0:
106 print('Test logs copied to the following files:')
107 print("\t" + "\n\t".join(locallogs))
108
109 sys.exit(exitstatus)
110
111
112if __name__ == '__main__':
113 logging.warning('This script is thought to be broken')
114 logging.warning('If it is working, please report it to the UTAH team via '
115 'ubuntu-utah-devel@lists.ubuntu.com')
116 try:
117 run_test_bamboo_feeder()
118 finally:
119 cleanup.run()
1200
=== removed file 'examples/run_test_cobbler.py'
--- examples/run_test_cobbler.py 2013-04-10 15:34:49 +0000
+++ examples/run_test_cobbler.py 1970-01-01 00:00:00 +0000
@@ -1,127 +0,0 @@
1#!/usr/bin/env python
2
3# Ubuntu Testing Automation Harness
4# Copyright 2012 Canonical Ltd.
5
6# This program is free software: you can redistribute it and/or modify it
7# under the terms of the GNU General Public License version 3, as published
8# by the Free Software Foundation.
9
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranties of
12# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13# PURPOSE. See the GNU General Public License for more details.
14
15# You should have received a copy of the GNU General Public License along
16# with this program. If not, see <http://www.gnu.org/licenses/>.
17
18"""Provision a machine with cobbler and run a test."""
19
20
21import argparse
22import sys
23import logging
24
25from utah.cleanup import cleanup
26from utah.exceptions import UTAHException
27from utah.group import check_user_group, print_group_error_message
28from utah.provisioning.baremetal.cobbler import CobblerMachine
29from utah.provisioning.baremetal.inventory import \
30 ManualBaremetalSQLiteInventory
31from utah.run import (
32 common_arguments,
33 custom_arguments,
34 name_argument,
35 run_tests,
36 configure_logging,
37 ReturnCodes,
38)
39
40
41def get_parser():
42 parser = argparse.ArgumentParser(
43 description=('Provision a machine using cobbler '
44 'and run one or more UTAH runlists there.'),
45 epilog=("For example:\n"
46 "Provision a machine using a precise server image "
47 "with i386 architecture and run the two given runlists\n"
48 "\t%(prog)s -s precise -t server -a i386 \\\n"
49 "\t\t/usr/share/utah/client/examples/master.run \\\n"
50 "\t\t'http://people.canonical.com/~max/max_test.run'"),
51 formatter_class=argparse.RawDescriptionHelpFormatter)
52 parser = common_arguments(parser)
53 parser = custom_arguments(parser)
54 parser = name_argument(parser)
55 return parser
56
57
58def run_test_cobbler(args=None):
59 if args is None:
60 args = get_parser().parse_args()
61
62 if not check_user_group():
63 print_group_error_message(__file__)
64 sys.exit(ReturnCodes.GROUP_ERROR)
65
66 locallogs = []
67 exitstatus = ReturnCodes.SUCCESS
68 machine = None
69
70 configure_logging(args.debug)
71
72 try:
73 inventory = ManualBaremetalSQLiteInventory()
74 kw = {}
75 for arg in ['arch',
76 'boot',
77 'image',
78 'preseed',
79 'rewrite',
80 'series',
81 ]:
82 value = getattr(args, arg)
83 if value is not None:
84 kw[arg] = value
85 if getattr(args, 'type') is not None:
86 kw['installtype'] = args.type
87 machine = inventory.request(CobblerMachine,
88 clean=(not args.no_destroy),
89 debug=args.debug, dlpercentincrement=10,
90 name=args.name, new=True, **kw)
91 exitstatus, locallogs = run_tests(args, machine)
92
93 except UTAHException as error:
94 mesg = 'Exception: ' + str(error)
95 try:
96 logging.error(mesg)
97 except (AttributeError, NameError):
98 sys.stderr.write(mesg)
99 exitstatus = ReturnCodes.UTAH_EXCEPTION_ERROR
100 except Exception:
101 logging.exception('Unhandled error in UTAH')
102 exitstatus = ReturnCodes.UNHANDLED_ERROR
103 finally:
104 if machine is not None:
105 try:
106 machine.destroy()
107 except UTAHException as error:
108 sys.stderr.write('Failed to destroy machine: ' + str(error))
109
110 if len(locallogs) != 0:
111 print('Test logs copied to the following files:')
112 print("\t" + "\n\t".join(locallogs))
113
114 sys.exit(exitstatus)
115
116
117if __name__ == '__main__':
118 logging.warning('This script is deprecated; please use run_utah_tests.py')
119 logging.warning('Add the -m physical argument to your existing list, i.e.:')
120 argv = list(sys.argv)
121 argv[0] = 'run_utah_tests.py'
122 argv.extend(['-m', 'physical'])
123 logging.warning(' '.join(argv))
124 try:
125 run_test_cobbler()
126 finally:
127 cleanup.run()
1280
=== removed file 'examples/run_test_vm.py'
--- examples/run_test_vm.py 2013-04-10 15:34:49 +0000
+++ examples/run_test_vm.py 1970-01-01 00:00:00 +0000
@@ -1,115 +0,0 @@
1#!/usr/bin/env python
2
3# Ubuntu Testing Automation Harness
4# Copyright 2012 Canonical Ltd.
5
6# This program is free software: you can redistribute it and/or modify it
7# under the terms of the GNU General Public License version 3, as published
8# by the Free Software Foundation.
9
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranties of
12# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13# PURPOSE. See the GNU General Public License for more details.
14
15# You should have received a copy of the GNU General Public License along
16# with this program. If not, see <http://www.gnu.org/licenses/>.
17
18"""Create a VM and run a test."""
19
20
21import argparse
22import logging
23import sys
24
25from utah.cleanup import cleanup
26from utah.exceptions import UTAHException
27from utah.group import check_user_group, print_group_error_message
28from utah.provisioning.vm.vm import TinySQLiteInventory
29from utah.run import (
30 common_arguments,
31 run_tests,
32 configure_logging,
33 ReturnCodes,
34)
35
36
37def get_parser():
38 parser = argparse.ArgumentParser(
39 description=('Create a virtual machine '
40 'and run a UTAH runlist there.'),
41 epilog=("For example:\n"
42 "Provision a VM using a precise server image "
43 "with i386 architecture and run the two given runlists\n"
44 "\t%(prog)s -s precise -t server -a i386 \\\n"
45 "\t\t/usr/share/utah/client/examples/master.run \\\n"
46 "\t\t'http://people.canonical.com/~max/max_test.run'"),
47 formatter_class=argparse.RawDescriptionHelpFormatter)
48 return common_arguments(parser)
49
50
51def run_test_vm(args=None):
52 if args is None:
53 args = get_parser().parse_args()
54
55 if not check_user_group():
56 print_group_error_message(__file__)
57 sys.exit(ReturnCodes.GROUP_ERROR)
58
59 locallogs = []
60 exitstatus = ReturnCodes.SUCCESS
61 machine = None
62
63 configure_logging(args.debug)
64
65 try:
66 inventory = TinySQLiteInventory()
67 kw = {}
68 for arg in ['arch', 'series']:
69 value = getattr(args, arg)
70 if value is not None:
71 kw[arg] = value
72 if args.type is not None:
73 kw.update([('installtype', args.type)])
74 machine = inventory.request(clean=(not args.no_destroy),
75 debug=args.debug, new=True,
76 dlpercentincrement=10, **kw)
77 exitstatus, locallogs = run_tests(args, machine)
78
79 except UTAHException as error:
80 sys.stderr.write('Exception: ' + str(error))
81 exitstatus = ReturnCodes.UTAH_EXCEPTION_ERROR
82 except Exception:
83 logging.exception('Unhandled error in UTAH')
84 exitstatus = ReturnCodes.UNHANDLED_ERROR
85 finally:
86 if not args.no_destroy and machine is not None:
87 try:
88 machine.destroy()
89 except UTAHException as error:
90 sys.stderr.write('Failed to destroy machine: ' + str(error))
91 finally:
92 try:
93 inventory.destroy(machine.machineid)
94 except UTAHException as error:
95 sys.stderr.write('Failed to update inventory: '
96 + str(error))
97 finally:
98 del machine
99 if len(locallogs) != 0:
100 print('Test logs copied to the following files:')
101 print("\t" + "\n\t".join(locallogs))
102
103 sys.exit(exitstatus)
104
105
106if __name__ == '__main__':
107 logging.warning('This script is deprecated; please use run_utah_tests.py')
108 logging.warning('The same command line arguments should work there, i.e.:')
109 argv = list(sys.argv)
110 argv[0] = 'run_utah_tests.py'
111 logging.warning(' '.join(argv))
112 try:
113 run_test_vm()
114 finally:
115 cleanup.run()
1160
=== modified file 'examples/run_utah_tests.py'
--- examples/run_utah_tests.py 2013-04-24 11:37:21 +0000
+++ examples/run_utah_tests.py 2013-04-25 15:05:30 +0000
@@ -20,27 +20,31 @@
2020
21import argparse21import argparse
22import logging22import logging
23import os
23import sys24import sys
25
24from traceback import format_exception26from traceback import format_exception
2527
26import utah28import utah
29
27from utah import config30from utah import config
28from utah.cleanup import cleanup31from utah.cleanup import cleanup
32from utah.exceptions import UTAHException
29from utah.group import check_user_group, print_group_error_message33from utah.group import check_user_group, print_group_error_message
34from utah.provisioning.baremetal.bamboofeeder import BambooFeederMachine
35from utah.provisioning.baremetal.cobbler import CobblerMachine
36from utah.provisioning.baremetal.inventory import \
37 ManualBaremetalSQLiteInventory
38from utah.provisioning.ssh import ProvisionedMachine
39from utah.provisioning.vm.vm import TinySQLiteInventory
30from utah.run import (40from utah.run import (
31 common_arguments,
32 custom_arguments,
33 file_arguments,
34 name_argument,
35 virtual_arguments,
36 configure_logging,41 configure_logging,
42 master_runlist_argument,
37 run_tests,43 run_tests,
38 ReturnCodes,44 ReturnCodes,
39)45)
40from utah.timeout import timeout, UTAHTimeout46from utah.timeout import timeout, UTAHTimeout
41from run_install_test import run_install_test47from utah.url import url_argument
42from utah.provisioning.ssh import ProvisionedMachine
43from utah.exceptions import UTAHException
4448
4549
46def get_parser():50def get_parser():
@@ -64,11 +68,63 @@
64 parser.add_argument('--skip-provisioning', action='store_true',68 parser.add_argument('--skip-provisioning', action='store_true',
65 help=('Reuse a system that is already provisioned '69 help=('Reuse a system that is already provisioned '
66 '(name argument must be passed)'))70 '(name argument must be passed)'))
67 parser = common_arguments(parser)71 parser.add_argument('runlist', metavar='runlist',
68 parser = custom_arguments(parser)72 type=master_runlist_argument,
69 parser = file_arguments(parser)73 help='URLs of runlist files to run')
70 parser = name_argument(parser)74 parser.add_argument('-s', '--series', metavar='SERIES',
71 parser = virtual_arguments(parser)75 choices=config.serieschoices,
76 help='Series to use for VM creation (%(choices)s)')
77 parser.add_argument('-t', '--type', metavar='TYPE',
78 choices=('desktop', 'server', 'mini', 'alternate'),
79 help=('Install type to use for VM creation '
80 '(%(choices)s)'))
81 parser.add_argument('-a', '--arch', metavar='ARCH',
82 choices=('i386', 'amd64', 'arm'),
83 help=('Architecture to use for VM creation '
84 '(%(choices)s)'))
85 parser.add_argument('-n', '--no-destroy', action='store_true',
86 help='Preserve VM after tests have run')
87 parser.add_argument('-d', '--debug', action='store_true',
88 help='Enable debug logging')
89 parser.add_argument('-j', '--json', action='store_true',
90 help='Enable json logging (default is YAML)')
91 parser.add_argument('-f', '--files', action='append',
92 help='File or directory to copy from test system ')
93 parser.add_argument('-o', '--outdir',
94 help=('Directory to store locally copied files '
95 '(Default is {}/machine-name)'
96 .format(config.logpath)))
97 parser.add_argument('--dumplogs', action='store_true',
98 help='Write client output logs to standard out')
99 parser.add_argument('--outputpreseed', action='store_true',
100 help='Copy preseed to logs directory and list as '
101 'log file in output')
102 parser.add_argument('-i', '--image', type=url_argument,
103 help='Image/ISO file to use for installation')
104 parser.add_argument('-p', '--preseed', type=url_argument,
105 help='Preseed file to use for installation')
106 parser.add_argument('-b', '--boot',
107 help='Boot arguments for initial installation')
108 parser.add_argument('--rewrite', choices=('all', 'minimal', 'casperonly',
109 'none'), help='Enable or disable automatic '
110 'configuration rewriting')
111 parser.add_argument('-k', '--kernel', type=url_argument,
112 help='Kernel file to use for installation')
113 parser.add_argument('-r', '--initrd', type=url_argument,
114 help='InitRD file to use for installation')
115 parser.add_argument('--name', help='Name of machine to provision')
116 parser.add_argument('-e', '--emulator',
117 help=('Emulator to use (kvm and qemu are supported, '
118 'kvm will be favored if available)'))
119 parser.add_argument('-x', '--xml', type=url_argument,
120 help='XML VM definition file')
121 parser.add_argument('-g', '--gigabytes', action='append',
122 help=('Size in gigabytes of virtual disk, '
123 'specify more than once for multiple disks'))
124 parser.add_argument('--diskbus', metavar='DISKBUS',
125 choices=('virtio', 'sata', 'ide'),
126 help=('Disk bus to use for customvm installation '
127 '(%(choices)s)'))
72 return parser128 return parser
73129
74130
@@ -78,57 +134,71 @@
78134
79 if not check_user_group():135 if not check_user_group():
80 print_group_error_message(__file__)136 print_group_error_message(__file__)
81 sys.exit(ReturnCodes.GROUP_ERROR)137 return ReturnCodes.GROUP_ERROR
82138
83 if args.machinetype is None:139 if args.arch:
140 arch = args.arch
141 else:
142 arch = config.arch
143 if args.machinetype:
144 machinetype = args.machinetype
145 else:
84 machinetype = config.machinetype146 machinetype = config.machinetype
85 else:
86 machinetype = args.machinetype
87147
88 configure_logging(args.debug)148 configure_logging(args.debug)
89 logging.info('UTAH version: %s', utah.__version__)149 logging.info('UTAH version: %s', utah.__version__)
90150
91 # Default is now CustomVM151 exitstatus = ReturnCodes.SUCCESS
92 function = run_install_test152 locallogs = []
93153
94 if args.skip_provisioning:154 if args.skip_provisioning:
95 def run_provisioned_tests(args):155 # TBD: Inventory should be used to verify machine
96 """Run test cases in a provisioned machine."""156 # is not running other tests
97 locallogs = []157 machine = ProvisionedMachine(name=args.name)
98 try:158 else:
99 # TBD: Inventory should be used to verify machine159 kw = {'clean': (not args.no_destroy),
100 # is not running other tests160 'new': True,
101 machine = ProvisionedMachine(name=args.name)161 }
102 exitstatus, locallogs = run_tests(args, machine)162 for arg in ['arch',
103 finally:163 'boot',
104 if len(locallogs) != 0:164 'debug',
105 print('Test logs copied to the following files:')165 'image',
106 print("\t" + "\n\t".join(locallogs))166 'initrd',
107 sys.exit(ReturnCodes.SUCCESS)167 'kernel',
108168 'name',
109 function = run_provisioned_tests169 'preseed',
110 if args.arch is not None and 'arm' in args.arch:170 'rewrite',
111 # If arch is arm, use BambooFeederMachine171 'series',
112 from run_test_bamboo_feeder import run_test_bamboo_feeder172 ]:
113 function = run_test_bamboo_feeder173 kw[arg] = getattr(args, arg)
114 elif machinetype == 'physical':174 kw['installtype'] = args.type
115 # If machinetype is physical but arch isn't arm, use CobblerMachine175 if machinetype == 'physical':
116 from run_test_cobbler import run_test_cobbler176 if arch and 'arm' in arch:
117 function = run_test_cobbler177 inventory = ManualBaremetalSQLiteInventory(
118178 db=os.path.join('~', '.utah-bamboofeeder-inventory'),
119 function(args=args)179 lockfile=os.path.join('~', '.utah-bamboofeeder-lock'))
180 kw['machinetype'] = BambooFeederMachine
181 else:
182 inventory = ManualBaremetalSQLiteInventory()
183 kw['machinetype'] = CobblerMachine
184 else:
185 inventory = TinySQLiteInventory()
186 for arg in ['diskbus', 'emulator', 'xml']:
187 kw[arg] = getattr(args, arg)
188 kw['disksizes'] = args.gigabytes
189 machine = inventory.request(**kw)
190 exitstatus, locallogs = run_tests(args, machine)
191 if len(locallogs) > 0:
192 print('Test logs copied to the following files:')
193 print("\t" + "\n\t".join(locallogs))
194
195 return(exitstatus)
196
120197
121if __name__ == '__main__':198if __name__ == '__main__':
122 try:199 try:
123 try:200 exitstatus = timeout(getattr(config, 'jobtimeout', None),
124 if isinstance(config.jobtimeout, int):201 run_utah_tests)
125 timeout(config.jobtimeout, run_utah_tests)
126 else:
127 run_utah_tests()
128 except AttributeError:
129 run_utah_tests()
130 finally:
131 cleanup.run()
132 except UTAHTimeout as exception:202 except UTAHTimeout as exception:
133 sys.stderr.write('UTAH timeout: {}\n'.format(exception.message))203 sys.stderr.write('UTAH timeout: {}\n'.format(exception.message))
134 sys.exit(ReturnCodes.TIMEOUT_ERROR)204 sys.exit(ReturnCodes.TIMEOUT_ERROR)
@@ -139,3 +209,6 @@
139 sys.stderr.write('Unhandled error in UTAH:\n{}\n'209 sys.stderr.write('Unhandled error in UTAH:\n{}\n'
140 .format(''.join(format_exception(*sys.exc_info()))))210 .format(''.join(format_exception(*sys.exc_info()))))
141 sys.exit(ReturnCodes.UNHANDLED_ERROR)211 sys.exit(ReturnCodes.UNHANDLED_ERROR)
212 finally:
213 cleanup.run()
214 sys.exit(exitstatus)
142215
=== modified file 'utah/config.py'
--- utah/config.py 2013-04-04 14:55:25 +0000
+++ utah/config.py 2013-04-25 15:05:30 +0000
@@ -60,6 +60,8 @@
60 boottimeout=90,60 boottimeout=90,
61 # Time to wait between checking if system is available over ssh61 # Time to wait between checking if system is available over ssh
62 checktimeout=15,62 checktimeout=15,
63 # Default setting for whether to clean up after a test run
64 clean=True,
63 # Default log level to print to the console65 # Default log level to print to the console
64 consoleloglevel=logging.WARNING,66 consoleloglevel=logging.WARNING,
65 # Default debug setting67 # Default debug setting
@@ -67,7 +69,7 @@
67 # Command to download test images69 # Command to download test images
68 dlcommand='dl-ubuntu-test-iso',70 dlcommand='dl-ubuntu-test-iso',
69 # Percentage increment at which to report download updates71 # Percentage increment at which to report download updates
70 dlpercentincrement=1,72 dlpercentincrement=10,
71 # Number of times to retry image download73 # Number of times to retry image download
72 dlretries=10,74 dlretries=10,
73 # Default diskbus for VMs75 # Default diskbus for VMs
@@ -117,8 +119,12 @@
117 outputpreseed=False,119 outputpreseed=False,
118 # Directory where utah client and other needed packages reside120 # Directory where utah client and other needed packages reside
119 packagedir=os.path.join('/', 'usr', 'share', 'utah'),121 packagedir=os.path.join('/', 'usr', 'share', 'utah'),
122 # Command to use to power cycle machine
123 powercmd=None,
120 # Time to wait between power off and power on for physical systems124 # Time to wait between power off and power on for physical systems
121 powertimeout=15,125 powertimeout=15,
126 # Prefix for machine names
127 prefix='utah',
122 # Default preseed128 # Default preseed
123 preseed=os.path.join('/', 'etc', 'utah', 'default-preseed.cfg'),129 preseed=os.path.join('/', 'etc', 'utah', 'default-preseed.cfg'),
124 # Location of PXE configuration files130 # Location of PXE configuration files
125131
=== modified file 'utah/provisioning/baremetal/power.py'
--- utah/provisioning/baremetal/power.py 2013-04-04 13:19:16 +0000
+++ utah/provisioning/baremetal/power.py 2013-04-25 15:05:30 +0000
@@ -40,8 +40,7 @@
40 for item in machineinfo:40 for item in machineinfo:
41 if 'power' in item:41 if 'power' in item:
42 self.power[item] = machineinfo[item]42 self.power[item] = machineinfo[item]
43 if powercmd is not None:43 self.powercmd = (powercmd or config.powercmd)
44 self.powercmd = powercmd
45 super(PowerMixin, self).__init__(*args, **kw)44 super(PowerMixin, self).__init__(*args, **kw)
4645
47 def powercommand(self):46 def powercommand(self):
4847
=== modified file 'utah/provisioning/provisioning.py'
--- utah/provisioning/provisioning.py 2013-04-24 11:37:21 +0000
+++ utah/provisioning/provisioning.py 2013-04-25 15:05:30 +0000
@@ -65,11 +65,10 @@
65 """65 """
6666
67 def __init__(self, arch=None, boot=None, clean=True, debug=False,67 def __init__(self, arch=None, boot=None, clean=True, debug=False,
68 directory=None, image=None, dlpercentincrement=1,68 directory=None, image=None, dlpercentincrement=None,
69 initrd=None, installtype=None, kernel=None, machineid=None,69 initrd=None, installtype=None, kernel=None, machineid=None,
70 machineuuid=None, name=None, new=False, prefix='utah',70 machineuuid=None, name=None, new=False, preseed=None,
71 preseed=None, rewrite=None, series=None, template=None,71 rewrite=None, series=None, template=None, xml=None):
72 xml=None):
73 """Initialize the object representing the machine.72 """Initialize the object representing the machine.
7473
75 One of these groups of arguments should be included:74 One of these groups of arguments should be included:
@@ -96,7 +95,6 @@
96 supplied.95 supplied.
97 new: Request a new machine (or a reinstall if a specific machine96 new: Request a new machine (or a reinstall if a specific machine
98 was requested.)97 was requested.)
99 prefix: prefix for automatically named machines.
100 rewrite: How much to alter supplied preseed and xml files.98 rewrite: How much to alter supplied preseed and xml files.
101 all: everything we need for an automated install99 all: everything we need for an automated install
102 minimal: insert latecommand into preseed100 minimal: insert latecommand into preseed
@@ -115,44 +113,26 @@
115 """113 """
116 # TODO: Make this work right with super at some point.114 # TODO: Make this work right with super at some point.
117 # TODO: Consider a global temp file creator, maybe as part of install.115 # TODO: Consider a global temp file creator, maybe as part of install.
118 self.debug = debug116 args = ['arch',
119 self.dlpercentincrement = dlpercentincrement117 'boot',
120 self.machineid = machineid118 'clean',
121 self.new = new119 'debug',
122 self.prefix = prefix120 'dlpercentincrement',
123 self.template = template121 'installtype',
122 'new',
123 'rewrite',
124 'series',
125 'template',
126 'uuid',
127 ]
128 for arg in args:
129 setattr(self, arg, (locals()[arg] or getattr(config, arg)))
124130
125 self.boottimeout = config.boottimeout131 self.boottimeout = config.boottimeout
126132
127 if clean is None:
128 self.clean = True
129 else:
130 self.clean = clean
131
132 # TODO: Move namesetup into vm133 # TODO: Move namesetup into vm
133 self._namesetup(name)134 self._namesetup(name)
134135
135 if arch is None:
136 self.arch = config.arch
137 else:
138 self.arch = arch
139 if boot is None:
140 self.boot = config.boot
141 else:
142 self.boot = boot
143 if installtype is None:
144 self.installtype = config.installtype
145 else:
146 self.installtype = installtype
147 if rewrite is None:
148 self.rewrite = config.rewrite
149 else:
150 self.rewrite = rewrite
151 if series is None:
152 self.series = config.series
153 else:
154 self.series = series
155
156 if machineuuid is None:136 if machineuuid is None:
157 self.uuid = str(uuid.uuid4())137 self.uuid = str(uuid.uuid4())
158 else:138 else:
159139
=== modified file 'utah/provisioning/vm/vm.py'
--- utah/provisioning/vm/vm.py 2013-04-18 17:17:45 +0000
+++ utah/provisioning/vm/vm.py 2013-04-25 15:05:30 +0000
@@ -135,7 +135,7 @@
135 # TODO: probably remove parameters from the private methods135 # TODO: probably remove parameters from the private methods
136 def __init__(self, directory=None, diskbus=None, disksizes=None,136 def __init__(self, directory=None, diskbus=None, disksizes=None,
137 emulator=None, machineid=None, macs=None, name=None,137 emulator=None, machineid=None, macs=None, name=None,
138 prefix='utah', *args, **kw):138 prefix=None, *args, **kw):
139 # Make sure that no other virtualization solutions are running139 # Make sure that no other virtualization solutions are running
140 # TODO: see if this is needed for qemu or just kvm140 # TODO: see if this is needed for qemu or just kvm
141 process_checker = ProcessChecker()141 process_checker = ProcessChecker()
@@ -145,16 +145,9 @@
145 message = process_checker.get_error_message(app)145 message = process_checker.get_error_message(app)
146 raise UTAHVMProvisioningException(message)146 raise UTAHVMProvisioningException(message)
147147
148 if diskbus is None:148 args = ['diskbus', 'disksizes', 'emulator', 'prefix']
149 self.diskbus = config.diskbus149 for arg in args:
150 else:150 setattr(self, arg, (locals()[arg] or getattr(config, arg)))
151 self.diskbus = diskbus
152 if disksizes is None:
153 disksizes = config.disksizes
154 if disksizes is None:
155 self.disksizes = [8]
156 else:
157 self.disksizes = disksizes
158 self.disks = []151 self.disks = []
159 if name is None:152 if name is None:
160 autoname = True153 autoname = True
@@ -174,27 +167,20 @@
174 self._loggerunsetup()167 self._loggerunsetup()
175 self._loggersetup()168 self._loggersetup()
176 self._cmdlinesetup()169 self._cmdlinesetup()
177 if emulator is None:170 if self.emulator is None:
178 emulator = config.emulator
179 if emulator is None:
180 if self._supportsdomaintype('kvm'):171 if self._supportsdomaintype('kvm'):
181 self.logger.info(172 self.logger.info(
182 'Setting type to kvm since it is in libvirt capabilities')173 'Setting type to kvm since it is in libvirt capabilities')
183 self.domaintype = 'kvm'174 self.emulator = 'kvm'
184 elif self._supportsdomaintype('qemu'):175 elif self._supportsdomaintype('qemu'):
185 self.logger.info(176 self.logger.info(
186 'Setting type to qemu since it is in libvirt capabilities')177 'Setting type to qemu since it is in libvirt capabilities')
187 self.domaintype = 'qemu'178 self.emulator = 'qemu'
188 else:179 else:
189 raise UTAHVMProvisioningException(180 raise UTAHVMProvisioningException(
190 'kvm and qemu not supported in libvirt capabilities; '181 'kvm and qemu not supported in libvirt capabilities; '
191 'please make sure qemu and/or kvm are installed '182 'please make sure qemu and/or kvm are installed '
192 'and libvirt is configured correctly')183 'and libvirt is configured correctly')
193 else:
194 self.domaintype = emulator
195 if self.domaintype == 'qemu':
196 self.logger.debug('Raising boot timeout for qemu domain')
197 self.boottimeout *= 4
198 if macs is None:184 if macs is None:
199 macs = []185 macs = []
200 self.macs = macs186 self.macs = macs
@@ -292,7 +278,7 @@
292 xmlt.find('uuid').text = self.uuid278 xmlt.find('uuid').text = self.uuid
293 self.logger.debug(279 self.logger.debug(
294 'Setting type to qemu in case no hardware virtualization present')280 'Setting type to qemu in case no hardware virtualization present')
295 xmlt.getroot().set('type', self.domaintype)281 xmlt.getroot().set('type', self.emulator)
296 ose = xmlt.find('os')282 ose = xmlt.find('os')
297 if self.arch == ('i386'):283 if self.arch == ('i386'):
298 ose.find('type').set('arch', 'i686')284 ose.find('type').set('arch', 'i686')
299285
=== modified file 'utah/run.py'
--- utah/run.py 2013-04-19 19:27:58 +0000
+++ utah/run.py 2013-04-25 15:05:30 +0000
@@ -33,22 +33,21 @@
33 parse_yaml_file,33 parse_yaml_file,
34 ReturnCodes as ClientReturnCodes,34 ReturnCodes as ClientReturnCodes,
35)35)
36from utah.client.runner import Runner
37from utah.client.exceptions import (36from utah.client.exceptions import (
38 YAMLEmptyFile,37 YAMLEmptyFile,
39 YAMLParsingError,38 YAMLParsingError,
40)39)
40from utah.client.runner import Runner
41from utah.exceptions import UTAHException41from utah.exceptions import UTAHException
42from utah.retry import retry42from utah.retry import retry
43from utah.timeout import timeout43from utah.timeout import timeout
44from utah.url import url_argument44from utah.url import url_argument
45from utah.provisioning.ssh import ProvisionedMachine
4645
4746
48# Return codes for the server47# Return codes for the server
49class ReturnCodes:48class ReturnCodes:
5049
51 """Provide standard return codes for run\_ scripts."""50 r"""Provide standard return codes for run\_ scripts."""
5251
53 SUCCESS = 0 # No problems found52 SUCCESS = 0 # No problems found
54 UTAH_EXCEPTION_ERROR = 1 # UTAH exception caught53 UTAH_EXCEPTION_ERROR = 1 # UTAH exception caught
@@ -131,114 +130,8 @@
131 return filename130 return filename
132131
133132
134def common_arguments(parser):
135 """Centralize command line arguments for all run\_ scripts.
136
137 :returns: argparse parser with arguments added
138 :rtype: obj
139
140 """
141 parser.add_argument('runlist', metavar='runlist',
142 type=master_runlist_argument,
143 help='URLs of runlist files to run')
144 parser.add_argument('-s', '--series', metavar='SERIES',
145 choices=config.serieschoices,
146 help='Series to use for VM creation (%(choices)s)')
147 parser.add_argument('-t', '--type', metavar='TYPE',
148 choices=('desktop', 'server', 'mini', 'alternate'),
149 help=('Install type to use for VM creation '
150 '(%(choices)s)'))
151 parser.add_argument('-a', '--arch', metavar='ARCH',
152 choices=('i386', 'amd64'),
153 help=('Architecture to use for VM creation '
154 '(%(choices)s)'))
155 parser.add_argument('-n', '--no-destroy', action='store_true',
156 help='Preserve VM after tests have run')
157 parser.add_argument('-d', '--debug', action='store_true',
158 help='Enable debug logging')
159 parser.add_argument('-j', '--json', action='store_true',
160 help='Enable json logging (default is YAML)')
161 parser.add_argument('-f', '--files', action='append',
162 help='File or directory to copy from test system ')
163 parser.add_argument('-o', '--outdir',
164 help=('Directory to store locally copied files '
165 '(Default is {}/machine-name)'
166 .format(config.logpath)))
167 parser.add_argument('--dumplogs', action='store_true',
168 help='Write client output logs to standard out')
169 parser.add_argument('--outputpreseed', action='store_true',
170 help='Copy preseed to logs directory and list as '
171 'log file in output')
172 return parser
173
174
175def custom_arguments(parser):
176 """Centralize arguments for installing from an image.
177
178 :returns: argparse parser with arguments added
179 :rtype: obj
180
181 """
182 parser.add_argument('-i', '--image', type=url_argument,
183 help='Image/ISO file to use for installation')
184 parser.add_argument('-p', '--preseed', type=url_argument,
185 help='Preseed file to use for installation')
186 parser.add_argument('-b', '--boot',
187 help='Boot arguments for initial installation')
188 parser.add_argument('--rewrite', choices=('all', 'minimal', 'casperonly',
189 'none'), help='Enable or disable automatic '
190 'configuration rewriting')
191 return parser
192
193
194def file_arguments(parser):
195 """Centralize arguments for custom kernel and initrd support.
196
197 :returns: argparse parser with arguments added
198 :rtype: obj
199
200 """
201 parser.add_argument('-k', '--kernel', type=url_argument,
202 help='Kernel file to use for installation')
203 parser.add_argument('-r', '--initrd', type=url_argument,
204 help='InitRD file to use for installation')
205 return parser
206
207
208def name_argument(parser):
209 """Centralize arguments for named machines.
210
211 :returns: argparse parser with arguments added
212 :rtype: obj
213
214 """
215 parser.add_argument('--name', help='Name of machine to provision')
216 return parser
217
218
219def virtual_arguments(parser):
220 """Centralize arguments for virtual machines.
221
222 :returns: argparse parser with arguments added
223 :rtype: obj
224
225 """
226 parser.add_argument('-e', '--emulator',
227 help=('Emulator to use (kvm and qemu are supported, '
228 'kvm will be favored if available)'))
229 parser.add_argument('-x', '--xml', type=url_argument,
230 help='XML VM definition file')
231 parser.add_argument('-g', '--gigabytes', action='append',
232 help=('Size in gigabytes of virtual disk, '
233 'specify more than once for multiple disks'))
234 parser.add_argument('--diskbus', metavar='DISKBUS',
235 choices=('virtio', 'sata', 'ide'),
236 help=('Disk bus to use for customvm installation '
237 '(%(choices)s)'))
238 return parser
239
240
241def _get_runlist(url):133def _get_runlist(url):
134 # TODO: Make something that this and utah.iso._get_resource can both use
242 try:135 try:
243 return urllib.urlretrieve(url)[0]136 return urllib.urlretrieve(url)[0]
244 except urllib.ContentTooShortError as e:137 except urllib.ContentTooShortError as e:
@@ -329,21 +222,24 @@
329 """Copy preseed to locallogs.222 """Copy preseed to locallogs.
330223
331 If we are provisioning a system, we can optionally copy its preseed along224 If we are provisioning a system, we can optionally copy its preseed along
332 with other locallogs from the job. Systems already provisioned will not225 with other locallogs from the job.
333226
334 """227 """
335 if (not isinstance(machine, ProvisionedMachine) and228 if args.outputpreseed or config.outputpreseed:
336 (args.outputpreseed or config.outputpreseed)):
337 if args.outputpreseed:229 if args.outputpreseed:
338 logging.debug('Capturing preseed due to command line option')230 logging.debug('Capturing preseed due to command line option')
339231
340 p = os.path.join(config.logpath, '{}-preseed.cfg'.format(machine.name))232 p = os.path.join(config.logpath, '{}-preseed.cfg'.format(machine.name))
341 try:233 if machine.hasattr('finalpreseed'):
342 shutil.copyfile(machine.finalpreseed, p)234 try:
343 except (IOError, shutil.Error) as err:235 os.chmod(p, 0664)
344 logging.warning('Failed to copy preseed file: %s', err)236 shutil.copyfile(machine.finalpreseed, p)
237 except (IOError, OSError, shutil.Error) as err:
238 logging.warning('Failed to copy preseed file: %s', err)
239 else:
240 locallogs.append(p)
345 else:241 else:
346 locallogs.append(p)242 logging.debug('Machine has no preseed to capture')
347243
348244
349def run_tests(args, machine):245def run_tests(args, machine):
@@ -507,7 +403,7 @@
507403
508 """404 """
509 logging.info('Checking if UTAH client is finished')405 logging.info('Checking if UTAH client is finished')
510 machine.sshcheck()406 machine.activecheck()
511 try:407 try:
512 exitstatus = machine.run('/usr/share/utah/client/utah-done.py',408 exitstatus = machine.run('/usr/share/utah/client/utah-done.py',
513 quiet=True)[0]409 quiet=True)[0]

Subscribers

People subscribed via source and target branches