Make list methods consistent for container client

Make the list methods naming and doc string consistent
for container clients.

Partially implements blueprint consistent-service-method-names

Change-Id: Ibc770eef75a74880231d18670478e6ec99c90d1f
This commit is contained in:
ghanshyam 2017-09-14 02:56:16 +03:00
parent 12c58abe82
commit 871b1a837e
8 changed files with 30 additions and 48 deletions

View File

@ -43,7 +43,7 @@ def delete_containers(containers, container_client, object_client):
for cont in containers:
try:
params = {'limit': 9999, 'format': 'json'}
_, objlist = container_client.list_container_contents(cont, params)
_, objlist = container_client.list_container_objects(cont, params)
# delete every object in the container
for obj in objlist:
test_utils.call_and_ignore_notfound_exc(

View File

@ -96,7 +96,7 @@ class BulkTest(base.BaseObjectTest):
self.assertIn(container_name, [b['name'] for b in body])
param = {'format': 'json'}
resp, contents_list = self.container_client.list_container_contents(
resp, contents_list = self.container_client.list_container_objects(
container_name, param)
self.assertHeaders(resp, 'Container', 'GET')

View File

@ -130,7 +130,7 @@ class ContainerTest(base.BaseObjectTest):
container_name = self.create_container()
object_name, _ = self.create_object(container_name)
resp, object_list = self.container_client.list_container_contents(
resp, object_list = self.container_client.list_container_objects(
container_name)
self.assertHeaders(resp, 'Container', 'GET')
self.assertEqual([object_name], object_list)
@ -140,7 +140,7 @@ class ContainerTest(base.BaseObjectTest):
# get empty container contents list
container_name = self.create_container()
resp, object_list = self.container_client.list_container_contents(
resp, object_list = self.container_client.list_container_objects(
container_name)
self.assertHeaders(resp, 'Container', 'GET')
self.assertEmpty(object_list)
@ -153,7 +153,7 @@ class ContainerTest(base.BaseObjectTest):
self.create_object(container_name, object_name)
params = {'delimiter': '/'}
resp, object_list = self.container_client.list_container_contents(
resp, object_list = self.container_client.list_container_objects(
container_name,
params=params)
self.assertHeaders(resp, 'Container', 'GET')
@ -166,7 +166,7 @@ class ContainerTest(base.BaseObjectTest):
object_name, _ = self.create_object(container_name)
params = {'end_marker': object_name + 'zzzz'}
resp, object_list = self.container_client.list_container_contents(
resp, object_list = self.container_client.list_container_objects(
container_name,
params=params)
self.assertHeaders(resp, 'Container', 'GET')
@ -179,7 +179,7 @@ class ContainerTest(base.BaseObjectTest):
self.create_object(container_name)
params = {'format': 'json'}
resp, object_list = self.container_client.list_container_contents(
resp, object_list = self.container_client.list_container_objects(
container_name,
params=params)
self.assertHeaders(resp, 'Container', 'GET')
@ -198,7 +198,7 @@ class ContainerTest(base.BaseObjectTest):
self.create_object(container_name)
params = {'format': 'xml'}
resp, object_list = self.container_client.list_container_contents(
resp, object_list = self.container_client.list_container_objects(
container_name,
params=params)
self.assertHeaders(resp, 'Container', 'GET')
@ -222,7 +222,7 @@ class ContainerTest(base.BaseObjectTest):
object_name, _ = self.create_object(container_name)
params = {'limit': data_utils.rand_int_id(1, 10000)}
resp, object_list = self.container_client.list_container_contents(
resp, object_list = self.container_client.list_container_objects(
container_name,
params=params)
self.assertHeaders(resp, 'Container', 'GET')
@ -235,7 +235,7 @@ class ContainerTest(base.BaseObjectTest):
object_name, _ = self.create_object(container_name)
params = {'marker': 'AaaaObject1234567890'}
resp, object_list = self.container_client.list_container_contents(
resp, object_list = self.container_client.list_container_objects(
container_name,
params=params)
self.assertHeaders(resp, 'Container', 'GET')
@ -250,7 +250,7 @@ class ContainerTest(base.BaseObjectTest):
self.create_object(container_name, object_name)
params = {'path': 'Swift'}
resp, object_list = self.container_client.list_container_contents(
resp, object_list = self.container_client.list_container_objects(
container_name,
params=params)
self.assertHeaders(resp, 'Container', 'GET')
@ -264,7 +264,7 @@ class ContainerTest(base.BaseObjectTest):
prefix_key = object_name[0:8]
params = {'prefix': prefix_key}
resp, object_list = self.container_client.list_container_contents(
resp, object_list = self.container_client.list_container_objects(
container_name,
params=params)
self.assertHeaders(resp, 'Container', 'GET')

View File

@ -141,7 +141,7 @@ class ContainerNegativeTest(base.BaseObjectTest):
# that doesn't exist.
params = {'limit': 9999, 'format': 'json'}
self.assertRaises(exceptions.NotFound,
self.container_client.list_container_contents,
self.container_client.list_container_objects,
'nonexistent_container_name', params)
@decorators.attr(type=["negative"])
@ -155,7 +155,7 @@ class ContainerNegativeTest(base.BaseObjectTest):
self.assertHeaders(resp, 'Container', 'DELETE')
params = {'limit': 9999, 'format': 'json'}
self.assertRaises(exceptions.NotFound,
self.container_client.list_container_contents,
self.container_client.list_container_objects,
container_name, params)
@decorators.attr(type=["negative"])

View File

@ -102,7 +102,7 @@ class ContainerSyncTest(base.BaseObjectTest):
while self.attempts > 0:
object_lists = []
for c_client, cont in zip(cont_client, self.containers):
resp, object_list = c_client.list_container_contents(
resp, object_list = c_client.list_container_objects(
cont, params=params)
object_lists.append(dict(
(obj['name'], obj) for obj in object_list))

View File

@ -172,6 +172,6 @@ class ObjectSloTest(base.BaseObjectTest):
# Check only the format of common headers with custom matcher
self.assertThat(resp, custom_matchers.AreAllWellFormatted())
resp, body = self.container_client.list_container_contents(
resp, body = self.container_client.list_container_objects(
self.container_name)
self.assertEqual(int(resp['x-container-object-count']), 0)

View File

@ -1355,7 +1355,7 @@ class ObjectStorageScenarioTest(ScenarioTest):
present_obj = []
if not_present_obj is None:
not_present_obj = []
_, object_list = self.container_client.list_container_contents(
_, object_list = self.container_client.list_container_objects(
container_name)
if present_obj:
for obj in present_obj:

View File

@ -15,6 +15,7 @@
from xml.etree import ElementTree as etree
import debtcollector.moves
from oslo_serialization import jsonutils as json
from six.moves.urllib import parse as urllib
@ -90,47 +91,24 @@ class ContainerClient(rest_client.RestClient):
return resp, body
def list_container_metadata(self, container_name):
"""Retrieves container metadata headers"""
"""List all container metadata."""
url = str(container_name)
resp, body = self.head(url)
self.expected_success(204, resp.status)
return resp, body
def list_container_contents(self, container, params=None):
def list_container_objects(self, container_name, params=None):
"""List the objects in a container, given the container name
Returns the container object listing as a plain text list, or as
xml or json if that option is specified via the 'format' argument.
Returns the container object listing as a plain text list, or as
xml or json if that option is specified via the 'format' argument.
Optional Arguments:
limit = integer
For an integer value n, limits the number of results to at most
n values.
marker = 'string'
Given a string value x, return object names greater in value
than the specified marker.
prefix = 'string'
For a string value x, causes the results to be limited to names
beginning with the substring x.
format = 'json' or 'xml'
Specify either json or xml to return the respective serialized
response.
If json, returns a list of json objects
if xml, returns a string of xml
path = 'string'
For a string value x, return the object names nested in the
pseudo path (assuming preconditions are met - see below).
delimiter = 'character'
For a character c, return all the object names nested in the
container (without the need for the directory marker objects).
For a full list of available parameters, please refer to the official
API reference:
https://developer.openstack.org/api-ref/object-storage/?expanded=show-container-details-and-list-objects-detail
"""
url = str(container)
url = str(container_name)
if params:
url += '?'
url += '&%s' % urllib.urlencode(params)
@ -148,3 +126,7 @@ class ContainerClient(rest_client.RestClient):
self.expected_success([200, 204], resp.status)
return resp, body
list_container_contents = debtcollector.moves.moved_function(
list_container_objects, 'list_container_contents', __name__,
version='Queens', removal_version='Rocky')