Merge "Make it easier to give swift objects metadata"

This commit is contained in:
Jenkins 2016-05-31 15:38:24 +00:00 committed by Gerrit Code Review
commit ba5c6463af
2 changed files with 14 additions and 4 deletions

View File

@ -4621,7 +4621,7 @@ class OpenStackCloud(object):
def create_object(
self, container, name, filename=None,
md5=None, sha256=None, segment_size=None,
use_slo=True,
use_slo=True, metadata=None,
**headers):
"""Create a file object
@ -4644,9 +4644,14 @@ class OpenStackCloud(object):
Object, use a static rather than dyanmic object. Static Objects
will delete segment objects when the manifest object is deleted.
(optional, defaults to True)
:param metadata: This dict will get changed into headers that set
metadata of the object
:raises: ``OpenStackCloudException`` on operation error.
"""
if not metadata:
metadata = {}
if not filename:
filename = name
@ -4657,6 +4662,8 @@ class OpenStackCloud(object):
headers[OBJECT_MD5_KEY] = md5
headers[OBJECT_SHA256_KEY] = sha256
header_list = sorted([':'.join([k, v]) for (k, v) in headers.items()])
for (k, v) in metadata.items():
header_list.append(':'.join(['x-object-meta-' + k, v]))
# On some clouds this is not necessary. On others it is. I'm confused.
self.create_container(container)

View File

@ -55,14 +55,17 @@ class TestObject(base.BaseFunctionalTestCase):
self.demo_cloud.create_object(
container_name, name,
sparse_file.name,
segment_size=segment_size)
segment_size=segment_size,
metadata={'foo': 'bar'})
self.assertFalse(self.demo_cloud.is_object_stale(
container_name, name,
sparse_file.name
)
)
self.assertIsNotNone(
self.demo_cloud.get_object_metadata(container_name, name))
self.assertEqual(
'bar', self.demo_cloud.get_object_metadata(
container_name, name)['x-object-meta-foo']
)
self.assertIsNotNone(
self.demo_cloud.get_object(container_name, name))
self.assertEqual(