Merge "More user-friendly output for object metadata"
This commit is contained in:
commit
ad66801915
@ -251,6 +251,10 @@ def print_obj_metadata(metadata):
|
|||||||
|
|
||||||
:raises: ValueError
|
:raises: ValueError
|
||||||
"""
|
"""
|
||||||
|
user_metadata = {}
|
||||||
|
sys_metadata = {}
|
||||||
|
other_metadata = {}
|
||||||
|
|
||||||
if not metadata:
|
if not metadata:
|
||||||
raise ValueError('Metadata is None')
|
raise ValueError('Metadata is None')
|
||||||
path = metadata.pop('name', '')
|
path = metadata.pop('name', '')
|
||||||
@ -280,7 +284,25 @@ def print_obj_metadata(metadata):
|
|||||||
else:
|
else:
|
||||||
print 'Timestamp: Not found in metadata'
|
print 'Timestamp: Not found in metadata'
|
||||||
|
|
||||||
print 'User Metadata: %s' % metadata
|
for key, value in metadata.iteritems():
|
||||||
|
if is_user_meta('Object', key):
|
||||||
|
user_metadata[key] = value
|
||||||
|
elif is_sys_meta('Object', key):
|
||||||
|
sys_metadata[key] = value
|
||||||
|
else:
|
||||||
|
other_metadata[key] = value
|
||||||
|
|
||||||
|
def print_metadata(title, items):
|
||||||
|
print title
|
||||||
|
if items:
|
||||||
|
for meta_key in sorted(items):
|
||||||
|
print ' %s: %s' % (meta_key, items[meta_key])
|
||||||
|
else:
|
||||||
|
print ' No metadata found'
|
||||||
|
|
||||||
|
print_metadata('System Metadata:', sys_metadata)
|
||||||
|
print_metadata('User Metadata:', user_metadata)
|
||||||
|
print_metadata('Other Metadata:', other_metadata)
|
||||||
|
|
||||||
|
|
||||||
def print_info(db_type, db_file, swift_dir='/etc/swift'):
|
def print_info(db_type, db_file, swift_dir='/etc/swift'):
|
||||||
|
@ -446,14 +446,14 @@ class TestPrintObjFullMeta(TestCliInfoBase):
|
|||||||
self.assertRaisesMessage(ValueError, 'Metadata is None',
|
self.assertRaisesMessage(ValueError, 'Metadata is None',
|
||||||
print_obj_metadata, [])
|
print_obj_metadata, [])
|
||||||
|
|
||||||
def reset_metadata():
|
def get_metadata(items):
|
||||||
md = dict(name='/AUTH_admin/c/dummy')
|
md = dict(name='/AUTH_admin/c/dummy')
|
||||||
md['Content-Type'] = 'application/octet-stream'
|
md['Content-Type'] = 'application/octet-stream'
|
||||||
md['X-Timestamp'] = 106.3
|
md['X-Timestamp'] = 106.3
|
||||||
md['X-Object-Meta-Mtime'] = '107.3'
|
md.update(items)
|
||||||
return md
|
return md
|
||||||
|
|
||||||
metadata = reset_metadata()
|
metadata = get_metadata({'X-Object-Meta-Mtime': '107.3'})
|
||||||
out = StringIO()
|
out = StringIO()
|
||||||
with mock.patch('sys.stdout', out):
|
with mock.patch('sys.stdout', out):
|
||||||
print_obj_metadata(metadata)
|
print_obj_metadata(metadata)
|
||||||
@ -464,17 +464,93 @@ class TestPrintObjFullMeta(TestCliInfoBase):
|
|||||||
Object hash: 128fdf98bddd1b1e8695f4340e67a67a
|
Object hash: 128fdf98bddd1b1e8695f4340e67a67a
|
||||||
Content-Type: application/octet-stream
|
Content-Type: application/octet-stream
|
||||||
Timestamp: 1970-01-01T00:01:46.300000 (%s)
|
Timestamp: 1970-01-01T00:01:46.300000 (%s)
|
||||||
User Metadata: {'X-Object-Meta-Mtime': '107.3'}''' % (
|
System Metadata:
|
||||||
|
No metadata found
|
||||||
|
User Metadata:
|
||||||
|
X-Object-Meta-Mtime: 107.3
|
||||||
|
Other Metadata:
|
||||||
|
No metadata found''' % (
|
||||||
utils.Timestamp(106.3).internal)
|
utils.Timestamp(106.3).internal)
|
||||||
|
|
||||||
self.assertEquals(out.getvalue().strip(), exp_out)
|
self.assertEquals(out.getvalue().strip(), exp_out)
|
||||||
|
|
||||||
metadata = reset_metadata()
|
metadata = get_metadata({
|
||||||
|
'X-Object-Sysmeta-Mtime': '107.3',
|
||||||
|
'X-Object-Sysmeta-Name': 'Obj name',
|
||||||
|
})
|
||||||
|
out = StringIO()
|
||||||
|
with mock.patch('sys.stdout', out):
|
||||||
|
print_obj_metadata(metadata)
|
||||||
|
exp_out = '''Path: /AUTH_admin/c/dummy
|
||||||
|
Account: AUTH_admin
|
||||||
|
Container: c
|
||||||
|
Object: dummy
|
||||||
|
Object hash: 128fdf98bddd1b1e8695f4340e67a67a
|
||||||
|
Content-Type: application/octet-stream
|
||||||
|
Timestamp: 1970-01-01T00:01:46.300000 (%s)
|
||||||
|
System Metadata:
|
||||||
|
X-Object-Sysmeta-Mtime: 107.3
|
||||||
|
X-Object-Sysmeta-Name: Obj name
|
||||||
|
User Metadata:
|
||||||
|
No metadata found
|
||||||
|
Other Metadata:
|
||||||
|
No metadata found''' % (
|
||||||
|
utils.Timestamp(106.3).internal)
|
||||||
|
|
||||||
|
self.assertEquals(out.getvalue().strip(), exp_out)
|
||||||
|
|
||||||
|
metadata = get_metadata({
|
||||||
|
'X-Object-Meta-Mtime': '107.3',
|
||||||
|
'X-Object-Sysmeta-Mtime': '107.3',
|
||||||
|
'X-Object-Mtime': '107.3',
|
||||||
|
})
|
||||||
|
out = StringIO()
|
||||||
|
with mock.patch('sys.stdout', out):
|
||||||
|
print_obj_metadata(metadata)
|
||||||
|
exp_out = '''Path: /AUTH_admin/c/dummy
|
||||||
|
Account: AUTH_admin
|
||||||
|
Container: c
|
||||||
|
Object: dummy
|
||||||
|
Object hash: 128fdf98bddd1b1e8695f4340e67a67a
|
||||||
|
Content-Type: application/octet-stream
|
||||||
|
Timestamp: 1970-01-01T00:01:46.300000 (%s)
|
||||||
|
System Metadata:
|
||||||
|
X-Object-Sysmeta-Mtime: 107.3
|
||||||
|
User Metadata:
|
||||||
|
X-Object-Meta-Mtime: 107.3
|
||||||
|
Other Metadata:
|
||||||
|
X-Object-Mtime: 107.3''' % (
|
||||||
|
utils.Timestamp(106.3).internal)
|
||||||
|
|
||||||
|
self.assertEquals(out.getvalue().strip(), exp_out)
|
||||||
|
|
||||||
|
metadata = get_metadata({})
|
||||||
|
out = StringIO()
|
||||||
|
with mock.patch('sys.stdout', out):
|
||||||
|
print_obj_metadata(metadata)
|
||||||
|
exp_out = '''Path: /AUTH_admin/c/dummy
|
||||||
|
Account: AUTH_admin
|
||||||
|
Container: c
|
||||||
|
Object: dummy
|
||||||
|
Object hash: 128fdf98bddd1b1e8695f4340e67a67a
|
||||||
|
Content-Type: application/octet-stream
|
||||||
|
Timestamp: 1970-01-01T00:01:46.300000 (%s)
|
||||||
|
System Metadata:
|
||||||
|
No metadata found
|
||||||
|
User Metadata:
|
||||||
|
No metadata found
|
||||||
|
Other Metadata:
|
||||||
|
No metadata found''' % (
|
||||||
|
utils.Timestamp(106.3).internal)
|
||||||
|
|
||||||
|
self.assertEquals(out.getvalue().strip(), exp_out)
|
||||||
|
|
||||||
|
metadata = get_metadata({'X-Object-Meta-Mtime': '107.3'})
|
||||||
metadata['name'] = '/a-s'
|
metadata['name'] = '/a-s'
|
||||||
self.assertRaisesMessage(ValueError, 'Path is invalid',
|
self.assertRaisesMessage(ValueError, 'Path is invalid',
|
||||||
print_obj_metadata, metadata)
|
print_obj_metadata, metadata)
|
||||||
|
|
||||||
metadata = reset_metadata()
|
metadata = get_metadata({'X-Object-Meta-Mtime': '107.3'})
|
||||||
del metadata['name']
|
del metadata['name']
|
||||||
out = StringIO()
|
out = StringIO()
|
||||||
with mock.patch('sys.stdout', out):
|
with mock.patch('sys.stdout', out):
|
||||||
@ -482,12 +558,17 @@ User Metadata: {'X-Object-Meta-Mtime': '107.3'}''' % (
|
|||||||
exp_out = '''Path: Not found in metadata
|
exp_out = '''Path: Not found in metadata
|
||||||
Content-Type: application/octet-stream
|
Content-Type: application/octet-stream
|
||||||
Timestamp: 1970-01-01T00:01:46.300000 (%s)
|
Timestamp: 1970-01-01T00:01:46.300000 (%s)
|
||||||
User Metadata: {'X-Object-Meta-Mtime': '107.3'}''' % (
|
System Metadata:
|
||||||
|
No metadata found
|
||||||
|
User Metadata:
|
||||||
|
X-Object-Meta-Mtime: 107.3
|
||||||
|
Other Metadata:
|
||||||
|
No metadata found''' % (
|
||||||
utils.Timestamp(106.3).internal)
|
utils.Timestamp(106.3).internal)
|
||||||
|
|
||||||
self.assertEquals(out.getvalue().strip(), exp_out)
|
self.assertEquals(out.getvalue().strip(), exp_out)
|
||||||
|
|
||||||
metadata = reset_metadata()
|
metadata = get_metadata({'X-Object-Meta-Mtime': '107.3'})
|
||||||
del metadata['Content-Type']
|
del metadata['Content-Type']
|
||||||
out = StringIO()
|
out = StringIO()
|
||||||
with mock.patch('sys.stdout', out):
|
with mock.patch('sys.stdout', out):
|
||||||
@ -499,12 +580,17 @@ User Metadata: {'X-Object-Meta-Mtime': '107.3'}''' % (
|
|||||||
Object hash: 128fdf98bddd1b1e8695f4340e67a67a
|
Object hash: 128fdf98bddd1b1e8695f4340e67a67a
|
||||||
Content-Type: Not found in metadata
|
Content-Type: Not found in metadata
|
||||||
Timestamp: 1970-01-01T00:01:46.300000 (%s)
|
Timestamp: 1970-01-01T00:01:46.300000 (%s)
|
||||||
User Metadata: {'X-Object-Meta-Mtime': '107.3'}''' % (
|
System Metadata:
|
||||||
|
No metadata found
|
||||||
|
User Metadata:
|
||||||
|
X-Object-Meta-Mtime: 107.3
|
||||||
|
Other Metadata:
|
||||||
|
No metadata found''' % (
|
||||||
utils.Timestamp(106.3).internal)
|
utils.Timestamp(106.3).internal)
|
||||||
|
|
||||||
self.assertEquals(out.getvalue().strip(), exp_out)
|
self.assertEquals(out.getvalue().strip(), exp_out)
|
||||||
|
|
||||||
metadata = reset_metadata()
|
metadata = get_metadata({'X-Object-Meta-Mtime': '107.3'})
|
||||||
del metadata['X-Timestamp']
|
del metadata['X-Timestamp']
|
||||||
out = StringIO()
|
out = StringIO()
|
||||||
with mock.patch('sys.stdout', out):
|
with mock.patch('sys.stdout', out):
|
||||||
@ -516,6 +602,11 @@ User Metadata: {'X-Object-Meta-Mtime': '107.3'}''' % (
|
|||||||
Object hash: 128fdf98bddd1b1e8695f4340e67a67a
|
Object hash: 128fdf98bddd1b1e8695f4340e67a67a
|
||||||
Content-Type: application/octet-stream
|
Content-Type: application/octet-stream
|
||||||
Timestamp: Not found in metadata
|
Timestamp: Not found in metadata
|
||||||
User Metadata: {'X-Object-Meta-Mtime': '107.3'}'''
|
System Metadata:
|
||||||
|
No metadata found
|
||||||
|
User Metadata:
|
||||||
|
X-Object-Meta-Mtime: 107.3
|
||||||
|
Other Metadata:
|
||||||
|
No metadata found'''
|
||||||
|
|
||||||
self.assertEquals(out.getvalue().strip(), exp_out)
|
self.assertEquals(out.getvalue().strip(), exp_out)
|
||||||
|
Loading…
Reference in New Issue
Block a user