diff options
Diffstat (limited to 'ceilometermiddleware')
-rw-r--r-- | ceilometermiddleware/swift.py | 11 | ||||
-rw-r--r-- | ceilometermiddleware/tests/test_swift.py | 16 |
2 files changed, 25 insertions, 2 deletions
diff --git a/ceilometermiddleware/swift.py b/ceilometermiddleware/swift.py index b5dad37..0235628 100644 --- a/ceilometermiddleware/swift.py +++ b/ceilometermiddleware/swift.py @@ -179,8 +179,15 @@ class Swift(object): try: container = obj = None - version, account, remainder = path.replace( - '/', '', 1).split('/', 2) + path = path.replace('/', '', 1) + version, account, remainder = path.split('/', 2) + except ValueError: + try: + version, account = path.split('/', 1) + remainder = None + except ValueError: + return + try: if not version or not account: raise ValueError('Invalid path: %s' % path) if remainder: diff --git a/ceilometermiddleware/tests/test_swift.py b/ceilometermiddleware/tests/test_swift.py index 41aaf58..2ca0be9 100644 --- a/ceilometermiddleware/tests/test_swift.py +++ b/ceilometermiddleware/tests/test_swift.py @@ -365,3 +365,19 @@ class TestSwift(tests_base.TestCase): list(app(req.environ, self.start_response)) data = notify.call_args_list[0][0] self.assertIsNot(0, len(data[2]['target']['id'])) + + def test_head_account(self): + app = swift.Swift(FakeApp(body=['']), {}) + req = FakeRequest('/1.0/account', + environ={'REQUEST_METHOD': 'HEAD'}) + 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('objectstore.http.request', data[1]) + self.assertIsNone(data[2].get('measurements')) + metadata = data[2]['target']['metadata'] + self.assertEqual('1.0', metadata['version']) + self.assertIsNone(metadata['container']) + self.assertIsNone(metadata['object']) + self.assertEqual('head', data[2]['target']['action']) |