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