Merge "object_store: exposes the prefix parameter"
This commit is contained in:
@@ -7412,7 +7412,7 @@ class _OpenStackCloudMixin(_normalize.Normalizer):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def list_containers(self, full_listing=True):
|
def list_containers(self, full_listing=True, prefix=None):
|
||||||
"""List containers.
|
"""List containers.
|
||||||
|
|
||||||
:param full_listing: Ignored. Present for backwards compat
|
:param full_listing: Ignored. Present for backwards compat
|
||||||
@@ -7421,7 +7421,8 @@ class _OpenStackCloudMixin(_normalize.Normalizer):
|
|||||||
|
|
||||||
:raises: OpenStackCloudException on operation error.
|
:raises: OpenStackCloudException on operation error.
|
||||||
"""
|
"""
|
||||||
response = self.object_store.get('/', params=dict(format='json'))
|
params = dict(format='json', prefix=prefix)
|
||||||
|
response = self.object_store.get('/', params=params)
|
||||||
return self._get_and_munchify(None, _adapter._json_response(response))
|
return self._get_and_munchify(None, _adapter._json_response(response))
|
||||||
|
|
||||||
def search_containers(self, name=None, filters=None):
|
def search_containers(self, name=None, filters=None):
|
||||||
@@ -7971,18 +7972,21 @@ class _OpenStackCloudMixin(_normalize.Normalizer):
|
|||||||
container=container, object=name),
|
container=container, object=name),
|
||||||
headers=headers)
|
headers=headers)
|
||||||
|
|
||||||
def list_objects(self, container, full_listing=True):
|
def list_objects(self, container, full_listing=True, prefix=None):
|
||||||
"""List objects.
|
"""List objects.
|
||||||
|
|
||||||
:param container: Name of the container to list objects in.
|
:param container: Name of the container to list objects in.
|
||||||
:param full_listing: Ignored. Present for backwards compat
|
:param full_listing: Ignored. Present for backwards compat
|
||||||
|
:param string prefix:
|
||||||
|
only objects with this prefix will be returned.
|
||||||
|
(optional)
|
||||||
|
|
||||||
:returns: list of Munch of the objects
|
:returns: list of Munch of the objects
|
||||||
|
|
||||||
:raises: OpenStackCloudException on operation error.
|
:raises: OpenStackCloudException on operation error.
|
||||||
"""
|
"""
|
||||||
data = self._object_store_client.get(
|
params = dict(format='json', prefix=prefix)
|
||||||
container, params=dict(format='json'))
|
data = self._object_store_client.get(container, params=params)
|
||||||
return self._get_and_munchify(None, data)
|
return self._get_and_munchify(None, data)
|
||||||
|
|
||||||
def search_objects(self, container, name=None, filters=None):
|
def search_objects(self, container, name=None, filters=None):
|
||||||
|
@@ -37,6 +37,10 @@ class Container(_base.BaseResource):
|
|||||||
allow_list = True
|
allow_list = True
|
||||||
allow_head = True
|
allow_head = True
|
||||||
|
|
||||||
|
_query_mapping = resource.QueryParameters(
|
||||||
|
'prefix',
|
||||||
|
)
|
||||||
|
|
||||||
# Container body data (when id=None)
|
# Container body data (when id=None)
|
||||||
#: The name of the container.
|
#: The name of the container.
|
||||||
name = resource.Body("name", alternate_id=True, alias='id')
|
name = resource.Body("name", alternate_id=True, alias='id')
|
||||||
|
@@ -39,6 +39,10 @@ class Object(_base.BaseResource):
|
|||||||
allow_list = True
|
allow_list = True
|
||||||
allow_head = True
|
allow_head = True
|
||||||
|
|
||||||
|
_query_mapping = resource.QueryParameters(
|
||||||
|
'prefix',
|
||||||
|
)
|
||||||
|
|
||||||
# Data to be passed during a POST call to create an object on the server.
|
# Data to be passed during a POST call to create an object on the server.
|
||||||
# TODO(mordred) Make a base class BaseDataResource that can be used here
|
# TODO(mordred) Make a base class BaseDataResource that can be used here
|
||||||
# and with glance images that has standard overrides for dealing with
|
# and with glance images that has standard overrides for dealing with
|
||||||
|
@@ -42,6 +42,8 @@ class TestObject(base.BaseFunctionalTest):
|
|||||||
self.user_cloud.create_container(container_name)
|
self.user_cloud.create_container(container_name)
|
||||||
self.assertEqual(container_name,
|
self.assertEqual(container_name,
|
||||||
self.user_cloud.list_containers()[0]['name'])
|
self.user_cloud.list_containers()[0]['name'])
|
||||||
|
self.assertEqual([],
|
||||||
|
self.user_cloud.list_containers(prefix='somethin'))
|
||||||
sizes = (
|
sizes = (
|
||||||
(64 * 1024, 1), # 64K, one segment
|
(64 * 1024, 1), # 64K, one segment
|
||||||
(64 * 1024, 5) # 64MB, 5 segments
|
(64 * 1024, 5) # 64MB, 5 segments
|
||||||
@@ -90,6 +92,10 @@ class TestObject(base.BaseFunctionalTest):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
name,
|
name,
|
||||||
self.user_cloud.list_objects(container_name)[0]['name'])
|
self.user_cloud.list_objects(container_name)[0]['name'])
|
||||||
|
self.assertEqual(
|
||||||
|
[],
|
||||||
|
self.user_cloud.list_objects(container_name,
|
||||||
|
prefix='abc'))
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
self.user_cloud.delete_object(container_name, name))
|
self.user_cloud.delete_object(container_name, name))
|
||||||
self.assertEqual([], self.user_cloud.list_objects(container_name))
|
self.assertEqual([], self.user_cloud.list_objects(container_name))
|
||||||
|
@@ -282,6 +282,25 @@ class TestObject(BaseTestObject):
|
|||||||
self.assert_calls()
|
self.assert_calls()
|
||||||
self.assertEqual(objects, ret)
|
self.assertEqual(objects, ret)
|
||||||
|
|
||||||
|
def test_list_objects_with_prefix(self):
|
||||||
|
endpoint = '{endpoint}?format=json&prefix=test'.format(
|
||||||
|
endpoint=self.container_endpoint)
|
||||||
|
|
||||||
|
objects = [{
|
||||||
|
u'bytes': 20304400896,
|
||||||
|
u'last_modified': u'2016-12-15T13:34:13.650090',
|
||||||
|
u'hash': u'daaf9ed2106d09bba96cf193d866445e',
|
||||||
|
u'name': self.object,
|
||||||
|
u'content_type': u'application/octet-stream'}]
|
||||||
|
|
||||||
|
self.register_uris([dict(method='GET', uri=endpoint, complete_qs=True,
|
||||||
|
json=objects)])
|
||||||
|
|
||||||
|
ret = self.cloud.list_objects(self.container, prefix='test')
|
||||||
|
|
||||||
|
self.assert_calls()
|
||||||
|
self.assertEqual(objects, ret)
|
||||||
|
|
||||||
def test_list_objects_exception(self):
|
def test_list_objects_exception(self):
|
||||||
endpoint = '{endpoint}?format=json'.format(
|
endpoint = '{endpoint}?format=json'.format(
|
||||||
endpoint=self.container_endpoint)
|
endpoint=self.container_endpoint)
|
||||||
|
Reference in New Issue
Block a user