Example #1
0
 def test_send_build_event_smoke_missing_goma_file(self):
     args = get_arguments([
         '--event-mon-service-name', 'thing', '--build-event-type', 'BUILD',
         '--build-event-hostname', 'foo.bar.dns',
         '--build-event-build-name', 'whatever',
         '--build-event-goma-stats-path',
         os.path.join(DATA_DIR, 'this-file-does-not-exist')
     ])
     with self.assertRaises(IOError):
         common.send_build_event(args)
Example #2
0
  def main(self, opts):  # pragma: no cover
    status = 0

    try:
      if opts.build_event_type:
        success_metric.set(common.send_build_event(opts))

      elif opts.service_event_type:
        success_metric.set(common.send_service_event(opts))

      elif opts.events_from_file:
        success_metric.set(common.send_events_from_file(opts))

      else:
        print >> sys.stderr, ('At least one of the --*-event-type options or '
                              '--events-from-file should be provided. Nothing '
                              'was sent.')
        status = 2
        success_metric.set(False)
    except Exception:
      success_metric.set(False)
      traceback.print_exc()  # helps with debugging locally.
    finally:
      event_mon.close()
      try:
        ts_mon.flush()
      except ts_mon.MonitoringNoConfiguredMonitorError:
        logging.error("Unable to flush ts_mon because it's not configured.")
      except Exception:
        logging.exception("Flushing ts_mon metrics failed.")
    return status
Example #3
0
    def test_logrequest_path_build_type_override(self):
        # logrequest contains build event, overrid the type with an arg.
        with infra_libs.temporary_directory(prefix='common_test-') as tmpdir:
            outfile = os.path.join(tmpdir, 'out.bin')
            args = get_arguments([
                '--event-mon-run-type',
                'file',
                '--event-mon-output-file',
                outfile,
                '--event-mon-service-name',
                'thing',
                '--event-logrequest-path',
                os.path.join(DATA_DIR, 'build-foo-builder.bin'),
                '--build-event-build-number',
                '3',
                '--build-event-type',
                'STEP',
            ])
            self.assertEquals(args.event_mon_run_type, 'file')
            event_mon.process_argparse_options(args)
            common.process_argparse_options(args)
            self.assertTrue(common.send_build_event(args))

            # Now open the resulting file and check what was written
            with open(outfile, 'rb') as f:
                request = LogRequestLite.FromString(f.read())

        self.assertEqual(len(request.log_event), 1)
        event = ChromeInfraEvent.FromString(
            request.log_event[0].source_extension)
        self.assertEqual(event.build_event.host_name, 'myhostname')
        self.assertEqual(event.build_event.type, BuildEvent.STEP)
        self.assertEqual(event.build_event.build_number, 3)
        self.assertEqual(event.timestamp_kind, ChromeInfraEvent.BEGIN)
Example #4
0
    def test_send_build_event_with_goma_error_crashed(self):
        with infra_libs.temporary_directory(prefix='common_test-') as tmpdir:
            outfile = os.path.join(tmpdir, 'out.bin')
            args = get_arguments([
                '--event-mon-run-type', 'file', '--event-mon-output-file',
                outfile, '--event-mon-service-name', 'thing',
                '--build-event-type', 'BUILD', '--build-event-hostname',
                'foo.bar.dns', '--build-event-build-name', 'whatever',
                '--build-event-goma-error', 'GOMA_ERROR_CRASHED',
                '--build-event-goma-crash-report-id-path',
                os.path.join(DATA_DIR, 'goma_error_report.txt')
            ])
            self.assertEquals(args.event_mon_run_type, 'file')
            event_mon.process_argparse_options(args)
            self.assertTrue(common.send_build_event(args))

            # Now open the resulting file and check what was written
            with open(outfile, 'rb') as f:
                request = LogRequestLite.FromString(f.read())

        self.assertEqual(len(request.log_event), 1)
        event = ChromeInfraEvent.FromString(
            request.log_event[0].source_extension)
        self.assertEqual(event.build_event.goma_error,
                         BuildEvent.GOMA_ERROR_CRASHED)
        self.assertEqual(event.build_event.goma_crash_report_id,
                         '0123456789abcdef0')
        self.assertEqual(event.build_event.host_name, 'foo.bar.dns')
