Exemplo n.º 1
0
  def testNotAcceptingBuilds(self):
    self.mock(requests, 'get', self.requests_handler)
    self.res = self.Response(
        status_code=200,
        json=lambda: {'accepting_builds': False})

    accepting_builds, _ = master.get_varz(self.chromium_fyi)
    self.assertFalse(accepting_builds)
Exemplo n.º 2
0
 def testBadStatusCode(self):
   # We shouldn't get to the JSON function since we hit 404.
   # pylint: disable=redundant-unittest-assert
   self.res = self.Response(
       status_code=404,
       json=lambda: self.assertTrue(False))  # pragma: no cover
   self.mock(requests, 'get', self.requests_handler)
   accepting_builds, _ = master.get_varz(self.chromium_fyi)
   self.assertFalse(accepting_builds)
Exemplo n.º 3
0
  def testBadJson(self):
    def raiser():
      raise simplejson.scanner.JSONDecodeError('bad json', '', 0)
    self.res = self.Response(
        status_code=200,
        json=raiser)
    self.mock(requests, 'get', self.requests_handler)

    accepting_builds, _ = master.get_varz(self.chromium_fyi)
    self.assertFalse(accepting_builds)
Exemplo n.º 4
0
 def testGetBuildstate(self):
   self.mock(requests, 'get', self.requests_handler)
   self.res = self.Response(
       status_code=200,
       json=lambda: {
           'accepting_builds': True,
           'builders': {
             'test': {
               'current_builds': 3,
             },
             'other': {
               'current_builds': 1,
             },
             'empty': {},
           },
       })
   accepting_builds, running_builds = master.get_varz(self.chromium_fyi)
   self.assertTrue(accepting_builds)
   self.assertEqual(running_builds, {'test': 3, 'other': 1})
Exemplo n.º 5
0
def collect_evidence(master_directory, connection_timeout=30,
                     builder_filters=None):
  """Collects evidence from the OS for late state determination."""
  evidence = {}
  evidence['now'] = timestamp.utcnow_ts()
  evidence['last_boot'] = master.get_last_boot(master_directory)
  evidence['last_no_new_builds'] = master.get_last_no_new_builds(
      master_directory)
  evidence['buildbot_is_running'] = master.buildbot_is_running(master_directory)

  if evidence['buildbot_is_running']:
    accepting_builds, current_running_builds = master.get_varz(
        master_directory, timeout=connection_timeout)
    evidence['accepting_builds'] = accepting_builds

    if builder_filters:
      current_running_builds = {
          b: c for b, c in current_running_builds.iteritems()
          if any(f.match(b) for f in builder_filters)}

    # Add up the total number of running builds.
    current_running_builds = sum(current_running_builds.itervalues())
    evidence['current_running_builds'] = current_running_builds
  return evidence
Exemplo n.º 6
0
 def testConnectionErr(self):
   def timeout(*_args, **_kwargs):
     raise requests.exceptions.ConnectionError('error')
   self.mock(requests, 'get', timeout)
   accepting_builds, _ = master.get_varz(self.chromium_fyi)
   self.assertIsNone(accepting_builds)
Exemplo n.º 7
0
 def testAcceptingBuildsNoMaster(self):
   accepting_builds, _ = master.get_varz(self.chromium_webkit)
   self.assertIsNone(accepting_builds)