def test_raises_rally_error_on_unknown_problems(self): def raise_unknown_error(): raise elasticsearch.exceptions.SerializationError("unit-test") client = metrics.EsClient(EsClientTests.ClientMock([{"host": "127.0.0.1", "port": "9243"}])) with self.assertRaises(exceptions.RallyError) as ctx: client.guarded(raise_unknown_error) self.assertEqual("An unknown error occurred while running the operation [raise_unknown_error] against your Elasticsearch metrics " "store on host [127.0.0.1] at port [9243].", ctx.exception.args[0])
def test_fails_after_too_many_timeouts(self): def gateway_timeout(): raise elasticsearch.exceptions.TransportError(504, "Gateway timeout") client = metrics.EsClient(EsClientTests.ClientMock([{"host": "127.0.0.1", "port": "9243"}])) with self.assertRaises(exceptions.RallyError) as ctx: client.guarded(gateway_timeout) self.assertEqual("A transport error occurred while running the operation [gateway_timeout] against your Elasticsearch metrics " "store on host [127.0.0.1] at port [9243].", ctx.exception.args[0])
def test_raises_sytem_setup_error_on_authentication_problems(self): def raise_authentication_error(): raise elasticsearch.exceptions.AuthenticationException("unit-test") client = metrics.EsClient(EsClientTests.ClientMock([{"host": "127.0.0.1", "port": "9243"}])) with self.assertRaises(exceptions.SystemSetupError) as ctx: client.guarded(raise_authentication_error) self.assertEqual("The configured user could not authenticate against your Elasticsearch metrics store running on host [127.0.0.1] " "at port [9243] (wrong password?). Please fix the configuration in [%s/.rally/rally.ini]." % os.path.expanduser("~"), ctx.exception.args[0])
def test_raises_sytem_setup_error_on_connection_problems(self): def raise_connection_error(): raise elasticsearch.exceptions.ConnectionError("unit-test") client = metrics.EsClient(EsClientTests.ClientMock([{"host": "127.0.0.1", "port": "9200"}])) with self.assertRaises(exceptions.SystemSetupError) as ctx: client.guarded(raise_connection_error) self.assertEqual("Could not connect to your Elasticsearch metrics store. Please check that it is running on host [127.0.0.1] at " "port [9200] or fix the configuration in [%s/.rally/rally.ini]." % os.path.expanduser("~"), ctx.exception.args[0])
def test_raises_sytem_setup_error_on_authorization_problems(self): def raise_authorization_error(): raise elasticsearch.exceptions.AuthorizationException("unit-test") client = metrics.EsClient(EsClientTests.ClientMock([{"host": "127.0.0.1", "port": "9243"}])) with self.assertRaises(exceptions.SystemSetupError) as ctx: client.guarded(raise_authorization_error) self.assertEqual("The configured user does not have enough privileges to run the operation [raise_authorization_error] against " "your Elasticsearch metrics store running on host [127.0.0.1] at port [9243]. Please adjust your x-pack " "configuration or specify a user with enough privileges in the configuration in [%s/.rally/rally.ini]." % os.path.expanduser("~"), ctx.exception.args[0])
def test_retries_on_timeouts(self): gateway_timeout = elasticsearch.exceptions.TransportError(504, "Gateway timeout") # should return on first success operation = mock.Mock(side_effect=[gateway_timeout, gateway_timeout, "success", gateway_timeout]) client = metrics.EsClient(EsClientTests.ClientMock([{"host": "127.0.0.1", "port": "9243"}])) self.assertEqual("success", client.guarded(operation)) operation.assert_has_calls([ mock.call(), mock.call(), mock.call() ])