~utah/utah/dev

« back to all changes in this revision

Viewing changes to examples/run_test_vm.py

Merging more of Javier's static analysis fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 
15
15
 
16
16
def get_parser():
17
 
    parser = argparse.ArgumentParser(description='Create a virtual machine and run a UTAH runlist there.', epilog="For example:\n\t%(prog)s -s oneiric -t server -a i386 /usr/share/utah/client/examples/master.run 'http://people.canonical.com/~max/max_test.run'", formatter_class=argparse.RawDescriptionHelpFormatter)
18
 
    parser.add_argument('runlists', metavar='runlist', nargs='+', help='URLs of runlist files to run')
19
 
    parser.add_argument('-s', '--series', choices=('hardy', 'lucid', 'natty', 'oneiric', 'precise', 'quantal'), default='oneiric', help='Series to use for VM creation')
20
 
    parser.add_argument('-t', '--type', choices=('desktop', 'server', 'mini', 'alternate'), default='server', help='Install type to use for VM creation')
21
 
    parser.add_argument('-a', '--arch', choices=('i386', 'amd64'), default='i386', help='Architecture to use for VM creation')
22
 
    parser.add_argument('-n', '--no-destroy', action='store_true', help='Preserve VM after tests have run')
23
 
    parser.add_argument('-d', '--debug', action='store_true', help='Enable debug logging')
24
 
    parser.add_argument('-j', '--json', action='store_true', help='Enable json logging (Default is YAML)')
 
17
    parser = argparse.ArgumentParser(
 
18
            description=('Create a virtual machine '
 
19
                         'and run a UTAH runlist there.'),
 
20
            epilog=("For example:\n"
 
21
                    "\t%(prog)s -s oneiric -t server -a i386 "
 
22
                    "/usr/share/utah/client/examples/master.run "
 
23
                    "'http://people.canonical.com/~max/max_test.run'"),
 
24
            formatter_class=argparse.RawDescriptionHelpFormatter)
 
25
    parser.add_argument('runlists', metavar='runlist', nargs='+',
 
26
                        help='URLs of runlist files to run')
 
27
    parser.add_argument('-s', '--series',
 
28
                        choices=('hardy', 'lucid', 'natty',
 
29
                                 'oneiric', 'precise', 'quantal'),
 
30
                        default='oneiric',
 
31
                        help='Series to use for VM creation')
 
32
    parser.add_argument('-t', '--type',
 
33
                        choices=('desktop', 'server', 'mini', 'alternate'),
 
34
                        default='server',
 
35
                        help='Install type to use for VM creation')
 
36
    parser.add_argument('-a', '--arch', choices=('i386', 'amd64'),
 
37
                        default='i386',
 
38
                        help='Architecture to use for VM creation')
 
39
    parser.add_argument('-n', '--no-destroy', action='store_true',
 
40
                        help='Preserve VM after tests have run')
 
41
    parser.add_argument('-d', '--debug', action='store_true',
 
42
                        help='Enable debug logging')
 
43
    parser.add_argument('-j', '--json', action='store_true',
 
44
                        help='Enable json logging (Default is YAML)')
25
45
    return parser
26
46
 
27
47
 
53
73
                kw.update([(arg, value)])
54
74
        if args.type is not None:
55
75
            kw.update([('installtype', args.type)])
56
 
        machine = inventory.request(debug=args.debug, new=True, dlpercentincrement=10, **kw)
 
76
        machine = inventory.request(debug=args.debug, new=True,
 
77
                                    dlpercentincrement=10, **kw)
57
78
        for logger in [machine.logger] + machine.logger.handlers:
58
79
            if logger.level > logging.INFO:
59
80
                logger.setLevel(logging.INFO)
61
82
        for runlist in args.runlists:
62
83
            locallist = urllib.urlretrieve(runlist)[0]
63
84
            listname = os.path.split(runlist)[1]
64
 
            remotelog = os.path.normpath(os.path.join(config.logpath, machine.name + '_' + listname + '_tmp'))
65
 
            locallog = os.path.normpath(os.path.join(config.logpath, machine.name + '_' + listname + time.strftime('_%Y-%m-%d_%H-%m-%S', time.gmtime()) + suffix))
 
85
            remotelog = os.path.join(config.logpath,
 
86
                    machine.name + '_' + listname + '_tmp')
 
87
            remotelog = os.path.normpath(remotelog)
 
88
            locallog = os.path.join(config.logpath,
 
89
                    machine.name + '_' + listname
 
90
                    + time.strftime('_%Y-%m-%d_%H-%m-%S', time.gmtime())
 
91
                    + suffix)
 
92
            locallog = os.path.normpath(locallog)
66
93
            try:
67
94
                machine.uploadfiles([locallist], os.path.normpath('/tmp'))
68
 
                machine.run('utah' + extraopts + ' -r /tmp/' + os.path.split(locallist)[1] + ' -o ' + remotelog, root=True)
 
95
                options = (' -r /tmp/' + os.path.split(locallist)[1]
 
96
                           + ' -o ' + remotelog)
 
97
                machine.run('utah' + extraopts + options, root=True)
69
98
                machine.downloadfiles([remotelog], locallog)
70
99
                print('Test log copied to ' + locallog)
71
100
                locallogs.append(locallog)