Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1376)

Unified Diff: recipe_engine/step_runner.py

Issue 2985323002: Add support for LUCI_CONTEXT.
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: recipe_engine/step_runner.py
diff --git a/recipe_engine/step_runner.py b/recipe_engine/step_runner.py
index 380eeb4421fbe8c918d41942a5bc18c7d9a29664..fb432df2f28c893e8b24075417b4d20ea38cdda5 100644
--- a/recipe_engine/step_runner.py
+++ b/recipe_engine/step_runner.py
@@ -23,6 +23,8 @@ from . import stream
from . import types
from . import util
+from libs import luci_context as luci_ctx
+
import subprocess42
@@ -211,7 +213,8 @@ class SubprocessStepRunner(StepRunner):
# The subprocess will inherit and close these handles.
retcode = self._run_cmd(
cmd=step_config.cmd, timeout=step_config.timeout, handles=handles,
- env=step_env, cwd=step_config.cwd)
+ env=step_env, luci_context=rendered_step.config.luci_context,
+ cwd=step_config.cwd)
except subprocess42.TimeoutExpired as e:
#FIXME: Make this respect the infra_step argument
step_stream.set_step_status('FAILURE')
@@ -307,7 +310,7 @@ class SubprocessStepRunner(StepRunner):
yield ''
stream.output_iter(step_stream, gen_step_prelude())
- def _run_cmd(self, cmd, timeout, handles, env, cwd):
+ def _run_cmd(self, cmd, timeout, handles, env, luci_context, cwd):
"""Runs cmd (subprocess-style).
Args:
@@ -315,6 +318,7 @@ class SubprocessStepRunner(StepRunner):
handles: A dictionary from ('stdin', 'stdout', 'stderr'), each value
being *either* a stream.StreamEngine.Stream or a python file object
to direct that subprocess's filehandle to.
+ luci_context: full value of LUCI_CONTEXT dict.
iannucci 2017/08/04 18:55:50 Maybe "entire intended value of the LUCI_CONTEXT d
env: the full environment to run the command in -- this is passed
unaltered to subprocess.Popen.
cwd: the working directory of the command.
@@ -333,47 +337,52 @@ class SubprocessStepRunner(StepRunner):
# stdin must be a real handle, if it exists
fhandles['stdin'] = handles.get('stdin')
- with _modify_lookup_path(env.get('PATH')):
- proc = subprocess42.Popen(
- cmd,
- env=env,
- cwd=cwd,
- detached=True,
- universal_newlines=True,
- **fhandles)
-
- # Safe to close file handles now that subprocess has inherited them.
- for handle in fhandles.itervalues():
- if isinstance(handle, file):
- handle.close()
-
- outstreams = {}
- linebufs = {}
-
- for key in ('stdout', 'stderr'):
- handle = handles.get(key)
- if isinstance(handle, stream.StreamEngine.Stream):
- outstreams[key] = handle
- linebufs[key] = _streamingLinebuf()
-
- if linebufs:
- # manually check the timeout, because we poll
- start_time = time.time()
- for pipe, data in proc.yield_any(timeout=1):
- if timeout and time.time() - start_time > timeout:
- # Don't know the name of the step, so raise this and it'll get caught
- raise subprocess42.TimeoutExpired(cmd, timeout)
-
- if pipe is None:
- continue
- buf = linebufs.get(pipe)
- if not buf:
- continue
- buf.ingest(data)
- for line in buf.get_buffered():
- outstreams[pipe].write_line(line)
- else:
- proc.wait(timeout)
+ with luci_ctx.replace(luci_context) as path:
Vadim Sh. 2017/07/29 00:40:55 no changes here except lines 340-343 Rietveld is t
+ if path:
iannucci 2017/08/04 18:55:50 nit: I would rename path to luci_ctx_path or somet
+ env = env.copy()
+ env['LUCI_CONTEXT'] = path
+
+ with _modify_lookup_path(env.get('PATH')):
+ proc = subprocess42.Popen(
+ cmd,
+ env=env,
+ cwd=cwd,
+ detached=True,
+ universal_newlines=True,
+ **fhandles)
+
+ # Safe to close file handles now that subprocess has inherited them.
+ for handle in fhandles.itervalues():
+ if isinstance(handle, file):
+ handle.close()
+
+ outstreams = {}
+ linebufs = {}
+
+ for key in ('stdout', 'stderr'):
+ handle = handles.get(key)
+ if isinstance(handle, stream.StreamEngine.Stream):
+ outstreams[key] = handle
+ linebufs[key] = _streamingLinebuf()
+
+ if linebufs:
+ # manually check the timeout, because we poll
+ start_time = time.time()
+ for pipe, data in proc.yield_any(timeout=1):
+ if timeout and time.time() - start_time > timeout:
+ # Don't know the name of the step, so raise this and it'll get caught
+ raise subprocess42.TimeoutExpired(cmd, timeout)
+
+ if pipe is None:
+ continue
+ buf = linebufs.get(pipe)
+ if not buf:
+ continue
+ buf.ingest(data)
+ for line in buf.get_buffered():
+ outstreams[pipe].write_line(line)
+ else:
+ proc.wait(timeout)
return proc.returncode

Powered by Google App Engine
This is Rietveld 408576698