Example #5
0
 def test_send_build_event_with_invalid_goma_stats(self):
     # Write a file to avoid mocks
     with infra_libs.temporary_directory(prefix='common_test-') as tmpdir:
         outfile = os.path.join(tmpdir, 'out.bin')
         args = get_arguments([
             '--event-mon-run-type', 'file', '--event-mon-output-file',
             outfile, '--event-mon-service-name', 'thing',
             '--build-event-type', 'BUILD', '--build-event-hostname',
             'foo.bar.dns', '--build-event-build-name', 'whatever',
             '--build-event-goma-stats-path',
             os.path.join(DATA_DIR, 'garbage')
         ])
         self.assertEquals(args.event_mon_run_type, 'file')
         event_mon.process_argparse_options(args)
         with self.assertRaises(google.protobuf.message.DecodeError):
             common.send_build_event(args)
Example #6
0
    def test_send_build_event_with_goma_stats(self):
        # Write a file to avoid mocks
        with infra_libs.temporary_directory(prefix='common_test-') as tmpdir:
            outfile = os.path.join(tmpdir, 'out.bin')
            args = get_arguments([
                '--event-mon-run-type', 'file', '--event-mon-output-file',
                outfile, '--event-mon-service-name', 'thing',
                '--build-event-type', 'BUILD', '--build-event-hostname',
                'foo.bar.dns', '--build-event-build-name', 'whatever',
                '--build-event-goma-stats-path',
                os.path.join(DATA_DIR, 'goma_stats.bin')
            ])
            self.assertEquals(args.event_mon_run_type, 'file')
            event_mon.process_argparse_options(args)
            self.assertTrue(common.send_build_event(args))

            # Now open the resulting file and check what was written
            with open(outfile, 'rb') as f:
                request = LogRequestLite.FromString(f.read())

        self.assertEqual(len(request.log_event), 1)
        event = ChromeInfraEvent.FromString(
            request.log_event[0].source_extension)
        self.assertEqual(event.build_event.goma_stats.request_stats.total, 10)
        self.assertEqual(event.build_event.goma_stats.request_stats.success, 9)
        self.assertEqual(event.build_event.goma_stats.request_stats.failure, 1)
        self.assertEqual(event.build_event.host_name, 'foo.bar.dns')
Example #7
0
 def test_send_build_event_smoke(self):
     args = get_arguments([
         '--event-mon-service-name', 'thing', '--build-event-type',
         'SCHEDULER', '--build-event-hostname', 'foo.bar.dns',
         '--build-event-build-name', 'whatever'
     ])
     self.assertTrue(common.send_build_event(args))
Example #8
0
 def test_send_build_event_with_non_existing_goma_error_report(self):
     # Write a file to avoid mocks
     with infra_libs.temporary_directory(prefix='common_test-') as tmpdir:
         outfile = os.path.join(tmpdir, 'out.bin')
         args = get_arguments([
             '--event-mon-run-type', 'file', '--event-mon-output-file',
             outfile, '--event-mon-service-name', 'thing',
             '--build-event-type', 'BUILD', '--build-event-hostname',
             'foo.bar.dns', '--build-event-build-name', 'whatever',
             '--build-event-goma-error', 'GOMA_ERROR_CRASHED',
             '--build-event-goma-crash-report-id-path',
             os.path.join(DATA_DIR, 'this-file-does-not-exist')
         ])
         self.assertEquals(args.event_mon_run_type, 'file')
         event_mon.process_argparse_options(args)
         with self.assertRaises(IOError):
             common.send_build_event(args)