Commit 8cd3cf29 authored by machenbach's avatar machenbach Committed by Commit bot

[release] Add monitoring state to auto-roller json output.

The option --json-output will make the auto-roller dump a
json file with a monitoring_state key. This can be one of:
started, up_to_date, success.

BUG=chromium:559141
LOG=n
NOTRY=true

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

Cr-Commit-Position: refs/heads/master@{#32201}
parent 2755c5a1
......@@ -24,6 +24,7 @@ class Preparation(Step):
MESSAGE = "Preparation."
def RunStep(self):
self['json_output']['monitoring_state'] = 'preparation'
# Update v8 remote tracking branches.
self.GitFetchOrigin()
self.Git("fetch origin +refs/tags/*:refs/tags/*")
......@@ -33,6 +34,7 @@ class DetectLastRoll(Step):
MESSAGE = "Detect commit ID of the last Chromium roll."
def RunStep(self):
self['json_output']['monitoring_state'] = 'detect_last_roll'
self["last_roll"] = self._options.last_roll
if not self["last_roll"]:
# Interpret the DEPS file to retrieve the v8 revision.
......@@ -51,6 +53,7 @@ class DetectRevisionToRoll(Step):
MESSAGE = "Detect commit ID of the V8 revision to roll."
def RunStep(self):
self['json_output']['monitoring_state'] = 'detect_revision'
self["roll"] = self._options.revision
if self["roll"]:
# If the revision was passed on the cmd line, continue script execution
......@@ -78,6 +81,7 @@ class DetectRevisionToRoll(Step):
else:
print("There is no newer v8 revision than the one in Chromium (%s)."
% self["last_roll"])
self['json_output']['monitoring_state'] = 'up_to_date'
return True
......@@ -85,6 +89,7 @@ class PrepareRollCandidate(Step):
MESSAGE = "Robustness checks of the roll candidate."
def RunStep(self):
self['json_output']['monitoring_state'] = 'prepare_candidate'
self["roll_title"] = self.GitLog(n=1, format="%s",
git_hash=self["roll"])
......@@ -99,6 +104,7 @@ class SwitchChromium(Step):
MESSAGE = "Switch to Chromium checkout."
def RunStep(self):
self['json_output']['monitoring_state'] = 'switch_chromium'
cwd = self._options.chromium
self.InitialEnvironmentChecks(cwd)
# Check for a clean workdir.
......@@ -113,6 +119,7 @@ class UpdateChromiumCheckout(Step):
MESSAGE = "Update the checkout and create a new branch."
def RunStep(self):
self['json_output']['monitoring_state'] = 'update_chromium'
cwd = self._options.chromium
self.GitCheckout("master", cwd=cwd)
self.DeleteBranch("work-branch", cwd=cwd)
......@@ -129,6 +136,7 @@ class UploadCL(Step):
MESSAGE = "Create and upload CL."
def RunStep(self):
self['json_output']['monitoring_state'] = 'upload'
cwd = self._options.chromium
# Patch DEPS file.
if self.Command("roll-dep-svn", "v8 %s" %
......@@ -161,6 +169,7 @@ class CleanUp(Step):
MESSAGE = "Done!"
def RunStep(self):
self['json_output']['monitoring_state'] = 'success'
print("Congratulations, you have successfully rolled %s into "
"Chromium."
% self["roll"])
......
......@@ -738,9 +738,12 @@ class Step(GitRecipesMixin):
class BootstrapStep(Step):
MESSAGE = "Bootstrapping v8 checkout."
MESSAGE = "Bootstrapping checkout and state."
def RunStep(self):
# Reserve state entry for json output.
self['json_output'] = {}
if os.path.realpath(self.default_cwd) == os.path.realpath(V8_BASE):
self.Die("Can't use v8 checkout with calling script as work checkout.")
# Directory containing the working v8 checkout.
......@@ -868,17 +871,15 @@ class ScriptsBase(object):
for (number, step_class) in enumerate([BootstrapStep] + step_classes):
steps.append(MakeStep(step_class, number, self._state, self._config,
options, self._side_effect_handler))
step_summary = []
try:
for step in steps[options.step:]:
terminate = step.Run()
step_summary.append(step._text)
if terminate:
if step.Run():
return 0
finally:
if options.json_output:
with open(options.json_output, "w") as f:
json.dump({"step_summary": step_summary}, f)
json.dump(self._state['json_output'], f)
return 0
......
......@@ -1031,6 +1031,7 @@ deps = {
def testChromiumRollUpToDate(self):
TEST_CONFIG["CHROMIUM"] = self.MakeEmptyTempDirectory()
json_output_file = os.path.join(TEST_CONFIG["CHROMIUM"], "out.json")
TextToFile(self.FAKE_DEPS, os.path.join(TEST_CONFIG["CHROMIUM"], "DEPS"))
self.Expect([
Cmd("git fetch origin", ""),
......@@ -1047,12 +1048,18 @@ deps = {
])
result = auto_roll.AutoRoll(TEST_CONFIG, self).Run(
AUTO_PUSH_ARGS + ["-c", TEST_CONFIG["CHROMIUM"]])
AUTO_PUSH_ARGS + [
"-c", TEST_CONFIG["CHROMIUM"],
"--json-output", json_output_file])
self.assertEquals(0, result)
json_output = json.loads(FileToText(json_output_file))
self.assertEquals("up_to_date", json_output["monitoring_state"])
def testChromiumRoll(self):
# Setup fake directory structures.
TEST_CONFIG["CHROMIUM"] = self.MakeEmptyTempDirectory()
json_output_file = os.path.join(TEST_CONFIG["CHROMIUM"], "out.json")
TextToFile(self.FAKE_DEPS, os.path.join(TEST_CONFIG["CHROMIUM"], "DEPS"))
TextToFile("", os.path.join(TEST_CONFIG["CHROMIUM"], ".git"))
chrome_dir = TEST_CONFIG["CHROMIUM"]
......@@ -1096,12 +1103,15 @@ deps = {
self.Expect(expectations)
args = ["-a", "author@chromium.org", "-c", chrome_dir,
"-r", "reviewer@chromium.org"]
"-r", "reviewer@chromium.org", "--json-output", json_output_file]
auto_roll.AutoRoll(TEST_CONFIG, self).Run(args)
deps = FileToText(os.path.join(chrome_dir, "DEPS"))
self.assertTrue(re.search("\"v8_revision\": \"22624\"", deps))
json_output = json.loads(FileToText(json_output_file))
self.assertEquals("success", json_output["monitoring_state"])
def testCheckLastPushRecently(self):
self.Expect([
Cmd("git fetch origin +refs/tags/*:refs/tags/*", ""),
......
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