aboutsummaryrefslogtreecommitdiffstats
path: root/utils/job-prereq.py
blob: c04959bef86fadc03268ab5544126d94366a3dfc (plain)
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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

import agljobtemplate
import argparse
import os
import yaml

FILE_MAP = {
    "kernel",
    "dtb",
    "initrd",
    "nbdroot",
}

FILE_MAP_X86 = {
    "kernel",
    "initrd",
    "nbdroot",
}

# Mapping for qemu between command line QEMU args and LAVA yaml template file names
FILE_MAP_QEMU = {
    "kernel": "kernel",
    "initrd": "rootvd",
}

def parse_cmdline(machines):
    description = "Print to stdout the file names needed to create a LAVA job"
    parser = argparse.ArgumentParser(description=description,
                                     formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('-v', action='version', version='%(prog)s 1.0')
    parser.add_argument('--machine', action='store', choices=machines,
                        help="Machine to output the job prerequisites.",
                        required=True)
    parser.add_argument('--dtb', action='store_true')
    parser.add_argument('--kernel', action='store_true')
    parser.add_argument('--initrd', action='store_true')
    parser.add_argument('--nbdroot', action='store_true')
    parser.add_argument('--build-type', action='store', dest='build_type',
                        nargs=3,
                        help="The type of build. It defines the URL to upload to.",
                        required=True)
    parser.add_argument('--branch', dest='vcs_branch', action='store', default='master',
                         help='The build branch.')

    args = parser.parse_args()
    return args


def main():
    templates_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../templates')
    ajt = agljobtemplate.Agljobtemplate(templates_dir)
    args = parse_cmdline(ajt.machines)
    if args.build_type[0] == "ci":
        job = ajt.render_job(build_type=args.build_type[0],
                         changeid=args.build_type[1],
                         patchset=args.build_type[2],
                         machine=args.machine, vcs_branch=args.vcs_branch)
    else:
        job = ajt.render_job(build_type=args.build_type[0],
                        vcs_branch=args.vcs_branch,
                        version=args.build_type[2],
                        machine=args.machine)

    job_yaml = yaml.safe_load(job)
    if args.machine == "qemux86-64" or args.machine == "qemuarm" or args.machine == "qemuarm64":
        for key in FILE_MAP_QEMU:
            if getattr(args, key):
                    print job_yaml["actions"][0]["deploy"]["images"][FILE_MAP_QEMU[key]].get("url").split('/')[-1]
    elif args.machine == "intel-corei7-64" or args.machine == "upsquare":
        for key in FILE_MAP_X86:
            if getattr(args, key):
                    print job_yaml["actions"][0]["deploy"][key].get("url").split('/')[-1]
    else:
        for key in FILE_MAP:
            if getattr(args, key):
                    print job_yaml["actions"][0]["deploy"][key].get("url").split('/')[-1]

if __name__ == '__main__':
    main()