From 627125bf88adbeed7b9c079a5f7dc75b06480ee0 Mon Sep 17 00:00:00 2001 From: gordon chung Date: Thu, 7 Apr 2016 08:06:35 -0400 Subject: 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 0789e5e30ca71b05d893b050a724f3c48421d183) --- ceilometermiddleware/swift.py | 2 +- ceilometermiddleware/tests/test_swift.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ceilometermiddleware/swift.py b/ceilometermiddleware/swift.py index 925a879..ba2db38 100644 --- a/ceilometermiddleware/swift.py +++ b/ceilometermiddleware/swift.py @@ -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() diff --git a/ceilometermiddleware/tests/test_swift.py b/ceilometermiddleware/tests/test_swift.py index 18f6977..2e7287a 100644 --- a/ceilometermiddleware/tests/test_swift.py +++ b/ceilometermiddleware/tests/test_swift.py @@ -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'}) -- cgit v1.2.1