Skip to content

Commit d721871

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add per policy container count to account stat output"
2 parents f90d7f2 + 40857cf commit d721871

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

swiftclient/command_helpers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ def stat_account(conn, options):
4545
policies.add(policy_name)
4646

4747
for policy in policies:
48+
container_count_header = (POLICY_HEADER_PREFIX + policy +
49+
'-container-count')
50+
if container_count_header in headers:
51+
items.append(
52+
('Containers in policy "' + policy + '"',
53+
prt_bytes(headers[container_count_header],
54+
options['human']).lstrip())
55+
)
4856
items.extend((
4957
('Objects in policy "' + policy + '"',
5058
prt_bytes(

tests/unit/test_command_helpers.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,32 @@ def test_stat_account_policy_stat(self):
124124
"""
125125
self.assertOut(expected)
126126

127+
def test_stat_account_policy_stat_with_container_counts(self):
128+
# stub head_account
129+
stub_headers = {
130+
'x-account-container-count': 42,
131+
'x-account-object-count': 1000000,
132+
'x-account-bytes-used': 2 ** 30,
133+
'x-account-storage-policy-nada-container-count': 10,
134+
'x-account-storage-policy-nada-object-count': 1000000,
135+
'x-account-storage-policy-nada-bytes-used': 2 ** 30,
136+
}
137+
self.conn.head_account.return_value = stub_headers
138+
139+
with self.output_manager as output_manager:
140+
items, headers = h.stat_account(self.conn, self.options)
141+
h.print_account_stats(items, headers, output_manager)
142+
expected = """
143+
Account: a
144+
Containers: 42
145+
Objects: 1000000
146+
Bytes: 1073741824
147+
Containers in policy "nada": 10
148+
Objects in policy "nada": 1000000
149+
Bytes in policy "nada": 1073741824
150+
"""
151+
self.assertOut(expected)
152+
127153
def test_stat_container_human(self):
128154
self.options['human'] = True
129155
# stub head container request

0 commit comments

Comments
 (0)