def testInvokeFuncComplex(self): """Tests invoke with two different properties.""" def func(a, b): return a prop_defs = { 'a': recipe_api.Property(), 'b': recipe_api.Property(), } props = { 'a': 1, 'b': 2, } self.assertEqual(1, self.invoke(func, props, prop_defs))
def testInvokeClass(self): """Tests invoking a class.""" class test(object): def __init__(self, a, b): self.answer = a prop_defs = { 'a': recipe_api.Property(), 'b': recipe_api.Property(), } props = { 'a': 1, 'b': 2, } self.assertEqual(1, self.invoke(test, props, prop_defs).answer)
def testParamName(self): """ Tests setting a param name correctly carries through to a bound property. """ prop = recipe_api.Property(param_name='b') bound = prop.bind('a', RECIPE_PROPERTY, 'fake_repo::fake_recipe') self.assertEqual('b', bound.param_name)
def testMustBeBound(self): """Tests that calling invoke with a non BoundProperty fails.""" prop_defs = { "a": recipe_api.Property() } with self.assertRaises(ValueError): self.invoke(lambda a: None, {}, {}, prop_defs, ['a'])
def testParamNameDotted(self): """ Tests setting a param name correctly carries through to a bound property. """ prop = recipe_api.Property(param_name='good_name') bound = prop.bind('bad.name-time', RECIPE_PROPERTY, 'fake_package::fake_recipe') self.assertEqual('good_name', bound.param_name)
def testModuleName(self): """ Tests declaring $repo_name/module properties. """ prop = recipe_api.Property(param_name='foo') prop.bind('$fake_repo/fake_module', MODULE_PROPERTY, 'fake_repo::fake_module') with self.assertRaises(ValueError): prop.bind('$fake_repo/wrong_module', MODULE_PROPERTY, 'fake_repo::fake_module') with self.assertRaises(ValueError): prop.bind('$fake_repo/fake_module', RECIPE_PROPERTY, 'fake_repo::fake_module:example')
def _makeProp(self, *args, **kwargs): return recipe_api.Property(*args, **kwargs)
from recipe_engine import recipe_api DEPS = [ 'gclient', 'presubmit', 'recipe_engine/buildbucket', 'recipe_engine/context', 'recipe_engine/cq', 'recipe_engine/json', 'recipe_engine/path', 'recipe_engine/properties', 'recipe_engine/runtime', ] PROPERTIES = { 'patch_project': recipe_api.Property(None), 'patch_repository_url': recipe_api.Property(None), } def RunSteps(api, patch_project, patch_repository_url): api.gclient.set_config('infra') with api.context(cwd=api.path['cache'].join('builder')): bot_update_step = api.presubmit.prepare() return api.presubmit.execute(bot_update_step) def GenTests(api): yield (api.test('success') + api.runtime(is_experimental=False, is_luci=True) + api.buildbucket.try_build(project='infra') + api.step_data(
def make_prop(**kwargs): name = kwargs.pop('name', 'dumb_name') return recipe_api.Property(**kwargs).bind(name, RECIPE_PROPERTY, 'fake_repo::fake_recipe')
# Copyright 2017 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. from recipe_engine import post_process from recipe_engine import recipe_api DEPS = [ 'gclient', 'recipe_engine/properties', ] PROPERTIES = { 'patch_project': recipe_api.Property(), } def RunSteps(api, patch_project): src_cfg = api.gclient.make_config(CACHE_DIR='[ROOT]/git_cache') soln = src_cfg.solutions.add() soln.name = 'src' soln.url = 'https://chromium.googlesource.com/chromium/src.git' src_cfg.patch_projects['v8'] = ('src/v8', 'HEAD') src_cfg.patch_projects['v8/v8'] = ('src/v8', 'HEAD') api.gclient.c = src_cfg patch_root = api.gclient.calculate_patch_root(patch_project) api.gclient.set_patch_project_revision(patch_project)
DEPS = [ 'depot_tools/depot_tools', 'recipe_engine/buildbucket', 'recipe_engine/context', 'recipe_engine/file', 'recipe_engine/path', 'recipe_engine/properties', 'recipe_engine/runtime', 'recipe_engine/step', 'recipe_engine/url', ] PROPERTIES = { 'bucket': recipe_api.Property( default=None, help='override GS bucket to upload cached git repos to'), 'repo_urls': recipe_api.Property( default=None, help='List of repo urls to limit work to just these repos. Each must:\n' ' * not have /a/ as path prefix\n' ' * no trailing slash\n' ' * no .git suffix\n' 'For example, "https://chromium.googlesource.com/infra/infra".') } BUILDER_MAPPING = { 'git-cache-chromium': 'https://chromium.googlesource.com/', } TEST_REPOS = """All-Projects
'recipe_engine/properties', ] from recipe_engine import recipe_api # Toposorted for best results. # TODO(phajdan.jr): get the list of public projects from luci-config. PROJECTS = [ 'depot_tools', 'build', ] PROPERTIES = { 'projects': recipe_api.Property(default=PROJECTS), } def RunSteps(api, projects): api.recipe_autoroller.prepare_checkout() api.recipe_autoroller.roll_projects(projects) def GenTests(api): yield ( api.test('basic') + api.properties(projects=['build']) + api.recipe_autoroller.roll_data('build') )
# Use of this source code is governed under the Apache License, Version 2.0 # that can be found in the LICENSE file. from recipe_engine import recipe_api, config DEPS = [ 'context', 'path', 'properties', 'step', ] RETURN_SCHEMA = config.ReturnSchema(test_me=config.Single(int)) PROPERTIES = { 'bad_return': recipe_api.Property(default=False), 'access_invalid_data': recipe_api.Property(default=False), 'timeout': recipe_api.Property(default=0, kind=int), } def RunSteps(api, bad_return, access_invalid_data, timeout): if bad_return: return RETURN_SCHEMA.new(test_me='this should fail') elif timeout: # Timeout causes the recipe engine to raise an exception if your step takes # longer to run than you allow. Units are seconds. if timeout == 1: api.step('timeout', ['sleep', '20'], timeout=1) elif timeout == 2: try:
# found in the LICENSE file. """Rolls recipes.cfg dependencies for public projects.""" DEPS = [ 'recipe_autoroller', 'recipe_engine/json', 'recipe_engine/properties', 'recipe_engine/runtime', 'recipe_engine/time', ] from recipe_engine import recipe_api from recipe_engine.post_process import MustRun PROPERTIES = { 'projects': recipe_api.Property(), } def RunSteps(api, projects): api.recipe_autoroller.roll_projects(projects) def GenTests(api): # For conciseness. repo_spec = api.recipe_autoroller.repo_spec def test(name): return (api.test(name) + api.runtime(is_luci=True, is_experimental=False) + api.properties(projects=[
def make_prop(**kwargs): name = kwargs.pop('name', "dumb_name") return recipe_api.Property(**kwargs).bind( name, recipe_api.BoundProperty.RECIPE_PROPERTY, 'fake_package::fake_recipe')
# Copyright 2013 The LUCI Authors. All rights reserved. # Use of this source code is governed under the Apache License, Version 2.0 # that can be found in the LICENSE file. from recipe_engine import recipe_api, config DEPS = [ 'context', 'json', 'path', 'properties', 'step', ] PROPERTIES = { 'bad_return': recipe_api.Property(default=False), 'access_invalid_data': recipe_api.Property(default=False), 'access_deep_invalid_data': recipe_api.Property(default=False), 'assign_extra_junk': recipe_api.Property(default=False), 'timeout': recipe_api.Property(default=0, kind=int), } def RunSteps(api, bad_return, access_invalid_data, access_deep_invalid_data, assign_extra_junk, timeout): if timeout: # Timeout causes the recipe engine to raise an exception if your step takes # longer to run than you allow. Units are seconds. if timeout == 1: api.step('timeout', ['sleep', '20'], timeout=1) elif timeout == 2:
# Copyright 2017 The LUCI Authors. All rights reserved. # Use of this source code is governed under the Apache License, Version 2.0 # that can be found in the LICENSE file. from recipe_engine import recipe_api DEPS = [ 'properties', 'step', ] PROPERTIES = { 'timeout': recipe_api.Property(default=0, kind=int), } def RunSteps(api, timeout): # Timeout causes the recipe engine to raise an exception if your step takes # longer to run than you allow. Units are seconds. try: api.step('timeout', ['sleep', '20'], timeout=1) except api.step.StepFailure as ex: assert ex.had_timeout api.step('caught timeout (failure)', []) # If the step was marked as an infra_step, then it raises InfraFailure # on timeout. try: api.step('timeout', ['sleep', '20'], timeout=1, infra_step=True)
cmd = [ '/opt/infra-tools/authutil', 'token', '-service-account-json', '/creds/service_accounts/service-account-%s.json' % service_account ] result = api.step( 'Get auth token', cmd, stdout=api.raw_io.output(), step_test_data=lambda: api.raw_io.test_api.stream_output('ya29.foobar')) return result.stdout.strip() PROPERTIES = { 'projects': recipe_api.Property(default=PROJECTS), # To generate an auth token for running locally, run # infra/go/bin/authutil login 'auth_token': recipe_api.Property(default=None), 'service_account': recipe_api.Property( default=None, kind=str, help="The name of the service account to use when running on a bot. For " "example, if you use \"recipe-roller\", this recipe will try to use " "the /creds/service_accounts/service-account-recipe-roller.json " "service account") } def RunSteps(api, projects, auth_token, service_account): api.luci_config.set_config('basic')