Skip to content

Commit 1f8b814

Browse files
author
Steve Martinelli
committed
Fix up object-store show commands
1) Change metadata to appear under a common 'properties' key, and use the utility to format them, this applied to object, account and container. 2) Clean up container and object output, which were setting the x-container-meta-owner property, but this is metadata only for the container, so it's pointless to have, removed it. 3) Container show was showing read/write ACLs and sync stuff, but these are not being returned by my swift by default, so I moved these to be checks, so we don't clutter the output. Change-Id: Ife7521fe9c2724035b06963c118bd6016ba2f5b5
1 parent 4759a84 commit 1f8b814

7 files changed

Lines changed: 48 additions & 38 deletions

File tree

openstackclient/api/object_store_v1.py

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import io
1717
import os
18+
1819
import six
1920
from six.moves import urllib
2021

@@ -176,13 +177,24 @@ def container_show(
176177
'x-container-object-count',
177178
None,
178179
),
179-
'meta-owner': response.headers.get('x-container-meta-owner', None),
180-
'bytes_used': response.headers.get('x-container-bytes-used', None),
181-
'read_acl': response.headers.get('x-container-read', None),
182-
'write_acl': response.headers.get('x-container-write', None),
183-
'sync_to': response.headers.get('x-container-sync-to', None),
184-
'sync_key': response.headers.get('x-container-sync-key', None),
180+
'bytes_used': response.headers.get('x-container-bytes-used', None)
185181
}
182+
183+
if 'x-container-read' in response.headers:
184+
data['read_acl'] = response.headers.get('x-container-read', None)
185+
if 'x-container-write' in response.headers:
186+
data['write_acl'] = response.headers.get('x-container-write', None)
187+
if 'x-container-sync-to' in response.headers:
188+
data['sync_to'] = response.headers.get('x-container-sync-to', None)
189+
if 'x-container-sync-key' in response.headers:
190+
data['sync_key'] = response.headers.get('x-container-sync-key',
191+
None)
192+
193+
properties = self._get_properties(response.headers,
194+
'x-container-meta-')
195+
if properties:
196+
data['properties'] = properties
197+
186198
return data
187199

