~nuclearbob/utah/bug1043419

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/python

import argparse
import sys

from utah.url import url_argument
from utah.group import check_user_group, print_group_error_message
from utah.timeout import timeout, UTAHTimeout
from utah import config
from run_test_vm import run_test_vm


def get_parser():
    parser = argparse.ArgumentParser(
            description=('Provision a machine '
                         'and run one or more UTAH runlists there.\n\n'
                         'The appropriate run_*.py script will be called, '
                         'depending on the parameters passed.'),
            epilog=("For example:\n"
                    "Provision a VM using a precise server image "
                    "with i386 architecture and run the two given runlists\n"
                    "\t%(prog)s -s precise -t server -a i386 \\\n"
                    "\t\t/usr/share/utah/client/examples/master.run \\\n"
                    "\t\t'http://people.canonical.com/~max/max_test.run'"),
            formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('runlists', metavar='runlist', nargs='+',
                        type=url_argument, help='URLs of runlist files to run')
    parser.add_argument('-m', '--machinetype', metavar='MACHINETYPE',
                        choices=('physical', 'virtual'), default='virtual',
                        help='Type of machine to provision (%(choices)s)')
    parser.add_argument('-e', '--emulator',
                        help=('Emulator to use (kvm and qemu are supported, '
                              'kvm will be favored if available)'))
    parser.add_argument('-i', '--image', type=url_argument,
                        help='Image/ISO file to use for installation')
    parser.add_argument('-k', '--kernel', type=url_argument,
                        help='Kernel file to use for installation')
    parser.add_argument('-r', '--initrd', type=url_argument,
                        help='InitRD file to use for installation')
    parser.add_argument('-p', '--preseed', type=url_argument,
                        help='Preseed file to use for installation')
    parser.add_argument('-b', '--boot',
                        help='Boot arguments for initial installation')
    parser.add_argument('-x', '--xml', type=url_argument,
                        help='XML VM definition file')
    parser.add_argument('-g', '--gigabytes', action='append',
                        help=('Size in gigabytes of virtual disk, '
                              'specify more than once for multiple disks'))
    parser.add_argument('-s', '--series', metavar='SERIES',
                        choices=('hardy', 'lucid', 'natty',
                                 'oneiric', 'precise', 'quantal'),
                        help='Series to use for installation (%(choices)s)')
    parser.add_argument('-t', '--type', metavar='TYPE',
                        choices=('desktop', 'server', 'mini', 'alternate'),
                        help=('Install type to use for installation '
                              '(%(choices)s)'))
    parser.add_argument('-a', '--arch', metavar='ARCH',
                        choices=('i386', 'amd64', 'arm'),
                        help=('Architecture to use for installation '
                              '(%(choices)s)'))
    parser.add_argument('-v', '--variant',
                        help='Variant of architecture, i.e., armel, armhf')
    parser.add_argument('-n', '--no-destroy', action='store_true',
                        help='Preserve machine after tests have run')
    parser.add_argument('-d', '--debug', action='store_true',
                        help='Enable debug logging')
    parser.add_argument('-j', '--json', action='store_true',
                        help='Enable json logging (default is YAML)')
    parser.add_argument('--diskbus', metavar='DISKBUS',
                        choices=('virtio', 'sata', 'ide'),
                        help=('Disk bus to use for customvm installation '
                              '(%(choices)s)'))
    parser.add_argument('--name', help='Name of machine to provision'
                        + ' (currently only supported for physical machine'
                        + ' provisioning)')
    return parser


def run_utah_tests(args=None):
    if not check_user_group():
        print_group_error_message(__file__)
        sys.exit(3)

    if args is None:
        args = get_parser().parse_args()

    if args.arch is not None and 'arm' in args.arch:
        sys.stderr.write("ARM support is not included in this release.\n")
        sys.stderr.write("Please check the roadmap, "
                         "as it will be included in a future version.\n")
        sys.exit(4)

    function = run_test_vm

    for option in [args.boot, args.emulator, args.image, args.initrd,
                   args.kernel, args.preseed, args.xml]:
        if option is not None:
            from run_install_test import run_install_test
            function = run_install_test
            break

    if args.machinetype == 'physical':
        from run_test_cobbler import run_test_cobbler
        function = run_test_cobbler

    function(args=args)

if __name__ == '__main__':
    try:
        if type(config.jobtimeout) == int:
            try:
                timeout(config.jobtimeout, run_utah_tests)
            except UTAHTimeout:
                sys.stderr.write('Job failed to complete after '
                                 + str(config.jobtimeout) + ' seconds.')
                sys.exit(3)
        else:
            run_utah_tests()
    except AttributeError:
        run_utah_tests()