示例#1
0
  def test_get_build_event_test_result_mapping(self):
    # Tests the hacky mapping between buildbot results and the proto values.
    hostname = 'bot.host.name'
    build_name = 'build_name'
    build_number = 314159265
    build_scheduling_time = 123456789

    # WARNINGS -> WARNING
    log_event = monitoring.get_build_event(
      'BUILD',
      hostname,
      build_name,
      build_number=build_number,
      build_scheduling_time=build_scheduling_time,
      result='WARNINGS')  # with an S

    self.assertIsInstance(log_event, LogRequestLite.LogEventLite)

    # Check that source_extension deserializes to the right thing.
    event = ChromeInfraEvent.FromString(log_event.source_extension)
    self.assertTrue(event.HasField('build_event'))
    self.assertEquals(event.build_event.type, BuildEvent.BUILD)
    self.assertEquals(event.build_event.host_name, hostname)
    self.assertEquals(event.build_event.build_name, build_name)
    self.assertEquals(event.build_event.build_number, build_number)
    self.assertEquals(event.build_event.build_scheduling_time_ms,
                      build_scheduling_time)
    self.assertEquals(event.build_event.result, BuildEvent.WARNING) # no S

    # EXCEPTION -> INFRA_FAILURE
    log_event = monitoring.get_build_event(
      'BUILD',
      hostname,
      build_name,
      build_number=build_number,
      build_scheduling_time=build_scheduling_time,
      result='EXCEPTION')

    self.assertIsInstance(log_event, LogRequestLite.LogEventLite)

    # Check that source_extension deserializes to the right thing.
    event = ChromeInfraEvent.FromString(log_event.source_extension)
    self.assertTrue(event.HasField('build_event'))
    self.assertEquals(event.build_event.type, BuildEvent.BUILD)
    self.assertEquals(event.build_event.host_name, hostname)
    self.assertEquals(event.build_event.build_name, build_name)
    self.assertEquals(event.build_event.build_number, build_number)
    self.assertEquals(event.build_event.build_scheduling_time_ms,
                      build_scheduling_time)
    self.assertEquals(event.build_event.result, BuildEvent.INFRA_FAILURE)
示例#2
0
  def test_get_build_event_valid_result_wrong_type(self):
    # SCHEDULER can't have a result
    hostname = 'bot.host.name'
    build_name = 'build_name'
    build_number = 314159265
    build_scheduling_time = 123456789
    result = 'SUCCESS'

    log_event = monitoring.get_build_event(
      'SCHEDULER',
      hostname,
      build_name,
      build_number=build_number,
      build_scheduling_time=build_scheduling_time,
      result=result)

    self.assertIsInstance(log_event, LogRequestLite.LogEventLite)

    # Check that source_extension deserializes to the right thing.
    event = ChromeInfraEvent.FromString(log_event.source_extension)
    self.assertTrue(event.HasField('build_event'))
    self.assertEquals(event.build_event.type, BuildEvent.SCHEDULER)
    self.assertEquals(event.build_event.host_name, hostname)
    self.assertEquals(event.build_event.build_name, build_name)
    self.assertEquals(event.build_event.build_number, build_number)
    self.assertEquals(event.build_event.build_scheduling_time_ms,
                      build_scheduling_time)
    self.assertEquals(event.build_event.result, BuildEvent.SUCCESS)
示例#3
0
  def test_get_build_event_with_invalid_result(self):
    hostname = 'bot.host.name'
    build_name = 'build_name'
    build_number = 314159265
    build_scheduling_time = 123456789
    result = '---INVALID---'

    log_event = monitoring.get_build_event(
      'BUILD',
      hostname,
      build_name,
      build_number=build_number,
      build_scheduling_time=build_scheduling_time,
      result=result)

    self.assertIsInstance(log_event, LogRequestLite.LogEventLite)

    # Check that source_extension deserializes to the right thing.
    event = ChromeInfraEvent.FromString(log_event.source_extension)
    self.assertTrue(event.HasField('build_event'))
    self.assertEquals(event.build_event.type, BuildEvent.BUILD)
    self.assertEquals(event.build_event.host_name, hostname)
    self.assertEquals(event.build_event.build_name, build_name)
    self.assertEquals(event.build_event.build_number, build_number)
    self.assertEquals(event.build_event.build_scheduling_time_ms,
                      build_scheduling_time)

    self.assertFalse(event.build_event.HasField('result'))
