Skip to content

Commit

Permalink
Merge "Add per policy container count to account stat output"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Sep 25, 2014
2 parents f90d7f2 + 40857cf commit d721871
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions swiftclient/command_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def stat_account(conn, options):
policies.add(policy_name)

for policy in policies:
container_count_header = (POLICY_HEADER_PREFIX + policy +
'-container-count')
if container_count_header in headers:
items.append(
('Containers in policy "' + policy + '"',
prt_bytes(headers[container_count_header],
options['human']).lstrip())
)
items.extend((
('Objects in policy "' + policy + '"',
prt_bytes(
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/test_command_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,32 @@ def test_stat_account_policy_stat(self):
"""
self.assertOut(expected)

def test_stat_account_policy_stat_with_container_counts(self):
# stub head_account
stub_headers = {
'x-account-container-count': 42,
'x-account-object-count': 1000000,
'x-account-bytes-used': 2 ** 30,
'x-account-storage-policy-nada-container-count': 10,
'x-account-storage-policy-nada-object-count': 1000000,
'x-account-storage-policy-nada-bytes-used': 2 ** 30,
}
self.conn.head_account.return_value = stub_headers

with self.output_manager as output_manager:
items, headers = h.stat_account(self.conn, self.options)
h.print_account_stats(items, headers, output_manager)
expected = """
Account: a
Containers: 42
Objects: 1000000
Bytes: 1073741824
Containers in policy "nada": 10
Objects in policy "nada": 1000000
Bytes in policy "nada": 1073741824
"""
self.assertOut(expected)

def test_stat_container_human(self):
self.options['human'] = True
# stub head container request
Expand Down

0 comments on commit d721871

Please sign in to comment.