diff --git a/keystoneclient/middleware/auth_token.py b/keystoneclient/middleware/auth_token.py index cd89cf159..52605f46a 100644 --- a/keystoneclient/middleware/auth_token.py +++ b/keystoneclient/middleware/auth_token.py @@ -462,11 +462,12 @@ class AuthProtocol(object): def _assert_valid_memcache_protection_config(self): if self._memcache_security_strategy: if self._memcache_security_strategy not in ('MAC', 'ENCRYPT'): - raise Exception('memcache_security_strategy must be ' - 'ENCRYPT or MAC') + raise ConfigurationError('memcache_security_strategy must be ' + 'ENCRYPT or MAC') if not self._memcache_secret_key: - raise Exception('mecmache_secret_key must be defined when ' - 'a memcache_security_strategy is defined') + raise ConfigurationError('mecmache_secret_key must be defined ' + 'when a memcache_security_strategy ' + 'is defined') def _init_cache(self, env): cache = self._conf_get('cache') diff --git a/keystoneclient/tests/test_auth_token_middleware.py b/keystoneclient/tests/test_auth_token_middleware.py index 25ff51451..afc717d70 100644 --- a/keystoneclient/tests/test_auth_token_middleware.py +++ b/keystoneclient/tests/test_auth_token_middleware.py @@ -771,31 +771,36 @@ class CommonAuthTokenMiddlewareTest(object): 'memcached_servers': ['localhost:11211'], 'memcache_security_strategy': 'Encrypt' } - self.assertRaises(Exception, self.set_middleware, conf=conf) + self.assertRaises(auth_token.ConfigurationError, self.set_middleware, + conf=conf) # test invalue memcache_security_strategy conf = { 'memcached_servers': ['localhost:11211'], 'memcache_security_strategy': 'whatever' } - self.assertRaises(Exception, self.set_middleware, conf=conf) + self.assertRaises(auth_token.ConfigurationError, self.set_middleware, + conf=conf) # test missing memcache_secret_key conf = { 'memcached_servers': ['localhost:11211'], 'memcache_security_strategy': 'mac' } - self.assertRaises(Exception, self.set_middleware, conf=conf) + self.assertRaises(auth_token.ConfigurationError, self.set_middleware, + conf=conf) conf = { 'memcached_servers': ['localhost:11211'], 'memcache_security_strategy': 'Encrypt', 'memcache_secret_key': '' } - self.assertRaises(Exception, self.set_middleware, conf=conf) + self.assertRaises(auth_token.ConfigurationError, self.set_middleware, + conf=conf) conf = { 'memcached_servers': ['localhost:11211'], 'memcache_security_strategy': 'mAc', 'memcache_secret_key': '' } - self.assertRaises(Exception, self.set_middleware, conf=conf) + self.assertRaises(auth_token.ConfigurationError, self.set_middleware, + conf=conf) def test_config_revocation_cache_timeout(self): conf = { diff --git a/keystoneclient/tests/v3/test_endpoints.py b/keystoneclient/tests/v3/test_endpoints.py index 673452396..050a646ec 100644 --- a/keystoneclient/tests/v3/test_endpoints.py +++ b/keystoneclient/tests/v3/test_endpoints.py @@ -14,6 +14,7 @@ import uuid +from keystoneclient import exceptions from keystoneclient.tests.v3 import utils from keystoneclient.v3 import endpoints @@ -49,7 +50,7 @@ class EndpointTests(utils.TestCase, utils.CrudTests): def test_create_invalid_interface(self): ref = self.new_ref(interface=uuid.uuid4().hex) - self.assertRaises(Exception, self.manager.create, + self.assertRaises(exceptions.ValidationError, self.manager.create, **utils.parameterize(ref)) def test_update_public_interface(self): @@ -66,7 +67,8 @@ class EndpointTests(utils.TestCase, utils.CrudTests): def test_update_invalid_interface(self): ref = self.new_ref(interface=uuid.uuid4().hex) - self.assertRaises(Exception, self.manager.update, + ref['endpoint'] = "fake_endpoint" + self.assertRaises(exceptions.ValidationError, self.manager.update, **utils.parameterize(ref)) def test_list_public_interface(self): @@ -87,5 +89,5 @@ class EndpointTests(utils.TestCase, utils.CrudTests): def test_list_invalid_interface(self): interface = uuid.uuid4().hex expected_path = 'v3/%s?interface=%s' % (self.collection_key, interface) - self.assertRaises(Exception, self.manager.list, + self.assertRaises(exceptions.ValidationError, self.manager.list, expected_path=expected_path, interface=interface) diff --git a/keystoneclient/v3/endpoints.py b/keystoneclient/v3/endpoints.py index 7030d287a..4950fa588 100644 --- a/keystoneclient/v3/endpoints.py +++ b/keystoneclient/v3/endpoints.py @@ -15,6 +15,7 @@ # under the License. from keystoneclient import base +from keystoneclient import exceptions VALID_INTERFACES = ['public', 'admin', 'internal'] @@ -45,7 +46,7 @@ class EndpointManager(base.CrudManager): if interface is not None and interface not in VALID_INTERFACES: msg = '"interface" must be one of: %s' msg = msg % ', '.join(VALID_INTERFACES) - raise Exception(msg) + raise exceptions.ValidationError(msg) def create(self, service, url, interface=None, region=None, enabled=True, **kwargs): diff --git a/tox.ini b/tox.ini index bc0144a25..c41c8b8b2 100644 --- a/tox.ini +++ b/tox.ini @@ -27,9 +27,8 @@ commands = python setup.py testr --coverage --testr-args='{posargs}' downloadcache = ~/cache/pip [flake8] -# H202: assertRaises Exception too broad # F821: undefined name # H304: no relative imports -ignore = F821,H202,H304 +ignore = F821,H304 show-source = True exclude = .venv,.tox,dist,doc,*egg,build