~asac/linaro-ci/lci-build-tools_dtbs-v1

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
128
129
130
131
#!/usr/bin/python
"""
Generate a job definition from a template using the latest hwpack and rootfs
of specified types.
"""
import os, sys
import re
import json
from find_latest import find_latest_rootfs, find_ci_latest

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": 20000,
  "actions": [
    {
      "command": "deploy_linaro_image"
    },
    {
      "command": "boot_linaro_image"
    },
    {
      "command": "submit_results",
      "parameters": {
        "stream": os.getenv("BUNDLE_STREAM_NAME", "/anonymous/plars/"),
        "server": "http://validation.linaro.org/lava-server/RPC2/"
      }
    }
  ],
  "job_name": job_name,
  "device_type": os.getenv("BOARD_TYPE", "unknown")
}

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 == 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+))?")

# Dict for lava_test_install 
lava_test_install_command = {}
lava_test_install_command["command"] = "lava_test_install"
lava_test_install_command["parameters"] = { "tests" : [], "timeout" : 4000 }

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

# add the lava test shell stuff
lava_test_shell_command = {}
lava_test_shell_command["command"] = "lava_test_shell"
lava_test_shell_command["parameters"] = {}
lava_test_shell_command["parameters"]["testdef_repos"] = [{ "bzr-repo" : "lp:~asac/+junk/asac-smoke-base-yaml", "testdef": "asac-smoke-basic.yaml" }]
lava_test_shell_command["parameters"]["timeout"] = 1800
template['actions'].insert(run_cmd_pos, lava_test_shell_command)
run_cmd_pos = run_cmd_pos + 1

for testcase in testcases:
    r = regex.search(testcase)
    if r.group("testcase") != None:
        lava_test_install_command["parameters"]["tests"].\
                                 append(r.group("testcase"))

        # append lava_test_run commands
        timeout = 4800
        if r.group('timeout'):
         timeout = r.group('timeout')

        lava_test_run_command = {}
        lava_test_run_command["command"] = "lava_test_run"
        lava_test_run_command["parameters"] = {"test_name" : r.group('testcase'),
                                               "timeout" : timeout }

        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
template['actions'].insert(install_cmd_pos, lava_test_install_command)

print json.dumps(template, indent=2)