Fix handling of empty reseller_prefix

The reseller_prefix can be an empty string. Make sure that the bare
account string is used in case it's empty.

Closes-Bug: #1835894
Change-Id: If181f812d06cfb68f07faf6b6bd050574eafde46
This commit is contained in:
Takashi Kajinami 2025-02-14 00:02:21 +09:00
parent 56fd0a302e
commit a54503e992
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',