示例#4
0
  def test_get_build_event_with_step_info_wrong_type(self):
    # BUILD event with step info is invalid.
    hostname = 'bot.host.name'
    build_name = 'build_name'
    build_number = 314159265
    build_scheduling_time = 123456789
    step_name = 'step_name'
    step_number = 0  # valid step number

    log_event = monitoring.get_build_event(
      'BUILD',
      hostname,
      build_name,
      build_number=build_number,
      build_scheduling_time=build_scheduling_time,
      step_name=step_name,
      step_number=step_number)

    self.assertIsInstance(log_event, LogRequestLite.LogEventLite)

    # Check that source_extension deserializes to the right thing.
    event = ChromeInfraEvent.FromString(log_event.source_extension)
    self.assertTrue(event.HasField('build_event'))
    self.assertEquals(event.build_event.type, BuildEvent.BUILD)
    self.assertEquals(event.build_event.host_name, hostname)
    self.assertEquals(event.build_event.build_name, build_name)
    self.assertEquals(event.build_event.build_number, build_number)
    self.assertEquals(event.build_event.build_scheduling_time_ms,
                      build_scheduling_time)
    self.assertEquals(event.build_event.step_name, step_name)
    self.assertEquals(event.build_event.step_number, step_number)
示例#5
0
  def test_get_build_event_step_info_missing_build_info(self):
    hostname = 'bot.host.name'
    build_name = 'build_name'
    step_name = 'step_name'
    step_number = 0  # valid step number

    log_event = monitoring.get_build_event(
      'STEP',
      hostname,
      build_name,
      step_name=step_name,
      step_number=step_number)

    self.assertIsInstance(log_event, LogRequestLite.LogEventLite)

    # Check that source_extension deserializes to the right thing.
    event = ChromeInfraEvent.FromString(log_event.source_extension)
    self.assertTrue(event.HasField('build_event'))
    self.assertEquals(event.build_event.type, BuildEvent.STEP)
    self.assertEquals(event.build_event.host_name, hostname)
    self.assertEquals(event.build_event.build_name, build_name)
    self.assertEquals(event.build_event.step_name, step_name)
    self.assertEquals(event.build_event.step_number, step_number)

    self.assertFalse(event.build_event.HasField('build_number'))
    self.assertFalse(event.build_event.HasField('build_scheduling_time_ms'))
示例#6
0
  def test_get_build_event_valid_goma_stats_wrong_step_name(self):
    # SCHEDULER can't have a result
    hostname = 'bot.host.name'
    build_name = 'build_name'
    build_number = 314159265
    build_scheduling_time = 123456789
    step_name = 'invalid'
    goma_stats = GomaStats()
    goma_stats_gz = base64.b64encode(
        zlib.compress(goma_stats.SerializeToString()))

    log_event = monitoring.get_build_event(
      'STEP',
      hostname,
      build_name,
      build_number=build_number,
      build_scheduling_time=build_scheduling_time,
      step_name=step_name,
      goma_stats_gz=goma_stats_gz)

    self.assertIsInstance(log_event, LogRequestLite.LogEventLite)

    # Check that source_extension deserializes to the right thing.
    event = ChromeInfraEvent.FromString(log_event.source_extension)
    self.assertTrue(event.HasField('build_event'))
    self.assertEquals(event.build_event.type, BuildEvent.STEP)
    self.assertEquals(event.build_event.host_name, hostname)
    self.assertEquals(event.build_event.build_name, build_name)
    self.assertEquals(event.build_event.build_number, build_number)
    self.assertEquals(event.build_event.build_scheduling_time_ms,
                      build_scheduling_time)
    self.assertEquals(event.build_event.goma_stats, goma_stats)
示例#7
0
  def test_get_build_event_with_invalid_service_name(self):
    hostname = 'bot.host.name'
    build_name = 'build_name'
    service_name = 1234  # invalid
    log_event = monitoring.get_build_event(
      'BUILD', hostname, build_name, service_name=service_name)

    self.assertIsNone(log_event)
