Jan Tattermusch | 320bd61 | 2015-09-15 12:44:35 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright 2015, Google Inc. |
| 3 | # All rights reserved. |
| 4 | # |
| 5 | # Redistribution and use in source and binary forms, with or without |
| 6 | # modification, are permitted provided that the following conditions are |
| 7 | # met: |
| 8 | # |
| 9 | # * Redistributions of source code must retain the above copyright |
| 10 | # notice, this list of conditions and the following disclaimer. |
| 11 | # * Redistributions in binary form must reproduce the above |
| 12 | # copyright notice, this list of conditions and the following disclaimer |
| 13 | # in the documentation and/or other materials provided with the |
| 14 | # distribution. |
| 15 | # * Neither the name of Google Inc. nor the names of its |
| 16 | # contributors may be used to endorse or promote products derived from |
| 17 | # this software without specific prior written permission. |
| 18 | # |
| 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | |
| 31 | """Run interop (cross-language) tests in parallel.""" |
| 32 | |
| 33 | import argparse |
Carl Mastrangelo | e7f8e8e | 2015-12-08 17:22:44 -0800 | [diff] [blame^] | 34 | import atexit |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 35 | import dockerjob |
Jan Tattermusch | 320bd61 | 2015-09-15 12:44:35 -0700 | [diff] [blame] | 36 | import itertools |
Jan Tattermusch | 320bd61 | 2015-09-15 12:44:35 -0700 | [diff] [blame] | 37 | import jobset |
Carl Mastrangelo | e7f8e8e | 2015-12-08 17:22:44 -0800 | [diff] [blame^] | 38 | import json |
Jan Tattermusch | 210a0ea | 2015-10-02 15:05:36 -0700 | [diff] [blame] | 39 | import multiprocessing |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 40 | import os |
Carl Mastrangelo | e7f8e8e | 2015-12-08 17:22:44 -0800 | [diff] [blame^] | 41 | import re |
Adele Zhou | a30f829 | 2015-11-02 13:15:46 -0800 | [diff] [blame] | 42 | import report_utils |
Carl Mastrangelo | e7f8e8e | 2015-12-08 17:22:44 -0800 | [diff] [blame^] | 43 | import subprocess |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 44 | import sys |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 45 | import tempfile |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 46 | import time |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 47 | import uuid |
Jan Tattermusch | 320bd61 | 2015-09-15 12:44:35 -0700 | [diff] [blame] | 48 | |
Carl Mastrangelo | e7f8e8e | 2015-12-08 17:22:44 -0800 | [diff] [blame^] | 49 | # Docker doesn't clean up after itself, so we do it on exit. |
| 50 | atexit.register(lambda: subprocess.call(['stty', 'echo'])) |
| 51 | |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 52 | ROOT = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '../..')) |
| 53 | os.chdir(ROOT) |
| 54 | |
| 55 | _DEFAULT_SERVER_PORT=8080 |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 56 | |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 57 | # TOOD(jtattermusch) wrapped languages use this variable for location |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 58 | # of roots.pem. We might want to use GRPC_DEFAULT_SSL_ROOTS_FILE_PATH |
| 59 | # supported by C core SslCredentials instead. |
| 60 | _SSL_CERT_ENV = { 'SSL_CERT_FILE':'/usr/local/share/grpc/roots.pem' } |
| 61 | |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 62 | |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 63 | class CXXLanguage: |
| 64 | |
| 65 | def __init__(self): |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 66 | self.client_cwd = None |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 67 | self.server_cwd = None |
Jan Tattermusch | 0a14f62 | 2015-10-09 14:34:29 -0700 | [diff] [blame] | 68 | self.safename = 'cxx' |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 69 | |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 70 | def client_cmd(self, args): |
| 71 | return ['bins/opt/interop_client'] + args |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 72 | |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 73 | def cloud_to_prod_env(self): |
Jan Tattermusch | fb8c77d | 2015-10-06 09:33:37 -0700 | [diff] [blame] | 74 | return {} |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 75 | |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 76 | def server_cmd(self, args): |
| 77 | return ['bins/opt/interop_server', '--use_tls=true'] + args |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 78 | |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 79 | def global_env(self): |
| 80 | return {} |
| 81 | |
Jan Tattermusch | 289b7b9 | 2015-10-21 18:09:59 -0700 | [diff] [blame] | 82 | def unimplemented_test_cases(self): |
| 83 | return [] |
| 84 | |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 85 | def __str__(self): |
| 86 | return 'c++' |
| 87 | |
| 88 | |
| 89 | class CSharpLanguage: |
| 90 | |
| 91 | def __init__(self): |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 92 | self.client_cwd = 'src/csharp/Grpc.IntegrationTesting.Client/bin/Debug' |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 93 | self.server_cwd = 'src/csharp/Grpc.IntegrationTesting.Server/bin/Debug' |
Jan Tattermusch | 0a14f62 | 2015-10-09 14:34:29 -0700 | [diff] [blame] | 94 | self.safename = str(self) |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 95 | |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 96 | def client_cmd(self, args): |
| 97 | return ['mono', 'Grpc.IntegrationTesting.Client.exe'] + args |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 98 | |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 99 | def cloud_to_prod_env(self): |
| 100 | return _SSL_CERT_ENV |
| 101 | |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 102 | def server_cmd(self, args): |
| 103 | return ['mono', 'Grpc.IntegrationTesting.Server.exe', '--use_tls=true'] + args |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 104 | |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 105 | def global_env(self): |
| 106 | return {} |
| 107 | |
Jan Tattermusch | 289b7b9 | 2015-10-21 18:09:59 -0700 | [diff] [blame] | 108 | def unimplemented_test_cases(self): |
| 109 | return [] |
| 110 | |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 111 | def __str__(self): |
| 112 | return 'csharp' |
| 113 | |
| 114 | |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 115 | class JavaLanguage: |
| 116 | |
| 117 | def __init__(self): |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 118 | self.client_cwd = '../grpc-java' |
| 119 | self.server_cwd = '../grpc-java' |
Jan Tattermusch | 0a14f62 | 2015-10-09 14:34:29 -0700 | [diff] [blame] | 120 | self.safename = str(self) |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 121 | |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 122 | def client_cmd(self, args): |
| 123 | return ['./run-test-client.sh'] + args |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 124 | |
| 125 | def cloud_to_prod_env(self): |
Jan Tattermusch | fb8c77d | 2015-10-06 09:33:37 -0700 | [diff] [blame] | 126 | return {} |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 127 | |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 128 | def server_cmd(self, args): |
| 129 | return ['./run-test-server.sh', '--use_tls=true'] + args |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 130 | |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 131 | def global_env(self): |
| 132 | return {} |
| 133 | |
Jan Tattermusch | 289b7b9 | 2015-10-21 18:09:59 -0700 | [diff] [blame] | 134 | def unimplemented_test_cases(self): |
| 135 | return [] |
| 136 | |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 137 | def __str__(self): |
| 138 | return 'java' |
| 139 | |
| 140 | |
Jan Tattermusch | cc1bde7 | 2015-10-05 12:47:45 -0700 | [diff] [blame] | 141 | class GoLanguage: |
| 142 | |
| 143 | def __init__(self): |
Jan Tattermusch | cc1bde7 | 2015-10-05 12:47:45 -0700 | [diff] [blame] | 144 | # TODO: this relies on running inside docker |
| 145 | self.client_cwd = '/go/src/google.golang.org/grpc/interop/client' |
| 146 | self.server_cwd = '/go/src/google.golang.org/grpc/interop/server' |
Jan Tattermusch | 0a14f62 | 2015-10-09 14:34:29 -0700 | [diff] [blame] | 147 | self.safename = str(self) |
Jan Tattermusch | cc1bde7 | 2015-10-05 12:47:45 -0700 | [diff] [blame] | 148 | |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 149 | def client_cmd(self, args): |
| 150 | return ['go', 'run', 'client.go'] + args |
Jan Tattermusch | cc1bde7 | 2015-10-05 12:47:45 -0700 | [diff] [blame] | 151 | |
| 152 | def cloud_to_prod_env(self): |
Jan Tattermusch | fb8c77d | 2015-10-06 09:33:37 -0700 | [diff] [blame] | 153 | return {} |
Jan Tattermusch | cc1bde7 | 2015-10-05 12:47:45 -0700 | [diff] [blame] | 154 | |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 155 | def server_cmd(self, args): |
| 156 | return ['go', 'run', 'server.go', '--use_tls=true'] + args |
Jan Tattermusch | cc1bde7 | 2015-10-05 12:47:45 -0700 | [diff] [blame] | 157 | |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 158 | def global_env(self): |
| 159 | return {} |
| 160 | |
Jan Tattermusch | 289b7b9 | 2015-10-21 18:09:59 -0700 | [diff] [blame] | 161 | def unimplemented_test_cases(self): |
| 162 | return [] |
| 163 | |
Jan Tattermusch | cc1bde7 | 2015-10-05 12:47:45 -0700 | [diff] [blame] | 164 | def __str__(self): |
| 165 | return 'go' |
| 166 | |
| 167 | |
Carl Mastrangelo | de44910 | 2015-10-28 11:05:49 -0700 | [diff] [blame] | 168 | class Http2Client: |
| 169 | """Represents the HTTP/2 Interop Test |
| 170 | |
| 171 | This pretends to be a language in order to be built and run, but really it |
| 172 | isn't. |
| 173 | """ |
| 174 | def __init__(self): |
| 175 | self.client_cwd = None |
| 176 | self.safename = str(self) |
| 177 | |
Masood Malekghassemi | 0a9cc3c | 2015-11-09 12:24:05 -0800 | [diff] [blame] | 178 | def client_cmd(self, args): |
| 179 | return ['tools/http2_interop/http2_interop.test', '-test.v'] + args |
Carl Mastrangelo | de44910 | 2015-10-28 11:05:49 -0700 | [diff] [blame] | 180 | |
| 181 | def cloud_to_prod_env(self): |
| 182 | return {} |
| 183 | |
| 184 | def global_env(self): |
| 185 | return {} |
| 186 | |
| 187 | def unimplemented_test_cases(self): |
| 188 | return _TEST_CASES |
| 189 | |
| 190 | def __str__(self): |
| 191 | return 'http2' |
| 192 | |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 193 | class NodeLanguage: |
| 194 | |
| 195 | def __init__(self): |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 196 | self.client_cwd = None |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 197 | self.server_cwd = None |
Jan Tattermusch | 0a14f62 | 2015-10-09 14:34:29 -0700 | [diff] [blame] | 198 | self.safename = str(self) |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 199 | |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 200 | def client_cmd(self, args): |
| 201 | return ['node', 'src/node/interop/interop_client.js'] + args |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 202 | |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 203 | def cloud_to_prod_env(self): |
| 204 | return _SSL_CERT_ENV |
| 205 | |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 206 | def server_cmd(self, args): |
| 207 | return ['node', 'src/node/interop/interop_server.js', '--use_tls=true'] + args |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 208 | |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 209 | def global_env(self): |
| 210 | return {} |
| 211 | |
Jan Tattermusch | 289b7b9 | 2015-10-21 18:09:59 -0700 | [diff] [blame] | 212 | def unimplemented_test_cases(self): |
| 213 | return [] |
| 214 | |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 215 | def __str__(self): |
| 216 | return 'node' |
| 217 | |
Jan Tattermusch | f88f3e2 | 2015-09-16 17:50:45 -0700 | [diff] [blame] | 218 | |
| 219 | class PHPLanguage: |
| 220 | |
| 221 | def __init__(self): |
Jan Tattermusch | f88f3e2 | 2015-09-16 17:50:45 -0700 | [diff] [blame] | 222 | self.client_cwd = None |
Jan Tattermusch | 0a14f62 | 2015-10-09 14:34:29 -0700 | [diff] [blame] | 223 | self.safename = str(self) |
Jan Tattermusch | f88f3e2 | 2015-09-16 17:50:45 -0700 | [diff] [blame] | 224 | |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 225 | def client_cmd(self, args): |
| 226 | return ['src/php/bin/interop_client.sh'] + args |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 227 | |
Jan Tattermusch | f88f3e2 | 2015-09-16 17:50:45 -0700 | [diff] [blame] | 228 | def cloud_to_prod_env(self): |
| 229 | return _SSL_CERT_ENV |
| 230 | |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 231 | def global_env(self): |
Stanley Cheung | 22b6bed | 2015-10-15 16:54:52 -0700 | [diff] [blame] | 232 | return {} |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 233 | |
Jan Tattermusch | 289b7b9 | 2015-10-21 18:09:59 -0700 | [diff] [blame] | 234 | def unimplemented_test_cases(self): |
| 235 | return [] |
| 236 | |
Jan Tattermusch | f88f3e2 | 2015-09-16 17:50:45 -0700 | [diff] [blame] | 237 | def __str__(self): |
| 238 | return 'php' |
| 239 | |
| 240 | |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 241 | class RubyLanguage: |
| 242 | |
| 243 | def __init__(self): |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 244 | self.client_cwd = None |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 245 | self.server_cwd = None |
Jan Tattermusch | 0a14f62 | 2015-10-09 14:34:29 -0700 | [diff] [blame] | 246 | self.safename = str(self) |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 247 | |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 248 | def client_cmd(self, args): |
| 249 | return ['ruby', 'src/ruby/bin/interop/interop_client.rb'] + args |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 250 | |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 251 | def cloud_to_prod_env(self): |
| 252 | return _SSL_CERT_ENV |
| 253 | |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 254 | def server_cmd(self, args): |
| 255 | return ['ruby', 'src/ruby/bin/interop/interop_server.rb', '--use_tls=true'] + args |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 256 | |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 257 | def global_env(self): |
| 258 | return {} |
| 259 | |
Jan Tattermusch | 289b7b9 | 2015-10-21 18:09:59 -0700 | [diff] [blame] | 260 | def unimplemented_test_cases(self): |
| 261 | return [] |
| 262 | |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 263 | def __str__(self): |
| 264 | return 'ruby' |
| 265 | |
| 266 | |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 267 | class PythonLanguage: |
| 268 | |
| 269 | def __init__(self): |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 270 | self.client_cwd = None |
| 271 | self.server_cwd = None |
| 272 | self.safename = str(self) |
| 273 | |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 274 | def client_cmd(self, args): |
| 275 | return [ |
Masood Malekghassemi | eaa7d20 | 2015-12-07 14:38:53 -0800 | [diff] [blame] | 276 | 'src/python/grpcio/.tox/py27/bin/python', |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 277 | 'src/python/grpcio/setup.py', |
| 278 | 'run_interop', |
| 279 | '--client', |
| 280 | '--args=\'{}\''.format(' '.join(args)) |
| 281 | ] |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 282 | |
| 283 | def cloud_to_prod_env(self): |
| 284 | return _SSL_CERT_ENV |
| 285 | |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 286 | def server_cmd(self, args): |
| 287 | return [ |
Masood Malekghassemi | eaa7d20 | 2015-12-07 14:38:53 -0800 | [diff] [blame] | 288 | 'src/python/grpcio/.tox/py27/bin/python', |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 289 | 'src/python/grpcio/setup.py', |
| 290 | 'run_interop', |
| 291 | '--server', |
| 292 | '--args=\'{}\''.format(' '.join(args) + ' --use_tls=true') |
| 293 | ] |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 294 | |
| 295 | def global_env(self): |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 296 | return {'LD_LIBRARY_PATH': '{}/libs/opt'.format(DOCKER_WORKDIR_ROOT)} |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 297 | |
Jan Tattermusch | 289b7b9 | 2015-10-21 18:09:59 -0700 | [diff] [blame] | 298 | def unimplemented_test_cases(self): |
| 299 | return ['jwt_token_creds', 'per_rpc_creds'] |
| 300 | |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 301 | def __str__(self): |
| 302 | return 'python' |
| 303 | |
| 304 | |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 305 | _LANGUAGES = { |
| 306 | 'c++' : CXXLanguage(), |
| 307 | 'csharp' : CSharpLanguage(), |
Jan Tattermusch | cc1bde7 | 2015-10-05 12:47:45 -0700 | [diff] [blame] | 308 | 'go' : GoLanguage(), |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 309 | 'java' : JavaLanguage(), |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 310 | 'node' : NodeLanguage(), |
Jan Tattermusch | f88f3e2 | 2015-09-16 17:50:45 -0700 | [diff] [blame] | 311 | 'php' : PHPLanguage(), |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 312 | 'ruby' : RubyLanguage(), |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 313 | 'python' : PythonLanguage(), |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 314 | } |
Jan Tattermusch | 320bd61 | 2015-09-15 12:44:35 -0700 | [diff] [blame] | 315 | |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 316 | # languages supported as cloud_to_cloud servers |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 317 | _SERVERS = ['c++', 'node', 'csharp', 'java', 'go', 'ruby', 'python'] |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 318 | |
Jan Tattermusch | 320bd61 | 2015-09-15 12:44:35 -0700 | [diff] [blame] | 319 | _TEST_CASES = ['large_unary', 'empty_unary', 'ping_pong', |
Jan Tattermusch | 1f1c5c5 | 2015-10-09 14:36:28 -0700 | [diff] [blame] | 320 | 'empty_stream', 'client_streaming', 'server_streaming', |
Jan Tattermusch | 13bf36a | 2015-10-14 17:01:00 -0700 | [diff] [blame] | 321 | 'cancel_after_begin', 'cancel_after_first_response', |
| 322 | 'timeout_on_sleeping_server'] |
Jan Tattermusch | 320bd61 | 2015-09-15 12:44:35 -0700 | [diff] [blame] | 323 | |
Jan Tattermusch | fb8c77d | 2015-10-06 09:33:37 -0700 | [diff] [blame] | 324 | _AUTH_TEST_CASES = ['compute_engine_creds', 'jwt_token_creds', |
| 325 | 'oauth2_auth_token', 'per_rpc_creds'] |
| 326 | |
Carl Mastrangelo | 2dd55db | 2015-11-19 10:51:48 -0800 | [diff] [blame] | 327 | _HTTP2_TEST_CASES = ["tls", "framing"] |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 328 | |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 329 | DOCKER_WORKDIR_ROOT = '/var/local/git/grpc' |
| 330 | |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 331 | def docker_run_cmdline(cmdline, image, docker_args=[], cwd=None, environ=None): |
| 332 | """Wraps given cmdline array to create 'docker run' cmdline from it.""" |
| 333 | docker_cmdline = ['docker', 'run', '-i', '--rm=true'] |
| 334 | |
| 335 | # turn environ into -e docker args |
| 336 | if environ: |
| 337 | for k,v in environ.iteritems(): |
| 338 | docker_cmdline += ['-e', '%s=%s' % (k,v)] |
| 339 | |
| 340 | # set working directory |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 341 | workdir = DOCKER_WORKDIR_ROOT |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 342 | if cwd: |
| 343 | workdir = os.path.join(workdir, cwd) |
| 344 | docker_cmdline += ['-w', workdir] |
| 345 | |
| 346 | docker_cmdline += docker_args + [image] + cmdline |
| 347 | return docker_cmdline |
| 348 | |
| 349 | |
| 350 | def bash_login_cmdline(cmdline): |
| 351 | """Creates bash -l -c cmdline from args list.""" |
| 352 | # Use login shell: |
| 353 | # * rvm and nvm require it |
| 354 | # * makes error messages clearer if executables are missing |
| 355 | return ['bash', '-l', '-c', ' '.join(cmdline)] |
| 356 | |
| 357 | |
Masood Malekghassemi | 0a9cc3c | 2015-11-09 12:24:05 -0800 | [diff] [blame] | 358 | def auth_options(language, test_case): |
Jan Tattermusch | fb8c77d | 2015-10-06 09:33:37 -0700 | [diff] [blame] | 359 | """Returns (cmdline, env) tuple with cloud_to_prod_auth test options.""" |
| 360 | |
| 361 | language = str(language) |
Masood Malekghassemi | 0a9cc3c | 2015-11-09 12:24:05 -0800 | [diff] [blame] | 362 | cmdargs = [] |
| 363 | env = {} |
Jan Tattermusch | fb8c77d | 2015-10-06 09:33:37 -0700 | [diff] [blame] | 364 | |
| 365 | # TODO(jtattermusch): this file path only works inside docker |
| 366 | key_filepath = '/root/service_account/stubbyCloudTestingTest-ee3fce360ac5.json' |
| 367 | oauth_scope_arg = '--oauth_scope=https://www.googleapis.com/auth/xapi.zoo' |
| 368 | key_file_arg = '--service_account_key_file=%s' % key_filepath |
| 369 | default_account_arg = '--default_service_account=830293263384-compute@developer.gserviceaccount.com' |
| 370 | |
| 371 | if test_case in ['jwt_token_creds', 'per_rpc_creds', 'oauth2_auth_token']: |
Jan Tattermusch | 3b6fef1 | 2015-10-19 19:33:24 -0700 | [diff] [blame] | 372 | if language in ['csharp', 'node', 'php', 'python', 'ruby']: |
Jan Tattermusch | fb8c77d | 2015-10-06 09:33:37 -0700 | [diff] [blame] | 373 | env['GOOGLE_APPLICATION_CREDENTIALS'] = key_filepath |
| 374 | else: |
Masood Malekghassemi | 0a9cc3c | 2015-11-09 12:24:05 -0800 | [diff] [blame] | 375 | cmdargs += [key_file_arg] |
Jan Tattermusch | fb8c77d | 2015-10-06 09:33:37 -0700 | [diff] [blame] | 376 | |
| 377 | if test_case in ['per_rpc_creds', 'oauth2_auth_token']: |
Masood Malekghassemi | 0a9cc3c | 2015-11-09 12:24:05 -0800 | [diff] [blame] | 378 | cmdargs += [oauth_scope_arg] |
Jan Tattermusch | fb8c77d | 2015-10-06 09:33:37 -0700 | [diff] [blame] | 379 | |
Jan Tattermusch | 64d7c24 | 2015-10-08 08:02:27 -0700 | [diff] [blame] | 380 | if test_case == 'oauth2_auth_token' and language == 'c++': |
| 381 | # C++ oauth2 test uses GCE creds and thus needs to know the default account |
Masood Malekghassemi | 0a9cc3c | 2015-11-09 12:24:05 -0800 | [diff] [blame] | 382 | cmdargs += [default_account_arg] |
Jan Tattermusch | 64d7c24 | 2015-10-08 08:02:27 -0700 | [diff] [blame] | 383 | |
Jan Tattermusch | fb8c77d | 2015-10-06 09:33:37 -0700 | [diff] [blame] | 384 | if test_case == 'compute_engine_creds': |
Masood Malekghassemi | 0a9cc3c | 2015-11-09 12:24:05 -0800 | [diff] [blame] | 385 | cmdargs += [oauth_scope_arg, default_account_arg] |
Jan Tattermusch | fb8c77d | 2015-10-06 09:33:37 -0700 | [diff] [blame] | 386 | |
Masood Malekghassemi | 0a9cc3c | 2015-11-09 12:24:05 -0800 | [diff] [blame] | 387 | return (cmdargs, env) |
Jan Tattermusch | fb8c77d | 2015-10-06 09:33:37 -0700 | [diff] [blame] | 388 | |
| 389 | |
Jan Tattermusch | e268628 | 2015-10-08 16:27:07 -0700 | [diff] [blame] | 390 | def _job_kill_handler(job): |
| 391 | if job._spec.container_name: |
| 392 | dockerjob.docker_kill(job._spec.container_name) |
Jan Tattermusch | 39e3cb3 | 2015-10-22 18:21:08 -0700 | [diff] [blame] | 393 | # When the job times out and we decide to kill it, |
| 394 | # we need to wait a before restarting the job |
| 395 | # to prevent "container name already in use" error. |
| 396 | # TODO(jtattermusch): figure out a cleaner way to to this. |
| 397 | time.sleep(2) |
Jan Tattermusch | e268628 | 2015-10-08 16:27:07 -0700 | [diff] [blame] | 398 | |
| 399 | |
Jan Tattermusch | fb8c77d | 2015-10-06 09:33:37 -0700 | [diff] [blame] | 400 | def cloud_to_prod_jobspec(language, test_case, docker_image=None, auth=False): |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 401 | """Creates jobspec for cloud-to-prod interop test""" |
Masood Malekghassemi | 0a9cc3c | 2015-11-09 12:24:05 -0800 | [diff] [blame] | 402 | container_name = None |
| 403 | cmdargs = [ |
Jan Tattermusch | c8b9441 | 2015-10-21 17:57:28 -0700 | [diff] [blame] | 404 | '--server_host_override=grpc-test.sandbox.google.com', |
| 405 | '--server_host=grpc-test.sandbox.google.com', |
| 406 | '--server_port=443', |
| 407 | '--use_tls=true', |
| 408 | '--test_case=%s' % test_case] |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 409 | environ = dict(language.cloud_to_prod_env(), **language.global_env()) |
Jan Tattermusch | fb8c77d | 2015-10-06 09:33:37 -0700 | [diff] [blame] | 410 | if auth: |
Masood Malekghassemi | 0a9cc3c | 2015-11-09 12:24:05 -0800 | [diff] [blame] | 411 | auth_cmdargs, auth_env = auth_options(language, test_case) |
| 412 | cmdargs += auth_cmdargs |
| 413 | environ.update(auth_env) |
| 414 | cmdline = bash_login_cmdline(language.client_cmd(cmdargs)) |
| 415 | cwd = language.client_cwd |
Jan Tattermusch | fb8c77d | 2015-10-06 09:33:37 -0700 | [diff] [blame] | 416 | |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 417 | if docker_image: |
Jan Tattermusch | 0a14f62 | 2015-10-09 14:34:29 -0700 | [diff] [blame] | 418 | container_name = dockerjob.random_name('interop_client_%s' % language.safename) |
Jan Tattermusch | e268628 | 2015-10-08 16:27:07 -0700 | [diff] [blame] | 419 | cmdline = docker_run_cmdline(cmdline, |
| 420 | image=docker_image, |
| 421 | cwd=cwd, |
| 422 | environ=environ, |
| 423 | docker_args=['--net=host', |
| 424 | '--name', container_name]) |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 425 | cwd = None |
| 426 | environ = None |
| 427 | |
Jan Tattermusch | fb8c77d | 2015-10-06 09:33:37 -0700 | [diff] [blame] | 428 | suite_name='cloud_to_prod_auth' if auth else 'cloud_to_prod' |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 429 | test_job = jobset.JobSpec( |
| 430 | cmdline=cmdline, |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 431 | cwd=cwd, |
| 432 | environ=environ, |
Adele Zhou | e4c3561 | 2015-10-16 15:34:23 -0700 | [diff] [blame] | 433 | shortname='%s:%s:%s' % (suite_name, language, test_case), |
Jan Tattermusch | 29fd005 | 2015-10-22 18:58:57 -0700 | [diff] [blame] | 434 | timeout_seconds=90, |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 435 | flake_retries=5 if args.allow_flakes else 0, |
Jan Tattermusch | e268628 | 2015-10-08 16:27:07 -0700 | [diff] [blame] | 436 | timeout_retries=2 if args.allow_flakes else 0, |
| 437 | kill_handler=_job_kill_handler) |
| 438 | test_job.container_name = container_name |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 439 | return test_job |
| 440 | |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 441 | |
| 442 | def cloud_to_cloud_jobspec(language, test_case, server_name, server_host, |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 443 | server_port, docker_image=None): |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 444 | """Creates jobspec for cloud-to-cloud interop test""" |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 445 | cmdline = bash_login_cmdline(language.client_cmd([ |
| 446 | '--server_host_override=foo.test.google.fr', |
| 447 | '--use_tls=true', |
| 448 | '--use_test_ca=true', |
| 449 | '--test_case=%s' % test_case, |
| 450 | '--server_host=%s' % server_host, |
| 451 | '--server_port=%s' % server_port])) |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 452 | cwd = language.client_cwd |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 453 | environ = language.global_env() |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 454 | if docker_image: |
Jan Tattermusch | 0a14f62 | 2015-10-09 14:34:29 -0700 | [diff] [blame] | 455 | container_name = dockerjob.random_name('interop_client_%s' % language.safename) |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 456 | cmdline = docker_run_cmdline(cmdline, |
| 457 | image=docker_image, |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 458 | environ=environ, |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 459 | cwd=cwd, |
Jan Tattermusch | e268628 | 2015-10-08 16:27:07 -0700 | [diff] [blame] | 460 | docker_args=['--net=host', |
| 461 | '--name', container_name]) |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 462 | cwd = None |
Jan Tattermusch | e268628 | 2015-10-08 16:27:07 -0700 | [diff] [blame] | 463 | |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 464 | test_job = jobset.JobSpec( |
| 465 | cmdline=cmdline, |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 466 | cwd=cwd, |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 467 | environ=environ, |
Adele Zhou | e4c3561 | 2015-10-16 15:34:23 -0700 | [diff] [blame] | 468 | shortname='cloud_to_cloud:%s:%s_server:%s' % (language, server_name, |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 469 | test_case), |
Jan Tattermusch | 29fd005 | 2015-10-22 18:58:57 -0700 | [diff] [blame] | 470 | timeout_seconds=90, |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 471 | flake_retries=5 if args.allow_flakes else 0, |
Jan Tattermusch | e268628 | 2015-10-08 16:27:07 -0700 | [diff] [blame] | 472 | timeout_retries=2 if args.allow_flakes else 0, |
| 473 | kill_handler=_job_kill_handler) |
| 474 | test_job.container_name = container_name |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 475 | return test_job |
| 476 | |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 477 | |
| 478 | def server_jobspec(language, docker_image): |
| 479 | """Create jobspec for running a server""" |
Jan Tattermusch | 0a14f62 | 2015-10-09 14:34:29 -0700 | [diff] [blame] | 480 | container_name = dockerjob.random_name('interop_server_%s' % language.safename) |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 481 | cmdline = bash_login_cmdline( |
| 482 | language.server_cmd(['--port=%s' % _DEFAULT_SERVER_PORT])) |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 483 | environ = language.global_env() |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 484 | docker_cmdline = docker_run_cmdline(cmdline, |
| 485 | image=docker_image, |
| 486 | cwd=language.server_cwd, |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 487 | environ=environ, |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 488 | docker_args=['-p', str(_DEFAULT_SERVER_PORT), |
Jan Tattermusch | e268628 | 2015-10-08 16:27:07 -0700 | [diff] [blame] | 489 | '--name', container_name]) |
Carl Mastrangelo | de44910 | 2015-10-28 11:05:49 -0700 | [diff] [blame] | 490 | |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 491 | server_job = jobset.JobSpec( |
| 492 | cmdline=docker_cmdline, |
Masood Malekghassemi | 18cc842 | 2015-10-09 17:55:45 -0700 | [diff] [blame] | 493 | environ=environ, |
Adele Zhou | e4c3561 | 2015-10-16 15:34:23 -0700 | [diff] [blame] | 494 | shortname='interop_server_%s' % language, |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 495 | timeout_seconds=30*60) |
Jan Tattermusch | e268628 | 2015-10-08 16:27:07 -0700 | [diff] [blame] | 496 | server_job.container_name = container_name |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 497 | return server_job |
| 498 | |
| 499 | |
| 500 | def build_interop_image_jobspec(language, tag=None): |
| 501 | """Creates jobspec for building interop docker image for a language""" |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 502 | if not tag: |
Jan Tattermusch | 0a14f62 | 2015-10-09 14:34:29 -0700 | [diff] [blame] | 503 | tag = 'grpc_interop_%s:%s' % (language.safename, uuid.uuid4()) |
Stanley Cheung | 22b6bed | 2015-10-15 16:54:52 -0700 | [diff] [blame] | 504 | env = {'INTEROP_IMAGE': tag, |
| 505 | 'BASE_NAME': 'grpc_interop_%s' % language.safename} |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 506 | if not args.travis: |
Stanley Cheung | 22b6bed | 2015-10-15 16:54:52 -0700 | [diff] [blame] | 507 | env['TTY_FLAG'] = '-t' |
| 508 | # This env variable is used to get around the github rate limit |
| 509 | # error when running the PHP `composer install` command |
| 510 | # TODO(stanleycheung): find a more elegant way to do this |
Stanley Cheung | f565dfb | 2015-10-15 17:57:09 -0700 | [diff] [blame] | 511 | if language.safename == 'php' and os.path.exists('/var/local/.composer/auth.json'): |
Stanley Cheung | 22b6bed | 2015-10-15 16:54:52 -0700 | [diff] [blame] | 512 | env['BUILD_INTEROP_DOCKER_EXTRA_ARGS'] = \ |
Adele Zhou | e4c3561 | 2015-10-16 15:34:23 -0700 | [diff] [blame] | 513 | '-v /var/local/.composer/auth.json:/root/.composer/auth.json:ro' |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 514 | build_job = jobset.JobSpec( |
| 515 | cmdline=['tools/jenkins/build_interop_image.sh'], |
Stanley Cheung | 22b6bed | 2015-10-15 16:54:52 -0700 | [diff] [blame] | 516 | environ=env, |
Adele Zhou | e4c3561 | 2015-10-16 15:34:23 -0700 | [diff] [blame] | 517 | shortname='build_docker_%s' % (language), |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 518 | timeout_seconds=30*60) |
| 519 | build_job.tag = tag |
| 520 | return build_job |
| 521 | |
| 522 | |
Carl Mastrangelo | e7f8e8e | 2015-12-08 17:22:44 -0800 | [diff] [blame^] | 523 | def aggregate_http2_results(stdout): |
| 524 | match = re.search(r'\{"cases[^\]]*\]\}', stdout) |
| 525 | if not match: |
| 526 | return None |
| 527 | |
| 528 | results = json.loads(match.group(0)) |
| 529 | skipped = 0 |
| 530 | passed = 0 |
| 531 | failed = 0 |
| 532 | failed_cases = [] |
| 533 | for case in results['cases']: |
| 534 | if case.get('skipped', False): |
| 535 | skipped += 1 |
| 536 | else: |
| 537 | if case.get('passed', False): |
| 538 | passed += 1 |
| 539 | else: |
| 540 | failed += 1 |
| 541 | failed_cases.append(case.get('name', "NONAME")) |
| 542 | return { |
| 543 | 'passed': passed, |
| 544 | 'failed': failed, |
| 545 | 'skipped': skipped, |
| 546 | 'failed_cases': ', '.join(failed_cases), |
| 547 | 'percent': 1.0 * passed / (passed + failed) |
| 548 | } |
| 549 | |
Jan Tattermusch | 320bd61 | 2015-09-15 12:44:35 -0700 | [diff] [blame] | 550 | argp = argparse.ArgumentParser(description='Run interop tests.') |
| 551 | argp.add_argument('-l', '--language', |
| 552 | choices=['all'] + sorted(_LANGUAGES), |
| 553 | nargs='+', |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 554 | default=['all'], |
| 555 | help='Clients to run.') |
Jan Tattermusch | 210a0ea | 2015-10-02 15:05:36 -0700 | [diff] [blame] | 556 | argp.add_argument('-j', '--jobs', default=multiprocessing.cpu_count(), type=int) |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 557 | argp.add_argument('--cloud_to_prod', |
| 558 | default=False, |
| 559 | action='store_const', |
| 560 | const=True, |
| 561 | help='Run cloud_to_prod tests.') |
Jan Tattermusch | fb8c77d | 2015-10-06 09:33:37 -0700 | [diff] [blame] | 562 | argp.add_argument('--cloud_to_prod_auth', |
| 563 | default=False, |
| 564 | action='store_const', |
| 565 | const=True, |
| 566 | help='Run cloud_to_prod_auth tests.') |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 567 | argp.add_argument('-s', '--server', |
| 568 | choices=['all'] + sorted(_SERVERS), |
| 569 | action='append', |
| 570 | help='Run cloud_to_cloud servers in a separate docker ' + |
| 571 | 'image. Servers can only be started automatically if ' + |
| 572 | '--use_docker option is enabled.', |
| 573 | default=[]) |
| 574 | argp.add_argument('--override_server', |
| 575 | action='append', |
Adele Zhou | e4c3561 | 2015-10-16 15:34:23 -0700 | [diff] [blame] | 576 | type=lambda kv: kv.split('='), |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 577 | help='Use servername=HOST:PORT to explicitly specify a server. E.g. csharp=localhost:50000', |
| 578 | default=[]) |
| 579 | argp.add_argument('-t', '--travis', |
| 580 | default=False, |
| 581 | action='store_const', |
| 582 | const=True) |
| 583 | argp.add_argument('--use_docker', |
| 584 | default=False, |
| 585 | action='store_const', |
| 586 | const=True, |
| 587 | help='Run all the interop tests under docker. That provides ' + |
| 588 | 'additional isolation and prevents the need to install ' + |
| 589 | 'language specific prerequisites. Only available on Linux.') |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 590 | argp.add_argument('--allow_flakes', |
| 591 | default=False, |
| 592 | action='store_const', |
| 593 | const=True, |
Adele Zhou | e4c3561 | 2015-10-16 15:34:23 -0700 | [diff] [blame] | 594 | help='Allow flaky tests to show as passing (re-runs failed tests up to five times)') |
Carl Mastrangelo | de44910 | 2015-10-28 11:05:49 -0700 | [diff] [blame] | 595 | argp.add_argument('--http2_interop', |
| 596 | default=False, |
| 597 | action='store_const', |
| 598 | const=True, |
| 599 | help='Enable HTTP/2 interop tests') |
Masood Malekghassemi | 0a9cc3c | 2015-11-09 12:24:05 -0800 | [diff] [blame] | 600 | |
Jan Tattermusch | 320bd61 | 2015-09-15 12:44:35 -0700 | [diff] [blame] | 601 | args = argp.parse_args() |
| 602 | |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 603 | servers = set(s for s in itertools.chain.from_iterable(_SERVERS |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 604 | if x == 'all' else [x] |
| 605 | for x in args.server)) |
| 606 | |
| 607 | if args.use_docker: |
| 608 | if not args.travis: |
| 609 | print 'Seen --use_docker flag, will run interop tests under docker.' |
| 610 | print |
| 611 | print 'IMPORTANT: The changes you are testing need to be locally committed' |
| 612 | print 'because only the committed changes in the current branch will be' |
| 613 | print 'copied to the docker environment.' |
| 614 | time.sleep(5) |
| 615 | |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 616 | if not args.use_docker and servers: |
Adele Zhou | e4c3561 | 2015-10-16 15:34:23 -0700 | [diff] [blame] | 617 | print 'Running interop servers is only supported with --use_docker option enabled.' |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 618 | sys.exit(1) |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 619 | |
Jan Tattermusch | f49936a | 2015-09-16 15:44:26 -0700 | [diff] [blame] | 620 | languages = set(_LANGUAGES[l] |
| 621 | for l in itertools.chain.from_iterable( |
| 622 | _LANGUAGES.iterkeys() if x == 'all' else [x] |
| 623 | for x in args.language)) |
Masood Malekghassemi | 0a9cc3c | 2015-11-09 12:24:05 -0800 | [diff] [blame] | 624 | |
Carl Mastrangelo | de44910 | 2015-10-28 11:05:49 -0700 | [diff] [blame] | 625 | http2Interop = Http2Client() if args.http2_interop else None |
Jan Tattermusch | 320bd61 | 2015-09-15 12:44:35 -0700 | [diff] [blame] | 626 | |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 627 | docker_images={} |
| 628 | if args.use_docker: |
| 629 | # languages for which to build docker images |
| 630 | languages_to_build = set(_LANGUAGES[k] for k in set([str(l) for l in languages] + |
| 631 | [s for s in servers])) |
Carl Mastrangelo | de44910 | 2015-10-28 11:05:49 -0700 | [diff] [blame] | 632 | if args.http2_interop: |
| 633 | languages_to_build.add(http2Interop) |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 634 | |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 635 | build_jobs = [] |
| 636 | for l in languages_to_build: |
| 637 | job = build_interop_image_jobspec(l) |
| 638 | docker_images[str(l)] = job.tag |
| 639 | build_jobs.append(job) |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 640 | |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 641 | if build_jobs: |
| 642 | jobset.message('START', 'Building interop docker images.', do_newline=True) |
Adele Zhou | e4c3561 | 2015-10-16 15:34:23 -0700 | [diff] [blame] | 643 | num_failures, _ = jobset.run( |
| 644 | build_jobs, newline_on_success=True, maxjobs=args.jobs) |
| 645 | if num_failures == 0: |
Masood Malekghassemi | 0a9cc3c | 2015-11-09 12:24:05 -0800 | [diff] [blame] | 646 | jobset.message('SUCCESS', 'All docker images built successfully.', |
Adele Zhou | e4c3561 | 2015-10-16 15:34:23 -0700 | [diff] [blame] | 647 | do_newline=True) |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 648 | else: |
Masood Malekghassemi | 0a9cc3c | 2015-11-09 12:24:05 -0800 | [diff] [blame] | 649 | jobset.message('FAILED', 'Failed to build interop docker images.', |
Adele Zhou | e4c3561 | 2015-10-16 15:34:23 -0700 | [diff] [blame] | 650 | do_newline=True) |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 651 | for image in docker_images.itervalues(): |
| 652 | dockerjob.remove_image(image, skip_nonexistent=True) |
Carl Mastrangelo | 7a17140 | 2015-10-26 14:01:03 -0700 | [diff] [blame] | 653 | sys.exit(1) |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 654 | |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 655 | # Start interop servers. |
| 656 | server_jobs={} |
| 657 | server_addresses={} |
| 658 | try: |
| 659 | for s in servers: |
| 660 | lang = str(s) |
| 661 | spec = server_jobspec(_LANGUAGES[lang], docker_images.get(lang)) |
| 662 | job = dockerjob.DockerJob(spec) |
| 663 | server_jobs[lang] = job |
| 664 | server_addresses[lang] = ('localhost', job.mapped_port(_DEFAULT_SERVER_PORT)) |
Jan Tattermusch | 8266c67 | 2015-09-17 09:18:03 -0700 | [diff] [blame] | 665 | |
Jan Tattermusch | 210a0ea | 2015-10-02 15:05:36 -0700 | [diff] [blame] | 666 | |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 667 | jobs = [] |
| 668 | if args.cloud_to_prod: |
| 669 | for language in languages: |
| 670 | for test_case in _TEST_CASES: |
Jan Tattermusch | 289b7b9 | 2015-10-21 18:09:59 -0700 | [diff] [blame] | 671 | if not test_case in language.unimplemented_test_cases(): |
| 672 | test_job = cloud_to_prod_jobspec(language, test_case, |
| 673 | docker_image=docker_images.get(str(language))) |
| 674 | jobs.append(test_job) |
Masood Malekghassemi | 0a9cc3c | 2015-11-09 12:24:05 -0800 | [diff] [blame] | 675 | |
Carl Mastrangelo | e7f8e8e | 2015-12-08 17:22:44 -0800 | [diff] [blame^] | 676 | if args.http2_interop: |
Carl Mastrangelo | de44910 | 2015-10-28 11:05:49 -0700 | [diff] [blame] | 677 | for test_case in _HTTP2_TEST_CASES: |
| 678 | test_job = cloud_to_prod_jobspec(http2Interop, test_case, |
| 679 | docker_image=docker_images.get(str(http2Interop))) |
| 680 | jobs.append(test_job) |
Masood Malekghassemi | 0a9cc3c | 2015-11-09 12:24:05 -0800 | [diff] [blame] | 681 | |
Jan Tattermusch | 320bd61 | 2015-09-15 12:44:35 -0700 | [diff] [blame] | 682 | |
Jan Tattermusch | fb8c77d | 2015-10-06 09:33:37 -0700 | [diff] [blame] | 683 | if args.cloud_to_prod_auth: |
| 684 | for language in languages: |
| 685 | for test_case in _AUTH_TEST_CASES: |
Jan Tattermusch | 289b7b9 | 2015-10-21 18:09:59 -0700 | [diff] [blame] | 686 | if not test_case in language.unimplemented_test_cases(): |
| 687 | test_job = cloud_to_prod_jobspec(language, test_case, |
| 688 | docker_image=docker_images.get(str(language)), |
| 689 | auth=True) |
| 690 | jobs.append(test_job) |
Jan Tattermusch | fb8c77d | 2015-10-06 09:33:37 -0700 | [diff] [blame] | 691 | |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 692 | for server in args.override_server: |
| 693 | server_name = server[0] |
| 694 | (server_host, server_port) = server[1].split(':') |
| 695 | server_addresses[server_name] = (server_host, server_port) |
Jan Tattermusch | 320bd61 | 2015-09-15 12:44:35 -0700 | [diff] [blame] | 696 | |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 697 | for server_name, server_address in server_addresses.iteritems(): |
| 698 | (server_host, server_port) = server_address |
| 699 | for language in languages: |
| 700 | for test_case in _TEST_CASES: |
Jan Tattermusch | 289b7b9 | 2015-10-21 18:09:59 -0700 | [diff] [blame] | 701 | if not test_case in language.unimplemented_test_cases(): |
| 702 | test_job = cloud_to_cloud_jobspec(language, |
| 703 | test_case, |
| 704 | server_name, |
| 705 | server_host, |
| 706 | server_port, |
| 707 | docker_image=docker_images.get(str(language))) |
| 708 | jobs.append(test_job) |
Masood Malekghassemi | 0a9cc3c | 2015-11-09 12:24:05 -0800 | [diff] [blame] | 709 | |
Carl Mastrangelo | de44910 | 2015-10-28 11:05:49 -0700 | [diff] [blame] | 710 | if args.http2_interop: |
| 711 | for test_case in _HTTP2_TEST_CASES: |
Carl Mastrangelo | 3b2e1bd | 2015-11-06 14:31:55 -0800 | [diff] [blame] | 712 | if server_name == "go": |
| 713 | # TODO(carl-mastrangelo): Reenable after https://github.com/grpc/grpc-go/issues/434 |
Jorge Canizales | 340661d | 2015-12-07 13:34:57 -0800 | [diff] [blame] | 714 | continue |
Carl Mastrangelo | de44910 | 2015-10-28 11:05:49 -0700 | [diff] [blame] | 715 | test_job = cloud_to_cloud_jobspec(http2Interop, |
| 716 | test_case, |
| 717 | server_name, |
| 718 | server_host, |
| 719 | server_port, |
| 720 | docker_image=docker_images.get(str(http2Interop))) |
| 721 | jobs.append(test_job) |
Jan Tattermusch | 320bd61 | 2015-09-15 12:44:35 -0700 | [diff] [blame] | 722 | |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 723 | if not jobs: |
Adele Zhou | e4c3561 | 2015-10-16 15:34:23 -0700 | [diff] [blame] | 724 | print 'No jobs to run.' |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 725 | for image in docker_images.itervalues(): |
| 726 | dockerjob.remove_image(image, skip_nonexistent=True) |
| 727 | sys.exit(1) |
| 728 | |
Masood Malekghassemi | 0a9cc3c | 2015-11-09 12:24:05 -0800 | [diff] [blame] | 729 | num_failures, resultset = jobset.run(jobs, newline_on_success=True, |
Adele Zhou | 2271ab5 | 2015-10-28 13:59:14 -0700 | [diff] [blame] | 730 | maxjobs=args.jobs) |
Adele Zhou | e4c3561 | 2015-10-16 15:34:23 -0700 | [diff] [blame] | 731 | if num_failures: |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 732 | jobset.message('FAILED', 'Some tests failed', do_newline=True) |
Adele Zhou | e4c3561 | 2015-10-16 15:34:23 -0700 | [diff] [blame] | 733 | else: |
| 734 | jobset.message('SUCCESS', 'All tests passed', do_newline=True) |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 735 | |
Adele Zhou | 3bc7ba4 | 2015-11-05 10:21:58 -0800 | [diff] [blame] | 736 | report_utils.render_junit_xml_report(resultset, 'report.xml') |
Masood Malekghassemi | 0a9cc3c | 2015-11-09 12:24:05 -0800 | [diff] [blame] | 737 | |
Carl Mastrangelo | e7f8e8e | 2015-12-08 17:22:44 -0800 | [diff] [blame^] | 738 | for name, job in resultset.iteritems(): |
| 739 | if "http2" in name: |
| 740 | job[0].http2results = aggregate_http2_results(job[0].message) |
| 741 | |
Adele Zhou | 3bc7ba4 | 2015-11-05 10:21:58 -0800 | [diff] [blame] | 742 | report_utils.render_interop_html_report( |
Adele Zhou | 2271ab5 | 2015-10-28 13:59:14 -0700 | [diff] [blame] | 743 | set([str(l) for l in languages]), servers, _TEST_CASES, _AUTH_TEST_CASES, |
Carl Mastrangelo | de44910 | 2015-10-28 11:05:49 -0700 | [diff] [blame] | 744 | _HTTP2_TEST_CASES, resultset, num_failures, |
| 745 | args.cloud_to_prod_auth or args.cloud_to_prod, args.http2_interop) |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 746 | |
| 747 | finally: |
| 748 | # Check if servers are still running. |
| 749 | for server, job in server_jobs.iteritems(): |
| 750 | if not job.is_running(): |
| 751 | print 'Server "%s" has exited prematurely.' % server |
| 752 | |
| 753 | dockerjob.finish_jobs([j for j in server_jobs.itervalues()]) |
| 754 | |
| 755 | for image in docker_images.itervalues(): |
| 756 | print 'Removing docker image %s' % image |
| 757 | dockerjob.remove_image(image) |