Merge "Fix handling of empty reseller_prefix"

This commit is contained in:
Zuul 2025-03-24 11:07:44 +00:00 committed by Gerrit Code Review
commit 2a1cb8b2c6
2 changed files with 17 additions and 3 deletions

View File

@ -355,9 +355,13 @@ class Swift(object):
header.upper())
# build object store details
if self.reseller_prefix:
resource_id = account.partition(self.reseller_prefix)[2] or path
else:
resource_id = account
target = cadf_resource.Resource(
typeURI='service/storage/object',
id=account.partition(self.reseller_prefix)[2] or path)
id=resource_id)
target.metadata = resource_metadata
target.action = method.lower()

View File

@ -337,7 +337,7 @@ class TestSwift(tests_base.TestCase):
data = notify.call_args_list[0][0]
self.assertEqual("account", data[2]['target']['id'])
def test_custom_prefix(self):
def test_custom_reseller_prefix(self):
app = swift.Swift(FakeApp(), {'reseller_prefix': 'CUSTOM_'})
req = FakeRequest('/1.0/CUSTOM_account/container/obj',
environ={'REQUEST_METHOD': 'GET'})
@ -347,6 +347,16 @@ class TestSwift(tests_base.TestCase):
data = notify.call_args_list[0][0]
self.assertEqual("account", data[2]['target']['id'])
def test_empty_reseller_prefix(self):
app = swift.Swift(FakeApp(), {'reseller_prefix': ''})
req = FakeRequest('/1.0/account/container/obj',
environ={'REQUEST_METHOD': 'GET'})
with mock.patch('oslo_messaging.Notifier.info') as notify:
list(app(req.environ, self.start_response))
self.assertEqual(1, len(notify.call_args_list))
data = notify.call_args_list[0][0]
self.assertEqual("account", data[2]['target']['id'])
def test_incomplete_reseller_prefix(self):
# Custom reseller prefix set, but without trailing underscore
app = swift.Swift(
@ -397,7 +407,7 @@ class TestSwift(tests_base.TestCase):
list(app(req.environ, self.start_response))
self.assertEqual(calls, len(notify.call_args_list))
def test_empty_reseller_prefix(self):
def test_only_reseller_prefix(self):
app = swift.Swift(
FakeApp(), {'reseller_prefix': 'CUSTOM'})
req = FakeRequest('/1.0/CUSTOM/container/obj',