Fix object_client methods to accept headers and query param
Many of the method of object_client accept many headers and query param. This commit makes them to accept all headers and query param. Partially implements blueprint consistent-service-method-names Change-Id: I80668c00a38db00958bbe54421e69798d54482d7
This commit is contained in:
parent
88eadcf26d
commit
f36476e65a
@ -40,10 +40,10 @@ class ObjectExpiryTest(base.BaseObjectTest):
|
||||
def _test_object_expiry(self, metadata):
|
||||
# update object metadata
|
||||
resp, _ = \
|
||||
self.object_client.update_object_metadata(self.container_name,
|
||||
self.object_name,
|
||||
metadata,
|
||||
metadata_prefix='')
|
||||
self.object_client.create_or_update_object_metadata(
|
||||
self.container_name,
|
||||
self.object_name,
|
||||
headers=metadata)
|
||||
# verify object metadata
|
||||
resp, _ = \
|
||||
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)
|
||||
|
||||
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,
|
||||
object_name,
|
||||
metadata,
|
||||
metadata_prefix='')
|
||||
headers=metadata)
|
||||
self.assertHeaders(resp, 'Object', 'POST')
|
||||
|
||||
resp, _ = self.object_client.list_object_metadata(
|
||||
@ -354,11 +353,10 @@ class ObjectTest(base.BaseObjectTest):
|
||||
metadata=create_metadata)
|
||||
|
||||
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,
|
||||
object_name,
|
||||
update_metadata,
|
||||
metadata_prefix='')
|
||||
headers=update_metadata)
|
||||
self.assertHeaders(resp, 'Object', 'POST')
|
||||
|
||||
resp, _ = self.object_client.list_object_metadata(
|
||||
@ -379,11 +377,10 @@ class ObjectTest(base.BaseObjectTest):
|
||||
|
||||
update_metadata = {'X-Object-Meta-test-meta2': 'Meta2',
|
||||
'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,
|
||||
object_name,
|
||||
update_metadata,
|
||||
metadata_prefix='')
|
||||
headers=update_metadata)
|
||||
self.assertHeaders(resp, 'Object', 'POST')
|
||||
|
||||
resp, _ = self.object_client.list_object_metadata(
|
||||
@ -407,11 +404,10 @@ class ObjectTest(base.BaseObjectTest):
|
||||
metadata=None)
|
||||
object_prefix = '%s/%s' % (self.container_name, object_name)
|
||||
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,
|
||||
object_name,
|
||||
update_metadata,
|
||||
metadata_prefix='')
|
||||
headers=update_metadata)
|
||||
self.assertHeaders(resp, 'Object', 'POST')
|
||||
|
||||
resp, _ = self.object_client.list_object_metadata(
|
||||
@ -426,11 +422,10 @@ class ObjectTest(base.BaseObjectTest):
|
||||
object_name, _ = self.create_object(self.container_name)
|
||||
|
||||
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,
|
||||
object_name,
|
||||
update_metadata,
|
||||
metadata_prefix='')
|
||||
headers=update_metadata)
|
||||
self.assertHeaders(resp, 'Object', 'POST')
|
||||
|
||||
resp, _ = self.object_client.list_object_metadata(
|
||||
@ -451,11 +446,10 @@ class ObjectTest(base.BaseObjectTest):
|
||||
metadata=create_metadata)
|
||||
|
||||
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,
|
||||
object_name,
|
||||
update_metadata,
|
||||
metadata_prefix='')
|
||||
headers=update_metadata)
|
||||
self.assertHeaders(resp, 'Object', 'POST')
|
||||
|
||||
resp, _ = self.object_client.list_object_metadata(
|
||||
@ -816,10 +810,11 @@ class ObjectTest(base.BaseObjectTest):
|
||||
# set object metadata
|
||||
meta_key = data_utils.rand_name(name='test')
|
||||
meta_value = data_utils.rand_name(name='MetaValue')
|
||||
orig_metadata = {meta_key: meta_value}
|
||||
resp, _ = self.object_client.update_object_metadata(src_container_name,
|
||||
object_name,
|
||||
orig_metadata)
|
||||
orig_metadata = {'X-Object-Meta-' + meta_key: meta_value}
|
||||
resp, _ = self.object_client.create_or_update_object_metadata(
|
||||
src_container_name,
|
||||
object_name,
|
||||
headers=orig_metadata)
|
||||
self.assertHeaders(resp, 'Object', 'POST')
|
||||
|
||||
# copy object from source container to destination container
|
||||
@ -926,8 +921,8 @@ class ObjectTest(base.BaseObjectTest):
|
||||
object_name, data='')
|
||||
self.assertHeaders(resp, 'Object', 'PUT')
|
||||
|
||||
resp, _ = self.object_client.update_object_metadata(
|
||||
self.container_name, object_name, metadata, metadata_prefix='')
|
||||
resp, _ = self.object_client.create_or_update_object_metadata(
|
||||
self.container_name, object_name, headers=metadata)
|
||||
self.assertHeaders(resp, 'Object', 'POST')
|
||||
|
||||
resp, _ = self.object_client.list_object_metadata(
|
||||
|
@ -51,28 +51,27 @@ class ObjectClient(rest_client.RestClient):
|
||||
self.expected_success([200, 204], resp.status)
|
||||
return resp, body
|
||||
|
||||
def update_object_metadata(self, container, object_name, metadata,
|
||||
metadata_prefix='X-Object-Meta-'):
|
||||
def create_or_update_object_metadata(self, container, object_name,
|
||||
headers=None):
|
||||
"""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))
|
||||
resp, body = self.post(url, None, headers=headers)
|
||||
self.expected_success(202, resp.status)
|
||||
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."""
|
||||
|
||||
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)
|
||||
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."""
|
||||
|
||||
headers = {}
|
||||
@ -81,6 +80,8 @@ class ObjectClient(rest_client.RestClient):
|
||||
headers[str(key)] = metadata[key]
|
||||
|
||||
url = "{0}/{1}".format(container, object_name)
|
||||
if params:
|
||||
url += '?%s' % urlparse.urlencode(params)
|
||||
resp, body = self.get(url, headers=headers)
|
||||
self.expected_success([200, 206], resp.status)
|
||||
return resp, body
|
||||
@ -117,8 +118,7 @@ class ObjectClient(rest_client.RestClient):
|
||||
path = str(parsed.path) + "/"
|
||||
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
|
||||
conn.putrequest('PUT', path)
|
||||
|
||||
@ -152,7 +152,7 @@ class ObjectClient(rest_client.RestClient):
|
||||
return resp.status, resp.reason
|
||||
|
||||
|
||||
def create_connection(parsed_url):
|
||||
def _create_connection(parsed_url):
|
||||
"""Helper function to create connection with httplib
|
||||
|
||||
: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,
|
||||
'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):
|
||||
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):
|
||||
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):
|
||||
self._validate_create_object_continue('hello', mock_poc,
|
||||
initial_status=201)
|
||||
|
Loading…
Reference in New Issue
Block a user