summaryrefslogtreecommitdiff
path: root/browser-test-lava.py
blob: b656fb2b4894ffb50eafa2eef2930d566ce5d1db (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/python
# based on post-build-lava.py

import os
import sys
import json
import xmlrpclib
import urllib2
import re

def obfuscate_credentials(s):
    return re.sub(r"([^ ]:).+?(@)", r"\1xxx\2", s)

def main():
    """Script entry point: return some JSON based on calling args.
    We should be called from Jenkins and expect the following to be defined:
    JOB_NAME
    JOB_BUILD_NUMBER
    DEVICE_TYPE
    BUNDLE_STREAM_NAME, default:/private/team/linaro/developers-and-community-builds/
    LAVA_USER
    LAVA_TOKEN
    LAVA_SERVER, default:validation.linaro.org/lava-server/RPC2/
    IMAGE_TYPE, default:ubuntu-desktop
    IMAGE_URL
    """

    # CI base URL
    ci_base_url = "https://ci.linaro.org/jenkins/job/"
    # Snapshots base URL
    snapshots_url = "http://snapshots.linaro.org"

    # Name of the hardware pack project
    job_name = os.environ.get("JOB_NAME")
    # The hardware pack build number
    job_build_number = os.environ.get("JOB_BUILD_NUMBER")
    # Device type
    device_type = os.environ.get("DEVICE_TYPE", "Undefined")
    if device_type == "Undefined":
	sys.exit("Device type is not defined.")

    image_type = os.environ.get("IMAGE_TYPE", "ubuntu-desktop")
    image_url = os.environ.get("IMAGE_URL", "Undefined")
    if image_url == "Undefined":
	sys.exit("IMAGE_URL is not defined.")

    distribution = 'precise'
    architecture = 'armhf'
    hwpack_type = "hwpack_type" 

    # Bundle stream name
    bundle_stream_name = os.environ.get("BUNDLE_STREAM_NAME", \
	    "/private/team/linaro/developers-and-community-builds/")
    # LAVA user
    lava_user = os.environ.get("LAVA_USER")
    if lava_user == None:
	f = open('/var/run/lava/lava-user')
	lava_user = f.read().strip()
	f.close()
    # LAVA token
    lava_token = os.environ.get("LAVA_TOKEN")
    if lava_token == None:
	f = open('/var/run/lava/lava-token')
	lava_token = f.read().strip()
	f.close()
    # LAVA server URL
    lava_server = os.environ.get("LAVA_SERVER", \
	    "validation.linaro.org/lava-server/RPC2/")
    # LAVA server base URL
    lava_server_root = lava_server.rstrip("/")
    if lava_server_root.endswith("/RPC2"):
	lava_server_root = lava_server_root[:-len("/RPC2")]

    actions = [
	    {
		"command": "deploy_linaro_image",
		"parameters": {
		    "image": "%s" % image_url,
		    },
		"metadata": {
		    "ubuntu.image_type": "%s" % image_type,
		    },
		},
	    {
		"command": "boot_linaro_image",
		},
	    {
		"command": "lava_test_install",
		"parameters": {
		    "tests": ["browser-benchmarks"]
		    },
		},
	    {
		"command": "lava_test_run",
		"parameters": {
		    "test_name": "browser-benchmarks",
		    }
		},
	    {
		"command": "submit_results",
		"parameters": {
		    "stream": bundle_stream_name,
		    "server": "%s%s" % ("http://", lava_server)
		    }
		},
	    ]

    config = json.dumps({"timeout": 18000,
	"actions": actions,
	"job_name": "%s%s/%s/" % (ci_base_url, \
		job_name, \
		job_build_number),
	"device_type": device_type,
	}, indent=2)

    print config

    skip_lava = os.environ.get("SKIP_LAVA")
    if skip_lava == None:
	try:
	    server_url = \
		    "https://{lava_user:>s}:{lava_token:>s}@{lava_server:>s}"
	    server = \
		    xmlrpclib.ServerProxy(server_url.format(\
		    lava_user=lava_user, \
		    lava_token=lava_token, \
		    lava_server=lava_server))
	    lava_job_id = server.scheduler.submit_job(config)
	except xmlrpclib.ProtocolError, e:
	    print "Error making a LAVA request:", obfuscate_credentials(str(e))
	    sys.exit(1)

	print "LAVA Job Id: %s, URL: http://%s/scheduler/job/%s" % \
		(lava_job_id, lava_server_root, lava_job_id)
	json.dump({'lava_url': "http://" + lava_server_root,
	    'job_id': lava_job_id},
	    open('lava-job-info', 'w'))
    else:
	print "LAVA job submission skipped."

if __name__ == "__main__":
    main()