Andy Doan | 61b4d77 | 2012-04-24 10:03:28 -0500 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
Andy Doan | 61b4d77 | 2012-04-24 10:03:28 -0500 | [diff] [blame] | 3 | import os |
Andy Doan | 61b4d77 | 2012-04-24 10:03:28 -0500 | [diff] [blame] | 4 | import sys |
Fathi Boudra | c14068b | 2012-12-06 17:42:11 +0200 | [diff] [blame] | 5 | import json |
Andy Doan | 61b4d77 | 2012-04-24 10:03:28 -0500 | [diff] [blame] | 6 | import xmlrpclib |
Fathi Boudra | c14068b | 2012-12-06 17:42:11 +0200 | [diff] [blame] | 7 | import re |
Andy Doan | 61b4d77 | 2012-04-24 10:03:28 -0500 | [diff] [blame] | 8 | |
Fathi Boudra | c14068b | 2012-12-06 17:42:11 +0200 | [diff] [blame] | 9 | tests_nano = [ |
| 10 | 'device-tree', |
| 11 | 'gatortests', |
| 12 | 'perf', |
| 13 | 'pwrmgmt', |
| 14 | ] |
| 15 | |
| 16 | tests_alip = [ |
| 17 | 'bootchart', |
| 18 | ] |
| 19 | |
| 20 | tests_desktop = [ |
| 21 | 'e2eaudiotest', |
| 22 | 'bluetooth-enablement', |
| 23 | 'wifi-enablement', |
| 24 | 'leb-basic-graphics', |
| 25 | ] |
| 26 | |
| 27 | tests_openembedded = [ |
| 28 | ] |
Andy Doan | 61b4d77 | 2012-04-24 10:03:28 -0500 | [diff] [blame] | 29 | |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 30 | # Mapping device type - bundle stream |
Andy Doan | 3462e4c | 2012-05-18 10:58:06 -0500 | [diff] [blame] | 31 | DEVICE_STREAM = { |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 32 | 'beaglexm': 'beaglexm', |
| 33 | 'origen': 'leb-origen', |
Andy Doan | 3462e4c | 2012-05-18 10:58:06 -0500 | [diff] [blame] | 34 | 'panda': 'leb-panda-4430', |
Paul Larson | 2730851 | 2012-08-17 14:09:05 -0500 | [diff] [blame] | 35 | 'panda-es': 'leb-panda-es', |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 36 | 'rtsm_foundation-armv8': 'vexpress64', |
| 37 | 'rtsm_ve-a15x1-a7x1': 'vexpress', |
| 38 | 'rtsm_ve-a15x4-a7x4': 'vexpress', |
| 39 | 'rtsm_ve-armv8': 'vexpress', |
Andy Doan | 3462e4c | 2012-05-18 10:58:06 -0500 | [diff] [blame] | 40 | 'snowball_sd': 'leb-snowball', |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 41 | 'vexpress-a5': 'vexpress', |
Fathi Boudra | 76551e5 | 2012-09-19 17:51:33 +0300 | [diff] [blame] | 42 | 'vexpress-a9': 'vexpress', |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 43 | 'vexpress-tc2': 'vexpress', |
Andy Doan | 3462e4c | 2012-05-18 10:58:06 -0500 | [diff] [blame] | 44 | } |
| 45 | |
Andy Doan | 61b4d77 | 2012-04-24 10:03:28 -0500 | [diff] [blame] | 46 | |
| 47 | def obfuscate_credentials(s): |
| 48 | return re.sub(r"([^ ]:).+?(@)", r"\1xxx\2", s) |
| 49 | |
Fathi Boudra | c14068b | 2012-12-06 17:42:11 +0200 | [diff] [blame] | 50 | |
Andy Doan | 61b4d77 | 2012-04-24 10:03:28 -0500 | [diff] [blame] | 51 | def main(): |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 52 | """Script entry point: return some JSON based on calling args. |
| 53 | We should be called from Jenkins and expect the following to be defined: |
| 54 | $HWPACK_BUILD_NUMBER $HWPACK_JOB_NAME HWPACK_FILE_NAME $DEVICE_TYPE |
| 55 | """ |
Andy Doan | 61b4d77 | 2012-04-24 10:03:28 -0500 | [diff] [blame] | 56 | |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 57 | # Snapshots base URL |
| 58 | snapshots_url = "http://snapshots.linaro.org" |
| 59 | |
| 60 | # Name of the hardware pack project |
| 61 | hwpack_job_name = os.environ.get("HWPACK_JOB_NAME") |
| 62 | # The hardware pack build number |
| 63 | hwpack_build_number = os.environ.get("HWPACK_BUILD_NUMBER") |
| 64 | # Hardware pack file name |
| 65 | hwpack_file_name = os.environ.get("HWPACK_FILE_NAME", "Undefined") |
| 66 | if hwpack_file_name == "Undefined": |
| 67 | sys.exit("Hardware pack is not defined.") |
| 68 | # Device type |
| 69 | device_type = os.environ.get("DEVICE_TYPE", "Undefined") |
| 70 | if device_type == "Undefined": |
| 71 | sys.exit("Device type is not defined.") |
| 72 | |
| 73 | # Distribution, architecture and hardware pack type |
| 74 | ret_split = hwpack_job_name.split("-", 2) |
| 75 | (distribution, architecture, hwpack_type) =\ |
| 76 | ret_split[0], ret_split[1], ret_split[2] |
| 77 | if hwpack_type.startswith('pre-built-images-'): |
Fathi Boudra | d4ed3e2 | 2012-12-09 21:21:31 +0200 | [diff] [blame] | 78 | hwpack_type = hwpack_type[(len("pre-built-images-")):] |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 79 | # Rootfs type, default is developer |
| 80 | rootfs_type = os.getenv("ROOTFS_TYPE", "developer") |
Fathi Boudra | c14068b | 2012-12-06 17:42:11 +0200 | [diff] [blame] | 81 | |
| 82 | # Bundle stream name |
| 83 | bundle_stream_name = os.environ.get("BUNDLE_STREAM_NAME", \ |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 84 | "/private/team/linaro/pre-built-%s/" % DEVICE_STREAM[device_type]) |
Fathi Boudra | c14068b | 2012-12-06 17:42:11 +0200 | [diff] [blame] | 85 | # LAVA user |
| 86 | lava_user = os.environ.get("LAVA_USER") |
| 87 | if lava_user == None: |
| 88 | f = open('/var/run/lava/lava-user') |
| 89 | lava_user = f.read().strip() |
| 90 | f.close() |
| 91 | # LAVA token |
| 92 | lava_token = os.environ.get("LAVA_TOKEN") |
| 93 | if lava_token == None: |
| 94 | f = open('/var/run/lava/lava-token') |
| 95 | lava_token = f.read().strip() |
| 96 | f.close() |
| 97 | # LAVA server URL |
| 98 | lava_server = os.environ.get("LAVA_SERVER", \ |
| 99 | "validation.linaro.org/lava-server/RPC2/") |
| 100 | # LAVA server base URL |
| 101 | lava_server_root = lava_server.rstrip("/") |
| 102 | if lava_server_root.endswith("/RPC2"): |
| 103 | lava_server_root = lava_server_root[:-len("/RPC2")] |
| 104 | |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 105 | image_url = "%s/%s/pre-built/%s/%s/%s" %\ |
| 106 | (snapshots_url, \ |
| 107 | distribution, \ |
| 108 | hwpack_type, \ |
| 109 | hwpack_build_number, \ |
| 110 | hwpack_file_name) |
| 111 | |
Senthil Kumaran | b30d738 | 2012-12-19 15:11:47 +0530 | [diff] [blame^] | 112 | git_repo = "git://git.linaro.org/ubuntu/test-definitions.git" |
Senthil Kumaran | 672ac4d | 2012-12-19 15:10:59 +0530 | [diff] [blame] | 113 | |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 114 | # tests set specific to an image |
Fathi Boudra | c51e091 | 2012-06-15 18:18:41 +0300 | [diff] [blame] | 115 | tests = tests_nano |
| 116 | |
Ricardo Salveti de Araujo | acf2854 | 2012-06-27 18:56:00 -0300 | [diff] [blame] | 117 | # if ubuntu-desktop, cover more test cases (LEB) |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 118 | if rootfs_type == 'ubuntu-desktop': |
Fathi Boudra | c51e091 | 2012-06-15 18:18:41 +0300 | [diff] [blame] | 119 | tests += tests_desktop |
Andy Doan | bc19b7c | 2012-05-17 12:08:16 -0500 | [diff] [blame] | 120 | |
Ricardo Salveti de Araujo | 6ad9433 | 2012-06-29 02:48:18 -0300 | [diff] [blame] | 121 | # if alip, specific tests like bootchart (which should be first) |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 122 | if rootfs_type == 'alip': |
Ricardo Salveti de Araujo | 6ad9433 | 2012-06-29 02:48:18 -0300 | [diff] [blame] | 123 | tests = tests_alip + tests |
| 124 | |
Ricardo Salveti de Araujo | acf2854 | 2012-06-27 18:56:00 -0300 | [diff] [blame] | 125 | # removing bluetooth and wifi for devices that don't support it |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 126 | if device_type in ['beaglexm', 'vexpress-a9', 'mx53loco']: |
Ricardo Salveti de Araujo | dd78097 | 2012-06-29 11:48:47 -0300 | [diff] [blame] | 127 | try: |
| 128 | tests.remove('bluetooth-enablement') |
| 129 | tests.remove('wifi-enablement') |
| 130 | except ValueError: |
| 131 | pass |
Ricardo Salveti de Araujo | acf2854 | 2012-06-27 18:56:00 -0300 | [diff] [blame] | 132 | |
| 133 | # vexpress doesn't support PM, so disable pwrmgmt |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 134 | if device_type in ['vexpress-a9']: |
Ricardo Salveti de Araujo | dd78097 | 2012-06-29 11:48:47 -0300 | [diff] [blame] | 135 | try: |
| 136 | tests.remove('pwrmgmt') |
| 137 | except ValueError: |
| 138 | pass |
Andy Doan | e9bf215 | 2012-06-12 15:42:10 -0500 | [diff] [blame] | 139 | |
Fathi Boudra | 62eb6a9 | 2012-12-06 19:02:56 +0200 | [diff] [blame] | 140 | if distribution == 'openembedded': |
Fathi Boudra | c14068b | 2012-12-06 17:42:11 +0200 | [diff] [blame] | 141 | tests = tests_openembedded |
Fathi Boudra | 4079a58 | 2012-12-06 19:42:58 +0200 | [diff] [blame] | 142 | actions = [{ |
| 143 | "command": "deploy_linaro_image", |
| 144 | "parameters": { |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 145 | "image": "%s" % image_url, |
Fathi Boudra | 4079a58 | 2012-12-06 19:42:58 +0200 | [diff] [blame] | 146 | }, |
| 147 | "metadata": { |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 148 | "hwpack.type": "%s" % hwpack_type, |
| 149 | "hwpack.build": "%s" % hwpack_build_number, |
| 150 | "rootfs.type": "%s" % rootfs_type, |
Fathi Boudra | 4079a58 | 2012-12-06 19:42:58 +0200 | [diff] [blame] | 151 | "distribution": "%s" % distribution, |
| 152 | } |
| 153 | }] |
| 154 | else: # Distribution is Ubuntu |
| 155 | actions = [{ |
| 156 | "command": "deploy_linaro_image", |
| 157 | "parameters": { |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 158 | "image": "%s" % image_url, |
Fathi Boudra | 4079a58 | 2012-12-06 19:42:58 +0200 | [diff] [blame] | 159 | }, |
| 160 | "metadata": { |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 161 | "ubuntu.name": "%s" % hwpack_type, |
| 162 | "ubuntu.build": "%s" % hwpack_build_number, |
| 163 | "rootfs.type": "%s" % rootfs_type, |
Fathi Boudra | c14068b | 2012-12-06 17:42:11 +0200 | [diff] [blame] | 164 | "ubuntu.distribution": "%s" % distribution, |
Fathi Boudra | 4079a58 | 2012-12-06 19:42:58 +0200 | [diff] [blame] | 165 | } |
| 166 | }] |
| 167 | |
Fathi Boudra | a9bbadb | 2012-12-07 16:10:29 +0200 | [diff] [blame] | 168 | if len(tests) > 0: |
Senthil Kumaran | b30d738 | 2012-12-19 15:11:47 +0530 | [diff] [blame^] | 169 | test_list = [] |
| 170 | for test in tests: |
| 171 | test_list.append({"git-repo": git_repo, |
| 172 | "testdef": 'ubuntu/{0}.yaml'.format(test)}) |
Fathi Boudra | c14068b | 2012-12-06 17:42:11 +0200 | [diff] [blame] | 173 | actions.append({ |
Senthil Kumaran | 672ac4d | 2012-12-19 15:10:59 +0530 | [diff] [blame] | 174 | "command": "lava_test_shell", |
Fathi Boudra | c14068b | 2012-12-06 17:42:11 +0200 | [diff] [blame] | 175 | "parameters": { |
Senthil Kumaran | b30d738 | 2012-12-19 15:11:47 +0530 | [diff] [blame^] | 176 | "testdef_repos": test_list |
Fathi Boudra | c14068b | 2012-12-06 17:42:11 +0200 | [diff] [blame] | 177 | } |
| 178 | }) |
| 179 | |
| 180 | actions.append({ |
| 181 | "command": "submit_results", |
| 182 | "parameters": { |
| 183 | "stream": bundle_stream_name, |
| 184 | "server": "%s%s" % ("http://", lava_server) |
| 185 | } |
| 186 | }) |
| 187 | |
| 188 | config = json.dumps({"timeout": 18000, |
| 189 | "actions": actions, |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 190 | "job_name": hwpack_job_name, |
| 191 | "device_type": device_type, |
Fathi Boudra | c14068b | 2012-12-06 17:42:11 +0200 | [diff] [blame] | 192 | }, indent=2) |
Fathi Boudra | 79c1e8b | 2012-12-02 10:36:57 +0200 | [diff] [blame] | 193 | |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 194 | print config |
| 195 | |
Fathi Boudra | 79c1e8b | 2012-12-02 10:36:57 +0200 | [diff] [blame] | 196 | skip_lava = os.environ.get("SKIP_LAVA") |
| 197 | if skip_lava == None: |
Fathi Boudra | 79c1e8b | 2012-12-02 10:36:57 +0200 | [diff] [blame] | 198 | try: |
Fathi Boudra | c14068b | 2012-12-06 17:42:11 +0200 | [diff] [blame] | 199 | server_url = \ |
| 200 | "https://{lava_user:>s}:{lava_token:>s}@{lava_server:>s}" |
| 201 | server = \ |
| 202 | xmlrpclib.ServerProxy(server_url.format(\ |
| 203 | lava_user=lava_user, \ |
| 204 | lava_token=lava_token, \ |
| 205 | lava_server=lava_server)) |
| 206 | lava_job_id = server.scheduler.submit_job(config) |
Fathi Boudra | 79c1e8b | 2012-12-02 10:36:57 +0200 | [diff] [blame] | 207 | except xmlrpclib.ProtocolError, e: |
Fathi Boudra | c14068b | 2012-12-06 17:42:11 +0200 | [diff] [blame] | 208 | print "Error making a LAVA request:", obfuscate_credentials(str(e)) |
Fathi Boudra | 79c1e8b | 2012-12-02 10:36:57 +0200 | [diff] [blame] | 209 | sys.exit(1) |
Fathi Boudra | c14068b | 2012-12-06 17:42:11 +0200 | [diff] [blame] | 210 | |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 211 | print "LAVA Job Id: %s, URL: http://%s/scheduler/job/%s" % \ |
| 212 | (lava_job_id, lava_server_root, lava_job_id) |
Fathi Boudra | c14068b | 2012-12-06 17:42:11 +0200 | [diff] [blame] | 213 | json.dump({'lava_url': "http://" + lava_server_root, |
| 214 | 'job_id': lava_job_id}, |
| 215 | open('lava-job-info', 'w')) |
Fathi Boudra | 8e4ce56 | 2012-12-08 14:35:17 +0200 | [diff] [blame] | 216 | |
Fathi Boudra | de02059 | 2012-12-10 13:25:14 +0200 | [diff] [blame] | 217 | lava_job_info_orig = hwpack_file_name.replace(".img.gz", ".html") |
| 218 | top_dir = os.environ.get("WORKSPACE", ".") |
| 219 | for root, dirs, files in os.walk(top_dir): |
| 220 | for file in files: |
| 221 | if file == lava_job_info_orig: |
| 222 | lava_job_info_orig = os.path.join(root, file) |
Fathi Boudra | 5e48102 | 2012-12-08 19:21:16 +0200 | [diff] [blame] | 223 | |
Fathi Boudra | de02059 | 2012-12-10 13:25:14 +0200 | [diff] [blame] | 224 | with open(lava_job_info_orig) as f: |
| 225 | buffer = f.read() |
Fathi Boudra | 5e48102 | 2012-12-08 19:21:16 +0200 | [diff] [blame] | 226 | |
Fathi Boudra | de02059 | 2012-12-10 13:25:14 +0200 | [diff] [blame] | 227 | buffer = buffer.replace("var lavaJobId = 0", \ |
| 228 | "var lavaJobId = " + str(lava_job_id), 1) |
| 229 | |
| 230 | lava_job_info = lava_job_info_orig.replace(".html",\ |
| 231 | "-" + device_type + ".html") |
| 232 | with open(lava_job_info, 'w') as f: |
| 233 | f.write(buffer) |
| 234 | os.remove(lava_job_info_orig) |
Fathi Boudra | 79c1e8b | 2012-12-02 10:36:57 +0200 | [diff] [blame] | 235 | else: |
| 236 | print "LAVA job submission skipped." |
Andy Doan | 61b4d77 | 2012-04-24 10:03:28 -0500 | [diff] [blame] | 237 | |
| 238 | if __name__ == "__main__": |
| 239 | main() |