diff options
author | gordon chung <gord@live.ca> | 2016-04-07 08:06:35 -0400 |
---|---|---|
committer | gordon chung <gord@live.ca> | 2016-04-19 13:57:29 +0000 |
commit | 24af138e96907e97b2d294d5d939e05ca97a7de0 (patch) | |
tree | a62739083786152f3417adf3e444149cb96eb5b6 /ceilometermiddleware | |
parent | 642ee832484b705d671bf208db4e5f21403f04e7 (diff) | |
download | ceilometermiddleware-24af138e96907e97b2d294d5d939e05ca97a7de0.tar.gz |
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)
Diffstat (limited to 'ceilometermiddleware')
-rw-r--r-- | ceilometermiddleware/swift.py | 2 | ||||
-rw-r--r-- | ceilometermiddleware/tests/test_swift.py | 13 |
2 files changed, 13 insertions, 2 deletions
diff --git a/ceilometermiddleware/swift.py b/ceilometermiddleware/swift.py index 9d09c1a..564e1cf 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 4df627d..115b45a 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'}) |