def test_ssl_error(self, es): es.cluster.health.side_effect = elasticsearch.ConnectionError( "N/A", "[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:719)", urllib3.exceptions.SSLError("[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:719)"), ) with pytest.raises(exceptions.SystemSetupError, match="Could not connect to cluster via https. Is this an https endpoint?"): client.wait_for_rest_layer(es, max_attempts=3)
def start(self, race_id): cmd = "start --runtime-jdk=\"bundled\" --installation-id={} --race-id={}".format( self.installation_id, race_id) if esrally(self.cfg, cmd) != 0: raise AssertionError("Failed to start Elasticsearch test cluster.") es = client.EsClientFactory(hosts=[{ "host": "127.0.0.1", "port": self.http_port }], client_options={}).create() client.wait_for_rest_layer(es)
def test_ssl_error(self, es): import elasticsearch import urllib3.exceptions es.cluster.health.side_effect = elasticsearch.ConnectionError( "N/A", "[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:719)", urllib3.exceptions.SSLError( "[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:719)")) with self.assertRaisesRegex( expected_exception=exceptions.SystemSetupError, expected_regex= "Could not connect to cluster via https. Is this an https endpoint?" ): client.wait_for_rest_layer(es, max_attempts=3)
def cluster_distribution_version(cfg, client_factory=client.EsClientFactory): """ Attempt to get the cluster's distribution version even before it is actually started (which makes only sense for externally provisioned clusters). :param cfg: The current config object. :param client_factory: Factory class that creates the Elasticsearch client. :return: The distribution version. """ hosts = cfg.opts("client", "hosts").default client_options = cfg.opts("client", "options").default es = client_factory(hosts, client_options).create() # unconditionally wait for the REST layer - if it's not up by then, we'll intentionally raise the original error client.wait_for_rest_layer(es) return es.info()["version"]["number"]
def test_retries_on_transport_errors(self, es, sleep): es.cluster.health.side_effect = [ elasticsearch.TransportError(503, "Service Unavailable"), elasticsearch.TransportError(401, "Unauthorized"), elasticsearch.TransportError(408, "Timed Out"), elasticsearch.TransportError(408, "Timed Out"), {"version": {"number": "5.0.0", "build_hash": "abc123"}}, ] assert client.wait_for_rest_layer(es, max_attempts=5)
def test_successfully_waits_for_rest_layer(self, es): es.transport.hosts = [ {"host": "node-a.example.org", "port": 9200}, {"host": "node-b.example.org", "port": 9200}, ] assert client.wait_for_rest_layer(es, max_attempts=3) es.cluster.health.assert_has_calls( [ mock.call(wait_for_nodes=">=2"), ] )
def wait_for_rest_api(self): skip_rest_api_check = self.config.opts("mechanic", "skip.rest.api.check") if skip_rest_api_check: self.logger.info("Skipping REST API check.") else: es_default = self.es_clients["default"] self.logger.info("Checking if REST API is available.") if client.wait_for_rest_layer(es_default, max_attempts=40): self.logger.info("REST API is available.") else: self.logger.error( "REST API layer is not yet available. Stopping benchmark.") raise exceptions.SystemSetupError( "Elasticsearch REST API layer is not available.")
def test_dont_retry_eternally_on_transport_errors(self, es, sleep): es.cluster.health.side_effect = elasticsearch.TransportError( 401, "Unauthorized") self.assertFalse(client.wait_for_rest_layer(es, max_attempts=3))