From 6a241a20c9c17ede1985e5c1f4c63fcaf2a2dbc7 Mon Sep 17 00:00:00 2001 From: Erno Kuvaja Date: Fri, 9 Jul 2021 14:08:59 +0100 Subject: Raise correct exception from "Quota full" Swift driver reraises the client exception causing glance-api to return 500. Lets raise g_s StoreFull correctly instead. Change-Id: I5be151afe242a75142e74d488c4787a35929e189 Closes-bug: #1926404 --- glance_store/_drivers/swift/store.py | 2 ++ glance_store/tests/unit/test_swift_store.py | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/glance_store/_drivers/swift/store.py b/glance_store/_drivers/swift/store.py index 9a531e4..baef35b 100644 --- a/glance_store/_drivers/swift/store.py +++ b/glance_store/_drivers/swift/store.py @@ -1074,6 +1074,8 @@ class BaseStore(driver.Store): if e.http_status == http_client.CONFLICT: msg = _("Swift already has an image at this location") raise exceptions.Duplicate(message=msg) + elif e.http_status == http_client.REQUEST_ENTITY_TOO_LARGE: + raise exceptions.StorageFull(message=e.msg) msg = (_(u"Failed to add object to Swift.\n" "Got error from Swift: %s.") diff --git a/glance_store/tests/unit/test_swift_store.py b/glance_store/tests/unit/test_swift_store.py index 809d50e..9018ccd 100644 --- a/glance_store/tests/unit/test_swift_store.py +++ b/glance_store/tests/unit/test_swift_store.py @@ -479,6 +479,33 @@ class SwiftTests(object): expected_image_id, image_swift, expected_swift_size, HASH_ALGO) self.assertEqual(expected_location, location) + def test_add_raises_storage_full(self): + + conf = copy.deepcopy(SWIFT_CONF) + conf['default_swift_reference'] = 'store_2' + self.config(**conf) + moves.reload_module(swift) + self.mock_keystone_client() + self.store = Store(self.conf) + self.store.configure() + + def fake_put_object_entity_too_large(*args, **kwargs): + msg = "Test Out of Quota" + raise swiftclient.ClientException( + msg, http_status=http_client.REQUEST_ENTITY_TOO_LARGE) + + self.useFixture(fixtures.MockPatch( + 'swiftclient.client.put_object', fake_put_object_entity_too_large)) + + expected_swift_size = FIVE_KB + expected_swift_contents = b"*" * expected_swift_size + expected_image_id = str(uuid.uuid4()) + image_swift = six.BytesIO(expected_swift_contents) + + self.assertRaises(exceptions.StorageFull, self.store.add, + expected_image_id, image_swift, + expected_swift_size, HASH_ALGO) + @mock.patch('glance_store._drivers.swift.utils' '.is_multiple_swift_store_accounts_enabled', mock.Mock(return_value=False)) -- cgit v1.2.1