示例#8
0
  def test_get_build_event_invalid_hostname(self):
    # an invalid hostname is not a critical error.
    builder_name = 'builder_name'
    log_event = monitoring.get_build_event('BUILD', None, builder_name)
    self.assertIsInstance(log_event, LogRequestLite.LogEventLite)

    # Check that source_extension deserializes to the right thing.
    event = ChromeInfraEvent.FromString(log_event.source_extension)
    self.assertTrue(event.HasField('build_event'))
    self.assertEquals(event.build_event.type, BuildEvent.BUILD)
    self.assertEquals(event.build_event.build_name, builder_name)

    self.assertFalse(event.build_event.HasField('host_name'))
示例#9
0
  def test_get_build_event_default(self):
    hostname = 'bot.host.name'
    build_name = 'build_name'
    log_event = monitoring.get_build_event('BUILD', hostname, build_name)

    self.assertIsInstance(log_event, LogRequestLite.LogEventLite)
    self.assertTrue(log_event.HasField('event_time_ms'))
    self.assertTrue(log_event.HasField('source_extension'))

    # Check that source_extension deserializes to the right thing.
    event = ChromeInfraEvent.FromString(log_event.source_extension)
    self.assertTrue(event.HasField('build_event'))
    self.assertEquals(event.build_event.type, BuildEvent.BUILD)
    self.assertEquals(event.build_event.host_name, hostname)
    self.assertEquals(event.build_event.build_name, build_name)
示例#10
0
  def test_get_build_event_missing_build_number(self):
    hostname = 'bot.host.name'
    build_name = 'build_name'
    build_scheduling_time = 123456789
    log_event = monitoring.get_build_event(
      'BUILD',
      hostname,
      build_name,
      build_scheduling_time=build_scheduling_time)

    self.assertIsInstance(log_event, LogRequestLite.LogEventLite)

    # Check that source_extension deserializes to the right thing.
    event = ChromeInfraEvent.FromString(log_event.source_extension)
    self.assertTrue(event.HasField('build_event'))
    self.assertEquals(event.build_event.type, BuildEvent.BUILD)
    self.assertEquals(event.build_event.host_name, hostname)
    self.assertEquals(event.build_event.build_name, build_name)
    self.assertEquals(event.build_event.build_scheduling_time_ms,
                      build_scheduling_time)

    self.assertFalse(event.build_event.HasField('build_number'))
示例#11
0
  def test_get_build_event_invalid_scheduler(self):
    # Providing a build number on a scheduler event is invalid.
    hostname = 'bot.host.name'
    build_name = 'build_name'
    build_number = 314159265  # int32
    log_event = monitoring.get_build_event(
      'SCHEDULER',
      hostname,
      build_name,
      build_number=build_number)

    self.assertIsInstance(log_event, LogRequestLite.LogEventLite)

    # Check that source_extension deserializes to the right thing.
    event = ChromeInfraEvent.FromString(log_event.source_extension)
    self.assertTrue(event.HasField('build_event'))
    self.assertEquals(event.build_event.type, BuildEvent.SCHEDULER)
    self.assertEquals(event.build_event.host_name, hostname)
    self.assertEquals(event.build_event.build_name, build_name)
    self.assertEquals(event.build_event.build_number, build_number)

    self.assertFalse(event.build_event.HasField('build_scheduling_time_ms'))
示例#12
0
  def test_get_build_event_with_build_zero(self):
    # testing 0 is important because bool(0) == False
    hostname = 'bot.host.name'
    build_name = 'build_name'
    build_number = 0
    build_scheduling_time = 123456789
    log_event = monitoring.get_build_event(
      'BUILD',
      hostname,
      build_name,
      build_number=build_number,
      build_scheduling_time=build_scheduling_time)

    self.assertIsInstance(log_event, LogRequestLite.LogEventLite)

    # Check that source_extension deserializes to the right thing.
    event = ChromeInfraEvent.FromString(log_event.source_extension)
    self.assertTrue(event.HasField('build_event'))
    self.assertEquals(event.build_event.type, BuildEvent.BUILD)
    self.assertEquals(event.build_event.host_name, hostname)
    self.assertEquals(event.build_event.build_name, build_name)
    self.assertEquals(event.build_event.build_number, build_number)
    self.assertEquals(event.build_event.build_scheduling_time_ms,
                      build_scheduling_time)
示例#13
0
 def test_get_build_event_invalid_type(self):
   # An invalid type is a critical error.
   log_event = monitoring.get_build_event('INVALID_TYPE',
                                           'bot.host.name',
                                           'build_name')
   self.assertIsNone(log_event)