Commit 6eb23e25 authored by hinoka@google.com's avatar hinoka@google.com

Revert of Bot update cleanup (patchset #5 id:80001 of https://codereview.chromium.org/1686273002/ )

Reason for revert:
Separating change into smaller changes.

Original issue's description:
> Bot update cleanup
> 
> * Remove activation check
> * Remove messages
> * Remove deps2git
> * Remove build_internal pointer by:
> ** Moving chrome svn url into bot_update.py (This isn't secret anyways.)
> ** Move patch.exe into depot_tools (No reason this should've been internal...)
> ** Default everything to active, so no need for checks anyways.
> 
> BUG=
> 
> Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=298809

TBR=martiniss@chromium.org,eseidel@chromium.org,estaab@chromium.org,iannucci@chromium.org,hinoka@chromium.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=

Review URL: https://codereview.chromium.org/1706893003

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@298826 0039d316-1c4b-4281-b951-d872f2087c98
parent b0f36188
......@@ -8,6 +8,12 @@
from recipe_engine import recipe_api
# This is just for testing, to indicate if a master is using a Git scheduler
# or not.
SVN_MASTERS = (
'experimental.svn',
)
def jsonish_to_python(spec, is_top=False):
"""Turn a json spec into a python parsable object.
......@@ -61,10 +67,9 @@ class BotUpdateApi(recipe_api.RecipeApi):
def properties(self):
return self._properties
# Note: force is ignored.
def ensure_checkout(self, gclient_config=None, suffix=None,
patch=True, update_presentation=True,
force=True, patch_root=None, no_shallow=False,
force=False, patch_root=None, no_shallow=False,
with_branch_heads=False, refs=None,
patch_project_roots=None, patch_oauth2=False,
output_manifest=True, clobber=False,
......@@ -75,6 +80,11 @@ class BotUpdateApi(recipe_api.RecipeApi):
cfg = gclient_config or self.m.gclient.c
spec_string = jsonish_to_python(cfg.as_jsonish(), True)
# Used by bot_update to determine if we want to run or not.
master = self.m.properties['mastername']
builder = self.m.properties['buildername']
slave = self.m.properties['slavename']
# Construct our bot_update command. This basically be inclusive of
# everything required for bot_update to know:
root = patch_root
......@@ -126,13 +136,18 @@ class BotUpdateApi(recipe_api.RecipeApi):
rev_map = self.m.gclient.c.got_revision_mapping.as_jsonish()
flags = [
# 1. What do we want to check out (spec/root/rev/rev_map).
# 1. Do we want to run? (master/builder/slave).
['--master', master],
['--builder', builder],
['--slave', slave],
# 2. What do we want to check out (spec/root/rev/rev_map).
['--spec', spec_string],
['--root', root],
['--revision_mapping_file', self.m.json.input(rev_map)],
['--git-cache-dir', self.m.path['git_cache']],
# 2. How to find the patch, if any (issue/patchset/patch_url).
# 3. How to find the patch, if any (issue/patchset/patch_url).
['--issue', issue],
['--patchset', patchset],
['--patch_url', patch_url],
......@@ -142,7 +157,7 @@ class BotUpdateApi(recipe_api.RecipeApi):
['--apply_issue_email_file', email_file],
['--apply_issue_key_file', key_file],
# 3. Hookups to JSON output back into recipes.
# 4. Hookups to JSON output back into recipes.
['--output_json', self.m.json.output()],]
......@@ -182,6 +197,8 @@ class BotUpdateApi(recipe_api.RecipeApi):
if clobber:
cmd.append('--clobber')
if force:
cmd.append('--force')
if no_shallow:
cmd.append('--no_shallow')
if output_manifest:
......@@ -190,9 +207,11 @@ class BotUpdateApi(recipe_api.RecipeApi):
cmd.append('--with_branch_heads')
# Inject Json output for testing.
git_mode = self.m.properties.get('mastername') not in SVN_MASTERS
first_sln = cfg.solutions[0].name
step_test_data = lambda: self.test_api.output_json(
root, first_sln, rev_map, self.m.properties.get('fail_patch', False),
master, builder, slave, root, first_sln, rev_map, git_mode, force,
self.m.properties.get('fail_patch', False),
output_manifest=output_manifest, fixed_revisions=fixed_revisions)
# Add suffixes to the step name, if specified.
......
......@@ -4,6 +4,12 @@
"python",
"-u",
"RECIPE_MODULE[depot_tools::bot_update]/resources/bot_update.py",
"--master",
"chromium.linux",
"--builder",
"Linux Builder",
"--slave",
"totallyaslave-m1",
"--spec",
"cache_dir = None\nsolutions = [{'deps_file': 'DEPS', 'managed': True, 'name': 'src', 'url': 'svn://svn.chromium.org/chrome/trunk/src'}]",
"--root",
......
......@@ -4,6 +4,12 @@
"python",
"-u",
"RECIPE_MODULE[depot_tools::bot_update]/resources/bot_update.py",
"--master",
"chromium.linux",
"--builder",
"Linux Builder",
"--slave",
"totallyaslave-m1",
"--spec",
"cache_dir = None\nsolutions = [{'deps_file': 'DEPS', 'managed': True, 'name': 'src', 'url': 'svn://svn.chromium.org/chrome/trunk/src'}]",
"--root",
......
......@@ -4,6 +4,12 @@
"python",
"-u",
"RECIPE_MODULE[depot_tools::bot_update]/resources/bot_update.py",
"--master",
"chromium.linux",
"--builder",
"Linux Builder",
"--slave",
"totallyaslave-m1",
"--spec",
"cache_dir = None\nsolutions = [{'deps_file': 'DEPS', 'managed': True, 'name': 'src', 'url': 'svn://svn.chromium.org/chrome/trunk/src'}]",
"--root",
......
......@@ -4,6 +4,12 @@
"python",
"-u",
"RECIPE_MODULE[depot_tools::bot_update]/resources/bot_update.py",
"--master",
"experimental",
"--builder",
"Experimental Builder",
"--slave",
"somehost",
"--spec",
"cache_dir = None\nsolutions = [{'deps_file': 'DEPS', 'managed': True, 'name': 'src', 'url': 'svn://svn.chromium.org/chrome/trunk/src'}]",
"--root",
......@@ -24,24 +30,11 @@
},
"name": "bot_update",
"~followup_annotations": [
"@@@STEP_TEXT@Some step text@@@",
"@@@STEP_LOG_LINE@json.output@{@@@",
"@@@STEP_LOG_LINE@json.output@ \"did_run\": true, @@@",
"@@@STEP_LOG_LINE@json.output@ \"fixed_revisions\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"src\": \"HEAD\"@@@",
"@@@STEP_LOG_LINE@json.output@ }, @@@",
"@@@STEP_LOG_LINE@json.output@ \"patch_failure\": false, @@@",
"@@@STEP_LOG_LINE@json.output@ \"patch_root\": \"src\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"properties\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"got_cr_revision\": \"f27fede2220bcd326aee3e86ddfd4ebd0fe58cb9\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"got_cr_revision_cp\": \"refs/heads/master@{#170242}\"@@@",
"@@@STEP_LOG_LINE@json.output@ }, @@@",
"@@@STEP_LOG_LINE@json.output@ \"root\": \"src\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"step_text\": \"Some step text\"@@@",
"@@@STEP_LOG_LINE@json.output@ \"did_run\": false, @@@",
"@@@STEP_LOG_LINE@json.output@ \"patch_failure\": false@@@",
"@@@STEP_LOG_LINE@json.output@}@@@",
"@@@STEP_LOG_END@json.output@@@",
"@@@SET_BUILD_PROPERTY@got_cr_revision@\"f27fede2220bcd326aee3e86ddfd4ebd0fe58cb9\"@@@",
"@@@SET_BUILD_PROPERTY@got_cr_revision_cp@\"refs/heads/master@{#170242}\"@@@"
"@@@STEP_LOG_END@json.output@@@"
]
},
{
......
......@@ -4,6 +4,12 @@
"python",
"-u",
"RECIPE_MODULE[depot_tools::bot_update]/resources/bot_update.py",
"--master",
"experimental",
"--builder",
"Experimental Builder",
"--slave",
"somehost",
"--spec",
"cache_dir = None\nsolutions = [{'deps_file': 'DEPS', 'managed': True, 'name': 'src', 'url': 'svn://svn.chromium.org/chrome/trunk/src'}]",
"--root",
......@@ -15,7 +21,8 @@
"--output_json",
"/path/to/tmp/json",
"--revision",
"src@HEAD"
"src@HEAD",
"--force"
],
"cwd": "[SLAVE_BUILD]",
"env": {
......
......@@ -4,6 +4,12 @@
"python",
"-u",
"RECIPE_MODULE[depot_tools::bot_update]/resources/bot_update.py",
"--master",
"experimental",
"--builder",
"Experimental Builder",
"--slave",
"somehost",
"--spec",
"cache_dir = None\nsolutions = [{'deps_file': 'DEPS', 'managed': True, 'name': 'src', 'url': 'svn://svn.chromium.org/chrome/trunk/src'}]",
"--root",
......@@ -24,24 +30,11 @@
},
"name": "bot_update",
"~followup_annotations": [
"@@@STEP_TEXT@Some step text@@@",
"@@@STEP_LOG_LINE@json.output@{@@@",
"@@@STEP_LOG_LINE@json.output@ \"did_run\": true, @@@",
"@@@STEP_LOG_LINE@json.output@ \"fixed_revisions\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"src\": \"HEAD\"@@@",
"@@@STEP_LOG_LINE@json.output@ }, @@@",
"@@@STEP_LOG_LINE@json.output@ \"patch_failure\": false, @@@",
"@@@STEP_LOG_LINE@json.output@ \"patch_root\": \"src\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"properties\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"got_cr_revision\": \"f27fede2220bcd326aee3e86ddfd4ebd0fe58cb9\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"got_cr_revision_cp\": \"refs/heads/master@{#170242}\"@@@",
"@@@STEP_LOG_LINE@json.output@ }, @@@",
"@@@STEP_LOG_LINE@json.output@ \"root\": \"src\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"step_text\": \"Some step text\"@@@",
"@@@STEP_LOG_LINE@json.output@ \"did_run\": false, @@@",
"@@@STEP_LOG_LINE@json.output@ \"patch_failure\": false@@@",
"@@@STEP_LOG_LINE@json.output@}@@@",
"@@@STEP_LOG_END@json.output@@@",
"@@@SET_BUILD_PROPERTY@got_cr_revision@\"f27fede2220bcd326aee3e86ddfd4ebd0fe58cb9\"@@@",
"@@@SET_BUILD_PROPERTY@got_cr_revision_cp@\"refs/heads/master@{#170242}\"@@@"
"@@@STEP_LOG_END@json.output@@@"
]
},
{
......
[
{
"cmd": [
"python",
"-u",
"RECIPE_MODULE[depot_tools::bot_update]/resources/bot_update.py",
"--master",
"experimental",
"--builder",
"Experimental Builder",
"--slave",
"somehost",
"--spec",
"cache_dir = None\nsolutions = [{'deps_file': 'DEPS', 'managed': True, 'name': 'src', 'url': 'svn://svn.chromium.org/chrome/trunk/src'}]",
"--root",
"src",
"--revision_mapping_file",
"{\"src\": \"got_cr_revision\"}",
"--git-cache-dir",
"[GIT_CACHE]",
"--output_json",
"/path/to/tmp/json",
"--revision",
"src@HEAD"
],
"cwd": "[SLAVE_BUILD]",
"env": {
"PATH": "%(PATH)s:RECIPE_PACKAGE[depot_tools]"
},
"name": "bot_update",
"~followup_annotations": [
"@@@STEP_LOG_LINE@json.output@{@@@",
"@@@STEP_LOG_LINE@json.output@ \"did_run\": false, @@@",
"@@@STEP_LOG_LINE@json.output@ \"patch_failure\": false@@@",
"@@@STEP_LOG_LINE@json.output@}@@@",
"@@@STEP_LOG_END@json.output@@@"
]
},
{
"name": "$result",
"recipe_result": null,
"status_code": 0
}
]
\ No newline at end of file
......@@ -4,6 +4,12 @@
"python",
"-u",
"RECIPE_MODULE[depot_tools::bot_update]/resources/bot_update.py",
"--master",
"experimental",
"--builder",
"Experimental Builder",
"--slave",
"somehost",
"--spec",
"cache_dir = None\nsolutions = [{'deps_file': 'DEPS', 'managed': True, 'name': 'src', 'url': 'svn://svn.chromium.org/chrome/trunk/src'}]",
"--root",
......@@ -23,24 +29,11 @@
},
"name": "bot_update",
"~followup_annotations": [
"@@@STEP_TEXT@Some step text@@@",
"@@@STEP_LOG_LINE@json.output@{@@@",
"@@@STEP_LOG_LINE@json.output@ \"did_run\": true, @@@",
"@@@STEP_LOG_LINE@json.output@ \"fixed_revisions\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"src\": \"revision\"@@@",
"@@@STEP_LOG_LINE@json.output@ }, @@@",
"@@@STEP_LOG_LINE@json.output@ \"patch_failure\": false, @@@",
"@@@STEP_LOG_LINE@json.output@ \"patch_root\": \"src\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"properties\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"got_cr_revision\": \"f27fede2220bcd326aee3e86ddfd4ebd0fe58cb9\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"got_cr_revision_cp\": \"refs/heads/master@{#170242}\"@@@",
"@@@STEP_LOG_LINE@json.output@ }, @@@",
"@@@STEP_LOG_LINE@json.output@ \"root\": \"src\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"step_text\": \"Some step text\"@@@",
"@@@STEP_LOG_LINE@json.output@ \"did_run\": false, @@@",
"@@@STEP_LOG_LINE@json.output@ \"patch_failure\": false@@@",
"@@@STEP_LOG_LINE@json.output@}@@@",
"@@@STEP_LOG_END@json.output@@@",
"@@@SET_BUILD_PROPERTY@got_cr_revision@\"f27fede2220bcd326aee3e86ddfd4ebd0fe58cb9\"@@@",
"@@@SET_BUILD_PROPERTY@got_cr_revision_cp@\"refs/heads/master@{#170242}\"@@@"
"@@@STEP_LOG_END@json.output@@@"
]
},
{
......
[
{
"cmd": [
"python",
"-u",
"RECIPE_MODULE[depot_tools::bot_update]/resources/bot_update.py",
"--master",
"experimental.svn",
"--builder",
"Experimental SVN Builder",
"--slave",
"somehost",
"--spec",
"cache_dir = None\nsolutions = [{'deps_file': 'DEPS', 'managed': True, 'name': 'src', 'url': 'svn://svn.chromium.org/chrome/trunk/src'}]",
"--root",
"src",
"--revision_mapping_file",
"{\"src\": \"got_cr_revision\"}",
"--git-cache-dir",
"[GIT_CACHE]",
"--output_json",
"/path/to/tmp/json",
"--revision",
"src@HEAD",
"--force"
],
"cwd": "[SLAVE_BUILD]",
"env": {
"PATH": "%(PATH)s:RECIPE_PACKAGE[depot_tools]"
},
"name": "bot_update",
"~followup_annotations": [
"@@@STEP_TEXT@Some step text@@@",
"@@@STEP_LOG_LINE@json.output@{@@@",
"@@@STEP_LOG_LINE@json.output@ \"did_run\": true, @@@",
"@@@STEP_LOG_LINE@json.output@ \"fixed_revisions\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"src\": \"HEAD\"@@@",
"@@@STEP_LOG_LINE@json.output@ }, @@@",
"@@@STEP_LOG_LINE@json.output@ \"patch_failure\": false, @@@",
"@@@STEP_LOG_LINE@json.output@ \"patch_root\": \"src\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"properties\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"got_cr_revision\": 170242, @@@",
"@@@STEP_LOG_LINE@json.output@ \"got_cr_revision_cp\": \"refs/heads/master@{#170242}\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"got_cr_revision_git\": \"f27fede2220bcd326aee3e86ddfd4ebd0fe58cb9\"@@@",
"@@@STEP_LOG_LINE@json.output@ }, @@@",
"@@@STEP_LOG_LINE@json.output@ \"root\": \"src\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"step_text\": \"Some step text\"@@@",
"@@@STEP_LOG_LINE@json.output@}@@@",
"@@@STEP_LOG_END@json.output@@@",
"@@@SET_BUILD_PROPERTY@got_cr_revision@170242@@@",
"@@@SET_BUILD_PROPERTY@got_cr_revision_git@\"f27fede2220bcd326aee3e86ddfd4ebd0fe58cb9\"@@@",
"@@@SET_BUILD_PROPERTY@got_cr_revision_cp@\"refs/heads/master@{#170242}\"@@@"
]
},
{
"name": "$result",
"recipe_result": null,
"status_code": 0
}
]
\ No newline at end of file
......@@ -4,6 +4,12 @@
"python",
"-u",
"RECIPE_MODULE[depot_tools::bot_update]/resources/bot_update.py",
"--master",
"tryserver.chromium.linux",
"--builder",
"linux_rel",
"--slave",
"totallyaslave-c4",
"--spec",
"cache_dir = None\nsolutions = [{'deps_file': 'DEPS', 'managed': True, 'name': 'src', 'url': 'svn://svn.chromium.org/chrome/trunk/src'}]",
"--root",
......
......@@ -4,6 +4,12 @@
"python",
"-u",
"RECIPE_MODULE[depot_tools::bot_update]/resources/bot_update.py",
"--master",
"tryserver.chromium.linux",
"--builder",
"linux_rel",
"--slave",
"totallyaslave-c4",
"--spec",
"cache_dir = None\nsolutions = [{'deps_file': 'DEPS', 'managed': True, 'name': 'src', 'url': 'svn://svn.chromium.org/chrome/trunk/src'}]",
"--root",
......
......@@ -4,6 +4,12 @@
"python",
"-u",
"RECIPE_MODULE[depot_tools::bot_update]/resources/bot_update.py",
"--master",
"tryserver.chromium.linux",
"--builder",
"linux_rel",
"--slave",
"totallyaslave-c4",
"--spec",
"cache_dir = None\nsolutions = [{'deps_file': 'DEPS', 'managed': True, 'name': 'src', 'url': 'svn://svn.chromium.org/chrome/trunk/src'}]",
"--root",
......
......@@ -4,6 +4,12 @@
"python",
"-u",
"RECIPE_MODULE[depot_tools::bot_update]/resources/bot_update.py",
"--master",
"tryserver.chromium.linux",
"--builder",
"linux_rel",
"--slave",
"totallyaslave-c4",
"--spec",
"cache_dir = None\nsolutions = [{'deps_file': 'DEPS', 'managed': True, 'name': 'src', 'url': 'svn://svn.chromium.org/chrome/trunk/src'}]",
"--root",
......
......@@ -4,6 +4,12 @@
"python",
"-u",
"RECIPE_MODULE[depot_tools::bot_update]/resources/bot_update.py",
"--master",
"tryserver.chromium.linux",
"--builder",
"linux_rel",
"--slave",
"totallyaslave-c4",
"--spec",
"cache_dir = None\nsolutions = [{'deps_file': 'DEPS', 'managed': True, 'name': 'src', 'url': 'svn://svn.chromium.org/chrome/trunk/src'}]",
"--root",
......
......@@ -4,6 +4,12 @@
"python",
"-u",
"RECIPE_MODULE[depot_tools::bot_update]/resources/bot_update.py",
"--master",
"tryserver.chromium.linux",
"--builder",
"linux_rel",
"--slave",
"totallyaslave-c4",
"--spec",
"cache_dir = None\nsolutions = [{'deps_file': 'DEPS', 'managed': True, 'name': 'src', 'url': 'svn://svn.chromium.org/chrome/trunk/src'}]",
"--root",
......
......@@ -4,6 +4,12 @@
"python",
"-u",
"RECIPE_MODULE[depot_tools::bot_update]/resources/bot_update.py",
"--master",
"tryserver.chromium.linux",
"--builder",
"linux_rel",
"--slave",
"totallyaslave-c4",
"--spec",
"cache_dir = None\nsolutions = [{'deps_file': 'DEPS', 'managed': True, 'name': 'src', 'url': 'svn://svn.chromium.org/chrome/trunk/src'}]",
"--root",
......
......@@ -43,57 +43,110 @@ def RunSteps(api):
def GenTests(api):
yield api.test('basic') + api.properties(
mastername='chromium.linux',
buildername='Linux Builder',
slavename='totallyaslave-m1',
patch=False,
revision='abc'
)
yield api.test('basic_with_branch_heads') + api.properties(
mastername='chromium.linux',
buildername='Linux Builder',
slavename='totallyaslave-m1',
with_branch_heads=True,
suffix='with branch heads'
)
yield api.test('basic_output_manifest') + api.properties(
mastername='chromium.linux',
buildername='Linux Builder',
slavename='totallyaslave-m1',
output_manifest=True,
)
yield api.test('tryjob') + api.properties(
mastername='tryserver.chromium.linux',
buildername='linux_rel',
slavename='totallyaslave-c4',
issue=12345,
patchset=654321,
patch_url='http://src.chromium.org/foo/bar'
)
yield api.test('trychange') + api.properties(
mastername='tryserver.chromium.linux',
buildername='linux_rel',
slavename='totallyaslave-c4',
refs=['+refs/change/1/2/333'],
)
yield api.test('trychange_oauth2') + api.properties(
mastername='tryserver.chromium.linux',
buildername='linux_rel',
slavename='totallyaslave-c4',
oauth2=True,
)
yield api.test('tryjob_fail') + api.properties(
mastername='tryserver.chromium.linux',
buildername='linux_rel',
slavename='totallyaslave-c4',
issue=12345,
patchset=654321,
patch_url='http://src.chromium.org/foo/bar',
) + api.step_data('bot_update', retcode=1)
yield api.test('tryjob_fail_patch') + api.properties(
mastername='tryserver.chromium.linux',
buildername='linux_rel',
slavename='totallyaslave-c4',
issue=12345,
patchset=654321,
patch_url='http://src.chromium.org/foo/bar',
fail_patch='apply',
) + api.step_data('bot_update', retcode=88)
yield api.test('tryjob_fail_patch_download') + api.properties(
mastername='tryserver.chromium.linux',
buildername='linux_rel',
slavename='totallyaslave-c4',
issue=12345,
patchset=654321,
patch_url='http://src.chromium.org/foo/bar',
fail_patch='download'
) + api.step_data('bot_update', retcode=87)
yield api.test('forced') + api.properties(
mastername='experimental',
buildername='Experimental Builder',
slavename='somehost',
force=1
)
yield api.test('no_shallow') + api.properties(
mastername='experimental',
buildername='Experimental Builder',
slavename='somehost',
no_shallow=1
)
yield api.test('off') + api.properties(
mastername='experimental',
buildername='Experimental Builder',
slavename='somehost',
)
yield api.test('svn_mode') + api.properties(
mastername='experimental.svn',
buildername='Experimental SVN Builder',
slavename='somehost',
force=1
)
yield api.test('clobber') + api.properties(
mastername='experimental',
buildername='Experimental Builder',
slavename='somehost',
clobber=1
)
yield api.test('reset_root_solution_revision') + api.properties(
mastername='experimental',
buildername='Experimental Builder',
slavename='somehost',
root_solution_revision='revision',
)
yield api.test('tryjob_v8') + api.properties(
mastername='tryserver.chromium.linux',
buildername='linux_rel',
slavename='totallyaslave-c4',
issue=12345,
patchset=654321,
patch_url='http://src.chromium.org/foo/bar',
......
......@@ -14,61 +14,73 @@ import bot_update
class BotUpdateTestApi(recipe_test_api.RecipeTestApi):
def output_json(self, root, first_sln, revision_mapping, fail_patch=False,
def output_json(self, master, builder, slave, root, first_sln,
revision_mapping, git_mode, force=False, fail_patch=False,
output_manifest=False, fixed_revisions=None):
"""Deterministically synthesize json.output test data for gclient's
--output-json option.
"""
active = bot_update.check_valid_host(master, builder, slave) or force
output = {
'did_run': True,
'did_run': active,
'patch_failure': False
}
properties = {
property_name: self.gen_revision(project_name, True)
for project_name, property_name in revision_mapping.iteritems()
}
properties.update({
'%s_cp' % property_name: ('refs/heads/master@{#%s}' %
self.gen_revision(project_name, False))
for project_name, property_name in revision_mapping.iteritems()
})
# Add in extra json output if active.
if active:
properties = {
property_name: self.gen_revision(project_name, git_mode)
for project_name, property_name in revision_mapping.iteritems()
}
properties.update({
'%s_cp' % property_name: ('refs/heads/master@{#%s}' %
self.gen_revision(project_name, False))
for project_name, property_name in revision_mapping.iteritems()
})
output.update({
'patch_root': root or first_sln,
'root': first_sln,
'properties': properties,
'step_text': 'Some step text'
})
# We also want to simulate outputting "got_revision_git": ...
# when git mode is off to match what bot_update.py does.
if not git_mode:
properties.update({
'%s_git' % property_name: self.gen_revision(project_name, True)
for project_name, property_name in revision_mapping.iteritems()
})
if output_manifest:
output.update({
'manifest': {
project_name: {
'repository': 'https://fake.org/%s.git' % project_name,
'revision': self.gen_revision(project_name, True),
}
for project_name in revision_mapping
}
'patch_root': root or first_sln,
'root': first_sln,
'properties': properties,
'step_text': 'Some step text'
})
if fixed_revisions:
output['fixed_revisions'] = fixed_revisions
if output_manifest:
output.update({
'manifest': {
project_name: {
'repository': 'https://fake.org/%s.git' % project_name,
'revision': self.gen_revision(project_name, git_mode),
}
for project_name in revision_mapping
}
})
if fixed_revisions:
output['fixed_revisions'] = fixed_revisions
if fail_patch:
output['log_lines'] = [('patch error', 'Patch failed to apply'),]
output['patch_failure'] = True
output['patch_apply_return_code'] = 1
if fail_patch == 'download':
output['patch_apply_return_code'] = 3
if fail_patch:
output['log_lines'] = [('patch error', 'Patch failed to apply'),]
output['patch_failure'] = True
output['patch_apply_return_code'] = 1
if fail_patch == 'download':
output['patch_apply_return_code'] = 3
return self.m.json.output(output)
@staticmethod
def gen_revision(project, git_mode):
def gen_revision(project, GIT_MODE):
"""Hash project to bogus deterministic revision values."""
h = hashlib.sha1(project)
if git_mode:
if GIT_MODE:
return h.hexdigest()
else:
return struct.unpack('!I', h.digest()[:4])[0] % 300000
#!/usr/bin/env python
# Copyright (c) 2015 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.
import codecs
import copy
import json
import os
import sys
import unittest
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
RESOURCE_DIR = os.path.join(
ROOT_DIR, 'recipe_modules', 'bot_update', 'resources')
sys.path.insert(0, RESOURCE_DIR)
sys.platform = 'linux2' # For consistency, ya know?
import bot_update
DEFAULT_PARAMS = {
'solutions': [{
'name': 'somename',
'url': 'https://fake.com'
}],
'revisions': [],
'first_sln': 'somename',
'target_os': None,
'target_os_only': None,
'patch_root': None,
'issue': None,
'patchset': None,
'patch_url': None,
'rietveld_server': None,
'gerrit_ref': None,
'gerrit_repo': None,
'revision_mapping': {},
'apply_issue_email_file': None,
'apply_issue_key_file': None,
'buildspec': False,
'gyp_env': None,
'shallow': False,
'runhooks': False,
'refs': [],
'git_cache_dir': 'fake_cache_dir'
}
class MockedPopen(object):
"""A fake instance of a called subprocess.
This is meant to be used in conjunction with MockedCall.
"""
def __init__(self, args=None, kwargs=None):
self.args = args or []
self.kwargs = kwargs or {}
self.return_value = None
self.fails = False
def returns(self, rv):
"""Set the return value when this popen is called.
rv can be a string, or a callable (eg function).
"""
self.return_value = rv
return self
def check(self, args, kwargs):
"""Check to see if the given args/kwargs call match this instance.
This does a partial match, so that a call to "git clone foo" will match
this instance if this instance was recorded as "git clone"
"""
if any(input_arg != expected_arg
for (input_arg, expected_arg) in zip(args, self.args)):
return False
return self.return_value
def __call__(self, args, kwargs):
"""Actually call this popen instance."""
if hasattr(self.return_value, '__call__'):
return self.return_value(*args, **kwargs)
return self.return_value
class MockedCall(object):
"""A fake instance of bot_update.call().
This object is pre-seeded with "answers" in self.expectations. The type
is a MockedPopen object, or any object with a __call__() and check() method.
The check() method is used to check to see if the correct popen object is
chosen (can be a partial match, eg a "git clone" popen module would match
a "git clone foo" call).
By default, if no answers have been pre-seeded, the call() returns successful
with an empty string.
"""
def __init__(self, fake_filesystem):
self.expectations = []
self.records = []
def expect(self, args=None, kwargs=None):
args = args or []
kwargs = kwargs or {}
popen = MockedPopen(args, kwargs)
self.expectations.append(popen)
return popen
def __call__(self, *args, **kwargs):
self.records.append((args, kwargs))
for popen in self.expectations:
if popen.check(args, kwargs):
self.expectations.remove(popen)
return popen(args, kwargs)
return ''
class MockedGclientSync():
"""A class producing a callable instance of gclient sync.
Because for bot_update, gclient sync also emits an output json file, we need
a callable object that can understand where the output json file is going, and
emit a (albite) fake file for bot_update to consume.
"""
def __init__(self, fake_filesystem):
self.output = {}
self.fake_filesystem = fake_filesystem
def __call__(self, *args, **_):
output_json_index = args.index('--output-json') + 1
with self.fake_filesystem.open(args[output_json_index], 'w') as f:
json.dump(self.output, f)
class FakeFile():
def __init__(self):
self.contents = ''
def write(self, buf):
self.contents += buf
def read(self):
return self.contents
def __enter__(self):
return self
def __exit__(self, _, __, ___):
pass
class FakeFilesystem():
def __init__(self):
self.files = {}
def open(self, target, mode='r', encoding=None):
if 'w' in mode:
self.files[target] = FakeFile()
return self.files[target]
return self.files[target]
def fake_git(*args, **kwargs):
return bot_update.call('git', *args, **kwargs)
class EnsureCheckoutUnittests(unittest.TestCase):
def setUp(self):
self.filesystem = FakeFilesystem()
self.call = MockedCall(self.filesystem)
self.gclient = MockedGclientSync(self.filesystem)
self.call.expect(('gclient', 'sync')).returns(self.gclient)
self.old_call = getattr(bot_update, 'call')
self.params = copy.deepcopy(DEFAULT_PARAMS)
setattr(bot_update, 'call', self.call)
setattr(bot_update, 'git', fake_git)
self.old_os_cwd = os.getcwd
setattr(os, 'getcwd', lambda: '/b/build/slave/foo/build')
setattr(bot_update, 'open', self.filesystem.open)
self.old_codecs_open = codecs.open
setattr(codecs, 'open', self.filesystem.open)
def tearDown(self):
setattr(bot_update, 'call', self.old_call)
setattr(os, 'getcwd', self.old_os_cwd)
delattr(bot_update, 'open')
setattr(codecs, 'open', self.old_codecs_open)
def testBasic(self):
bot_update.ensure_checkout(**self.params)
return self.call.records
def testBasicBuildspec(self):
self.params['buildspec'] = bot_update.BUILDSPEC_TYPE(
container='branches',
version='1.1.1.1'
)
bot_update.ensure_checkout(**self.params)
return self.call.records
def testBasicShallow(self):
self.params['shallow'] = True
bot_update.ensure_checkout(**self.params)
return self.call.records
def testBasicSVNPatch(self):
self.params['patch_url'] = 'svn://server.com/patch.diff'
self.params['patch_root'] = 'somename'
bot_update.ensure_checkout(**self.params)
return self.call.records
def testBasicRietveldPatch(self):
self.params['issue'] = '12345'
self.params['patchset'] = '1'
self.params['rietveld_server'] = 'https://rietveld.com'
self.params['patch_root'] = 'somename'
bot_update.ensure_checkout(**self.params)
return self.call.records
class SolutionsUnittests(unittest.TestCase):
def testBasicSVN(self):
sln = [{
'name': 'src',
'url': 'svn://svn-mirror.golo.chromium.org/chrome/trunk/src'
}, {
'name': 'git',
'url': 'https://abc.googlesource.com/foo.git'
}]
git_slns, root, buildspec = bot_update.solutions_to_git(sln)
self.assertEquals(root, '/chrome/trunk/src')
self.assertEquals(git_slns, [{
'deps_file': '.DEPS.git',
'managed': False,
'name': 'src',
'url': 'https://chromium.googlesource.com/chromium/src.git'
}, {
'url': 'https://abc.googlesource.com/foo.git',
'managed': False,
'name': 'git'
}])
self.assertFalse(buildspec)
bot_update.solutions_printer(git_slns)
def testBasicBuildspec(self):
sln = [{
'name': 'buildspec',
'url': ('svn://svn.chromium.org/chrome-internal/'
'trunk/tools/buildspec/releases/1234'),
}]
git_slns, root, buildspec = bot_update.solutions_to_git(sln)
self.assertEquals(
buildspec,
bot_update.BUILDSPEC_TYPE(container='releases', version='1234'))
self.assertEquals(
root, '/chrome-internal/trunk/tools/buildspec/releases/1234')
self.assertEquals(git_slns[0]['deps_file'], 'releases/1234/DEPS')
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment