headers_to_account_info include per policy stats
This commit adds per-policy stats to proxy.controllers.base.headers_to_account_info Change-Id: I800266d15aabcc7b6e0234de3c9b965b5c15a623 Closes-Bug: #1675776
This commit is contained in:
parent
f7c55c169a
commit
c653566f4a
@ -144,6 +144,18 @@ def headers_to_account_info(headers, status_int=HTTP_OK):
|
||||
'container_count': headers.get('x-account-container-count'),
|
||||
'total_object_count': headers.get('x-account-object-count'),
|
||||
'bytes': headers.get('x-account-bytes-used'),
|
||||
'storage_policies': {policy.idx: {
|
||||
'container_count': int(headers.get(
|
||||
'x-account-storage-policy-{}-container-count'.format(
|
||||
policy.name), 0)),
|
||||
'object_count': int(headers.get(
|
||||
'x-account-storage-policy-{}-object-count'.format(
|
||||
policy.name), 0)),
|
||||
'bytes': int(headers.get(
|
||||
'x-account-storage-policy-{}-bytes-used'.format(
|
||||
policy.name), 0))}
|
||||
for policy in POLICIES
|
||||
},
|
||||
'meta': meta,
|
||||
'sysmeta': sysmeta,
|
||||
}
|
||||
|
@ -26,8 +26,8 @@ from swift.common import exceptions
|
||||
from swift.common.utils import split_path
|
||||
from swift.common.header_key_dict import HeaderKeyDict
|
||||
from swift.common.http import is_success
|
||||
from swift.common.storage_policy import StoragePolicy
|
||||
from test.unit import fake_http_connect, FakeRing, FakeMemcache
|
||||
from swift.common.storage_policy import StoragePolicy, StoragePolicyCollection
|
||||
from test.unit import fake_http_connect, FakeRing, FakeMemcache, PatchPolicies
|
||||
from swift.proxy import server as proxy_server
|
||||
from swift.common.request_helpers import (
|
||||
get_sys_meta_prefix, get_object_transient_sysmeta
|
||||
@ -615,6 +615,30 @@ class TestFuncs(unittest.TestCase):
|
||||
resp,
|
||||
headers_to_account_info(headers.items(), 200))
|
||||
|
||||
def test_headers_to_account_info_storage_policies(self):
|
||||
headers = {
|
||||
'x-account-storage-policy-zero-object-count': '13',
|
||||
'x-account-storage-policy-zero-container-count': '120',
|
||||
'x-account-storage-policy-zero-bytes-used': '1002',
|
||||
'x-account-storage-policy-one-object-count': '10',
|
||||
'x-account-storage-policy-one-container-count': '20',
|
||||
}
|
||||
spc = StoragePolicyCollection([StoragePolicy(0, 'zero', True),
|
||||
StoragePolicy(1, 'one', False)])
|
||||
with PatchPolicies(spc):
|
||||
resp = headers_to_account_info(headers.items(), 200)
|
||||
self.assertEqual(
|
||||
resp['storage_policies'][0]['object_count'], 13)
|
||||
self.assertEqual(
|
||||
resp['storage_policies'][0]['container_count'], 120)
|
||||
self.assertEqual(
|
||||
resp['storage_policies'][0]['bytes'], 1002)
|
||||
self.assertEqual(
|
||||
resp['storage_policies'][1]['object_count'], 10)
|
||||
self.assertEqual(
|
||||
resp['storage_policies'][1]['container_count'], 20)
|
||||
self.assertEqual(resp['storage_policies'][1]['bytes'], 0)
|
||||
|
||||
def test_headers_to_object_info_missing(self):
|
||||
resp = headers_to_object_info({}, 404)
|
||||
self.assertEqual(resp['status'], 404)
|
||||
|
@ -331,6 +331,10 @@ class TestController(unittest.TestCase):
|
||||
'container_count': '12345',
|
||||
'total_object_count': None,
|
||||
'bytes': None,
|
||||
'storage_policies': {p.idx: {
|
||||
'container_count': 0,
|
||||
'object_count': 0,
|
||||
'bytes': 0} for p in POLICIES},
|
||||
'meta': {},
|
||||
'sysmeta': {}}
|
||||
self.assertEqual(container_info,
|
||||
@ -358,6 +362,10 @@ class TestController(unittest.TestCase):
|
||||
'container_count': None, # internally keep None
|
||||
'total_object_count': None,
|
||||
'bytes': None,
|
||||
'storage_policies': {p.idx: {
|
||||
'container_count': 0,
|
||||
'object_count': 0,
|
||||
'bytes': 0} for p in POLICIES},
|
||||
'meta': {},
|
||||
'sysmeta': {}}
|
||||
self.assertEqual(account_info,
|
||||
|
Loading…
Reference in New Issue
Block a user