def testErrorSupression(self): """"Test exception supression.""" for e in [parallel.BackgroundFailure]: with cros_test_lib.LoggingCapturer() as logs: with stats.UploadContext(): raise e() self.AssertLogsContain(logs, stats.UNCAUGHT_UPLOAD_ERROR)
def main(argv): options = _ParseCommandLine(argv) _PostParseCheck(options) # Set cros_build_lib debug level to hide RunCommand spew. if options.verbose: logging.getLogger().setLevel(logging.DEBUG) else: logging.getLogger().setLevel(logging.INFO) with stats.UploadContext() as queue: cmd_stats = stats.Stats.SafeInit(cmd_line=argv, cmd_base='deploy_chrome') if cmd_stats: queue.put([cmd_stats, stats.StatsUploader.URL, 1]) with osutils.TempDir(set_global=True) as tempdir: staging_dir = options.staging_dir if not staging_dir: staging_dir = os.path.join(tempdir, 'chrome') deploy = DeployChrome(options, tempdir, staging_dir) try: deploy.Perform() except failures_lib.StepFailure as ex: raise SystemExit(str(ex).strip()) deploy.Cleanup()
def main(argv): parser = GetOptions(commands.ListCommands()) # Cros currently does nothing without a subcmd. Print help if no args are # specified. if not argv: parser.print_help() return 1 namespace = parser.parse_args(argv) subcommand = namespace.cros_class(namespace) with stats.UploadContext() as queue: if subcommand.upload_stats: cmd_base = subcommand.options.cros_class.command_name cmd_stats = stats.Stats.SafeInit(cmd_line=sys.argv, cmd_base=cmd_base) if cmd_stats: queue.put([ cmd_stats, stats.StatsUploader.URL, subcommand.upload_stats_timeout ]) # TODO: to make command completion faster, send an interrupt signal to the # stats uploader task after the subcommand completes. _RunSubCommand(subcommand) return 0
def testNoErrors(self): """Test that we don't print anything when there are no errors.""" with cros_test_lib.LoggingCapturer() as logs: with stats.UploadContext() as queue: queue.put([stats.Stats()]) self.AssertLogsContain(logs, stats.UNCAUGHT_UPLOAD_ERROR, inverted=True) self.assertEquals(stats.StatsUploader._Upload.call_count, 1)
def testKeyboardInterruptHandling(self): """Test that KeyboardInterrupts during upload aren't logged. This must use the parallel library so that exceptions are converted into BackgroundFailures as they are in a real run. """ self.PatchObject(stats.StatsUploader, '_Upload', side_effect=KeyboardInterrupt()) with cros_test_lib.LoggingCapturer() as logs: with stats.UploadContext() as queue: queue.put([stats.Stats()]) self.AssertLogsContain(logs, stats.UNCAUGHT_UPLOAD_ERROR, inverted=True)
def main(argv): try: parser = GetOptions(command.ListCommands()) # Cros currently does nothing without a subcmd. Print help if no args are # specified. if not argv: parser.print_help() return 1 namespace = parser.parse_args(argv) subcommand = namespace.command_class(namespace) with stats.UploadContext() as queue: if subcommand.upload_stats: cmd_base = subcommand.options.command_class.command_name cmd_stats = stats.Stats.SafeInit(cmd_line=sys.argv, cmd_base=cmd_base) if cmd_stats: queue.put([ cmd_stats, stats.StatsUploader.URL, subcommand.upload_stats_timeout ]) # TODO: to make command completion faster, send an interrupt signal to the # stats uploader task after the subcommand completes. try: code = _RunSubCommand(subcommand) except (commandline.ChrootRequiredError, commandline.ExecRequiredError): # The higher levels want these passed back, so oblige. raise except Exception as e: code = 1 logging.error('cros %s failed before completing.', subcommand.command_name) if namespace.debug: raise else: logging.error(e) if code is not None: return code return 0 except KeyboardInterrupt: logging.debug('Aborted due to keyboard interrupt.') return 1
def RaiseContext(e): with stats.UploadContext(): raise e()