Merge "Fix object_client methods to accept headers and query param"
This commit is contained in:
commit
b28d78f1ff
@ -40,10 +40,10 @@ class ObjectExpiryTest(base.BaseObjectTest):
|
|||||||
def _test_object_expiry(self, metadata):
|
def _test_object_expiry(self, metadata):
|
||||||
# update object metadata
|
# update object metadata
|
||||||
resp, _ = \
|
resp, _ = \
|
||||||
self.object_client.update_object_metadata(self.container_name,
|
self.object_client.create_or_update_object_metadata(
|
||||||
self.object_name,
|
self.container_name,
|
||||||
metadata,
|
self.object_name,
|
||||||
metadata_prefix='')
|
headers=metadata)
|
||||||
# verify object metadata
|
# verify object metadata
|
||||||
resp, _ = \
|
resp, _ = \
|
||||||
self.object_client.list_object_metadata(self.container_name,
|
self.object_client.list_object_metadata(self.container_name,
|
||||||
|
@ -329,11 +329,10 @@ class ObjectTest(base.BaseObjectTest):
|
|||||||
object_name, _ = self.create_object(self.container_name)
|
object_name, _ = self.create_object(self.container_name)
|
||||||
|
|
||||||
metadata = {'X-Object-Meta-test-meta': 'Meta'}
|
metadata = {'X-Object-Meta-test-meta': 'Meta'}
|
||||||
resp, _ = self.object_client.update_object_metadata(
|
resp, _ = self.object_client.create_or_update_object_metadata(
|
||||||
self.container_name,
|
self.container_name,
|
||||||
object_name,
|
object_name,
|
||||||
metadata,
|
headers=metadata)
|
||||||
metadata_prefix='')
|
|
||||||
self.assertHeaders(resp, 'Object', 'POST')
|
self.assertHeaders(resp, 'Object', 'POST')
|
||||||
|
|
||||||
resp, _ = self.object_client.list_object_metadata(
|
resp, _ = self.object_client.list_object_metadata(
|
||||||
@ -354,11 +353,10 @@ class ObjectTest(base.BaseObjectTest):
|
|||||||
metadata=create_metadata)
|
metadata=create_metadata)
|
||||||
|
|
||||||
update_metadata = {'X-Remove-Object-Meta-test-meta1': 'Meta1'}
|
update_metadata = {'X-Remove-Object-Meta-test-meta1': 'Meta1'}
|
||||||
resp, _ = self.object_client.update_object_metadata(
|
resp, _ = self.object_client.create_or_update_object_metadata(
|
||||||
self.container_name,
|
self.container_name,
|
||||||
object_name,
|
object_name,
|
||||||
update_metadata,
|
headers=update_metadata)
|
||||||
metadata_prefix='')
|
|
||||||
self.assertHeaders(resp, 'Object', 'POST')
|
self.assertHeaders(resp, 'Object', 'POST')
|
||||||
|
|
||||||
resp, _ = self.object_client.list_object_metadata(
|
resp, _ = self.object_client.list_object_metadata(
|
||||||
@ -379,11 +377,10 @@ class ObjectTest(base.BaseObjectTest):
|
|||||||
|
|
||||||
update_metadata = {'X-Object-Meta-test-meta2': 'Meta2',
|
update_metadata = {'X-Object-Meta-test-meta2': 'Meta2',
|
||||||
'X-Remove-Object-Meta-test-meta1': 'Meta1'}
|
'X-Remove-Object-Meta-test-meta1': 'Meta1'}
|
||||||
resp, _ = self.object_client.update_object_metadata(
|
resp, _ = self.object_client.create_or_update_object_metadata(
|
||||||
self.container_name,
|
self.container_name,
|
||||||
object_name,
|
object_name,
|
||||||
update_metadata,
|
headers=update_metadata)
|
||||||
metadata_prefix='')
|
|
||||||
self.assertHeaders(resp, 'Object', 'POST')
|
self.assertHeaders(resp, 'Object', 'POST')
|
||||||
|
|
||||||
resp, _ = self.object_client.list_object_metadata(
|
resp, _ = self.object_client.list_object_metadata(
|
||||||
@ -407,11 +404,10 @@ class ObjectTest(base.BaseObjectTest):
|
|||||||
metadata=None)
|
metadata=None)
|
||||||
object_prefix = '%s/%s' % (self.container_name, object_name)
|
object_prefix = '%s/%s' % (self.container_name, object_name)
|
||||||
update_metadata = {'X-Object-Manifest': object_prefix}
|
update_metadata = {'X-Object-Manifest': object_prefix}
|
||||||
resp, _ = self.object_client.update_object_metadata(
|
resp, _ = self.object_client.create_or_update_object_metadata(
|
||||||
self.container_name,
|
self.container_name,
|
||||||
object_name,
|
object_name,
|
||||||
update_metadata,
|
headers=update_metadata)
|
||||||
metadata_prefix='')
|
|
||||||
self.assertHeaders(resp, 'Object', 'POST')
|
self.assertHeaders(resp, 'Object', 'POST')
|
||||||
|
|
||||||
resp, _ = self.object_client.list_object_metadata(
|
resp, _ = self.object_client.list_object_metadata(
|
||||||
@ -426,11 +422,10 @@ class ObjectTest(base.BaseObjectTest):
|
|||||||
object_name, _ = self.create_object(self.container_name)
|
object_name, _ = self.create_object(self.container_name)
|
||||||
|
|
||||||
update_metadata = {'X-Object-Meta-test-meta': ''}
|
update_metadata = {'X-Object-Meta-test-meta': ''}
|
||||||
resp, _ = self.object_client.update_object_metadata(
|
resp, _ = self.object_client.create_or_update_object_metadata(
|
||||||
self.container_name,
|
self.container_name,
|
||||||
object_name,
|
object_name,
|
||||||
update_metadata,
|
headers=update_metadata)
|
||||||
metadata_prefix='')
|
|
||||||
self.assertHeaders(resp, 'Object', 'POST')
|
self.assertHeaders(resp, 'Object', 'POST')
|
||||||
|
|
||||||
resp, _ = self.object_client.list_object_metadata(
|
resp, _ = self.object_client.list_object_metadata(
|
||||||
@ -451,11 +446,10 @@ class ObjectTest(base.BaseObjectTest):
|
|||||||
metadata=create_metadata)
|
metadata=create_metadata)
|
||||||
|
|
||||||
update_metadata = {'X-Remove-Object-Meta-test-meta': ''}
|
update_metadata = {'X-Remove-Object-Meta-test-meta': ''}
|
||||||
resp, _ = self.object_client.update_object_metadata(
|
resp, _ = self.object_client.create_or_update_object_metadata(
|
||||||
self.container_name,
|
self.container_name,
|
||||||
object_name,
|
object_name,
|
||||||
update_metadata,
|
headers=update_metadata)
|
||||||
metadata_prefix='')
|
|
||||||
self.assertHeaders(resp, 'Object', 'POST')
|
self.assertHeaders(resp, 'Object', 'POST')
|
||||||
|
|
||||||
resp, _ = self.object_client.list_object_metadata(
|
resp, _ = self.object_client.list_object_metadata(
|
||||||
@ -816,10 +810,11 @@ class ObjectTest(base.BaseObjectTest):
|
|||||||
# set object metadata
|
# set object metadata
|
||||||
meta_key = data_utils.rand_name(name='test')
|
meta_key = data_utils.rand_name(name='test')
|
||||||
meta_value = data_utils.rand_name(name='MetaValue')
|
meta_value = data_utils.rand_name(name='MetaValue')
|
||||||
orig_metadata = {meta_key: meta_value}
|
orig_metadata = {'X-Object-Meta-' + meta_key: meta_value}
|
||||||
resp, _ = self.object_client.update_object_metadata(src_container_name,
|
resp, _ = self.object_client.create_or_update_object_metadata(
|
||||||
object_name,
|
src_container_name,
|
||||||
orig_metadata)
|
object_name,
|
||||||
|
headers=orig_metadata)
|
||||||
self.assertHeaders(resp, 'Object', 'POST')
|
self.assertHeaders(resp, 'Object', 'POST')
|
||||||
|
|
||||||
# copy object from source container to destination container
|
# copy object from source container to destination container
|
||||||
@ -926,8 +921,8 @@ class ObjectTest(base.BaseObjectTest):
|
|||||||
object_name, data='')
|
object_name, data='')
|
||||||
self.assertHeaders(resp, 'Object', 'PUT')
|
self.assertHeaders(resp, 'Object', 'PUT')
|
||||||
|
|
||||||
resp, _ = self.object_client.update_object_metadata(
|
resp, _ = self.object_client.create_or_update_object_metadata(
|
||||||
self.container_name, object_name, metadata, metadata_prefix='')
|
self.container_name, object_name, headers=metadata)
|
||||||
self.assertHeaders(resp, 'Object', 'POST')
|
self.assertHeaders(resp, 'Object', 'POST')
|
||||||
|
|
||||||
resp, _ = self.object_client.list_object_metadata(
|
resp, _ = self.object_client.list_object_metadata(
|
||||||
|
@ -51,28 +51,27 @@ class ObjectClient(rest_client.RestClient):
|
|||||||
self.expected_success([200, 204], resp.status)
|
self.expected_success([200, 204], resp.status)
|
||||||
return resp, body
|
return resp, body
|
||||||
|
|
||||||
def update_object_metadata(self, container, object_name, metadata,
|
def create_or_update_object_metadata(self, container, object_name,
|
||||||
metadata_prefix='X-Object-Meta-'):
|
headers=None):
|
||||||
"""Add, remove, or change X-Object-Meta metadata for storage object."""
|
"""Add, remove, or change X-Object-Meta metadata for storage object."""
|
||||||
|
|
||||||
headers = {}
|
|
||||||
for key in metadata:
|
|
||||||
headers["%s%s" % (str(metadata_prefix), str(key))] = metadata[key]
|
|
||||||
|
|
||||||
url = "%s/%s" % (str(container), str(object_name))
|
url = "%s/%s" % (str(container), str(object_name))
|
||||||
resp, body = self.post(url, None, headers=headers)
|
resp, body = self.post(url, None, headers=headers)
|
||||||
self.expected_success(202, resp.status)
|
self.expected_success(202, resp.status)
|
||||||
return resp, body
|
return resp, body
|
||||||
|
|
||||||
def list_object_metadata(self, container, object_name):
|
def list_object_metadata(self, container, object_name,
|
||||||
|
params=None, headers=None):
|
||||||
"""List all storage object X-Object-Meta- metadata."""
|
"""List all storage object X-Object-Meta- metadata."""
|
||||||
|
|
||||||
url = "%s/%s" % (str(container), str(object_name))
|
url = "%s/%s" % (str(container), str(object_name))
|
||||||
resp, body = self.head(url)
|
if params:
|
||||||
|
url += '?%s' % urlparse.urlencode(params)
|
||||||
|
resp, body = self.head(url, headers=headers)
|
||||||
self.expected_success(200, resp.status)
|
self.expected_success(200, resp.status)
|
||||||
return resp, body
|
return resp, body
|
||||||
|
|
||||||
def get_object(self, container, object_name, metadata=None):
|
def get_object(self, container, object_name, metadata=None, params=None):
|
||||||
"""Retrieve object's data."""
|
"""Retrieve object's data."""
|
||||||
|
|
||||||
headers = {}
|
headers = {}
|
||||||
@ -81,6 +80,8 @@ class ObjectClient(rest_client.RestClient):
|
|||||||
headers[str(key)] = metadata[key]
|
headers[str(key)] = metadata[key]
|
||||||
|
|
||||||
url = "{0}/{1}".format(container, object_name)
|
url = "{0}/{1}".format(container, object_name)
|
||||||
|
if params:
|
||||||
|
url += '?%s' % urlparse.urlencode(params)
|
||||||
resp, body = self.get(url, headers=headers)
|
resp, body = self.get(url, headers=headers)
|
||||||
self.expected_success([200, 206], resp.status)
|
self.expected_success([200, 206], resp.status)
|
||||||
return resp, body
|
return resp, body
|
||||||
@ -117,8 +118,7 @@ class ObjectClient(rest_client.RestClient):
|
|||||||
path = str(parsed.path) + "/"
|
path = str(parsed.path) + "/"
|
||||||
path += "%s/%s" % (str(container), str(object_name))
|
path += "%s/%s" % (str(container), str(object_name))
|
||||||
|
|
||||||
conn = create_connection(parsed)
|
conn = _create_connection(parsed)
|
||||||
|
|
||||||
# Send the PUT request and the headers including the "Expect" header
|
# Send the PUT request and the headers including the "Expect" header
|
||||||
conn.putrequest('PUT', path)
|
conn.putrequest('PUT', path)
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ class ObjectClient(rest_client.RestClient):
|
|||||||
return resp.status, resp.reason
|
return resp.status, resp.reason
|
||||||
|
|
||||||
|
|
||||||
def create_connection(parsed_url):
|
def _create_connection(parsed_url):
|
||||||
"""Helper function to create connection with httplib
|
"""Helper function to create connection with httplib
|
||||||
|
|
||||||
:param parsed_url: parsed url of the remote location
|
:param parsed_url: parsed url of the remote location
|
||||||
|
@ -31,15 +31,15 @@ class TestObjectClient(base.TestCase):
|
|||||||
self.object_client = object_client.ObjectClient(self.fake_auth,
|
self.object_client = object_client.ObjectClient(self.fake_auth,
|
||||||
'swift', 'region1')
|
'swift', 'region1')
|
||||||
|
|
||||||
@mock.patch.object(object_client, 'create_connection')
|
@mock.patch.object(object_client, '_create_connection')
|
||||||
def test_create_object_continue_no_data(self, mock_poc):
|
def test_create_object_continue_no_data(self, mock_poc):
|
||||||
self._validate_create_object_continue(None, mock_poc)
|
self._validate_create_object_continue(None, mock_poc)
|
||||||
|
|
||||||
@mock.patch.object(object_client, 'create_connection')
|
@mock.patch.object(object_client, '_create_connection')
|
||||||
def test_create_object_continue_with_data(self, mock_poc):
|
def test_create_object_continue_with_data(self, mock_poc):
|
||||||
self._validate_create_object_continue('hello', mock_poc)
|
self._validate_create_object_continue('hello', mock_poc)
|
||||||
|
|
||||||
@mock.patch.object(object_client, 'create_connection')
|
@mock.patch.object(object_client, '_create_connection')
|
||||||
def test_create_continue_with_no_continue_received(self, mock_poc):
|
def test_create_continue_with_no_continue_received(self, mock_poc):
|
||||||
self._validate_create_object_continue('hello', mock_poc,
|
self._validate_create_object_continue('hello', mock_poc,
|
||||||
initial_status=201)
|
initial_status=201)
|
||||||
|
Loading…
Reference in New Issue
Block a user