Browse code

Fix ansible-test interpreter tracking.

Track the interpreter for each copy of the injector by the interpreter
path instead of the interpreter version. This avoids the possibility
of mixing different interpreters with the same version.

(cherry picked from commit fa53b4805bcf3573dee7d94ed6f6918d7183c92e)

Matt Clay authored on 2018/11/15 05:45:16
Showing 2 changed files
... ...
@@ -346,7 +346,7 @@ def command_network_integration(args):
346 346
     instances = []  # type: list [lib.thread.WrappedThread]
347 347
 
348 348
     if args.platform:
349
-        get_coverage_path(args, args.python_version, args.python_executable)  # initialize before starting threads
349
+        get_coverage_path(args, args.python_executable)  # initialize before starting threads
350 350
 
351 351
         configs = dict((config['platform_version'], config) for config in args.metadata.instance_config)
352 352
 
... ...
@@ -514,7 +514,7 @@ def command_windows_integration(args):
514 514
     httptester_id = None
515 515
 
516 516
     if args.windows:
517
-        get_coverage_path(args, args.python_version, args.python_executable)  # initialize before starting threads
517
+        get_coverage_path(args, args.python_executable)  # initialize before starting threads
518 518
 
519 519
         configs = dict((config['platform_version'], config) for config in args.metadata.instance_config)
520 520
 
... ...
@@ -197,7 +197,7 @@ def intercept_command(args, cmd, target_name, capture=False, env=None, data=None
197 197
     cmd = list(cmd)
198 198
     version = python_version or args.python_version
199 199
     interpreter = find_python(version, path)
200
-    inject_path = get_coverage_path(args, version, interpreter)
200
+    inject_path = get_coverage_path(args, interpreter)
201 201
     config_path = os.path.join(inject_path, 'injector.json')
202 202
     coverage_file = os.path.abspath(os.path.join(inject_path, '..', 'output', '%s=%s=%s=%s=coverage' % (
203 203
         args.command, target_name, args.coverage_label or 'local-%s' % version, 'python-%s' % version)))
... ...
@@ -222,19 +222,18 @@ def intercept_command(args, cmd, target_name, capture=False, env=None, data=None
222 222
     return run_command(args, cmd, capture=capture, env=env, data=data, cwd=cwd)
223 223
 
224 224
 
225
-def get_coverage_path(args, version, interpreter):
225
+def get_coverage_path(args, interpreter):
226 226
     """
227 227
     :type args: TestConfig
228
-    :type version: str
229 228
     :type interpreter: str
230 229
     :rtype: str
231 230
     """
232
-    coverage_path = COVERAGE_PATHS.get(version)
231
+    coverage_path = COVERAGE_PATHS.get(interpreter)
233 232
 
234 233
     if coverage_path:
235 234
         return os.path.join(coverage_path, 'coverage')
236 235
 
237
-    prefix = 'ansible-test-coverage-python-%s-' % version
236
+    prefix = 'ansible-test-coverage-'
238 237
     tmp_dir = '/tmp'
239 238
 
240 239
     if args.explain:
... ...
@@ -261,15 +260,15 @@ def get_coverage_path(args, version, interpreter):
261 261
     if not COVERAGE_PATHS:
262 262
         atexit.register(cleanup_coverage_dirs)
263 263
 
264
-    COVERAGE_PATHS[version] = coverage_path
264
+    COVERAGE_PATHS[interpreter] = coverage_path
265 265
 
266 266
     return os.path.join(coverage_path, 'coverage')
267 267
 
268 268
 
269 269
 def cleanup_coverage_dirs():
270 270
     """Clean up all coverage directories."""
271
-    for version, path in COVERAGE_PATHS.items():
272
-        display.info('Cleaning up coverage directory for Python %s: %s' % (version, path), verbosity=2)
271
+    for path in COVERAGE_PATHS.values():
272
+        display.info('Cleaning up coverage directory: %s' % path, verbosity=2)
273 273
         cleanup_coverage_dir(path)
274 274
 
275 275