use path as resource id when missing RESELLER prefix

we don't have an id if RESELLER prefix is not in path. this causes
an id to be autogenerated making each request a completely different
resource id.

this patch changes it so we just default to path as our id if one
cannot be computed.

Change-Id: I5775406a84b5f2ad0f95f366b7deca210d2f8e87
Closes-Bug: #1566940
(cherry picked from commit 0789e5e30c)
This commit is contained in:
gordon chung 2016-04-07 08:06:35 -04:00
parent e1417e2a9d
commit 627125bf88
2 changed files with 13 additions and 2 deletions

View File

@ -216,7 +216,7 @@ class Swift(object):
# build object store details
target = cadf_resource.Resource(
typeURI='service/storage/object',
id=account.partition(self.reseller_prefix)[2])
id=account.partition(self.reseller_prefix)[2] or path)
target.metadata = resource_metadata
target.action = method.lower()

View File

@ -317,7 +317,7 @@ class TestSwift(tests_base.TestCase):
data = notify.call_args_list[0][0]
self.assertEqual("account", data[2]['target']['id'])
def test_invalid_reseller_prefix(self):
def test_incomplete_reseller_prefix(self):
# Custom reseller prefix set, but without trailing underscore
app = swift.Swift(
FakeApp(), {'reseller_prefix': 'CUSTOM'})
@ -329,6 +329,17 @@ class TestSwift(tests_base.TestCase):
data = notify.call_args_list[0][0]
self.assertEqual("account", data[2]['target']['id'])
def test_invalid_reseller_prefix(self):
app = swift.Swift(
FakeApp(), {'reseller_prefix': 'AUTH_'})
req = FakeRequest('/1.0/admin/bucket',
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("1.0/admin/bucket", data[2]['target']['id'])
def test_ignore_requests_from_project(self):
app = swift.Swift(FakeApp(), {'ignore_projects': 'skip_proj'})