Index: recipe_engine/run.py |
diff --git a/recipe_engine/run.py b/recipe_engine/run.py |
index 6949ee70212269c415831ca60fb64b10cbd630e9..29f9b71664ab7f856b49229dedbb5d8b2139d73c 100644 |
--- a/recipe_engine/run.py |
+++ b/recipe_engine/run.py |
@@ -72,6 +72,7 @@ import os |
import re |
import subprocess |
import sys |
+import tempfile |
import threading |
import traceback |
@@ -81,6 +82,7 @@ import cStringIO |
from . import loader |
from . import recipe_api |
from . import recipe_test_api |
+from . import types |
from . import util |
@@ -433,7 +435,7 @@ def run_steps(properties, |
'TESTING_SLAVENAME' in os.environ)): |
properties['use_mirror'] = False |
- engine = RecipeEngine(stream, properties, test_data) |
+ engine = RecipeEngine(stream, properties, test_data, universe) |
# Create all API modules and top level RunSteps function. It doesn't launch |
# any recipe code yet; RunSteps needs to be called. |
@@ -750,11 +752,12 @@ class RecipeEngine(object): |
* step - uses engine.create_step(...). |
""" |
- def __init__(self, stream, properties, test_data): |
+ def __init__(self, stream, properties, test_data, universe): |
self._stream = stream |
self._properties = properties |
self._test_data = test_data |
self._step_history = collections.OrderedDict() |
+ self._universe = universe |
self._previous_step_annotation = None |
self._previous_step_result = None |
@@ -861,11 +864,12 @@ class RecipeEngine(object): |
raise exc(step['name'], step_result) |
- |
def run(self, recipe_script, api): |
"""Run a recipe represented by a recipe_script object. |
This function blocks until recipe finishes. |
+ It mainly executes the recipe, and has some exception handling logic, and |
+ adds the step history to the result. |
Args: |
recipe_script: The recipe to run, as represented by a RecipeScript object. |
@@ -940,4 +944,38 @@ class RecipeEngine(object): |
""" |
return step.as_jsonish() |
+ def depend_on(self, recipe, properties, distributor=None): |
+ return self.depend_on_multi( |
+ ((recipe, properties),), distributor=distributor)[0] |
+ |
+ def depend_on_multi(self, dependencies, distributor=None): |
+ if self._test_data.enabled: |
+ results = [] |
+ for recipe, properties in dependencies: |
+ recipe_script = self._universe.load_recipe(recipe) |
+ |
+ f = lambda *args, **kwargs: self._test_data.depend_on_data[types.freeze( |
+ (recipe, properties),)] |
+ results.append(loader._invoke_with_properties( |
+ f, properties, recipe_script.PROPERTIES, properties.keys())) |
+ |
Paweł Hajdan Jr.
2015/11/18 16:56:03
nit: Remove redundant empty line.
martiniss
2015/11/18 22:03:29
Fixed.
|
+ |
+ return results |
+ |
+ # TODO(martiniss) Add DM integration |
+ # For now, we just run the recipe locally. |
+ for recipe, properties in dependencies: |
+ with tempfile.NamedTemporaryFile() as f: |
+ cmd = [sys.executable, self._universe.package_deps.engine_recipes_py, |
+ '--package=%s' % self._universe.config_file, 'run', |
+ '--output-result-json=%s' % f.name, recipe] |
+ cmd.extend(['%s=%s' % (k, v) for k, v in properties.iteritems()]) |
+ |
+ retcode = subprocess.call(cmd) |
+ if retcode != 0: |
+ raise recipe_api.InfraFailure( |
Paweł Hajdan Jr.
2015/11/18 16:56:03
This isn't necessarily an infra failure, right? De
martiniss
2015/11/18 22:03:30
True. I changed this to be a step failure.
This
|
+ 'depend on %s failed with %d' % (recipe, retcode)) |
+ return json.load(f) |
+ |
+ |