summaryrefslogtreecommitdiff
path: root/get_latest_ci_hwpack
blob: 7fb15da49a369ecf9dce2adb1429597099b53ba6 (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
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
121
122
123
124
125
126
127
#!/usr/bin/python
"""
Generate a job definition from a template using the latest hwpack and rootfs
of specified types.
"""
import os
import sys
import re
import json
from find_latest import find_latest_rootfs, find_ci_latest


def main(board):
    if not board:
        board = 'unknown'

    hwpacktype = os.getenv("HWPACK_TYPE", "unknown")
    imagetype = os.getenv("ROOTFS_TYPE", "unknown")
    job_name = os.getenv("KERNEL_JOB_NAME", "unknown") + '_' + \
        os.getenv("HWPACK_BUILD_DATE", "unknown") + '_daily test'

    testplan = os.getenv("LAVA_TEST_PLAN", "ltp, pwrmgmt")
    osdevicetags = os.getenv("DEVICE_TAGS", "none")

    template = {
        "timeout": 18000,
        "actions": [{
                        "command": "deploy_linaro_image"
                    },
                    {
                        "command": "submit_results",
                        "parameters": {
                            "stream": os.getenv("BUNDLE_STREAM_NAME",
                                                "/anonymous/plars/"),
                            "server": "http://validation.linaro.org/RPC2/"
                        }
                    }],
        "job_name": job_name,
        "device_type": board
    }

    if osdevicetags != "none":
        devicetags = osdevicetags.split(',')
        template["device_tags"] = devicetags

    url = os.getenv("JOB_URL", "http://snapshots.linaro.org/kernel-hwpack/")
    hwpack_parent_url = os.getenv("KERNEL_NAME", "unknown")
    hwpack_dir_url = os.getenv("KERNEL_JOB_NAME", "unknown")
    hwpack_url_path = os.path.join(url, hwpack_parent_url)
    hwpack_url_path = os.path.join(hwpack_url_path, hwpack_dir_url)

    latest_hwpack = os.getenv('HWPACK_NAME', 'unknown')
    hwpack_url = find_ci_latest(hwpack_url_path, latest_hwpack)
    if hwpack_url is None:
        sys.exit(1)
    rootfs_url = find_latest_rootfs(imagetype)
    rootfs_name, rootfsdate, rootfsbuild = os.path.basename(rootfs_url). \
        rsplit(".", 2)[0].rsplit("-", 2)

    deploy_params = {'hwpack': hwpack_url, 'rootfs': rootfs_url}
    template['actions'][0]['parameters'] = deploy_params

    metadata = {}
    hwpack_filename = os.path.basename(hwpack_url)
    hwpackdate, hwpackbuild = hwpack_filename.rsplit('_', 4)[1].split('-')
    metadata['git_url'] = os.getenv("KERNEL_GIT",
                                    "git://git.linaro.org/kernel/unknown")
    metadata['kernel.gitweb_url'] = os.getenv("GIT_WEB_URL", "unknown")
    metadata['git_commitid'] = os.getenv("KERNEL_COMMIT", "unknown")
    metadata['kernel_name'] = os.getenv("KERNEL_NAME", "unknown")
    metadata['kernel_version'] = os.getenv("KERNEL_VERSION", "unknown")
    metadata['build.id'] = os.getenv("BUILD_ID", "unknown")
    metadata['kernel.config'] = os.getenv('KERNEL_CONFIG', 'unknown')
    metadata['kernel.build_url'] = os.getenv("KERNEL_BUILD_URL", "unknown")
    metadata['kernel.git_branch_name'] = os.getenv("KERNEL_BRANCH", "unknown")
    metadata['kernel.git_log_info'] = os.getenv("GIT_LOG", "unknown")
    metadata['hwpack.type'] = hwpacktype
    metadata['hwpack.date'] = hwpackdate

    metadata['rootfs.type'] = imagetype
    metadata['rootfs.date'] = rootfsdate
    metadata['rootfs.build'] = rootfsbuild

    template['actions'][0]['metadata'] = metadata

    testcases = testplan.split(',')
    testcases = [tc.strip() for tc in testplan.split(',')]
    regex = re.compile("(?P<testcase>^\w+)(\((?P<options>[^\)]+)\))?"
                       "(:(?P<timeout>\d+))?")

    # The positions in the template dict to insert test install/run commands
    run_cmd_pos = 1

    for testcase in testcases:
        r = regex.search(testcase)
        if r.group("testcase") is not None:
            # append commands
            timeout = 1200
            if r.group('timeout'):
                timeout = int(r.group('timeout'))

            test_list = [({
                'git-repo': 'git://git.linaro.org/qa/test-definitions.git',
                'testdef': '{distribution:>s}/{test:>s}.yaml'.format(
                distribution='ubuntu', test=r.group('testcase'))})]

            lava_test_run_command = {}
            lava_test_run_command["command"] = "lava_test_shell"
            lava_test_run_command["parameters"] = {
                "timeout": timeout,
                'testdef_repos': test_list
            }

            if r.group("options"):
                lava_test_run_command["parameters"]["test_options"] = \
                    r.group("options")

            template['actions'].insert(run_cmd_pos, lava_test_run_command)
            run_cmd_pos = run_cmd_pos + 1

    # append the lava test install command
    print json.dumps(template, indent=2)


if __name__ == '__main__':
    # We need only one argument, the board type.
    main(sys.argv[1])