From f46c961ffba6d64c3dcea111e7a9bb71a1015245 Mon Sep 17 00:00:00 2001 From: Eldar Nugaev Date: Mon, 11 Apr 2011 20:53:43 +0400 Subject: [PATCH] fix logging in swift --- glance/store/swift.py | 6 +++--- tests/unit/test_swift_store.py | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/glance/store/swift.py b/glance/store/swift.py index aee470d93d..3f07209d47 100644 --- a/glance/store/swift.py +++ b/glance/store/swift.py @@ -111,9 +111,9 @@ class SwiftBackend(glance.store.Backend): # should be a stateful object with options parsed once in # a constructor. if not auth_address: - logger.error(msg) msg = ("Could not find swift_store_auth_address in configuration " "options.") + logger.error(msg) raise glance.store.BackendException(msg) else: full_auth_address = auth_address @@ -121,15 +121,15 @@ class SwiftBackend(glance.store.Backend): full_auth_address = 'https://' + full_auth_address if not user: - logger.error(msg) msg = ("Could not find swift_store_user in configuration " "options.") + logger.error(msg) raise glance.store.BackendException(msg) if not key: - logger.error(msg) msg = ("Could not find swift_store_key in configuration " "options.") + logger.error(msg) raise glance.store.BackendException(msg) swift_conn = swift_client.Connection( diff --git a/tests/unit/test_swift_store.py b/tests/unit/test_swift_store.py index eaded164ab..b7fae7ccdb 100644 --- a/tests/unit/test_swift_store.py +++ b/tests/unit/test_swift_store.py @@ -324,6 +324,42 @@ class TestSwiftBackend(unittest.TestCase): SwiftBackend.add, 2, image_swift, SWIFT_OPTIONS) + def test_add_no_user(self): + """ + Tests that adding options without user raises + an appropriate exception + """ + image_swift = StringIO.StringIO("nevergonnamakeit") + options = SWIFT_OPTIONS.copy() + del options['swift_store_user'] + self.assertRaises(BackendException, + SwiftBackend.add, + 2, image_swift, options) + + def test_no_key(self): + """ + Tests that adding options without key raises + an appropriate exception + """ + image_swift = StringIO.StringIO("nevergonnamakeit") + options = SWIFT_OPTIONS.copy() + del options['swift_store_key'] + self.assertRaises(BackendException, + SwiftBackend.add, + 2, image_swift, options) + + def test_add_no_auth_address(self): + """ + Tests that adding options without auth address raises + an appropriate exception + """ + image_swift = StringIO.StringIO("nevergonnamakeit") + options = SWIFT_OPTIONS.copy() + del options['swift_store_auth_address'] + self.assertRaises(BackendException, + SwiftBackend.add, + 2, image_swift, options) + def test_delete(self): """ Test we can delete an existing image in the swift store