コード例 #1
0
  def test_all_calls_ok(self):
    self._mox.StubOutWithMock(urllib_request, 'urlopen')
    urllib_request.urlopen(
      'http://localhost:%s/health' % self.PORT, None, timeout=1.0).AndReturn(StringIO('ok'))
    urllib_request.urlopen(
      'http://localhost:%s/quitquitquit' % self.PORT, '', timeout=1.0).AndReturn(StringIO(''))
    urllib_request.urlopen(
      'http://localhost:%s/abortabortabort' % self.PORT, '', timeout=1.0).AndReturn(StringIO(''))

    self._mox.ReplayAll()

    signaler = HttpSignaler(self.PORT)
    assert signaler.health() == (True, None)
    assert signaler.quitquitquit() == (True, None)
    assert signaler.abortabortabort() == (True, None)
コード例 #2
0
  def _terminate_http(self):
    if 'health' not in self._ports:
      return

    http_signaler = HttpSignaler(self._ports['health'])

    # pass 1
    http_signaler.quitquitquit()
    self._clock.sleep(self.ESCALATION_WAIT.as_(Time.SECONDS))
    if self.status is not None:
      return True

    # pass 2
    http_signaler.abortabortabort()
    self._clock.sleep(self.ESCALATION_WAIT.as_(Time.SECONDS))
    if self.status is not None:
      return True
コード例 #3
0
  def test_exception(self):
    self._mox.StubOutWithMock(urllib_request, 'urlopen')
    urllib_request.urlopen(
        'http://localhost:%s/health' % self.PORT, None, timeout=1.0).AndRaise(
        SocketTimeout('Timed out'))

    self._mox.ReplayAll()

    assert not HttpSignaler(self.PORT).health()[0]
コード例 #4
0
  def test_health_not_ok(self):
    self._mox.StubOutWithMock(urllib_request, 'urlopen')
    urllib_request.urlopen(
        'http://localhost:%s/health' % self.PORT, None, timeout=1.0).AndReturn(StringIO('not ok'))

    self._mox.ReplayAll()

    health, reason = HttpSignaler(self.PORT).health()
    assert not health
    assert reason.startswith('Response differs from expected response')
コード例 #5
0
    def from_assigned_task(self, assigned_task, _):
        mesos_task = mesos_task_instance_from_assigned_task(assigned_task)
        portmap = resolve_ports(mesos_task, assigned_task.assignedPorts)

        if 'health' not in portmap:
            return None

        health_check_config = mesos_task.health_check_config().get()
        http_signaler = HttpSignaler(
            portmap['health'],
            timeout_secs=health_check_config.get('timeout_secs'))
        health_checker = HealthCheckerThread(
            http_signaler.health,
            interval_secs=health_check_config.get('interval_secs'),
            initial_interval_secs=health_check_config.get(
                'initial_interval_secs'),
            max_consecutive_failures=health_check_config.get(
                'max_consecutive_failures'))
        return health_checker
コード例 #6
0
    def _terminate_http(self):
        if 'health' not in self._ports:
            return

        http_signaler = HttpSignaler(self._ports['health'])

        # pass 1
        http_signaler.quitquitquit()
        self._clock.sleep(self.ESCALATION_WAIT.as_(Time.SECONDS))
        if self.status is not None:
            return True

        # pass 2
        http_signaler.abortabortabort()
        self._clock.sleep(self.ESCALATION_WAIT.as_(Time.SECONDS))
        if self.status is not None:
            return True