Change app.restapi to app.client_manager.session
This is step 1 toward using Keystone client's session.Session as the primary session/requests interface in OSC. * Move the session create into ClientManager and rename 'restapi' attribute to 'session' * Set up ClientManager and session loggers * Fix container and object command references to restapi/api Change-Id: I013d81520b336c7a6422cd22c05d1d65655e64f8
This commit is contained in:
parent
19b8605224
commit
4bbd03210f
@ -19,6 +19,7 @@ import logging
|
|||||||
import pkg_resources
|
import pkg_resources
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from openstackclient.common import restapi
|
||||||
from openstackclient.identity import client as identity_client
|
from openstackclient.identity import client as identity_client
|
||||||
|
|
||||||
|
|
||||||
@ -77,7 +78,18 @@ class ClientManager(object):
|
|||||||
self._insecure = not verify
|
self._insecure = not verify
|
||||||
else:
|
else:
|
||||||
self._cacert = verify
|
self._cacert = verify
|
||||||
self._insecure = True
|
self._insecure = False
|
||||||
|
|
||||||
|
self.session = restapi.RESTApi(
|
||||||
|
verify=verify,
|
||||||
|
debug=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Get logging from root logger
|
||||||
|
root_logger = logging.getLogger('')
|
||||||
|
LOG.setLevel(root_logger.getEffectiveLevel())
|
||||||
|
restapi_logger = logging.getLogger('restapi')
|
||||||
|
restapi_logger.setLevel(root_logger.getEffectiveLevel())
|
||||||
|
|
||||||
self.auth_ref = None
|
self.auth_ref = None
|
||||||
|
|
||||||
|
@ -66,7 +66,17 @@ def make_client(instance):
|
|||||||
insecure=instance._insecure,
|
insecure=instance._insecure,
|
||||||
trust_id=instance._trust_id,
|
trust_id=instance._trust_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# TODO(dtroyer): the identity v2 role commands use this yet, fix that
|
||||||
|
# so we can remove it
|
||||||
instance.auth_ref = client.auth_ref
|
instance.auth_ref = client.auth_ref
|
||||||
|
|
||||||
|
# NOTE(dtroyer): this is hanging around until restapi is replace by
|
||||||
|
# ksc session
|
||||||
|
instance.session.set_auth(
|
||||||
|
client.auth_ref.auth_token,
|
||||||
|
)
|
||||||
|
|
||||||
return client
|
return client
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ class CreateContainer(show.ShowOne):
|
|||||||
self.log.debug('take_action(%s)', parsed_args)
|
self.log.debug('take_action(%s)', parsed_args)
|
||||||
|
|
||||||
data = lib_container.create_container(
|
data = lib_container.create_container(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
self.app.client_manager.object_store.endpoint,
|
self.app.client_manager.object_store.endpoint,
|
||||||
parsed_args.container,
|
parsed_args.container,
|
||||||
)
|
)
|
||||||
@ -71,7 +71,7 @@ class DeleteContainer(command.Command):
|
|||||||
self.log.debug('take_action(%s)', parsed_args)
|
self.log.debug('take_action(%s)', parsed_args)
|
||||||
|
|
||||||
lib_container.delete_container(
|
lib_container.delete_container(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
self.app.client_manager.object_store.endpoint,
|
self.app.client_manager.object_store.endpoint,
|
||||||
parsed_args.container,
|
parsed_args.container,
|
||||||
)
|
)
|
||||||
@ -140,7 +140,7 @@ class ListContainer(lister.Lister):
|
|||||||
kwargs['full_listing'] = True
|
kwargs['full_listing'] = True
|
||||||
|
|
||||||
data = lib_container.list_containers(
|
data = lib_container.list_containers(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
self.app.client_manager.object_store.endpoint,
|
self.app.client_manager.object_store.endpoint,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
@ -170,7 +170,7 @@ class ShowContainer(show.ShowOne):
|
|||||||
self.log.debug('take_action(%s)', parsed_args)
|
self.log.debug('take_action(%s)', parsed_args)
|
||||||
|
|
||||||
data = lib_container.show_container(
|
data = lib_container.show_container(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
self.app.client_manager.object_store.endpoint,
|
self.app.client_manager.object_store.endpoint,
|
||||||
parsed_args.container,
|
parsed_args.container,
|
||||||
)
|
)
|
||||||
|
@ -23,46 +23,46 @@ except ImportError:
|
|||||||
|
|
||||||
|
|
||||||
def create_container(
|
def create_container(
|
||||||
api,
|
session,
|
||||||
url,
|
url,
|
||||||
container,
|
container,
|
||||||
):
|
):
|
||||||
"""Create a container
|
"""Create a container
|
||||||
|
|
||||||
:param api: a restapi object
|
:param session: a restapi object
|
||||||
:param url: endpoint
|
:param url: endpoint
|
||||||
:param container: name of container to create
|
:param container: name of container to create
|
||||||
:returns: dict of returned headers
|
:returns: dict of returned headers
|
||||||
"""
|
"""
|
||||||
|
|
||||||
response = api.put("%s/%s" % (url, container))
|
response = session.put("%s/%s" % (url, container))
|
||||||
url_parts = urlparse(url)
|
url_parts = urlparse(url)
|
||||||
data = {
|
data = {
|
||||||
'account': url_parts.path.split('/')[-1],
|
'account': url_parts.path.split('/')[-1],
|
||||||
'container': container,
|
'container': container,
|
||||||
|
'x-trans-id': response.headers.get('x-trans-id', None),
|
||||||
}
|
}
|
||||||
data['x-trans-id'] = response.headers.get('x-trans-id', None)
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def delete_container(
|
def delete_container(
|
||||||
api,
|
session,
|
||||||
url,
|
url,
|
||||||
container,
|
container,
|
||||||
):
|
):
|
||||||
"""Delete a container
|
"""Delete a container
|
||||||
|
|
||||||
:param api: a restapi object
|
:param session: a restapi object
|
||||||
:param url: endpoint
|
:param url: endpoint
|
||||||
:param container: name of container to delete
|
:param container: name of container to delete
|
||||||
"""
|
"""
|
||||||
|
|
||||||
api.delete("%s/%s" % (url, container))
|
session.delete("%s/%s" % (url, container))
|
||||||
|
|
||||||
|
|
||||||
def list_containers(
|
def list_containers(
|
||||||
api,
|
session,
|
||||||
url,
|
url,
|
||||||
marker=None,
|
marker=None,
|
||||||
limit=None,
|
limit=None,
|
||||||
@ -72,7 +72,7 @@ def list_containers(
|
|||||||
):
|
):
|
||||||
"""Get containers in an account
|
"""Get containers in an account
|
||||||
|
|
||||||
:param api: a restapi object
|
:param session: a restapi object
|
||||||
:param url: endpoint
|
:param url: endpoint
|
||||||
:param marker: marker query
|
:param marker: marker query
|
||||||
:param limit: limit query
|
:param limit: limit query
|
||||||
@ -85,7 +85,7 @@ def list_containers(
|
|||||||
|
|
||||||
if full_listing:
|
if full_listing:
|
||||||
data = listing = list_containers(
|
data = listing = list_containers(
|
||||||
api,
|
session,
|
||||||
url,
|
url,
|
||||||
marker,
|
marker,
|
||||||
limit,
|
limit,
|
||||||
@ -95,7 +95,7 @@ def list_containers(
|
|||||||
while listing:
|
while listing:
|
||||||
marker = listing[-1]['name']
|
marker = listing[-1]['name']
|
||||||
listing = list_containers(
|
listing = list_containers(
|
||||||
api,
|
session,
|
||||||
url,
|
url,
|
||||||
marker,
|
marker,
|
||||||
limit,
|
limit,
|
||||||
@ -117,34 +117,35 @@ def list_containers(
|
|||||||
params['end_marker'] = end_marker
|
params['end_marker'] = end_marker
|
||||||
if prefix:
|
if prefix:
|
||||||
params['prefix'] = prefix
|
params['prefix'] = prefix
|
||||||
return api.list(url, params=params)
|
return session.get(url, params=params).json()
|
||||||
|
|
||||||
|
|
||||||
def show_container(
|
def show_container(
|
||||||
api,
|
session,
|
||||||
url,
|
url,
|
||||||
container,
|
container,
|
||||||
):
|
):
|
||||||
"""Get container details
|
"""Get container details
|
||||||
|
|
||||||
:param api: a restapi object
|
:param session: a restapi object
|
||||||
:param url: endpoint
|
:param url: endpoint
|
||||||
:param container: name of container to show
|
:param container: name of container to show
|
||||||
:returns: dict of returned headers
|
:returns: dict of returned headers
|
||||||
"""
|
"""
|
||||||
|
|
||||||
response = api.head("%s/%s" % (url, container))
|
response = session.head("%s/%s" % (url, container))
|
||||||
url_parts = urlparse(url)
|
|
||||||
data = {
|
data = {
|
||||||
'account': url_parts.path.split('/')[-1],
|
'account': response.headers.get('x-container-meta-owner', None),
|
||||||
'container': container,
|
'container': container,
|
||||||
|
'object_count': response.headers.get(
|
||||||
|
'x-container-object-count',
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
'bytes_used': response.headers.get('x-container-bytes-used', None),
|
||||||
|
'read_acl': response.headers.get('x-container-read', None),
|
||||||
|
'write_acl': response.headers.get('x-container-write', None),
|
||||||
|
'sync_to': response.headers.get('x-container-sync-to', None),
|
||||||
|
'sync_key': response.headers.get('x-container-sync-key', None),
|
||||||
}
|
}
|
||||||
data['object_count'] = response.headers.get(
|
|
||||||
'x-container-object-count', None)
|
|
||||||
data['bytes_used'] = response.headers.get('x-container-bytes-used', None)
|
|
||||||
data['read_acl'] = response.headers.get('x-container-read', None)
|
|
||||||
data['write_acl'] = response.headers.get('x-container-write', None)
|
|
||||||
data['sync_to'] = response.headers.get('x-container-sync-to', None)
|
|
||||||
data['sync_key'] = response.headers.get('x-container-sync-key', None)
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
@ -25,14 +25,14 @@ except ImportError:
|
|||||||
|
|
||||||
|
|
||||||
def create_object(
|
def create_object(
|
||||||
api,
|
session,
|
||||||
url,
|
url,
|
||||||
container,
|
container,
|
||||||
object,
|
object,
|
||||||
):
|
):
|
||||||
"""Create an object, upload it to a container
|
"""Create an object, upload it to a container
|
||||||
|
|
||||||
:param api: a restapi object
|
:param session: a restapi object
|
||||||
:param url: endpoint
|
:param url: endpoint
|
||||||
:param container: name of container to store object
|
:param container: name of container to store object
|
||||||
:param object: local path to object
|
:param object: local path to object
|
||||||
@ -40,38 +40,38 @@ def create_object(
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
full_url = "%s/%s/%s" % (url, container, object)
|
full_url = "%s/%s/%s" % (url, container, object)
|
||||||
response = api.put(full_url, data=open(object))
|
response = session.put(full_url, data=open(object))
|
||||||
url_parts = urlparse(url)
|
url_parts = urlparse(url)
|
||||||
data = {
|
data = {
|
||||||
'account': url_parts.path.split('/')[-1],
|
'account': url_parts.path.split('/')[-1],
|
||||||
'container': container,
|
'container': container,
|
||||||
'object': object,
|
'object': object,
|
||||||
|
'x-trans-id': response.headers.get('X-Trans-Id', None),
|
||||||
|
'etag': response.headers.get('Etag', None),
|
||||||
}
|
}
|
||||||
data['x-trans-id'] = response.headers.get('X-Trans-Id', None)
|
|
||||||
data['etag'] = response.headers.get('Etag', None)
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def delete_object(
|
def delete_object(
|
||||||
api,
|
session,
|
||||||
url,
|
url,
|
||||||
container,
|
container,
|
||||||
object,
|
object,
|
||||||
):
|
):
|
||||||
"""Delete an object stored in a container
|
"""Delete an object stored in a container
|
||||||
|
|
||||||
:param api: a restapi object
|
:param session: a restapi object
|
||||||
:param url: endpoint
|
:param url: endpoint
|
||||||
:param container: name of container that stores object
|
:param container: name of container that stores object
|
||||||
:param container: name of object to delete
|
:param container: name of object to delete
|
||||||
"""
|
"""
|
||||||
|
|
||||||
api.delete("%s/%s/%s" % (url, container, object))
|
session.delete("%s/%s/%s" % (url, container, object))
|
||||||
|
|
||||||
|
|
||||||
def list_objects(
|
def list_objects(
|
||||||
api,
|
session,
|
||||||
url,
|
url,
|
||||||
container,
|
container,
|
||||||
marker=None,
|
marker=None,
|
||||||
@ -84,7 +84,7 @@ def list_objects(
|
|||||||
):
|
):
|
||||||
"""Get objects in a container
|
"""Get objects in a container
|
||||||
|
|
||||||
:param api: a restapi object
|
:param session: a restapi object
|
||||||
:param url: endpoint
|
:param url: endpoint
|
||||||
:param container: container name to get a listing for
|
:param container: container name to get a listing for
|
||||||
:param marker: marker query
|
:param marker: marker query
|
||||||
@ -101,7 +101,7 @@ def list_objects(
|
|||||||
|
|
||||||
if full_listing:
|
if full_listing:
|
||||||
data = listing = list_objects(
|
data = listing = list_objects(
|
||||||
api,
|
session,
|
||||||
url,
|
url,
|
||||||
container,
|
container,
|
||||||
marker,
|
marker,
|
||||||
@ -117,7 +117,7 @@ def list_objects(
|
|||||||
else:
|
else:
|
||||||
marker = listing[-1]['name']
|
marker = listing[-1]['name']
|
||||||
listing = list_objects(
|
listing = list_objects(
|
||||||
api,
|
session,
|
||||||
url,
|
url,
|
||||||
container,
|
container,
|
||||||
marker,
|
marker,
|
||||||
@ -131,7 +131,6 @@ def list_objects(
|
|||||||
data.extend(listing)
|
data.extend(listing)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
object_url = url
|
|
||||||
params = {
|
params = {
|
||||||
'format': 'json',
|
'format': 'json',
|
||||||
}
|
}
|
||||||
@ -147,32 +146,31 @@ def list_objects(
|
|||||||
params['prefix'] = prefix
|
params['prefix'] = prefix
|
||||||
if path:
|
if path:
|
||||||
params['path'] = path
|
params['path'] = path
|
||||||
url = "%s/%s" % (object_url, container)
|
requrl = "%s/%s" % (url, container)
|
||||||
return api.list(url, params=params)
|
return session.get(requrl, params=params).json()
|
||||||
|
|
||||||
|
|
||||||
def show_object(
|
def show_object(
|
||||||
api,
|
session,
|
||||||
url,
|
url,
|
||||||
container,
|
container,
|
||||||
obj,
|
obj,
|
||||||
):
|
):
|
||||||
"""Get object details
|
"""Get object details
|
||||||
|
|
||||||
:param api: a restapi object
|
:param session: a restapi object
|
||||||
:param url: endpoint
|
:param url: endpoint
|
||||||
:param container: container name to get a listing for
|
:param container: container name to get a listing for
|
||||||
:returns: dict of object properties
|
:returns: dict of object properties
|
||||||
"""
|
"""
|
||||||
|
|
||||||
response = api.head("%s/%s/%s" % (url, container, obj))
|
response = session.head("%s/%s/%s" % (url, container, obj))
|
||||||
url_parts = urlparse(url)
|
|
||||||
data = {
|
data = {
|
||||||
'account': url_parts.path.split('/')[-1],
|
'account': response.headers.get('x-container-meta-owner', None),
|
||||||
'container': container,
|
'container': container,
|
||||||
'object': obj,
|
'object': obj,
|
||||||
|
'content-type': response.headers.get('content-type', None),
|
||||||
}
|
}
|
||||||
data['content-type'] = response.headers.get('content-type', None)
|
|
||||||
if 'content-length' in response.headers:
|
if 'content-length' in response.headers:
|
||||||
data['content-length'] = response.headers.get('content-length', None)
|
data['content-length'] = response.headers.get('content-length', None)
|
||||||
if 'last-modified' in response.headers:
|
if 'last-modified' in response.headers:
|
||||||
@ -184,10 +182,10 @@ def show_object(
|
|||||||
'x-object-manifest', None)
|
'x-object-manifest', None)
|
||||||
for key, value in six.iteritems(response.headers):
|
for key, value in six.iteritems(response.headers):
|
||||||
if key.startswith('x-object-meta-'):
|
if key.startswith('x-object-meta-'):
|
||||||
data[key[len('x-object-meta-'):].title()] = value
|
data[key[len('x-object-meta-'):].lower()] = value
|
||||||
elif key not in (
|
elif key not in (
|
||||||
'content-type', 'content-length', 'last-modified',
|
'content-type', 'content-length', 'last-modified',
|
||||||
'etag', 'date', 'x-object-manifest'):
|
'etag', 'date', 'x-object-manifest', 'x-container-meta-owner'):
|
||||||
data[key.title()] = value
|
data[key.lower()] = value
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
@ -50,7 +50,7 @@ class CreateObject(show.ShowOne):
|
|||||||
self.log.debug('take_action(%s)', parsed_args)
|
self.log.debug('take_action(%s)', parsed_args)
|
||||||
|
|
||||||
data = lib_object.create_object(
|
data = lib_object.create_object(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
self.app.client_manager.object_store.endpoint,
|
self.app.client_manager.object_store.endpoint,
|
||||||
parsed_args.container,
|
parsed_args.container,
|
||||||
parsed_args.object,
|
parsed_args.object,
|
||||||
@ -82,7 +82,7 @@ class DeleteObject(command.Command):
|
|||||||
self.log.debug('take_action(%s)', parsed_args)
|
self.log.debug('take_action(%s)', parsed_args)
|
||||||
|
|
||||||
lib_object.delete_object(
|
lib_object.delete_object(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
self.app.client_manager.object_store.endpoint,
|
self.app.client_manager.object_store.endpoint,
|
||||||
parsed_args.container,
|
parsed_args.container,
|
||||||
parsed_args.object,
|
parsed_args.object,
|
||||||
@ -170,7 +170,7 @@ class ListObject(lister.Lister):
|
|||||||
kwargs['full_listing'] = True
|
kwargs['full_listing'] = True
|
||||||
|
|
||||||
data = lib_object.list_objects(
|
data = lib_object.list_objects(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
self.app.client_manager.object_store.endpoint,
|
self.app.client_manager.object_store.endpoint,
|
||||||
parsed_args.container,
|
parsed_args.container,
|
||||||
**kwargs
|
**kwargs
|
||||||
@ -206,7 +206,7 @@ class ShowObject(show.ShowOne):
|
|||||||
self.log.debug('take_action(%s)', parsed_args)
|
self.log.debug('take_action(%s)', parsed_args)
|
||||||
|
|
||||||
data = lib_object.show_object(
|
data = lib_object.show_object(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
self.app.client_manager.object_store.endpoint,
|
self.app.client_manager.object_store.endpoint,
|
||||||
parsed_args.container,
|
parsed_args.container,
|
||||||
parsed_args.object,
|
parsed_args.object,
|
||||||
|
@ -31,7 +31,6 @@ import openstackclient
|
|||||||
from openstackclient.common import clientmanager
|
from openstackclient.common import clientmanager
|
||||||
from openstackclient.common import commandmanager
|
from openstackclient.common import commandmanager
|
||||||
from openstackclient.common import exceptions as exc
|
from openstackclient.common import exceptions as exc
|
||||||
from openstackclient.common import restapi
|
|
||||||
from openstackclient.common import timing
|
from openstackclient.common import timing
|
||||||
from openstackclient.common import utils
|
from openstackclient.common import utils
|
||||||
from openstackclient.identity import client as identity_client
|
from openstackclient.identity import client as identity_client
|
||||||
@ -484,10 +483,6 @@ class OpenStackShell(app.App):
|
|||||||
self.verify = self.options.os_cacert
|
self.verify = self.options.os_cacert
|
||||||
else:
|
else:
|
||||||
self.verify = not self.options.insecure
|
self.verify = not self.options.insecure
|
||||||
self.restapi = restapi.RESTApi(
|
|
||||||
verify=self.verify,
|
|
||||||
debug=self.options.debug,
|
|
||||||
)
|
|
||||||
|
|
||||||
def prepare_to_run_command(self, cmd):
|
def prepare_to_run_command(self, cmd):
|
||||||
"""Set up auth and API versions"""
|
"""Set up auth and API versions"""
|
||||||
@ -498,12 +493,10 @@ class OpenStackShell(app.App):
|
|||||||
if cmd.best_effort:
|
if cmd.best_effort:
|
||||||
try:
|
try:
|
||||||
self.authenticate_user()
|
self.authenticate_user()
|
||||||
self.restapi.set_auth(self.client_manager.identity.auth_token)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.authenticate_user()
|
self.authenticate_user()
|
||||||
self.restapi.set_auth(self.client_manager.identity.auth_token)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def clean_up(self, cmd, result, err):
|
def clean_up(self, cmd, result, err):
|
||||||
@ -539,7 +532,6 @@ class OpenStackShell(app.App):
|
|||||||
# NOTE(dtroyer): Maintain the old behaviour for interactive use as
|
# NOTE(dtroyer): Maintain the old behaviour for interactive use as
|
||||||
# this path does not call prepare_to_run_command()
|
# this path does not call prepare_to_run_command()
|
||||||
self.authenticate_user()
|
self.authenticate_user()
|
||||||
self.restapi.set_auth(self.client_manager.identity.auth_token)
|
|
||||||
super(OpenStackShell, self).interact()
|
super(OpenStackShell, self).interact()
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,11 +14,26 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
from openstackclient.common import clientmanager
|
from openstackclient.common import clientmanager
|
||||||
|
from openstackclient.common import restapi
|
||||||
from openstackclient.tests import utils
|
from openstackclient.tests import utils
|
||||||
|
|
||||||
|
|
||||||
|
AUTH_REF = {'a': 1}
|
||||||
AUTH_TOKEN = "foobar"
|
AUTH_TOKEN = "foobar"
|
||||||
AUTH_URL = "http://0.0.0.0"
|
AUTH_URL = "http://0.0.0.0"
|
||||||
|
USERNAME = "itchy"
|
||||||
|
PASSWORD = "scratchy"
|
||||||
|
SERVICE_CATALOG = {'sc': '123'}
|
||||||
|
|
||||||
|
|
||||||
|
def FakeMakeClient(instance):
|
||||||
|
return FakeClient()
|
||||||
|
|
||||||
|
|
||||||
|
class FakeClient(object):
|
||||||
|
auth_ref = AUTH_REF
|
||||||
|
auth_token = AUTH_TOKEN
|
||||||
|
service_catalog = SERVICE_CATALOG
|
||||||
|
|
||||||
|
|
||||||
class Container(object):
|
class Container(object):
|
||||||
@ -28,18 +43,7 @@ class Container(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestClientManager(utils.TestCase):
|
class TestClientCache(utils.TestCase):
|
||||||
def setUp(self):
|
|
||||||
super(TestClientManager, self).setUp()
|
|
||||||
|
|
||||||
api_version = {"identity": "2.0"}
|
|
||||||
|
|
||||||
self.client_manager = clientmanager.ClientManager(
|
|
||||||
token=AUTH_TOKEN,
|
|
||||||
url=AUTH_URL,
|
|
||||||
auth_url=AUTH_URL,
|
|
||||||
api_version=api_version,
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_singleton(self):
|
def test_singleton(self):
|
||||||
# NOTE(dtroyer): Verify that the ClientCache descriptor only invokes
|
# NOTE(dtroyer): Verify that the ClientCache descriptor only invokes
|
||||||
@ -47,12 +51,88 @@ class TestClientManager(utils.TestCase):
|
|||||||
c = Container()
|
c = Container()
|
||||||
self.assertEqual(c.attr, c.attr)
|
self.assertEqual(c.attr, c.attr)
|
||||||
|
|
||||||
def test_make_client_identity_default(self):
|
|
||||||
|
class TestClientManager(utils.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
super(TestClientManager, self).setUp()
|
||||||
|
|
||||||
|
clientmanager.ClientManager.identity = \
|
||||||
|
clientmanager.ClientCache(FakeMakeClient)
|
||||||
|
|
||||||
|
def test_client_manager_token(self):
|
||||||
|
|
||||||
|
client_manager = clientmanager.ClientManager(
|
||||||
|
token=AUTH_TOKEN,
|
||||||
|
url=AUTH_URL,
|
||||||
|
verify=True,
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.client_manager.identity.auth_token,
|
|
||||||
AUTH_TOKEN,
|
AUTH_TOKEN,
|
||||||
|
client_manager._token,
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.client_manager.identity.management_url,
|
|
||||||
AUTH_URL,
|
AUTH_URL,
|
||||||
|
client_manager._url,
|
||||||
)
|
)
|
||||||
|
self.assertIsInstance(
|
||||||
|
client_manager.session,
|
||||||
|
restapi.RESTApi,
|
||||||
|
)
|
||||||
|
self.assertFalse(client_manager._insecure)
|
||||||
|
self.assertTrue(client_manager._verify)
|
||||||
|
|
||||||
|
def test_client_manager_password(self):
|
||||||
|
|
||||||
|
client_manager = clientmanager.ClientManager(
|
||||||
|
auth_url=AUTH_URL,
|
||||||
|
username=USERNAME,
|
||||||
|
password=PASSWORD,
|
||||||
|
verify=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
AUTH_URL,
|
||||||
|
client_manager._auth_url,
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
USERNAME,
|
||||||
|
client_manager._username,
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
PASSWORD,
|
||||||
|
client_manager._password,
|
||||||
|
)
|
||||||
|
self.assertIsInstance(
|
||||||
|
client_manager.session,
|
||||||
|
restapi.RESTApi,
|
||||||
|
)
|
||||||
|
self.assertTrue(client_manager._insecure)
|
||||||
|
self.assertFalse(client_manager._verify)
|
||||||
|
|
||||||
|
# These need to stick around until the old-style clients are gone
|
||||||
|
self.assertEqual(
|
||||||
|
AUTH_REF,
|
||||||
|
client_manager.auth_ref,
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
AUTH_TOKEN,
|
||||||
|
client_manager._token,
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
SERVICE_CATALOG,
|
||||||
|
client_manager._service_catalog,
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_client_manager_password_verify_ca(self):
|
||||||
|
|
||||||
|
client_manager = clientmanager.ClientManager(
|
||||||
|
auth_url=AUTH_URL,
|
||||||
|
username=USERNAME,
|
||||||
|
password=PASSWORD,
|
||||||
|
verify='cafile',
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertFalse(client_manager._insecure)
|
||||||
|
self.assertTrue(client_manager._verify)
|
||||||
|
self.assertEqual('cafile', client_manager._cacert)
|
||||||
|
@ -13,9 +13,12 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import json
|
||||||
import six
|
import six
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
AUTH_TOKEN = "foobar"
|
AUTH_TOKEN = "foobar"
|
||||||
AUTH_URL = "http://0.0.0.0"
|
AUTH_URL = "http://0.0.0.0"
|
||||||
@ -42,7 +45,6 @@ class FakeApp(object):
|
|||||||
self.stdin = sys.stdin
|
self.stdin = sys.stdin
|
||||||
self.stdout = _stdout or sys.stdout
|
self.stdout = _stdout or sys.stdout
|
||||||
self.stderr = sys.stderr
|
self.stderr = sys.stderr
|
||||||
self.restapi = None
|
|
||||||
|
|
||||||
|
|
||||||
class FakeClientManager(object):
|
class FakeClientManager(object):
|
||||||
@ -53,6 +55,7 @@ class FakeClientManager(object):
|
|||||||
self.object = None
|
self.object = None
|
||||||
self.volume = None
|
self.volume = None
|
||||||
self.network = None
|
self.network = None
|
||||||
|
self.session = None
|
||||||
self.auth_ref = None
|
self.auth_ref = None
|
||||||
|
|
||||||
|
|
||||||
@ -78,3 +81,15 @@ class FakeResource(object):
|
|||||||
k != 'manager')
|
k != 'manager')
|
||||||
info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys)
|
info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys)
|
||||||
return "<%s %s>" % (self.__class__.__name__, info)
|
return "<%s %s>" % (self.__class__.__name__, info)
|
||||||
|
|
||||||
|
|
||||||
|
class FakeResponse(requests.Response):
|
||||||
|
def __init__(self, headers={}, status_code=200, data=None, encoding=None):
|
||||||
|
super(FakeResponse, self).__init__()
|
||||||
|
|
||||||
|
self.status_code = status_code
|
||||||
|
|
||||||
|
self.headers.update(headers)
|
||||||
|
self._content = json.dumps(data)
|
||||||
|
if not isinstance(self._content, six.binary_type):
|
||||||
|
self._content = self._content.encode()
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
import mock
|
import mock
|
||||||
|
|
||||||
from openstackclient.object.v1.lib import container as lib_container
|
from openstackclient.object.v1.lib import container as lib_container
|
||||||
from openstackclient.tests.common import test_restapi as restapi
|
from openstackclient.tests import fakes
|
||||||
from openstackclient.tests.object.v1 import fakes as object_fakes
|
from openstackclient.tests.object.v1 import fakes as object_fakes
|
||||||
|
|
||||||
|
|
||||||
@ -39,156 +39,158 @@ class TestContainer(object_fakes.TestObjectv1):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestContainer, self).setUp()
|
super(TestContainer, self).setUp()
|
||||||
self.app.restapi = mock.MagicMock()
|
self.app.client_manager.session = mock.MagicMock()
|
||||||
|
|
||||||
|
|
||||||
class TestContainerList(TestContainer):
|
class TestContainerList(TestContainer):
|
||||||
|
|
||||||
def test_container_list_no_options(self):
|
def test_container_list_no_options(self):
|
||||||
resp = [{'name': 'is-name'}]
|
resp = [{'name': 'is-name'}]
|
||||||
self.app.restapi.list.return_value = resp
|
self.app.client_manager.session.get().json.return_value = resp
|
||||||
|
|
||||||
data = lib_container.list_containers(
|
data = lib_container.list_containers(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
fake_url,
|
fake_url,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check expected values
|
# Check expected values
|
||||||
self.app.restapi.list.assert_called_with(
|
self.app.client_manager.session.get.assert_called_with(
|
||||||
fake_url,
|
fake_url,
|
||||||
params={
|
params={
|
||||||
'format': 'json',
|
'format': 'json',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.assertEqual(data, resp)
|
self.assertEqual(resp, data)
|
||||||
|
|
||||||
def test_container_list_marker(self):
|
def test_container_list_marker(self):
|
||||||
resp = [{'name': 'is-name'}]
|
resp = [{'name': 'is-name'}]
|
||||||
self.app.restapi.list.return_value = resp
|
self.app.client_manager.session.get().json.return_value = resp
|
||||||
|
|
||||||
data = lib_container.list_containers(
|
data = lib_container.list_containers(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
fake_url,
|
fake_url,
|
||||||
marker='next',
|
marker='next',
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check expected values
|
# Check expected values
|
||||||
self.app.restapi.list.assert_called_with(
|
self.app.client_manager.session.get.assert_called_with(
|
||||||
fake_url,
|
fake_url,
|
||||||
params={
|
params={
|
||||||
'format': 'json',
|
'format': 'json',
|
||||||
'marker': 'next',
|
'marker': 'next',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.assertEqual(data, resp)
|
self.assertEqual(resp, data)
|
||||||
|
|
||||||
def test_container_list_limit(self):
|
def test_container_list_limit(self):
|
||||||
resp = [{'name': 'is-name'}]
|
resp = [{'name': 'is-name'}]
|
||||||
self.app.restapi.list.return_value = resp
|
self.app.client_manager.session.get().json.return_value = resp
|
||||||
|
|
||||||
data = lib_container.list_containers(
|
data = lib_container.list_containers(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
fake_url,
|
fake_url,
|
||||||
limit=5,
|
limit=5,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check expected values
|
# Check expected values
|
||||||
self.app.restapi.list.assert_called_with(
|
self.app.client_manager.session.get.assert_called_with(
|
||||||
fake_url,
|
fake_url,
|
||||||
params={
|
params={
|
||||||
'format': 'json',
|
'format': 'json',
|
||||||
'limit': 5,
|
'limit': 5,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.assertEqual(data, resp)
|
self.assertEqual(resp, data)
|
||||||
|
|
||||||
def test_container_list_end_marker(self):
|
def test_container_list_end_marker(self):
|
||||||
resp = [{'name': 'is-name'}]
|
resp = [{'name': 'is-name'}]
|
||||||
self.app.restapi.list.return_value = resp
|
self.app.client_manager.session.get().json.return_value = resp
|
||||||
|
|
||||||
data = lib_container.list_containers(
|
data = lib_container.list_containers(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
fake_url,
|
fake_url,
|
||||||
end_marker='last',
|
end_marker='last',
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check expected values
|
# Check expected values
|
||||||
self.app.restapi.list.assert_called_with(
|
self.app.client_manager.session.get.assert_called_with(
|
||||||
fake_url,
|
fake_url,
|
||||||
params={
|
params={
|
||||||
'format': 'json',
|
'format': 'json',
|
||||||
'end_marker': 'last',
|
'end_marker': 'last',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.assertEqual(data, resp)
|
self.assertEqual(resp, data)
|
||||||
|
|
||||||
def test_container_list_prefix(self):
|
def test_container_list_prefix(self):
|
||||||
resp = [{'name': 'is-name'}]
|
resp = [{'name': 'is-name'}]
|
||||||
self.app.restapi.list.return_value = resp
|
self.app.client_manager.session.get().json.return_value = resp
|
||||||
|
|
||||||
data = lib_container.list_containers(
|
data = lib_container.list_containers(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
fake_url,
|
fake_url,
|
||||||
prefix='foo/',
|
prefix='foo/',
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check expected values
|
# Check expected values
|
||||||
self.app.restapi.list.assert_called_with(
|
self.app.client_manager.session.get.assert_called_with(
|
||||||
fake_url,
|
fake_url,
|
||||||
params={
|
params={
|
||||||
'format': 'json',
|
'format': 'json',
|
||||||
'prefix': 'foo/',
|
'prefix': 'foo/',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.assertEqual(data, resp)
|
self.assertEqual(resp, data)
|
||||||
|
|
||||||
def test_container_list_full_listing(self):
|
def test_container_list_full_listing(self):
|
||||||
|
sess = self.app.client_manager.session
|
||||||
|
|
||||||
def side_effect(*args, **kwargs):
|
def side_effect(*args, **kwargs):
|
||||||
rv = self.app.restapi.list.return_value
|
rv = sess.get().json.return_value
|
||||||
self.app.restapi.list.return_value = []
|
sess.get().json.return_value = []
|
||||||
self.app.restapi.list.side_effect = None
|
sess.get().json.side_effect = None
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
resp = [{'name': 'is-name'}]
|
resp = [{'name': 'is-name'}]
|
||||||
self.app.restapi.list.return_value = resp
|
sess.get().json.return_value = resp
|
||||||
self.app.restapi.list.side_effect = side_effect
|
sess.get().json.side_effect = side_effect
|
||||||
|
|
||||||
data = lib_container.list_containers(
|
data = lib_container.list_containers(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
fake_url,
|
fake_url,
|
||||||
full_listing=True,
|
full_listing=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check expected values
|
# Check expected values
|
||||||
self.app.restapi.list.assert_called_with(
|
sess.get.assert_called_with(
|
||||||
fake_url,
|
fake_url,
|
||||||
params={
|
params={
|
||||||
'format': 'json',
|
'format': 'json',
|
||||||
'marker': 'is-name',
|
'marker': 'is-name',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.assertEqual(data, resp)
|
self.assertEqual(resp, data)
|
||||||
|
|
||||||
|
|
||||||
class TestContainerShow(TestContainer):
|
class TestContainerShow(TestContainer):
|
||||||
|
|
||||||
def test_container_show_no_options(self):
|
def test_container_show_no_options(self):
|
||||||
resp = {
|
resp = {
|
||||||
|
'X-Container-Meta-Owner': fake_account,
|
||||||
'x-container-object-count': 1,
|
'x-container-object-count': 1,
|
||||||
'x-container-bytes-used': 577,
|
'x-container-bytes-used': 577,
|
||||||
}
|
}
|
||||||
self.app.restapi.head.return_value = \
|
self.app.client_manager.session.head.return_value = \
|
||||||
restapi.FakeResponse(headers=resp)
|
fakes.FakeResponse(headers=resp)
|
||||||
|
|
||||||
data = lib_container.show_container(
|
data = lib_container.show_container(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
fake_url,
|
fake_url,
|
||||||
'is-name',
|
'is-name',
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check expected values
|
# Check expected values
|
||||||
self.app.restapi.head.assert_called_with(
|
self.app.client_manager.session.head.assert_called_with(
|
||||||
fake_url + '/is-name',
|
fake_url + '/is-name',
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -202,4 +204,4 @@ class TestContainerShow(TestContainer):
|
|||||||
'sync_to': None,
|
'sync_to': None,
|
||||||
'sync_key': None,
|
'sync_key': None,
|
||||||
}
|
}
|
||||||
self.assertEqual(data, data_expected)
|
self.assertEqual(data_expected, data)
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
import mock
|
import mock
|
||||||
|
|
||||||
from openstackclient.object.v1.lib import object as lib_object
|
from openstackclient.object.v1.lib import object as lib_object
|
||||||
from openstackclient.tests.common import test_restapi as restapi
|
from openstackclient.tests import fakes
|
||||||
from openstackclient.tests.object.v1 import fakes as object_fakes
|
from openstackclient.tests.object.v1 import fakes as object_fakes
|
||||||
|
|
||||||
|
|
||||||
@ -40,99 +40,99 @@ class TestObject(object_fakes.TestObjectv1):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestObject, self).setUp()
|
super(TestObject, self).setUp()
|
||||||
self.app.restapi = mock.MagicMock()
|
self.app.client_manager.session = mock.MagicMock()
|
||||||
|
|
||||||
|
|
||||||
class TestObjectListObjects(TestObject):
|
class TestObjectListObjects(TestObject):
|
||||||
|
|
||||||
def test_list_objects_no_options(self):
|
def test_list_objects_no_options(self):
|
||||||
resp = [{'name': 'is-name'}]
|
resp = [{'name': 'is-name'}]
|
||||||
self.app.restapi.list.return_value = resp
|
self.app.client_manager.session.get().json.return_value = resp
|
||||||
|
|
||||||
data = lib_object.list_objects(
|
data = lib_object.list_objects(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
fake_url,
|
fake_url,
|
||||||
fake_container,
|
fake_container,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check expected values
|
# Check expected values
|
||||||
self.app.restapi.list.assert_called_with(
|
self.app.client_manager.session.get.assert_called_with(
|
||||||
fake_url + '/' + fake_container,
|
fake_url + '/' + fake_container,
|
||||||
params={
|
params={
|
||||||
'format': 'json',
|
'format': 'json',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.assertEqual(data, resp)
|
self.assertEqual(resp, data)
|
||||||
|
|
||||||
def test_list_objects_marker(self):
|
def test_list_objects_marker(self):
|
||||||
resp = [{'name': 'is-name'}]
|
resp = [{'name': 'is-name'}]
|
||||||
self.app.restapi.list.return_value = resp
|
self.app.client_manager.session.get().json.return_value = resp
|
||||||
|
|
||||||
data = lib_object.list_objects(
|
data = lib_object.list_objects(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
fake_url,
|
fake_url,
|
||||||
fake_container,
|
fake_container,
|
||||||
marker='next',
|
marker='next',
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check expected values
|
# Check expected values
|
||||||
self.app.restapi.list.assert_called_with(
|
self.app.client_manager.session.get.assert_called_with(
|
||||||
fake_url + '/' + fake_container,
|
fake_url + '/' + fake_container,
|
||||||
params={
|
params={
|
||||||
'format': 'json',
|
'format': 'json',
|
||||||
'marker': 'next',
|
'marker': 'next',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.assertEqual(data, resp)
|
self.assertEqual(resp, data)
|
||||||
|
|
||||||
def test_list_objects_limit(self):
|
def test_list_objects_limit(self):
|
||||||
resp = [{'name': 'is-name'}]
|
resp = [{'name': 'is-name'}]
|
||||||
self.app.restapi.list.return_value = resp
|
self.app.client_manager.session.get().json.return_value = resp
|
||||||
|
|
||||||
data = lib_object.list_objects(
|
data = lib_object.list_objects(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
fake_url,
|
fake_url,
|
||||||
fake_container,
|
fake_container,
|
||||||
limit=5,
|
limit=5,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check expected values
|
# Check expected values
|
||||||
self.app.restapi.list.assert_called_with(
|
self.app.client_manager.session.get.assert_called_with(
|
||||||
fake_url + '/' + fake_container,
|
fake_url + '/' + fake_container,
|
||||||
params={
|
params={
|
||||||
'format': 'json',
|
'format': 'json',
|
||||||
'limit': 5,
|
'limit': 5,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.assertEqual(data, resp)
|
self.assertEqual(resp, data)
|
||||||
|
|
||||||
def test_list_objects_end_marker(self):
|
def test_list_objects_end_marker(self):
|
||||||
resp = [{'name': 'is-name'}]
|
resp = [{'name': 'is-name'}]
|
||||||
self.app.restapi.list.return_value = resp
|
self.app.client_manager.session.get().json.return_value = resp
|
||||||
|
|
||||||
data = lib_object.list_objects(
|
data = lib_object.list_objects(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
fake_url,
|
fake_url,
|
||||||
fake_container,
|
fake_container,
|
||||||
end_marker='last',
|
end_marker='last',
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check expected values
|
# Check expected values
|
||||||
self.app.restapi.list.assert_called_with(
|
self.app.client_manager.session.get.assert_called_with(
|
||||||
fake_url + '/' + fake_container,
|
fake_url + '/' + fake_container,
|
||||||
params={
|
params={
|
||||||
'format': 'json',
|
'format': 'json',
|
||||||
'end_marker': 'last',
|
'end_marker': 'last',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.assertEqual(data, resp)
|
self.assertEqual(resp, data)
|
||||||
|
|
||||||
def test_list_objects_delimiter(self):
|
def test_list_objects_delimiter(self):
|
||||||
resp = [{'name': 'is-name'}]
|
resp = [{'name': 'is-name'}]
|
||||||
self.app.restapi.list.return_value = resp
|
self.app.client_manager.session.get().json.return_value = resp
|
||||||
|
|
||||||
data = lib_object.list_objects(
|
data = lib_object.list_objects(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
fake_url,
|
fake_url,
|
||||||
fake_container,
|
fake_container,
|
||||||
delimiter='|',
|
delimiter='|',
|
||||||
@ -142,85 +142,86 @@ class TestObjectListObjects(TestObject):
|
|||||||
# NOTE(dtroyer): requests handles the URL encoding and we're
|
# NOTE(dtroyer): requests handles the URL encoding and we're
|
||||||
# mocking that so use the otherwise-not-legal
|
# mocking that so use the otherwise-not-legal
|
||||||
# pipe '|' char in the response.
|
# pipe '|' char in the response.
|
||||||
self.app.restapi.list.assert_called_with(
|
self.app.client_manager.session.get.assert_called_with(
|
||||||
fake_url + '/' + fake_container,
|
fake_url + '/' + fake_container,
|
||||||
params={
|
params={
|
||||||
'format': 'json',
|
'format': 'json',
|
||||||
'delimiter': '|',
|
'delimiter': '|',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.assertEqual(data, resp)
|
self.assertEqual(resp, data)
|
||||||
|
|
||||||
def test_list_objects_prefix(self):
|
def test_list_objects_prefix(self):
|
||||||
resp = [{'name': 'is-name'}]
|
resp = [{'name': 'is-name'}]
|
||||||
self.app.restapi.list.return_value = resp
|
self.app.client_manager.session.get().json.return_value = resp
|
||||||
|
|
||||||
data = lib_object.list_objects(
|
data = lib_object.list_objects(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
fake_url,
|
fake_url,
|
||||||
fake_container,
|
fake_container,
|
||||||
prefix='foo/',
|
prefix='foo/',
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check expected values
|
# Check expected values
|
||||||
self.app.restapi.list.assert_called_with(
|
self.app.client_manager.session.get.assert_called_with(
|
||||||
fake_url + '/' + fake_container,
|
fake_url + '/' + fake_container,
|
||||||
params={
|
params={
|
||||||
'format': 'json',
|
'format': 'json',
|
||||||
'prefix': 'foo/',
|
'prefix': 'foo/',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.assertEqual(data, resp)
|
self.assertEqual(resp, data)
|
||||||
|
|
||||||
def test_list_objects_path(self):
|
def test_list_objects_path(self):
|
||||||
resp = [{'name': 'is-name'}]
|
resp = [{'name': 'is-name'}]
|
||||||
self.app.restapi.list.return_value = resp
|
self.app.client_manager.session.get().json.return_value = resp
|
||||||
|
|
||||||
data = lib_object.list_objects(
|
data = lib_object.list_objects(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
fake_url,
|
fake_url,
|
||||||
fake_container,
|
fake_container,
|
||||||
path='next',
|
path='next',
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check expected values
|
# Check expected values
|
||||||
self.app.restapi.list.assert_called_with(
|
self.app.client_manager.session.get.assert_called_with(
|
||||||
fake_url + '/' + fake_container,
|
fake_url + '/' + fake_container,
|
||||||
params={
|
params={
|
||||||
'format': 'json',
|
'format': 'json',
|
||||||
'path': 'next',
|
'path': 'next',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.assertEqual(data, resp)
|
self.assertEqual(resp, data)
|
||||||
|
|
||||||
def test_list_objects_full_listing(self):
|
def test_list_objects_full_listing(self):
|
||||||
|
sess = self.app.client_manager.session
|
||||||
|
|
||||||
def side_effect(*args, **kwargs):
|
def side_effect(*args, **kwargs):
|
||||||
rv = self.app.restapi.list.return_value
|
rv = sess.get().json.return_value
|
||||||
self.app.restapi.list.return_value = []
|
sess.get().json.return_value = []
|
||||||
self.app.restapi.list.side_effect = None
|
sess.get().json.side_effect = None
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
resp = [{'name': 'is-name'}]
|
resp = [{'name': 'is-name'}]
|
||||||
self.app.restapi.list.return_value = resp
|
sess.get().json.return_value = resp
|
||||||
self.app.restapi.list.side_effect = side_effect
|
sess.get().json.side_effect = side_effect
|
||||||
|
|
||||||
data = lib_object.list_objects(
|
data = lib_object.list_objects(
|
||||||
self.app.restapi,
|
sess,
|
||||||
fake_url,
|
fake_url,
|
||||||
fake_container,
|
fake_container,
|
||||||
full_listing=True,
|
full_listing=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check expected values
|
# Check expected values
|
||||||
self.app.restapi.list.assert_called_with(
|
sess.get.assert_called_with(
|
||||||
fake_url + '/' + fake_container,
|
fake_url + '/' + fake_container,
|
||||||
params={
|
params={
|
||||||
'format': 'json',
|
'format': 'json',
|
||||||
'marker': 'is-name',
|
'marker': 'is-name',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.assertEqual(data, resp)
|
self.assertEqual(resp, data)
|
||||||
|
|
||||||
|
|
||||||
class TestObjectShowObjects(TestObject):
|
class TestObjectShowObjects(TestObject):
|
||||||
@ -228,19 +229,20 @@ class TestObjectShowObjects(TestObject):
|
|||||||
def test_object_show_no_options(self):
|
def test_object_show_no_options(self):
|
||||||
resp = {
|
resp = {
|
||||||
'content-type': 'text/alpha',
|
'content-type': 'text/alpha',
|
||||||
|
'x-container-meta-owner': fake_account,
|
||||||
}
|
}
|
||||||
self.app.restapi.head.return_value = \
|
self.app.client_manager.session.head.return_value = \
|
||||||
restapi.FakeResponse(headers=resp)
|
fakes.FakeResponse(headers=resp)
|
||||||
|
|
||||||
data = lib_object.show_object(
|
data = lib_object.show_object(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
fake_url,
|
fake_url,
|
||||||
fake_container,
|
fake_container,
|
||||||
fake_object,
|
fake_object,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check expected values
|
# Check expected values
|
||||||
self.app.restapi.head.assert_called_with(
|
self.app.client_manager.session.head.assert_called_with(
|
||||||
fake_url + '/%s/%s' % (fake_container, fake_object),
|
fake_url + '/%s/%s' % (fake_container, fake_object),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -250,7 +252,7 @@ class TestObjectShowObjects(TestObject):
|
|||||||
'object': fake_object,
|
'object': fake_object,
|
||||||
'content-type': 'text/alpha',
|
'content-type': 'text/alpha',
|
||||||
}
|
}
|
||||||
self.assertEqual(data, data_expected)
|
self.assertEqual(data_expected, data)
|
||||||
|
|
||||||
def test_object_show_all_options(self):
|
def test_object_show_all_options(self):
|
||||||
resp = {
|
resp = {
|
||||||
@ -258,22 +260,23 @@ class TestObjectShowObjects(TestObject):
|
|||||||
'content-length': 577,
|
'content-length': 577,
|
||||||
'last-modified': '20130101',
|
'last-modified': '20130101',
|
||||||
'etag': 'qaz',
|
'etag': 'qaz',
|
||||||
|
'x-container-meta-owner': fake_account,
|
||||||
'x-object-manifest': None,
|
'x-object-manifest': None,
|
||||||
'x-object-meta-wife': 'Wilma',
|
'x-object-meta-wife': 'Wilma',
|
||||||
'x-tra-header': 'yabba-dabba-do',
|
'x-tra-header': 'yabba-dabba-do',
|
||||||
}
|
}
|
||||||
self.app.restapi.head.return_value = \
|
self.app.client_manager.session.head.return_value = \
|
||||||
restapi.FakeResponse(headers=resp)
|
fakes.FakeResponse(headers=resp)
|
||||||
|
|
||||||
data = lib_object.show_object(
|
data = lib_object.show_object(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
fake_url,
|
fake_url,
|
||||||
fake_container,
|
fake_container,
|
||||||
fake_object,
|
fake_object,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check expected values
|
# Check expected values
|
||||||
self.app.restapi.head.assert_called_with(
|
self.app.client_manager.session.head.assert_called_with(
|
||||||
fake_url + '/%s/%s' % (fake_container, fake_object),
|
fake_url + '/%s/%s' % (fake_container, fake_object),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -286,7 +289,7 @@ class TestObjectShowObjects(TestObject):
|
|||||||
'last-modified': '20130101',
|
'last-modified': '20130101',
|
||||||
'etag': 'qaz',
|
'etag': 'qaz',
|
||||||
'x-object-manifest': None,
|
'x-object-manifest': None,
|
||||||
'Wife': 'Wilma',
|
'wife': 'Wilma',
|
||||||
'X-Tra-Header': 'yabba-dabba-do',
|
'x-tra-header': 'yabba-dabba-do',
|
||||||
}
|
}
|
||||||
self.assertEqual(data, data_expected)
|
self.assertEqual(data_expected, data)
|
||||||
|
@ -77,7 +77,7 @@ class TestContainerList(TestObject):
|
|||||||
kwargs = {
|
kwargs = {
|
||||||
}
|
}
|
||||||
c_mock.assert_called_with(
|
c_mock.assert_called_with(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
AUTH_URL,
|
AUTH_URL,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
@ -113,7 +113,7 @@ class TestContainerList(TestObject):
|
|||||||
'prefix': 'bit',
|
'prefix': 'bit',
|
||||||
}
|
}
|
||||||
c_mock.assert_called_with(
|
c_mock.assert_called_with(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
AUTH_URL,
|
AUTH_URL,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
@ -148,7 +148,7 @@ class TestContainerList(TestObject):
|
|||||||
'marker': object_fakes.container_name,
|
'marker': object_fakes.container_name,
|
||||||
}
|
}
|
||||||
c_mock.assert_called_with(
|
c_mock.assert_called_with(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
AUTH_URL,
|
AUTH_URL,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
@ -183,7 +183,7 @@ class TestContainerList(TestObject):
|
|||||||
'end_marker': object_fakes.container_name_3,
|
'end_marker': object_fakes.container_name_3,
|
||||||
}
|
}
|
||||||
c_mock.assert_called_with(
|
c_mock.assert_called_with(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
AUTH_URL,
|
AUTH_URL,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
@ -218,7 +218,7 @@ class TestContainerList(TestObject):
|
|||||||
'limit': 2,
|
'limit': 2,
|
||||||
}
|
}
|
||||||
c_mock.assert_called_with(
|
c_mock.assert_called_with(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
AUTH_URL,
|
AUTH_URL,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
@ -252,7 +252,7 @@ class TestContainerList(TestObject):
|
|||||||
kwargs = {
|
kwargs = {
|
||||||
}
|
}
|
||||||
c_mock.assert_called_with(
|
c_mock.assert_called_with(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
AUTH_URL,
|
AUTH_URL,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
@ -296,7 +296,7 @@ class TestContainerList(TestObject):
|
|||||||
'full_listing': True,
|
'full_listing': True,
|
||||||
}
|
}
|
||||||
c_mock.assert_called_with(
|
c_mock.assert_called_with(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
AUTH_URL,
|
AUTH_URL,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
@ -341,7 +341,7 @@ class TestContainerShow(TestObject):
|
|||||||
}
|
}
|
||||||
# lib.container.show_container(api, url, container)
|
# lib.container.show_container(api, url, container)
|
||||||
c_mock.assert_called_with(
|
c_mock.assert_called_with(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
AUTH_URL,
|
AUTH_URL,
|
||||||
object_fakes.container_name,
|
object_fakes.container_name,
|
||||||
**kwargs
|
**kwargs
|
||||||
|
@ -71,7 +71,7 @@ class TestObjectList(TestObject):
|
|||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
o_mock.assert_called_with(
|
o_mock.assert_called_with(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
AUTH_URL,
|
AUTH_URL,
|
||||||
object_fakes.container_name,
|
object_fakes.container_name,
|
||||||
)
|
)
|
||||||
@ -107,7 +107,7 @@ class TestObjectList(TestObject):
|
|||||||
'prefix': 'floppy',
|
'prefix': 'floppy',
|
||||||
}
|
}
|
||||||
o_mock.assert_called_with(
|
o_mock.assert_called_with(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
AUTH_URL,
|
AUTH_URL,
|
||||||
object_fakes.container_name_2,
|
object_fakes.container_name_2,
|
||||||
**kwargs
|
**kwargs
|
||||||
@ -143,7 +143,7 @@ class TestObjectList(TestObject):
|
|||||||
'delimiter': '=',
|
'delimiter': '=',
|
||||||
}
|
}
|
||||||
o_mock.assert_called_with(
|
o_mock.assert_called_with(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
AUTH_URL,
|
AUTH_URL,
|
||||||
object_fakes.container_name_2,
|
object_fakes.container_name_2,
|
||||||
**kwargs
|
**kwargs
|
||||||
@ -179,7 +179,7 @@ class TestObjectList(TestObject):
|
|||||||
'marker': object_fakes.object_name_2,
|
'marker': object_fakes.object_name_2,
|
||||||
}
|
}
|
||||||
o_mock.assert_called_with(
|
o_mock.assert_called_with(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
AUTH_URL,
|
AUTH_URL,
|
||||||
object_fakes.container_name_2,
|
object_fakes.container_name_2,
|
||||||
**kwargs
|
**kwargs
|
||||||
@ -215,7 +215,7 @@ class TestObjectList(TestObject):
|
|||||||
'end_marker': object_fakes.object_name_2,
|
'end_marker': object_fakes.object_name_2,
|
||||||
}
|
}
|
||||||
o_mock.assert_called_with(
|
o_mock.assert_called_with(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
AUTH_URL,
|
AUTH_URL,
|
||||||
object_fakes.container_name_2,
|
object_fakes.container_name_2,
|
||||||
**kwargs
|
**kwargs
|
||||||
@ -251,7 +251,7 @@ class TestObjectList(TestObject):
|
|||||||
'limit': 2,
|
'limit': 2,
|
||||||
}
|
}
|
||||||
o_mock.assert_called_with(
|
o_mock.assert_called_with(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
AUTH_URL,
|
AUTH_URL,
|
||||||
object_fakes.container_name_2,
|
object_fakes.container_name_2,
|
||||||
**kwargs
|
**kwargs
|
||||||
@ -287,7 +287,7 @@ class TestObjectList(TestObject):
|
|||||||
kwargs = {
|
kwargs = {
|
||||||
}
|
}
|
||||||
o_mock.assert_called_with(
|
o_mock.assert_called_with(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
AUTH_URL,
|
AUTH_URL,
|
||||||
object_fakes.container_name,
|
object_fakes.container_name,
|
||||||
**kwargs
|
**kwargs
|
||||||
@ -337,7 +337,7 @@ class TestObjectList(TestObject):
|
|||||||
'full_listing': True,
|
'full_listing': True,
|
||||||
}
|
}
|
||||||
o_mock.assert_called_with(
|
o_mock.assert_called_with(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
AUTH_URL,
|
AUTH_URL,
|
||||||
object_fakes.container_name,
|
object_fakes.container_name,
|
||||||
**kwargs
|
**kwargs
|
||||||
@ -384,7 +384,7 @@ class TestObjectShow(TestObject):
|
|||||||
}
|
}
|
||||||
# lib.container.show_container(api, url, container)
|
# lib.container.show_container(api, url, container)
|
||||||
c_mock.assert_called_with(
|
c_mock.assert_called_with(
|
||||||
self.app.restapi,
|
self.app.client_manager.session,
|
||||||
AUTH_URL,
|
AUTH_URL,
|
||||||
object_fakes.container_name,
|
object_fakes.container_name,
|
||||||
object_fakes.object_name_1,
|
object_fakes.object_name_1,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user