summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrathmesh Prabhu <pprabhu@chromium.org>2015-07-17 11:40:40 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-07-18 01:05:24 +0000
commit17f0742270498c9ce88af2e61027caca0307ee78 (patch)
tree98ce84f441c1b33d2ce9973f11df8abaf96e887a
parent6c8a2c9b5298fc506378272930aac6855d199f26 (diff)
downloadchromite-17f0742270498c9ce88af2e61027caca0307ee78.tar.gz
logging: Add knob to suppress PrintBuildbot* logging functions.
This CL adds a knob to modify the behavior of PrintBuildbot* functions. By default, these functions now dump logs in a way that buidbot does not recognize them as special log lines. When the knob is turned on, the buildbot recognizable special log lines are dumped. It also moves these functions to the cros_logging module, because they belong better to the logging module. Finally, by default, the cbuildbot entry point turns on this knob. BUG=chromium:510905 TEST=(1) unittests. (2) Trybot the hell out of this. Change-Id: I739dcbf13a60e20f68a1a692dba0c621ec297524 Reviewed-on: https://chromium-review.googlesource.com/286532 Reviewed-by: Prathmesh Prabhu <pprabhu@chromium.org> Commit-Queue: Prathmesh Prabhu <pprabhu@chromium.org> Tested-by: Prathmesh Prabhu <pprabhu@chromium.org>
-rw-r--r--cbuildbot/builders/generic_builders.py2
-rw-r--r--cbuildbot/chroot_lib.py6
-rw-r--r--cbuildbot/commands.py10
-rw-r--r--cbuildbot/lkgm_manager.py4
-rw-r--r--cbuildbot/lkgm_manager_unittest.py3
-rw-r--r--cbuildbot/results_lib.py4
-rw-r--r--cbuildbot/stages/afdo_stages.py3
-rw-r--r--cbuildbot/stages/build_stages.py8
-rw-r--r--cbuildbot/stages/chrome_stages.py10
-rw-r--r--cbuildbot/stages/completion_stages.py7
-rw-r--r--cbuildbot/stages/generic_stages.py10
-rw-r--r--cbuildbot/stages/release_stages.py5
-rw-r--r--cbuildbot/stages/report_stages.py7
-rw-r--r--cbuildbot/stages/sdk_stages.py2
-rw-r--r--cbuildbot/stages/stage_results_unittest.py7
-rw-r--r--cbuildbot/stages/sync_stages.py23
-rw-r--r--cbuildbot/stages/test_stages.py5
-rw-r--r--cbuildbot/stages/test_stages_unittest.py12
-rw-r--r--cbuildbot/tee.py3
-rw-r--r--cbuildbot/validation_pool.py3
-rw-r--r--lib/binpkg.py4
-rw-r--r--lib/cros_build_lib.py27
-rw-r--r--lib/cros_logging.py68
-rw-r--r--lib/cros_logging_unittest.py68
-rw-r--r--lib/parallel.py2
-rw-r--r--scripts/cbuildbot.py1
-rw-r--r--scripts/cros_generate_breakpad_symbols.py4
-rw-r--r--scripts/cros_sdk.py2
-rw-r--r--scripts/upload_prebuilts.py2
-rw-r--r--scripts/upload_symbols.py4
-rw-r--r--scripts/upload_symbols_unittest.py2
31 files changed, 203 insertions, 115 deletions
diff --git a/cbuildbot/builders/generic_builders.py b/cbuildbot/builders/generic_builders.py
index 6b6946b1c..4ac0542fc 100644
--- a/cbuildbot/builders/generic_builders.py
+++ b/cbuildbot/builders/generic_builders.py
@@ -335,7 +335,7 @@ class Builder(object):
success = results_lib.Results.BuildSucceededSoFar()
if exception_thrown and success:
success = False
- cros_build_lib.PrintBuildbotStepWarnings()
+ logging.PrintBuildbotStepWarnings()
print("""\
Exception thrown, but all stages marked successful. This is an internal error,
because the stage that threw the exception should be marked as failing.""")
diff --git a/cbuildbot/chroot_lib.py b/cbuildbot/chroot_lib.py
index 2c8050f3d..970fc2f07 100644
--- a/cbuildbot/chroot_lib.py
+++ b/cbuildbot/chroot_lib.py
@@ -12,7 +12,7 @@ from __future__ import print_function
import os
from chromite.cbuildbot import constants
-from chromite.lib import cros_build_lib
+from chromite.lib import cros_logging as logging
from chromite.lib import osutils
from chromite.lib import sudo
@@ -69,9 +69,9 @@ class ChrootManager(object):
"""
chroot = os.path.join(self._build_root, constants.DEFAULT_CHROOT_DIR)
if version and self.GetChrootVersion(chroot) == version:
- cros_build_lib.PrintBuildbotStepText('(Using existing chroot)')
+ logging.PrintBuildbotStepText('(Using existing chroot)')
else:
- cros_build_lib.PrintBuildbotStepText('(Using fresh chroot)')
+ logging.PrintBuildbotStepText('(Using fresh chroot)')
osutils.RmDir(chroot, ignore_missing=True, sudo=True)
def ClearChrootVersion(self, chroot=None):
diff --git a/cbuildbot/commands.py b/cbuildbot/commands.py
index 90692a9a2..49a8c386e 100644
--- a/cbuildbot/commands.py
+++ b/cbuildbot/commands.py
@@ -167,7 +167,7 @@ def BuildRootGitCleanup(buildroot):
git.GarbageCollection(cwd)
except cros_build_lib.RunCommandError as e:
result = e.result
- cros_build_lib.PrintBuildbotStepWarnings()
+ logging.PrintBuildbotStepWarnings()
logging.warning('\n%s', result.error)
# If there's no repository corruption, just delete the index.
@@ -1140,7 +1140,7 @@ def GenerateStackTraces(buildroot, board, test_results_dir,
if not asan_log_signaled:
asan_log_signaled = True
logging.error('Asan crash occurred. See asan_logs in Artifacts.')
- cros_build_lib.PrintBuildbotStepFailure()
+ logging.PrintBuildbotStepFailure()
# Append the processed file to archive.
filename = ArchiveFile(processed_file_path, archive_dir)
@@ -1497,7 +1497,7 @@ def UploadSymbols(buildroot, board, official, cnt, failed_list):
if ret.returncode:
# TODO(davidjames): Convert this to a fatal error.
# See http://crbug.com/212437
- cros_build_lib.PrintBuildbotStepWarnings()
+ logging.PrintBuildbotStepWarnings()
def PushImages(board, archive_url, dryrun, profile, sign_types=()):
@@ -1521,7 +1521,7 @@ def PushImages(board, archive_url, dryrun, profile, sign_types=()):
return pushimage.PushImage(archive_url, board, profile=profile,
sign_types=sign_types, dry_run=dryrun)
except pushimage.PushError as e:
- cros_build_lib.PrintBuildbotStepFailure()
+ logging.PrintBuildbotStepFailure()
return e.args[1]
@@ -1927,7 +1927,7 @@ def BuildStrippedPackagesTarball(buildroot, board, package_globs, archive_dir):
'Failed to find stripped files at %s.' %
(pkg, os.path.join(stripped_pkg_dir, pkg)))
if len(files) > 1:
- cros_build_lib.PrintBuildbotStepWarnings()
+ logging.PrintBuildbotStepWarnings()
logging.warning('Expected one stripped package for %s, found %d',
pkg, len(files))
diff --git a/cbuildbot/lkgm_manager.py b/cbuildbot/lkgm_manager.py
index ac82ddbd1..016c4b309 100644
--- a/cbuildbot/lkgm_manager.py
+++ b/cbuildbot/lkgm_manager.py
@@ -457,7 +457,7 @@ def GenerateBlameList(source_repo, lkgm_path, only_print_chumps=False):
if ex.result.returncode != 128:
raise
logging.warning('Detected branch removed from local checkout.')
- cros_build_lib.PrintBuildbotStepWarnings()
+ logging.PrintBuildbotStepWarnings()
return
current_author = None
current_committer = None
@@ -484,4 +484,4 @@ def GenerateBlameList(source_repo, lkgm_path, only_print_chumps=False):
items.insert(0, 'CHUMP')
elif only_print_chumps:
continue
- cros_build_lib.PrintBuildbotLink(' | '.join(items), review)
+ logging.PrintBuildbotLink(' | '.join(items), review)
diff --git a/cbuildbot/lkgm_manager_unittest.py b/cbuildbot/lkgm_manager_unittest.py
index 43f8394ab..d69187795 100644
--- a/cbuildbot/lkgm_manager_unittest.py
+++ b/cbuildbot/lkgm_manager_unittest.py
@@ -17,6 +17,7 @@ from chromite.cbuildbot import lkgm_manager
from chromite.cbuildbot import manifest_version
from chromite.cbuildbot import repository
from chromite.lib import cros_build_lib
+from chromite.lib import cros_logging as logging
from chromite.lib import cros_test_lib
from chromite.lib import git
from chromite.lib import osutils
@@ -296,7 +297,7 @@ class LKGMManagerTest(cros_test_lib.MockTempDirTestCase):
self.manager.incr_type = 'build'
self.PatchObject(cros_build_lib, 'RunCommand', side_effect=Exception())
exists_mock = self.PatchObject(os.path, 'exists', return_value=True)
- link_mock = self.PatchObject(cros_build_lib, 'PrintBuildbotLink')
+ link_mock = self.PatchObject(logging, 'PrintBuildbotLink')
project = {
'name': 'fake/repo',
diff --git a/cbuildbot/results_lib.py b/cbuildbot/results_lib.py
index a56ec8ce4..d0446dc83 100644
--- a/cbuildbot/results_lib.py
+++ b/cbuildbot/results_lib.py
@@ -253,7 +253,7 @@ class _Results(object):
# Output the bot-id/version used in the archive url.
link_name = '%s: %s' % (link_name, '/'.join(url.split('/')[-3:-1]))
out.write('%s %s' % (edge, named_url))
- cros_build_lib.PrintBuildbotLink(link_name, url, handle=out)
+ logging.PrintBuildbotLink(link_name, url, handle=out)
out.write(line)
for x in self.GetTracebacks():
@@ -263,7 +263,7 @@ class _Results(object):
out.write('\n')
if warnings:
- cros_build_lib.PrintBuildbotStepWarnings(out)
+ logging.PrintBuildbotStepWarnings(out)
Results = _Results()
diff --git a/cbuildbot/stages/afdo_stages.py b/cbuildbot/stages/afdo_stages.py
index 6d10372db..a953a9581 100644
--- a/cbuildbot/stages/afdo_stages.py
+++ b/cbuildbot/stages/afdo_stages.py
@@ -9,7 +9,6 @@ from __future__ import print_function
from chromite.cbuildbot import afdo
from chromite.cbuildbot import constants
from chromite.lib import alerts
-from chromite.lib import cros_build_lib
from chromite.lib import cros_logging as logging
from chromite.lib import gs
from chromite.lib import portage_util
@@ -55,7 +54,7 @@ class AFDODataGenerateStage(generic_stages.BoardSpecificBuilderStage,
'AFDO profile.')
# Will let system-exiting exceptions through.
except Exception:
- cros_build_lib.PrintBuildbotStepWarnings()
+ logging.PrintBuildbotStepWarnings()
logging.warning('AFDO profile generation failed with exception ',
exc_info=True)
diff --git a/cbuildbot/stages/build_stages.py b/cbuildbot/stages/build_stages.py
index 9c7cd0225..faacaa888 100644
--- a/cbuildbot/stages/build_stages.py
+++ b/cbuildbot/stages/build_stages.py
@@ -181,8 +181,8 @@ class InitSDKStage(generic_stages.BuilderStage):
self._build_root, chrome_root=self._run.options.chrome_root,
extra_env=self._portage_extra_env)
except failures_lib.BuildScriptFailure:
- cros_build_lib.PrintBuildbotStepText('Replacing broken chroot')
- cros_build_lib.PrintBuildbotStepWarnings()
+ logging.PrintBuildbotStepText('Replacing broken chroot')
+ logging.PrintBuildbotStepWarnings()
else:
# Clear the chroot manifest version as we are in the middle of building.
chroot_manager = chroot_lib.ChrootManager(self._build_root)
@@ -200,9 +200,9 @@ class InitSDKStage(generic_stages.BuilderStage):
post_ver = cros_build_lib.GetChrootVersion(chroot=chroot_path)
if pre_ver is not None and pre_ver != post_ver:
- cros_build_lib.PrintBuildbotStepText('%s->%s' % (pre_ver, post_ver))
+ logging.PrintBuildbotStepText('%s->%s' % (pre_ver, post_ver))
else:
- cros_build_lib.PrintBuildbotStepText(post_ver)
+ logging.PrintBuildbotStepText(post_ver)
commands.SetSharedUserPassword(
self._build_root,
diff --git a/cbuildbot/stages/chrome_stages.py b/cbuildbot/stages/chrome_stages.py
index 19ede780e..43356b343 100644
--- a/cbuildbot/stages/chrome_stages.py
+++ b/cbuildbot/stages/chrome_stages.py
@@ -75,13 +75,13 @@ class SyncChromeStage(generic_stages.BuilderStage,
kwargs = {}
if self._chrome_rev == constants.CHROME_REV_SPEC:
kwargs['revision'] = self.chrome_version
- cros_build_lib.PrintBuildbotStepText('revision %s' % kwargs['revision'])
+ logging.PrintBuildbotStepText('revision %s' % kwargs['revision'])
else:
if not self.chrome_version:
self.chrome_version = self._run.DetermineChromeVersion()
kwargs['tag'] = self.chrome_version
- cros_build_lib.PrintBuildbotStepText('tag %s' % kwargs['tag'])
+ logging.PrintBuildbotStepText('tag %s' % kwargs['tag'])
useflags = self._run.config.useflags
commands.SyncChrome(self._build_root, self._run.options.chrome_root,
@@ -121,7 +121,7 @@ class PatchChromeStage(generic_stages.BuilderStage):
if not colon:
subdir = 'src'
url = self.URL_BASE % {'id': patch}
- cros_build_lib.PrintBuildbotLink(spatch, url)
+ logging.PrintBuildbotLink(spatch, url)
commands.PatchChrome(self._run.options.chrome_root, patch, subdir)
@@ -163,7 +163,7 @@ class ChromeSDKStage(generic_stages.BoardSpecificBuilderStage,
raise artifact_stages.NothingToArchiveException(
'Failed to find package %s' % constants.CHROME_CP)
if len(files) > 1:
- cros_build_lib.PrintBuildbotStepWarnings()
+ logging.PrintBuildbotStepWarnings()
logging.warning('Expected one package for %s, found %d',
constants.CHROME_CP, len(files))
@@ -221,7 +221,7 @@ class ChromeSDKStage(generic_stages.BoardSpecificBuilderStage,
# Chrome no longer builds on Lucid. See crbug.com/276311
print('Ubuntu lucid is no longer supported.')
print('Please upgrade to Ubuntu Precise.')
- cros_build_lib.PrintBuildbotStepWarnings()
+ logging.PrintBuildbotStepWarnings()
return
steps = [self._BuildAndArchiveChromeSysroot, self._ArchiveChromeEbuildEnv,
diff --git a/cbuildbot/stages/completion_stages.py b/cbuildbot/stages/completion_stages.py
index 9af69aba5..2da529954 100644
--- a/cbuildbot/stages/completion_stages.py
+++ b/cbuildbot/stages/completion_stages.py
@@ -18,7 +18,6 @@ from chromite.cbuildbot import tree_status
from chromite.cbuildbot.stages import generic_stages
from chromite.cbuildbot.stages import sync_stages
from chromite.lib import clactions
-from chromite.lib import cros_build_lib
from chromite.lib import cros_logging as logging
from chromite.lib import git
from chromite.lib import portage_util
@@ -240,7 +239,7 @@ class MasterSlaveSyncCompletionStage(ManifestVersionedSyncCompletionStage):
no_stat: Set of builder names of slave builders that had status None.
"""
if failing or inflight or no_stat:
- cros_build_lib.PrintBuildbotStepWarnings()
+ logging.PrintBuildbotStepWarnings()
if failing:
logging.warning('\n'.join([
@@ -327,10 +326,10 @@ class MasterSlaveSyncCompletionStage(ManifestVersionedSyncCompletionStage):
else:
text = '%s: timed out' % builder
- cros_build_lib.PrintBuildbotLink(text, statuses[builder].dashboard_url)
+ logging.PrintBuildbotLink(text, statuses[builder].dashboard_url)
for builder in no_stat:
- cros_build_lib.PrintBuildbotStepText('%s did not start.' % builder)
+ logging.PrintBuildbotStepText('%s did not start.' % builder)
def GetSlaveStatuses(self):
"""Returns cached slave status results.
diff --git a/cbuildbot/stages/generic_stages.py b/cbuildbot/stages/generic_stages.py
index c7b04c5cf..b2654302f 100644
--- a/cbuildbot/stages/generic_stages.py
+++ b/cbuildbot/stages/generic_stages.py
@@ -309,7 +309,7 @@ class BuilderStage(object):
"""Can be overridden. Called before a stage is performed."""
# Tell the buildbot we are starting a new step for the waterfall
- cros_build_lib.PrintBuildbotStepName(self.name)
+ logging.PrintBuildbotStepName(self.name)
self._PrintLoudly('Start Stage %s - %s\n\n%s' % (
self.name, cros_build_lib.UserDateTimeFormat(), self.__doc__))
@@ -353,7 +353,7 @@ class BuilderStage(object):
warnings instead of stage failures.
"""
description = cls._StringifyException(exc_info)
- cros_build_lib.PrintBuildbotStepWarnings()
+ logging.PrintBuildbotStepWarnings()
logging.warning(description)
return (results_lib.Results.FORGIVEN, description, retrying)
@@ -372,7 +372,7 @@ class BuilderStage(object):
# Tell the user about the exception, and record it.
retrying = False
description = cls._StringifyException(exc_info)
- cros_build_lib.PrintBuildbotStepFailure()
+ logging.PrintBuildbotStepFailure()
logging.error(description)
return (exc_info[1], description, retrying)
@@ -763,7 +763,7 @@ class ArchivingStageMixin(object):
url = '%s/%s' % (self.download_url.rstrip('/'), filename)
if not text_to_display:
text_to_display = '%s%s' % (prefix, filename)
- cros_build_lib.PrintBuildbotLink(text_to_display, url)
+ logging.PrintBuildbotLink(text_to_display, url)
def _IsInUploadBlacklist(self, filename):
"""Check if this file is blacklisted to go into a board's extra buckets.
@@ -832,7 +832,7 @@ class ArchivingStageMixin(object):
self.archive_path, upload_urls, filename, self._run.debug,
update_list=True, acl=self.acl)
except failures_lib.GSUploadFailure as e:
- cros_build_lib.PrintBuildbotStepText('Upload failed')
+ logging.PrintBuildbotStepText('Upload failed')
if e.HasFatalFailure(
whitelist=[gs.GSContextException, timeout_util.TimeoutError]):
raise
diff --git a/cbuildbot/stages/release_stages.py b/cbuildbot/stages/release_stages.py
index aa6ecc801..c38272446 100644
--- a/cbuildbot/stages/release_stages.py
+++ b/cbuildbot/stages/release_stages.py
@@ -12,7 +12,6 @@ import os
from chromite.cbuildbot import commands
from chromite.cbuildbot import failures_lib
from chromite.cbuildbot.stages import artifact_stages
-from chromite.lib import cros_build_lib
from chromite.lib import cros_logging as logging
from chromite.lib import gs
from chromite.lib import osutils
@@ -280,7 +279,7 @@ class PaygenStage(artifact_stages.ArchivingStage):
except timeout_util.TimeoutError:
msg = 'Image signing timed out.'
logging.error(msg)
- cros_build_lib.PrintBuildbotStepText(msg)
+ logging.PrintBuildbotStepText(msg)
raise SignerResultsTimeout(msg)
# Log all signer results, then handle any signing failures.
@@ -288,7 +287,7 @@ class PaygenStage(artifact_stages.ArchivingStage):
for url_results in self.signing_results.values():
for url, signer_result in url_results.iteritems():
result_description = os.path.basename(url)
- cros_build_lib.PrintBuildbotStepText(result_description)
+ logging.PrintBuildbotStepText(result_description)
logging.info('Received results for: %s', result_description)
logging.info(json.dumps(signer_result, indent=4))
diff --git a/cbuildbot/stages/report_stages.py b/cbuildbot/stages/report_stages.py
index 1d57d3ac6..bd4843e1f 100644
--- a/cbuildbot/stages/report_stages.py
+++ b/cbuildbot/stages/report_stages.py
@@ -123,8 +123,8 @@ class BuildStartStage(generic_stages.BuilderStage):
@failures_lib.SetFailureType(failures_lib.InfrastructureFailure)
def PerformStage(self):
if self._run.config['doc']:
- cros_build_lib.PrintBuildbotLink('Builder documentation',
- self._run.config['doc'])
+ logging.PrintBuildbotLink('Builder documentation',
+ self._run.config['doc'])
WriteBasicMetadata(self._run)
d = self._run.attrs.metadata.GetDict()
@@ -170,8 +170,7 @@ class BuildStartStage(generic_stages.BuilderStage):
master_build_status['waterfall'],
master_build_status['builder_name'],
master_build_status['build_number'])
- cros_build_lib.PrintBuildbotLink('Link to master build',
- master_url)
+ logging.PrintBuildbotLink('Link to master build', master_url)
def HandleSkip(self):
"""Ensure that re-executions use the same db instance as initial db."""
diff --git a/cbuildbot/stages/sdk_stages.py b/cbuildbot/stages/sdk_stages.py
index 9da891e0b..bfe8c7e86 100644
--- a/cbuildbot/stages/sdk_stages.py
+++ b/cbuildbot/stages/sdk_stages.py
@@ -302,7 +302,7 @@ class SDKTestStage(generic_stages.BuilderStage):
# Build all the boards with the new sdk.
for board in self._boards:
- cros_build_lib.PrintBuildbotStepText(board)
+ logging.PrintBuildbotStepText(board)
cmd = ['./setup_board', '--board', board, '--skip_chroot_upgrade']
cros_build_lib.RunCommand(
cmd, cwd=self._build_root, enter_chroot=True,
diff --git a/cbuildbot/stages/stage_results_unittest.py b/cbuildbot/stages/stage_results_unittest.py
index 8fa5fe565..e971e4ff6 100644
--- a/cbuildbot/stages/stage_results_unittest.py
+++ b/cbuildbot/stages/stage_results_unittest.py
@@ -20,6 +20,7 @@ from chromite.cbuildbot.builders import simple_builders
from chromite.cbuildbot.stages import generic_stages
from chromite.cbuildbot.stages import sync_stages
from chromite.lib import cros_build_lib
+from chromite.lib import cros_logging as logging
from chromite.lib import cros_test_lib
from chromite.lib import parallel
@@ -119,6 +120,9 @@ class BuildStagesResultsTest(cros_test_lib.TestCase):
site_config = config_lib_unittest.MockSiteConfig()
build_config = site_config[self._bot_id]
self.build_root = '/fake_root'
+ # This test compares log output from the stages, so turn on buildbot
+ # logging.
+ logging.EnableBuildbotMarkers()
# Create a class to hold
class Options(object):
@@ -148,7 +152,8 @@ class BuildStagesResultsTest(cros_test_lib.TestCase):
def tearDown(self):
# Mimic exiting with statement for self._manager.
- self._manager.__exit__(None, None, None)
+ if hasattr(self, '_manager') and self._manager is not None:
+ self._manager.__exit__(None, None, None)
def _runStages(self):
"""Run a couple of stages so we can capture the results"""
diff --git a/cbuildbot/stages/sync_stages.py b/cbuildbot/stages/sync_stages.py
index 4c0489135..3d93be851 100644
--- a/cbuildbot/stages/sync_stages.py
+++ b/cbuildbot/stages/sync_stages.py
@@ -136,9 +136,9 @@ class PatchChangesStage(generic_stages.BuilderStage):
def ApplyChange(self, change):
if isinstance(change, cros_patch.GerritPatch):
- cros_build_lib.PrintBuildbotLink(str(change), change.url)
+ logging.PrintBuildbotLink(str(change), change.url)
elif isinstance(change, cros_patch.UploadedLocalPatch):
- cros_build_lib.PrintBuildbotStepText(str(change))
+ logging.PrintBuildbotStepText(str(change))
return validation_pool.PatchSeries.ApplyChange(self, change)
@@ -244,7 +244,7 @@ class BootstrapStage(PatchChangesStage):
# WARNING: For manifest patches, the Pre-CQ attempts to apply external
# patches to the internal manifest, and this means we may flag a conflict
# here even if the patch applies cleanly. TODO(davidjames): Fix this.
- cros_build_lib.PrintBuildbotStepWarnings()
+ logging.PrintBuildbotStepWarnings()
logging.error('Failed applying patches: %s\n'.join(map(str, failures)))
else:
PatchChangesStage.HandleApplyFailures(self, failures)
@@ -419,7 +419,7 @@ class SyncStage(generic_stages.BuilderStage):
# Print the blamelist.
if fresh_sync:
- cros_build_lib.PrintBuildbotStepText('(From scratch)')
+ logging.PrintBuildbotStepText('(From scratch)')
elif self._run.options.buildbot:
lkgm_manager.GenerateBlameList(self.repo, old_filename)
@@ -427,7 +427,7 @@ class SyncStage(generic_stages.BuilderStage):
if self._run.config.build_before_patching:
pre_build_passed = self.RunPrePatchBuild()
if not pre_build_passed:
- cros_build_lib.PrintBuildbotStepText('Pre-patch build failed.')
+ logging.PrintBuildbotStepText('Pre-patch build failed.')
class LKGMSyncStage(SyncStage):
@@ -481,7 +481,7 @@ class ManifestVersionedSyncStage(SyncStage):
def ForceVersion(self, version):
"""Creates a manifest manager from given version and returns manifest."""
- cros_build_lib.PrintBuildbotStepText(version)
+ logging.PrintBuildbotStepText(version)
return self.manifest_manager.BootstrapFromVersion(version)
def VersionIncrementType(self):
@@ -557,13 +557,13 @@ class ManifestVersionedSyncStage(SyncStage):
# Print the Blamelist here.
url_prefix = 'http://chromeos-images.corp.google.com/diff/report?'
url = url_prefix + 'from=%s&to=%s' % (previous_version, target_version)
- cros_build_lib.PrintBuildbotLink('Blamelist', url)
+ logging.PrintBuildbotLink('Blamelist', url)
# The testManifestVersionedSyncOnePartBranch interacts badly with this
# function. It doesn't fully initialize self.manifest_manager which
# causes target_version to be None. Since there isn't a clean fix in
# either direction, just throw this through str(). In the normal case,
# it's already a string anyways.
- cros_build_lib.PrintBuildbotStepText(str(target_version))
+ logging.PrintBuildbotStepText(str(target_version))
return to_return
@@ -962,10 +962,9 @@ class CommitQueueSyncStage(MasterSlaveLKGMSyncStage):
if self._run.config.build_before_patching:
assert not self._run.config.master
pre_build_passed = self.RunPrePatchBuild()
- cros_build_lib.PrintBuildbotStepName(
- 'CommitQueueSync : Apply Patches')
+ logging.PrintBuildbotStepName('CommitQueueSync : Apply Patches')
if not pre_build_passed:
- cros_build_lib.PrintBuildbotStepText('Pre-patch build failed.')
+ logging.PrintBuildbotStepText('Pre-patch build failed.')
# Make sure the chroot version is valid.
lkgm_version = self._GetLGKMVersionFromManifest(next_manifest)
@@ -1102,7 +1101,7 @@ class PreCQLauncherStage(SyncStage):
os.path.basename(patch.project),
str(patch),
)
- cros_build_lib.PrintBuildbotLink(' | '.join(items), patch.url)
+ logging.PrintBuildbotLink(' | '.join(items), patch.url)
def _ConfiguredVerificationsForChange(self, change):
"""Determine which configs to test |change| with.
diff --git a/cbuildbot/stages/test_stages.py b/cbuildbot/stages/test_stages.py
index ae0377e0b..bcf7a3573 100644
--- a/cbuildbot/stages/test_stages.py
+++ b/cbuildbot/stages/test_stages.py
@@ -18,7 +18,6 @@ from chromite.cbuildbot import lab_status
from chromite.cbuildbot import validation_pool
from chromite.cbuildbot.stages import generic_stages
from chromite.lib import cgroups
-from chromite.lib import cros_build_lib
from chromite.lib import cros_logging as logging
from chromite.lib import gs
from chromite.lib import image_test_lib
@@ -279,7 +278,7 @@ class HWTestStage(generic_stages.BoardSpecificBuilderStage,
def PerformStage(self):
# Wait for UploadHWTestArtifacts to generate the payloads.
if not self.GetParallel('payloads_generated', pretty_name='payloads'):
- cros_build_lib.PrintBuildbotStepWarnings('missing payloads')
+ logging.PrintBuildbotStepWarnings('missing payloads')
logging.warning('Cannot run HWTest because UploadTestArtifacts failed. '
'See UploadTestArtifacts for details.')
return
@@ -325,7 +324,7 @@ class AUTestStage(HWTestStage):
# Wait for UploadHWTestArtifacts to generate the payloads.
if not self.GetParallel('delta_payloads_generated',
pretty_name='delta payloads'):
- cros_build_lib.PrintBuildbotStepWarnings('missing delta payloads')
+ logging.PrintBuildbotStepWarnings('missing delta payloads')
logging.warning('Cannot run HWTest because UploadTestArtifacts failed. '
'See UploadTestArtifacts for details.')
return
diff --git a/cbuildbot/stages/test_stages_unittest.py b/cbuildbot/stages/test_stages_unittest.py
index ec5c5583e..bd68fe753 100644
--- a/cbuildbot/stages/test_stages_unittest.py
+++ b/cbuildbot/stages/test_stages_unittest.py
@@ -20,8 +20,8 @@ from chromite.cbuildbot.stages import generic_stages
from chromite.cbuildbot.stages import generic_stages_unittest
from chromite.cbuildbot.stages import test_stages
from chromite.lib import cgroups
-from chromite.lib import cros_build_lib
from chromite.lib import cros_build_lib_unittest
+from chromite.lib import cros_logging as logging
from chromite.lib import gs
from chromite.lib import osutils
from chromite.lib import path_util
@@ -77,12 +77,14 @@ class VMTestStageTest(generic_stages_unittest.AbstractStageTestCase,
gce_path = constants.TEST_IMAGE_GCE_TAR
board_runattrs = self._run.GetBoardRunAttrs(self._current_board)
+ # pylint: disable=unused-argument
def _MockRunTestSuite(buildroot, board, image_path, results_dir, test_type,
*args, **kwargs):
self.assertEndsWith(image_path, gce_path)
self.assertEqual(test_type, constants.GCE_VM_TEST_TYPE)
+ # pylint: enable=unused-argument
- def _MockWaitForGsPaths(_, paths, *args, **kwargs):
+ def _MockWaitForGsPaths(_, paths, *_args, **_kwargs):
self.assertEndsWith(paths[0], gce_path)
self.PatchObject(generic_stages.BoardSpecificBuilderStage, 'GetParallel',
@@ -156,9 +158,9 @@ class HWTestStageTest(generic_stages_unittest.AbstractStageTestCase,
self.lab_status_mock = self.PatchObject(lab_status, 'CheckLabStatus')
self.run_suite_mock = self.PatchObject(commands, 'RunHWTestSuite')
self.warning_mock = self.PatchObject(
- cros_build_lib, 'PrintBuildbotStepWarnings')
+ logging, 'PrintBuildbotStepWarnings')
self.failure_mock = self.PatchObject(
- cros_build_lib, 'PrintBuildbotStepFailure')
+ logging, 'PrintBuildbotStepFailure')
self.suite_config = None
self.suite = None
@@ -420,7 +422,7 @@ class AUTestStageTest(generic_stages_unittest.AbstractStageTestCase,
board_runattrs = self._run.GetBoardRunAttrs(self._current_board)
board_runattrs.SetParallel('delta_payloads_generated', False)
self.warning_mock = self.PatchObject(
- cros_build_lib, 'PrintBuildbotStepWarnings')
+ logging, 'PrintBuildbotStepWarnings')
self.run_suite_mock = self.PatchObject(commands, 'RunHWTestSuite')
self.RunStage()
diff --git a/cbuildbot/tee.py b/cbuildbot/tee.py
index 19f726e82..878f2093a 100644
--- a/cbuildbot/tee.py
+++ b/cbuildbot/tee.py
@@ -17,6 +17,7 @@ import sys
import traceback
from chromite.lib import cros_build_lib
+from chromite.lib import cros_logging as logging
# Max amount of data we're hold in the buffer at a given time.
@@ -146,7 +147,7 @@ class _TeeProcess(multiprocessing.Process):
failed = False
except Exception as e:
tb = traceback.format_exc()
- cros_build_lib.PrintBuildbotStepFailure(self._error_handle)
+ logging.PrintBuildbotStepFailure(self._error_handle)
self._error_handle.write(
'Unhandled exception occured in tee:\n%s\n' % (tb,))
# Try to signal the parent telling them of our
diff --git a/cbuildbot/validation_pool.py b/cbuildbot/validation_pool.py
index 8f6965a55..aa9958777 100644
--- a/cbuildbot/validation_pool.py
+++ b/cbuildbot/validation_pool.py
@@ -26,7 +26,6 @@ from chromite.cbuildbot import lkgm_manager
from chromite.cbuildbot import tree_status
from chromite.cbuildbot import triage_lib
from chromite.lib import clactions
-from chromite.lib import cros_build_lib
from chromite.lib import cros_logging as logging
from chromite.lib import gerrit
from chromite.lib import git
@@ -1562,7 +1561,7 @@ class ValidationPool(object):
if change.pass_count > 0:
s += ' | passed:%d' % change.pass_count
- cros_build_lib.PrintBuildbotLink(s, change.url)
+ logging.PrintBuildbotLink(s, change.url)
def ApplyPoolIntoRepo(self, manifest=None):
"""Applies changes from pool into the directory specified by the buildroot.
diff --git a/lib/binpkg.py b/lib/binpkg.py
index 067f30a25..e8a46042b 100644
--- a/lib/binpkg.py
+++ b/lib/binpkg.py
@@ -324,7 +324,7 @@ def GrabRemotePackageIndex(binhost_url):
f = _RetryUrlOpen(url)
except urllib2.HTTPError as e:
if e.code in HTTP_FORBIDDEN_CODES:
- cros_build_lib.PrintBuildbotStepWarnings()
+ logging.PrintBuildbotStepWarnings()
logging.error('Cannot GET %s: %s' % (url, str(e)))
return None
# Not found errors are normal if old prebuilts were cleaned out.
@@ -336,7 +336,7 @@ def GrabRemotePackageIndex(binhost_url):
gs_context = gs.GSContext()
output = gs_context.Cat(url)
except (cros_build_lib.RunCommandError, gs.GSNoSuchKey) as e:
- cros_build_lib.PrintBuildbotStepWarnings()
+ logging.PrintBuildbotStepWarnings()
logging.error('Cannot GET %s: %s' % (url, str(e)))
return None
f = cStringIO.StringIO(output)
diff --git a/lib/cros_build_lib.py b/lib/cros_build_lib.py
index 493415dd4..01d965240 100644
--- a/lib/cros_build_lib.py
+++ b/lib/cros_build_lib.py
@@ -669,33 +669,6 @@ def GetSysrootToolPath(sysroot, tool_name):
return os.path.join(sysroot, 'build', 'bin', tool_name)
-def PrintBuildbotLink(text, url, handle=None):
- """Prints out a link to buildbot."""
- text = ' '.join(text.split())
- (handle or sys.stderr).write('\n@@@STEP_LINK@%s@%s@@@\n' % (text, url))
-
-
-def PrintBuildbotStepText(text, handle=None):
- """Prints out stage text to buildbot."""
- text = ' '.join(text.split())
- (handle or sys.stderr).write('\n@@@STEP_TEXT@%s@@@\n' % (text,))
-
-
-def PrintBuildbotStepWarnings(handle=None):
- """Marks a stage as having warnings."""
- (handle or sys.stderr).write('\n@@@STEP_WARNINGS@@@\n')
-
-
-def PrintBuildbotStepFailure(handle=None):
- """Marks a stage as having failures."""
- (handle or sys.stderr).write('\n@@@STEP_FAILURE@@@\n')
-
-
-def PrintBuildbotStepName(name, handle=None):
- """Marks a step name for buildbot to display."""
- (handle or sys.stderr).write('\n@@@BUILD_STEP %s@@@\n' % name)
-
-
def ListFiles(base_dir):
"""Recursively list files in a directory.
diff --git a/lib/cros_logging.py b/lib/cros_logging.py
index de204664b..9c66d85be 100644
--- a/lib/cros_logging.py
+++ b/lib/cros_logging.py
@@ -11,6 +11,7 @@ logging level can only be used from here.
from __future__ import print_function
+import sys
# pylint: disable=unused-wildcard-import, wildcard-import
from logging import *
# pylint: enable=unused-wildcard-import, wildcard-import
@@ -31,3 +32,70 @@ addLevelName(NOTICE, 'NOTICE')
def notice(message, *args, **kwargs):
"""Log 'msg % args' with severity 'NOTICE'."""
log(NOTICE, message, *args, **kwargs)
+
+
+# Only buildbot aware entry-points need to spew buildbot specific logs. Require
+# user action for the special log lines.
+_buildbot_markers_enabled = False
+def EnableBuildbotMarkers():
+ # pylint: disable=global-statement
+ global _buildbot_markers_enabled
+ _buildbot_markers_enabled = True
+
+
+def _PrintForBuildbot(handle, buildbot_tag, *args):
+ """Log a line for buildbot.
+
+ This function dumps a line to log recognizable by buildbot if
+ EnableBuildbotMarkers has been called. Otherwise, it dumps the same line in a
+ human friendly way that buildbot ignores.
+
+ Args:
+ handle: The pipe to dump the log to. If None, log to sys.stderr.
+ buildbot_tag: A tag specifying the type of buildbot log.
+ *args: The rest of the str arguments to be dumped to the log.
+ """
+ if _buildbot_markers_enabled:
+ args_separator = '@'
+ args_prefix = '@'
+ end_marker = '@@@'
+ else:
+ args_separator = '; '
+ args_prefix = ': '
+ end_marker = ''
+
+ # Cast each argument, because we end up getting all sorts of objects from
+ # callers.
+ suffix = args_separator.join([str(x) for x in args])
+ if suffix:
+ suffix = args_prefix + suffix
+ line = '\n' + end_marker + buildbot_tag + suffix + end_marker + '\n'
+
+ if handle is None:
+ handle = sys.stderr
+ handle.write(line)
+
+
+def PrintBuildbotLink(text, url, handle=None):
+ """Prints out a link to buildbot."""
+ _PrintForBuildbot(handle, 'STEP_LINK', text, url)
+
+
+def PrintBuildbotStepText(text, handle=None):
+ """Prints out stage text to buildbot."""
+ _PrintForBuildbot(handle, 'STEP_TEXT', text)
+
+
+def PrintBuildbotStepWarnings(handle=None):
+ """Marks a stage as having warnings."""
+ _PrintForBuildbot(handle, 'STEP_WARNINGS')
+
+
+def PrintBuildbotStepFailure(handle=None):
+ """Marks a stage as having failures."""
+ _PrintForBuildbot(handle, 'STEP_FAILURE')
+
+
+def PrintBuildbotStepName(name, handle=None):
+ """Marks a step name for buildbot to display."""
+ _PrintForBuildbot(handle, 'BUILD_STEP', name)
diff --git a/lib/cros_logging_unittest.py b/lib/cros_logging_unittest.py
index 0a9f1250c..4a6ad9564 100644
--- a/lib/cros_logging_unittest.py
+++ b/lib/cros_logging_unittest.py
@@ -15,20 +15,64 @@ from chromite.lib import cros_test_lib
class CrosloggingTest(cros_test_lib.OutputTestCase):
"""Test logging works as expected."""
- def testNotice(self):
- """Test logging.notice works and is between INFO and WARNING."""
- logger = logging.getLogger()
+ def setUp(self):
+ self.logger = logging.getLogger()
sh = logging.StreamHandler(sys.stdout)
- logger.addHandler(sh)
+ self.logger.addHandler(sh)
- msg = 'notice message'
+ def AssertLogContainsMsg(self, msg, functor, *args, **kwargs):
+ """Asserts that calling functor logs a line that contains msg.
- logger.setLevel(logging.INFO)
+ Args:
+ msg: The message to look for.
+ functor: A function taking no arguments to test.
+ *args, **kwargs: passthrough arguments to AssertLogContainsMsg.
+ """
with self.OutputCapturer():
- logging.notice(msg)
- self.AssertOutputContainsLine(msg)
+ functor()
+ self.AssertOutputContainsLine(msg, *args, **kwargs)
- logger.setLevel(logging.WARNING)
- with self.OutputCapturer():
- logging.notice(msg)
- self.AssertOutputContainsLine(msg, invert=True)
+ def testNotice(self):
+ """Test logging.notice works and is between INFO and WARNING."""
+ msg = 'notice message'
+ self.logger.setLevel(logging.INFO)
+ self.AssertLogContainsMsg(msg, lambda: logging.notice(msg))
+ self.logger.setLevel(logging.WARNING)
+ self.AssertLogContainsMsg(msg, lambda: logging.notice(msg), invert=True)
+
+ def testPrintBuildbotFunctionsNoMarker(self):
+ """PrintBuildbot* without markers should not be recognized by buildbot."""
+ self.AssertLogContainsMsg('@@@STEP_LINK@',
+ lambda: logging.PrintBuildbotLink('name', 'url'),
+ check_stderr=True, invert=True)
+ self.AssertLogContainsMsg('@@@@STEP_TEXT@',
+ lambda: logging.PrintBuildbotStepText('text'),
+ check_stderr=True, invert=True)
+ self.AssertLogContainsMsg('@@@STEP_WARNINGS@@@',
+ logging.PrintBuildbotStepWarnings,
+ check_stderr=True, invert=True)
+ self.AssertLogContainsMsg('@@@STEP_FAILURE@@@',
+ logging.PrintBuildbotStepFailure,
+ check_stderr=True, invert=True)
+ self.AssertLogContainsMsg('@@@BUILD_STEP',
+ lambda: logging.PrintBuildbotStepName('name'),
+ check_stderr=True, invert=True)
+
+ def testPrintBuildbotFunctionsWithMarker(self):
+ """PrintBuildbot* with markers should be recognized by buildbot."""
+ logging.EnableBuildbotMarkers()
+ self.AssertLogContainsMsg('@@@STEP_LINK@name@url@@@',
+ lambda: logging.PrintBuildbotLink('name', 'url'),
+ check_stderr=True)
+ self.AssertLogContainsMsg('@@@STEP_TEXT@text@@@',
+ lambda: logging.PrintBuildbotStepText('text'),
+ check_stderr=True)
+ self.AssertLogContainsMsg('@@@STEP_WARNINGS@@@',
+ logging.PrintBuildbotStepWarnings,
+ check_stderr=True)
+ self.AssertLogContainsMsg('@@@STEP_FAILURE@@@',
+ logging.PrintBuildbotStepFailure,
+ check_stderr=True)
+ self.AssertLogContainsMsg('@@@BUILD_STEP@name@@@',
+ lambda: logging.PrintBuildbotStepName('name'),
+ check_stderr=True)
diff --git a/lib/parallel.py b/lib/parallel.py
index 4db9061ad..def0be444 100644
--- a/lib/parallel.py
+++ b/lib/parallel.py
@@ -356,7 +356,7 @@ class _BackgroundTask(multiprocessing.Process):
# Print error messages if anything exceptional occurred.
if len(all_errors) > len(task_errors):
- cros_build_lib.PrintBuildbotStepFailure()
+ logging.PrintBuildbotStepFailure()
msg = '\n'.join(x.str for x in all_errors if x)
logging.warning(msg)
traceback.print_stack()
diff --git a/scripts/cbuildbot.py b/scripts/cbuildbot.py
index f9d013889..b604b9377 100644
--- a/scripts/cbuildbot.py
+++ b/scripts/cbuildbot.py
@@ -1078,6 +1078,7 @@ def main(argv):
cros_build_lib.AssertOutsideChroot()
+ logging.EnableBuildbotMarkers()
if options.remote:
logging.getLogger().setLevel(logging.WARNING)
diff --git a/scripts/cros_generate_breakpad_symbols.py b/scripts/cros_generate_breakpad_symbols.py
index 4a581a627..2c7606b30 100644
--- a/scripts/cros_generate_breakpad_symbols.py
+++ b/scripts/cros_generate_breakpad_symbols.py
@@ -99,7 +99,7 @@ def GenerateBreakpadSymbol(elf_file, debug_file=None, breakpad_dir=None,
def _CrashCheck(ret, msg):
if ret < 0:
- cros_build_lib.PrintBuildbotStepWarnings()
+ logging.PrintBuildbotStepWarnings()
logging.warning('dump_syms crashed with %s; %s',
signals.StrSignal(-ret), msg)
@@ -130,7 +130,7 @@ def GenerateBreakpadSymbol(elf_file, debug_file=None, breakpad_dir=None,
if result.returncode:
# A lot of files (like kernel files) contain no debug information,
# do not consider such occurrences as errors.
- cros_build_lib.PrintBuildbotStepWarnings()
+ logging.PrintBuildbotStepWarnings()
_CrashCheck(result.returncode, 'giving up entirely')
if 'file contains no debugging information' in result.error:
logging.warning('no symbols found for %s', elf_file)
diff --git a/scripts/cros_sdk.py b/scripts/cros_sdk.py
index 226413aaa..b47475dd9 100644
--- a/scripts/cros_sdk.py
+++ b/scripts/cros_sdk.py
@@ -633,7 +633,7 @@ def main(argv):
else:
sdk_version = options.sdk_version
if options.buildbot_log_version:
- cros_build_lib.PrintBuildbotStepText(sdk_version)
+ logging.PrintBuildbotStepText(sdk_version)
# Based on selections, determine the tarball to fetch.
if options.sdk_url:
diff --git a/scripts/upload_prebuilts.py b/scripts/upload_prebuilts.py
index 36c9302d6..ccb1dcc19 100644
--- a/scripts/upload_prebuilts.py
+++ b/scripts/upload_prebuilts.py
@@ -473,7 +473,7 @@ class PrebuiltUploader(object):
link_name = 'Prebuilts[%s]: %s' % (self._target, self._version)
url = '%s%s/index.html' % (gs.PUBLIC_BASE_HTTPS_URL,
remote_location[len(gs.BASE_GS_URL):])
- cros_build_lib.PrintBuildbotLink(link_name, url)
+ logging.PrintBuildbotLink(link_name, url)
def _UploadSdkTarball(self, board_path, url_suffix, prepackaged,
toolchains_overlay_tarballs,
diff --git a/scripts/upload_symbols.py b/scripts/upload_symbols.py
index d7fd0370c..c6f9a114d 100644
--- a/scripts/upload_symbols.py
+++ b/scripts/upload_symbols.py
@@ -327,7 +327,7 @@ def UploadSymbol(upload_url, sym_item, file_limit=DEFAULT_FILE_LIMIT,
# Not sure what the best answer is in this case.
file_size = os.path.getsize(upload_item.sym_file)
if file_size > CRASH_SERVER_FILE_LIMIT:
- cros_build_lib.PrintBuildbotStepWarnings()
+ logging.PrintBuildbotStepWarnings()
logging.warning('upload file %s is awfully large, risking rejection by '
'the symbol server (%s > %s)', sym_file, file_size,
CRASH_SERVER_FILE_LIMIT)
@@ -737,7 +737,7 @@ def UploadSymbols(board=None, official=False, server=None, breakpad_dir=None,
# The process is taking too long, so kill it and complain.
if storage_notify_proc.is_alive():
logging.warning('notification process took too long')
- cros_build_lib.PrintBuildbotStepWarnings()
+ logging.PrintBuildbotStepWarnings()
# Kill it gracefully first (traceback) before tacking it down harder.
pid = storage_notify_proc.pid
diff --git a/scripts/upload_symbols_unittest.py b/scripts/upload_symbols_unittest.py
index cc3e18e8f..dc70c5379 100644
--- a/scripts/upload_symbols_unittest.py
+++ b/scripts/upload_symbols_unittest.py
@@ -430,7 +430,7 @@ class UploadSymbolTest(cros_test_lib.MockTempDirTestCase):
def testTruncateReallyLargeFiles(self):
"""Verify we try to shrink really big files"""
- warn_mock = self.PatchObject(cros_build_lib, 'PrintBuildbotStepWarnings')
+ warn_mock = self.PatchObject(logging, 'PrintBuildbotStepWarnings')
with open(self.sym_file, 'w+b') as f:
f.truncate(upload_symbols.CRASH_SERVER_FILE_LIMIT + 100)
f.seek(0)