Ejemplo n.º 1
0
  def test_all_calls_ok(self):
    self._mox.StubOutWithMock(urllib_request, 'urlopen')
    urllib_request.urlopen(
      'http://localhost:%s/quitquitquit' % self.PORT, '', timeout=1.0).AndReturn(OpenedURL(''))
    urllib_request.urlopen(
      'http://localhost:%s/abortabortabort' % self.PORT, '', timeout=1.0).AndReturn(OpenedURL(''))

    self._mox.ReplayAll()

    signaler = HttpSignaler(self.PORT)
    assert signaler.quitquitquit() == (True, None)
    assert signaler.abortabortabort() == (True, None)
Ejemplo n.º 2
0
    def test_all_calls_ok(self):
        self._mox.StubOutWithMock(urllib_request, 'urlopen')
        urllib_request.urlopen('http://localhost:%s/quitquitquit' % self.PORT,
                               '',
                               timeout=1.0).AndReturn(OpenedURL(''))
        urllib_request.urlopen('http://localhost:%s/abortabortabort' %
                               self.PORT,
                               '',
                               timeout=1.0).AndReturn(OpenedURL(''))

        self._mox.ReplayAll()

        signaler = HttpSignaler(self.PORT)
        assert signaler.quitquitquit() == (True, None)
        assert signaler.abortabortabort() == (True, None)
  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
Ejemplo n.º 4
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]
Ejemplo n.º 5
0
    def _terminate_http(self):
        http_signaler = HttpSignaler(self._lifecycle_port)

        for endpoint in self._escalation_endpoints:
            handled, _ = http_signaler(endpoint, use_post_method=True)

            if handled:
                self._clock.sleep(self.ESCALATION_WAIT.as_(Time.SECONDS))
                if self._runner.status is not None:
                    return True
Ejemplo n.º 6
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')
Ejemplo n.º 7
0
    def test_health_checks(self):
        self._mox.StubOutWithMock(urllib_request, 'urlopen')
        urllib_request.urlopen('http://localhost:%s/health' % self.PORT,
                               None,
                               timeout=1.0).AndReturn(OpenedURL('ok'))
        urllib_request.urlopen('http://localhost:%s/health' % self.PORT,
                               None,
                               timeout=1.0).AndReturn(OpenedURL('not ok'))
        urllib_request.urlopen('http://localhost:%s/health' % self.PORT,
                               None,
                               timeout=1.0).AndReturn(
                                   OpenedURL('not ok', code=200))
        urllib_request.urlopen('http://localhost:%s/health' % self.PORT,
                               None,
                               timeout=1.0).AndReturn(OpenedURL('ok',
                                                                code=400))
        urllib_request.urlopen('http://localhost:%s/health' % self.PORT,
                               None,
                               timeout=1.0).AndRaise(
                                   urllib_request.HTTPError(
                                       '', 501, '', None, None))
        urllib_request.urlopen('http://localhost:%s/health' % self.PORT,
                               None,
                               timeout=1.0).AndReturn(OpenedURL('ok',
                                                                code=200))
        urllib_request.urlopen('http://localhost:%s/random/endpoint' %
                               self.PORT,
                               None,
                               timeout=1.0).AndReturn(OpenedURL('ok'))

        self._mox.ReplayAll()

        signaler = HttpSignaler(self.PORT)
        assert signaler('/health', expected_response='ok') == (True, None)
        assert signaler('/health', expected_response='ok') == (
            False,
            'Response differs from expected response (expected "ok", got "not ok")'
        )
        assert signaler('/health', expected_response_code=200) == (True, None)
        assert signaler('/health', expected_response_code=200) == (
            False,
            'Response code differs from expected response (expected 200, got 400)'
        )
        assert signaler('/health', expected_response_code=200) == (
            False,
            'Response code differs from expected response (expected 200, got 501)'
        )
        assert signaler('/health',
                        expected_response='ok',
                        expected_response_code=200) == (True, None)
        assert signaler('/random/endpoint',
                        expected_response='ok') == (True, None)
Ejemplo n.º 8
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 = HealthChecker(
        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
Ejemplo n.º 9
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
Ejemplo n.º 10
0
    def from_assigned_task(self, assigned_task, sandbox):
        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 = HealthChecker(
            lambda: http_signaler(
                endpoint=health_check_config.get('endpoint'),
                expected_response=health_check_config.get('expected_response'),
                expected_response_code=health_check_config.get(
                    'expected_response_code')),
            sandbox,
            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