From e64a98df61e4ada28e88e3a0b66b82b87e9aa873 Mon Sep 17 00:00:00 2001 From: Pierre Padrixe Date: Wed, 22 Jan 2014 15:30:05 +0100 Subject: [PATCH] Add keystone host unreachable checks Raise HostUnreachableException if the property auth_url is wrong Implements blueprint keystone-auth-url-wrong Change-Id: Idf2a07b1535a4a3c53814a1a55959afc59caefe2 --- rally/benchmark/engine.py | 7 +++++-- rally/exceptions.py | 4 ++++ tests/benchmark/test_engine.py | 13 ++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/rally/benchmark/engine.py b/rally/benchmark/engine.py index 067e816c18..d74dac5d35 100644 --- a/rally/benchmark/engine.py +++ b/rally/benchmark/engine.py @@ -16,7 +16,7 @@ import json import jsonschema -from keystoneclient.v2_0 import client as keystone +from keystoneclient import exceptions as keystone_exceptions from rally.benchmark import base from rally.benchmark import runner @@ -156,8 +156,11 @@ class TestEngine(object): if not any("admin" == role['name'] for role in roles): raise exceptions.InvalidAdminException( username=self.endpoint["username"]) - except keystone.exceptions.Unauthorized: + except keystone_exceptions.Unauthorized: raise exceptions.InvalidEndpointsException() + except keystone_exceptions.AuthorizationFailure: + raise exceptions.HostUnreachableException( + url=self.endpoint['auth_url']) return self def __enter__(self): diff --git a/rally/exceptions.py b/rally/exceptions.py index b149461931..4b8394e402 100644 --- a/rally/exceptions.py +++ b/rally/exceptions.py @@ -160,3 +160,7 @@ class InvalidAdminException(InvalidArgumentsException): class InvalidEndpointsException(InvalidArgumentsException): msg_fmt = _("wrong keystone credentials specified in your endpoint" " properties. (HTTP 401)") + + +class HostUnreachableException(InvalidArgumentsException): + msg_fmt = _("unable to establish connection to the remote host: %(url)s") diff --git a/tests/benchmark/test_engine.py b/tests/benchmark/test_engine.py index 42fcf85b90..ebc38cb2c9 100644 --- a/tests/benchmark/test_engine.py +++ b/tests/benchmark/test_engine.py @@ -17,6 +17,8 @@ import mock +from keystoneclient import exceptions as keystone_exceptions + from rally.benchmark import engine from rally import consts from rally import exceptions @@ -133,12 +135,21 @@ class TestEngineTestCase(test.TestCase): @mock.patch("rally.cmd.main.api.engine.osclients.Clients" ".get_keystone_client") def test_bind_unauthorized_keystone(self, mock_osclients): - mock_osclients.side_effect = exceptions.InvalidEndpointsException + mock_osclients.side_effect = keystone_exceptions.Unauthorized tester = engine.TestEngine(self.valid_test_config_continuous_times, mock.MagicMock()) self.assertRaises(exceptions.InvalidEndpointsException, tester.bind, self.valid_endpoint) + @mock.patch("rally.cmd.main.api.engine.osclients.Clients" + ".get_keystone_client") + def test_bind_keystone_host_unreachable(self, mock_osclients): + mock_osclients.side_effect = keystone_exceptions.AuthorizationFailure + tester = engine.TestEngine(self.valid_test_config_continuous_times, + mock.MagicMock()) + self.assertRaises(exceptions.HostUnreachableException, + tester.bind, self.valid_endpoint) + @mock.patch("rally.benchmark.runner.ScenarioRunner.run") @mock.patch("rally.benchmark.utils.osclients") @mock.patch("rally.benchmark.engine.osclients")