188200
def container_unset(
@@ -434,12 +446,12 @@ def object_show(
434446
response = self._request('HEAD', "%s/%s" %
435447
(urllib.parse.quote(container),
436448
urllib.parse.quote(object)))
449+
437450
data = {
438451
'account': self._find_account_id(),
439452
'container': container,
440453
'object': object,
441454
'content-type': response.headers.get('content-type', None),
442-
'meta-owner': response.headers.get('x-container-meta-owner', None),
443455
}
444456
if 'content-length' in response.headers:
445457
data['content-length'] = response.headers.get(
@@ -455,19 +467,10 @@ def object_show(
455467
'x-object-manifest',
456468
None,
457469
)
458-
for key, value in six.iteritems(response.headers):
459-
if key.startswith('x-object-meta-'):
460-
data[key[len('x-object-meta-'):].lower()] = value
461-
elif key not in (
462-
'content-type',
463-
'content-length',
464-
'last-modified',
465-
'etag',
466-
'date',
467-
'x-object-manifest',
468-
'x-container-meta-owner',
469-
):
470-
data[key.lower()] = value
470+
471+
properties = self._get_properties(response.headers, 'x-object-meta-')
472+
if properties:
473+
data['properties'] = properties
471474

472475
return data
473476

@@ -495,12 +498,16 @@ def account_show(self):
495498
# catalog should be enough.
496499
response = self._request("HEAD", "")
497500
data = {}
498-
for k, v in response.headers.iteritems():
499-
data[k] = v
501+
502+
properties = self._get_properties(response.headers, 'x-account-meta-')
503+
if properties:
504+
data['properties'] = properties
505+
500506
# Map containers, bytes and objects a bit nicer
501-
data['Containers'] = data.pop('x-account-container-count', None)
502-
data['Objects'] = data.pop('x-account-object-count', None)
503-
data['Bytes'] = data.pop('x-account-bytes-used', None)
507+
data['Containers'] = response.headers.get('x-account-container-count',
508+
None)
509+
data['Objects'] = response.headers.get('x-account-object-count', None)
510+
data['Bytes'] = response.headers.get('x-account-bytes-used', None)
504511
# Add in Account info too
505512
data['Account'] = self._find_account_id()
506513
return data
@@ -549,3 +556,12 @@ def _set_properties(self, properties, header_tag):
549556
header_name = header_tag % k
550557
headers[header_name] = v
551558
return headers
559+
560+
def _get_properties(self, headers, header_tag):
561+
# Add in properties as a top level key, this is consistent with other
562+
# OSC commands
563+
properties = {}
564+
for k, v in six.iteritems(headers):
565+
if k.startswith(header_tag):
566+
properties[k[len(header_tag):]] = v
567+
return properties

openstackclient/object/v1/account.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class ShowAccount(show.ShowOne):
5555
@utils.log_method(log)
5656
def take_action(self, parsed_args):
5757
data = self.app.client_manager.object_store.account_show()
58+
if 'properties' in data:
59+
data['properties'] = utils.format_dict(data.pop('properties'))
5860
return zip(*sorted(six.iteritems(data)))
5961

6062

openstackclient/object/v1/container.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ def take_action(self, parsed_args):
229229
data = self.app.client_manager.object_store.container_show(
230230
container=parsed_args.container,
231231
)
232+
if 'properties' in data:
233+
data['properties'] = utils.format_dict(data.pop('properties'))
232234

233235
return zip(*sorted(six.iteritems(data)))
234236

openstackclient/object/v1/object.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ def take_action(self, parsed_args):
284284
container=parsed_args.container,
285285
object=parsed_args.object,
286286
)
287+
if 'properties' in data:
288+
data['properties'] = utils.format_dict(data.pop('properties'))
287289

288290
return zip(*sorted(six.iteritems(data)))
289291

openstackclient/tests/api/test_object_store_v1.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,6 @@ def test_container_show(self):
157157
'container': 'qaz',
158158
'object_count': '1',
159159
'bytes_used': '577',
160-
'meta-owner': FAKE_ACCOUNT,
161-
'read_acl': None,
162-
'write_acl': None,
163-
'sync_to': None,
164-
'sync_key': None,
165160
}
166161
self.requests_mock.register_uri(
167162
'HEAD',
@@ -323,10 +318,8 @@ def test_object_show(self):
323318
'content-type': 'text/alpha',
324319
'content-length': '577',
325320
'last-modified': '20130101',
326-
'meta-owner': FAKE_ACCOUNT,
327321
'etag': 'qaz',
328-
'wife': 'Wilma',
329-
'x-tra-header': 'yabba-dabba-do',
322+
'properties': {'wife': 'Wilma'},
330323
}
331324
self.requests_mock.register_uri(
332325
'HEAD',

openstackclient/tests/object/v1/test_container_all.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ def setUp(self):
286286

287287
def test_object_show_container(self):
288288
headers = {
289-
'x-container-meta-owner': object_fakes.ACCOUNT_ID,
290289
'x-container-object-count': '42',
291290
'x-container-bytes-used': '123',
292291
'x-container-read': 'qaz',
@@ -316,7 +315,6 @@ def test_object_show_container(self):
316315
'account',
317316
'bytes_used',
318317
'container',
319-
'meta-owner',
320318
'object_count',
321319
'read_acl',
322320
'sync_key',
@@ -328,7 +326,6 @@ def test_object_show_container(self):
328326
object_fakes.ACCOUNT_ID,
329327
'123',
330328
'ernie',
331-
object_fakes.ACCOUNT_ID,
332329
'42',
333330
'qaz',
334331
'rfv',

openstackclient/tests/object/v1/test_object_all.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ def test_object_show(self):
160160
'content-type',
161161
'etag',
162162
'last-modified',
163-
'meta-owner',
164163
'object',
165164
'x-object-manifest',
166165
)
@@ -172,7 +171,6 @@ def test_object_show(self):
172171
'text/plain',
173172
'4c4e39a763d58392724bccf76a58783a',
174173
'yesterday',
175-
object_fakes.ACCOUNT_ID,
176174
object_fakes.object_name_1,
177175
'manifest',
178176
)

0 commit comments

Comments
 (0)