Merge "Change app.restapi to app.client_manager.session"
This commit is contained in:
commit
dc9ce6d608
@ -19,6 +19,7 @@ import logging
|
||||
import pkg_resources
|
||||
import sys
|
||||
|
||||
from openstackclient.common import restapi
|
||||
from openstackclient.identity import client as identity_client
|
||||
|
||||
|
||||
@ -77,7 +78,18 @@ class ClientManager(object):
|
||||
self._insecure = not verify
|
||||
else:
|
||||
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
|
||||
|
||||
|
@ -66,7 +66,17 @@ def make_client(instance):
|
||||
insecure=instance._insecure,
|
||||
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
|
||||
|
||||
# NOTE(dtroyer): this is hanging around until restapi is replace by
|
||||
# ksc session
|
||||
instance.session.set_auth(
|
||||
client.auth_ref.auth_token,
|
||||
)
|
||||
|
||||
return client
|
||||
|
||||
|
||||
|
@ -45,7 +45,7 @@ class CreateContainer(show.ShowOne):
|
||||
self.log.debug('take_action(%s)', parsed_args)
|
||||
|
||||
data = lib_container.create_container(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
self.app.client_manager.object_store.endpoint,
|
||||
parsed_args.container,
|
||||
)
|
||||
@ -71,7 +71,7 @@ class DeleteContainer(command.Command):
|
||||
self.log.debug('take_action(%s)', parsed_args)
|
||||
|
||||
lib_container.delete_container(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
self.app.client_manager.object_store.endpoint,
|
||||
parsed_args.container,
|
||||
)
|
||||
@ -140,7 +140,7 @@ class ListContainer(lister.Lister):
|
||||
kwargs['full_listing'] = True
|
||||
|
||||
data = lib_container.list_containers(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
self.app.client_manager.object_store.endpoint,
|
||||
**kwargs
|
||||
)
|
||||
@ -170,7 +170,7 @@ class ShowContainer(show.ShowOne):
|
||||
self.log.debug('take_action(%s)', parsed_args)
|
||||
|
||||
data = lib_container.show_container(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
self.app.client_manager.object_store.endpoint,
|
||||
parsed_args.container,
|
||||
)
|
||||
|
@ -23,46 +23,46 @@ except ImportError:
|
||||
|
||||
|
||||
def create_container(
|
||||
api,
|
||||
session,
|
||||
url,
|
||||
container,
|
||||
):
|
||||
"""Create a container
|
||||
|
||||
:param api: a restapi object
|
||||
:param session: a restapi object
|
||||
:param url: endpoint
|
||||
:param container: name of container to create
|
||||
:returns: dict of returned headers
|
||||
"""
|
||||
|
||||
response = api.put("%s/%s" % (url, container))
|
||||
response = session.put("%s/%s" % (url, container))
|
||||
url_parts = urlparse(url)
|
||||
data = {
|
||||
'account': url_parts.path.split('/')[-1],
|
||||
'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
|
||||
|
||||
|
||||
def delete_container(
|
||||
api,
|
||||
session,
|
||||
url,
|
||||
container,
|
||||
):
|
||||
"""Delete a container
|
||||
|
||||
:param api: a restapi object
|
||||
:param session: a restapi object
|
||||
:param url: endpoint
|
||||
:param container: name of container to delete
|
||||
"""
|
||||
|
||||
api.delete("%s/%s" % (url, container))
|
||||
session.delete("%s/%s" % (url, container))
|
||||
|
||||
|
||||
def list_containers(
|
||||
api,
|
||||
session,
|
||||
url,
|
||||
marker=None,
|
||||
limit=None,
|
||||
@ -72,7 +72,7 @@ def list_containers(
|
||||
):
|
||||
"""Get containers in an account
|
||||
|
||||
:param api: a restapi object
|
||||
:param session: a restapi object
|
||||
:param url: endpoint
|
||||
:param marker: marker query
|
||||
:param limit: limit query
|
||||
@ -85,7 +85,7 @@ def list_containers(
|
||||
|
||||
if full_listing:
|
||||
data = listing = list_containers(
|
||||
api,
|
||||
session,
|
||||
url,
|
||||
marker,
|
||||
limit,
|
||||
@ -95,7 +95,7 @@ def list_containers(
|
||||
while listing:
|
||||
marker = listing[-1]['name']
|
||||
listing = list_containers(
|
||||
api,
|
||||
session,
|
||||
url,
|
||||
marker,
|
||||
limit,
|
||||
@ -117,34 +117,35 @@ def list_containers(
|
||||
params['end_marker'] = end_marker
|
||||
if prefix:
|
||||
params['prefix'] = prefix
|
||||
return api.list(url, params=params)
|
||||
return session.get(url, params=params).json()
|
||||
|
||||
|
||||
def show_container(
|
||||
api,
|
||||
session,
|
||||
url,
|
||||
container,
|
||||
):
|
||||
"""Get container details
|
||||
|
||||
:param api: a restapi object
|
||||
:param session: a restapi object
|
||||
:param url: endpoint
|
||||
:param container: name of container to show
|
||||
:returns: dict of returned headers
|
||||
"""
|
||||
|
||||
response = api.head("%s/%s" % (url, container))
|
||||
url_parts = urlparse(url)
|
||||
response = session.head("%s/%s" % (url, container))
|
||||
data = {
|
||||
'account': url_parts.path.split('/')[-1],
|
||||
'account': response.headers.get('x-container-meta-owner', None),
|
||||
'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
|
||||
|
@ -25,14 +25,14 @@ except ImportError:
|
||||
|
||||
|
||||
def create_object(
|
||||
api,
|
||||
session,
|
||||
url,
|
||||
container,
|
||||
object,
|
||||
):
|
||||
"""Create an object, upload it to a container
|
||||
|
||||
:param api: a restapi object
|
||||
:param session: a restapi object
|
||||
:param url: endpoint
|
||||
:param container: name of container to store object
|
||||
:param object: local path to object
|
||||
@ -40,38 +40,38 @@ def create_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)
|
||||
data = {
|
||||
'account': url_parts.path.split('/')[-1],
|
||||
'container': container,
|
||||
'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
|
||||
|
||||
|
||||
def delete_object(
|
||||
api,
|
||||
session,
|
||||
url,
|
||||
container,
|
||||
object,
|
||||
):
|
||||
"""Delete an object stored in a container
|
||||
|
||||
:param api: a restapi object
|
||||
:param session: a restapi object
|
||||
:param url: endpoint
|
||||
:param container: name of container that stores object
|
||||
: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(
|
||||
api,
|
||||
session,
|
||||
url,
|
||||
container,
|
||||
marker=None,
|
||||
@ -84,7 +84,7 @@ def list_objects(
|
||||
):
|
||||
"""Get objects in a container
|
||||
|
||||
:param api: a restapi object
|
||||
:param session: a restapi object
|
||||
:param url: endpoint
|
||||
:param container: container name to get a listing for
|
||||
:param marker: marker query
|
||||
@ -101,7 +101,7 @@ def list_objects(
|
||||
|
||||
if full_listing:
|
||||
data = listing = list_objects(
|
||||
api,
|
||||
session,
|
||||
url,
|
||||
container,
|
||||
marker,
|
||||
@ -117,7 +117,7 @@ def list_objects(
|
||||
else:
|
||||
marker = listing[-1]['name']
|
||||
listing = list_objects(
|
||||
api,
|
||||
session,
|
||||
url,
|
||||
container,
|
||||
marker,
|
||||
@ -131,7 +131,6 @@ def list_objects(
|
||||
data.extend(listing)
|
||||
return data
|
||||
|
||||
object_url = url
|
||||
params = {
|
||||
'format': 'json',
|
||||
}
|
||||
@ -147,32 +146,31 @@ def list_objects(
|
||||
params['prefix'] = prefix
|
||||
if path:
|
||||
params['path'] = path
|
||||
url = "%s/%s" % (object_url, container)
|
||||
return api.list(url, params=params)
|
||||
requrl = "%s/%s" % (url, container)
|
||||
return session.get(requrl, params=params).json()
|
||||
|
||||
|
||||
def show_object(
|
||||
api,
|
||||
session,
|
||||
url,
|
||||
container,
|
||||
obj,
|
||||
):
|
||||
"""Get object details
|
||||
|
||||
:param api: a restapi object
|
||||
:param session: a restapi object
|
||||
:param url: endpoint
|
||||
:param container: container name to get a listing for
|
||||
:returns: dict of object properties
|
||||
"""
|
||||
|
||||
response = api.head("%s/%s/%s" % (url, container, obj))
|
||||
url_parts = urlparse(url)
|
||||
response = session.head("%s/%s/%s" % (url, container, obj))
|
||||
data = {
|
||||
'account': url_parts.path.split('/')[-1],
|
||||
'account': response.headers.get('x-container-meta-owner', None),
|
||||
'container': container,
|
||||
'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:
|
||||
data['content-length'] = response.headers.get('content-length', None)
|
||||
if 'last-modified' in response.headers:
|
||||
@ -184,10 +182,10 @@ def show_object(
|
||||
'x-object-manifest', None)
|
||||
for key, value in six.iteritems(response.headers):
|
||||
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 (
|
||||
'content-type', 'content-length', 'last-modified',
|
||||
'etag', 'date', 'x-object-manifest'):
|
||||
data[key.title()] = value
|
||||
'etag', 'date', 'x-object-manifest', 'x-container-meta-owner'):
|
||||
data[key.lower()] = value
|
||||
|
||||
return data
|
||||
|
@ -50,7 +50,7 @@ class CreateObject(show.ShowOne):
|
||||
self.log.debug('take_action(%s)', parsed_args)
|
||||
|
||||
data = lib_object.create_object(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
self.app.client_manager.object_store.endpoint,
|
||||
parsed_args.container,
|
||||
parsed_args.object,
|
||||
@ -82,7 +82,7 @@ class DeleteObject(command.Command):
|
||||
self.log.debug('take_action(%s)', parsed_args)
|
||||
|
||||
lib_object.delete_object(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
self.app.client_manager.object_store.endpoint,
|
||||
parsed_args.container,
|
||||
parsed_args.object,
|
||||
@ -170,7 +170,7 @@ class ListObject(lister.Lister):
|
||||
kwargs['full_listing'] = True
|
||||
|
||||
data = lib_object.list_objects(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
self.app.client_manager.object_store.endpoint,
|
||||
parsed_args.container,
|
||||
**kwargs
|
||||
@ -206,7 +206,7 @@ class ShowObject(show.ShowOne):
|
||||
self.log.debug('take_action(%s)', parsed_args)
|
||||
|
||||
data = lib_object.show_object(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
self.app.client_manager.object_store.endpoint,
|
||||
parsed_args.container,
|
||||
parsed_args.object,
|
||||
|
@ -31,7 +31,6 @@ import openstackclient
|
||||
from openstackclient.common import clientmanager
|
||||
from openstackclient.common import commandmanager
|
||||
from openstackclient.common import exceptions as exc
|
||||
from openstackclient.common import restapi
|
||||
from openstackclient.common import timing
|
||||
from openstackclient.common import utils
|
||||
|
||||
@ -467,10 +466,6 @@ class OpenStackShell(app.App):
|
||||
self.verify = self.options.os_cacert
|
||||
else:
|
||||
self.verify = not self.options.insecure
|
||||
self.restapi = restapi.RESTApi(
|
||||
verify=self.verify,
|
||||
debug=self.options.debug,
|
||||
)
|
||||
|
||||
def prepare_to_run_command(self, cmd):
|
||||
"""Set up auth and API versions"""
|
||||
@ -481,12 +476,10 @@ class OpenStackShell(app.App):
|
||||
if cmd.best_effort:
|
||||
try:
|
||||
self.authenticate_user()
|
||||
self.restapi.set_auth(self.client_manager.identity.auth_token)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
self.authenticate_user()
|
||||
self.restapi.set_auth(self.client_manager.identity.auth_token)
|
||||
return
|
||||
|
||||
def clean_up(self, cmd, result, err):
|
||||
@ -522,7 +515,6 @@ class OpenStackShell(app.App):
|
||||
# NOTE(dtroyer): Maintain the old behaviour for interactive use as
|
||||
# this path does not call prepare_to_run_command()
|
||||
self.authenticate_user()
|
||||
self.restapi.set_auth(self.client_manager.identity.auth_token)
|
||||
super(OpenStackShell, self).interact()
|
||||
|
||||
|
||||
|
@ -14,11 +14,26 @@
|
||||
#
|
||||
|
||||
from openstackclient.common import clientmanager
|
||||
from openstackclient.common import restapi
|
||||
from openstackclient.tests import utils
|
||||
|
||||
|
||||
AUTH_REF = {'a': 1}
|
||||
AUTH_TOKEN = "foobar"
|
||||
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):
|
||||
@ -28,18 +43,7 @@ class Container(object):
|
||||
pass
|
||||
|
||||
|
||||
class TestClientManager(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,
|
||||
)
|
||||
class TestClientCache(utils.TestCase):
|
||||
|
||||
def test_singleton(self):
|
||||
# NOTE(dtroyer): Verify that the ClientCache descriptor only invokes
|
||||
@ -47,12 +51,88 @@ class TestClientManager(utils.TestCase):
|
||||
c = Container()
|
||||
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.client_manager.identity.auth_token,
|
||||
AUTH_TOKEN,
|
||||
client_manager._token,
|
||||
)
|
||||
self.assertEqual(
|
||||
self.client_manager.identity.management_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.
|
||||
#
|
||||
|
||||
import json
|
||||
import six
|
||||
import sys
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
AUTH_TOKEN = "foobar"
|
||||
AUTH_URL = "http://0.0.0.0"
|
||||
@ -42,7 +45,6 @@ class FakeApp(object):
|
||||
self.stdin = sys.stdin
|
||||
self.stdout = _stdout or sys.stdout
|
||||
self.stderr = sys.stderr
|
||||
self.restapi = None
|
||||
|
||||
|
||||
class FakeClientManager(object):
|
||||
@ -53,6 +55,7 @@ class FakeClientManager(object):
|
||||
self.object = None
|
||||
self.volume = None
|
||||
self.network = None
|
||||
self.session = None
|
||||
self.auth_ref = None
|
||||
|
||||
|
||||
@ -78,3 +81,15 @@ class FakeResource(object):
|
||||
k != 'manager')
|
||||
info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys)
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -39,156 +39,158 @@ class TestContainer(object_fakes.TestObjectv1):
|
||||
|
||||
def setUp(self):
|
||||
super(TestContainer, self).setUp()
|
||||
self.app.restapi = mock.MagicMock()
|
||||
self.app.client_manager.session = mock.MagicMock()
|
||||
|
||||
|
||||
class TestContainerList(TestContainer):
|
||||
|
||||
def test_container_list_no_options(self):
|
||||
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(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
fake_url,
|
||||
)
|
||||
|
||||
# Check expected values
|
||||
self.app.restapi.list.assert_called_with(
|
||||
self.app.client_manager.session.get.assert_called_with(
|
||||
fake_url,
|
||||
params={
|
||||
'format': 'json',
|
||||
}
|
||||
)
|
||||
self.assertEqual(data, resp)
|
||||
self.assertEqual(resp, data)
|
||||
|
||||
def test_container_list_marker(self):
|
||||
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(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
fake_url,
|
||||
marker='next',
|
||||
)
|
||||
|
||||
# Check expected values
|
||||
self.app.restapi.list.assert_called_with(
|
||||
self.app.client_manager.session.get.assert_called_with(
|
||||
fake_url,
|
||||
params={
|
||||
'format': 'json',
|
||||
'marker': 'next',
|
||||
}
|
||||
)
|
||||
self.assertEqual(data, resp)
|
||||
self.assertEqual(resp, data)
|
||||
|
||||
def test_container_list_limit(self):
|
||||
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(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
fake_url,
|
||||
limit=5,
|
||||
)
|
||||
|
||||
# Check expected values
|
||||
self.app.restapi.list.assert_called_with(
|
||||
self.app.client_manager.session.get.assert_called_with(
|
||||
fake_url,
|
||||
params={
|
||||
'format': 'json',
|
||||
'limit': 5,
|
||||
}
|
||||
)
|
||||
self.assertEqual(data, resp)
|
||||
self.assertEqual(resp, data)
|
||||
|
||||
def test_container_list_end_marker(self):
|
||||
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(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
fake_url,
|
||||
end_marker='last',
|
||||
)
|
||||
|
||||
# Check expected values
|
||||
self.app.restapi.list.assert_called_with(
|
||||
self.app.client_manager.session.get.assert_called_with(
|
||||
fake_url,
|
||||
params={
|
||||
'format': 'json',
|
||||
'end_marker': 'last',
|
||||
}
|
||||
)
|
||||
self.assertEqual(data, resp)
|
||||
self.assertEqual(resp, data)
|
||||
|
||||
def test_container_list_prefix(self):
|
||||
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(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
fake_url,
|
||||
prefix='foo/',
|
||||
)
|
||||
|
||||
# Check expected values
|
||||
self.app.restapi.list.assert_called_with(
|
||||
self.app.client_manager.session.get.assert_called_with(
|
||||
fake_url,
|
||||
params={
|
||||
'format': 'json',
|
||||
'prefix': 'foo/',
|
||||
}
|
||||
)
|
||||
self.assertEqual(data, resp)
|
||||
self.assertEqual(resp, data)
|
||||
|
||||
def test_container_list_full_listing(self):
|
||||
sess = self.app.client_manager.session
|
||||
|
||||
def side_effect(*args, **kwargs):
|
||||
rv = self.app.restapi.list.return_value
|
||||
self.app.restapi.list.return_value = []
|
||||
self.app.restapi.list.side_effect = None
|
||||
rv = sess.get().json.return_value
|
||||
sess.get().json.return_value = []
|
||||
sess.get().json.side_effect = None
|
||||
return rv
|
||||
|
||||
resp = [{'name': 'is-name'}]
|
||||
self.app.restapi.list.return_value = resp
|
||||
self.app.restapi.list.side_effect = side_effect
|
||||
sess.get().json.return_value = resp
|
||||
sess.get().json.side_effect = side_effect
|
||||
|
||||
data = lib_container.list_containers(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
fake_url,
|
||||
full_listing=True,
|
||||
)
|
||||
|
||||
# Check expected values
|
||||
self.app.restapi.list.assert_called_with(
|
||||
sess.get.assert_called_with(
|
||||
fake_url,
|
||||
params={
|
||||
'format': 'json',
|
||||
'marker': 'is-name',
|
||||
}
|
||||
)
|
||||
self.assertEqual(data, resp)
|
||||
self.assertEqual(resp, data)
|
||||
|
||||
|
||||
class TestContainerShow(TestContainer):
|
||||
|
||||
def test_container_show_no_options(self):
|
||||
resp = {
|
||||
'X-Container-Meta-Owner': fake_account,
|
||||
'x-container-object-count': 1,
|
||||
'x-container-bytes-used': 577,
|
||||
}
|
||||
self.app.restapi.head.return_value = \
|
||||
restapi.FakeResponse(headers=resp)
|
||||
self.app.client_manager.session.head.return_value = \
|
||||
fakes.FakeResponse(headers=resp)
|
||||
|
||||
data = lib_container.show_container(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
fake_url,
|
||||
'is-name',
|
||||
)
|
||||
|
||||
# Check expected values
|
||||
self.app.restapi.head.assert_called_with(
|
||||
self.app.client_manager.session.head.assert_called_with(
|
||||
fake_url + '/is-name',
|
||||
)
|
||||
|
||||
@ -202,4 +204,4 @@ class TestContainerShow(TestContainer):
|
||||
'sync_to': None,
|
||||
'sync_key': None,
|
||||
}
|
||||
self.assertEqual(data, data_expected)
|
||||
self.assertEqual(data_expected, data)
|
||||
|
@ -18,7 +18,7 @@
|
||||
import mock
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -40,99 +40,99 @@ class TestObject(object_fakes.TestObjectv1):
|
||||
|
||||
def setUp(self):
|
||||
super(TestObject, self).setUp()
|
||||
self.app.restapi = mock.MagicMock()
|
||||
self.app.client_manager.session = mock.MagicMock()
|
||||
|
||||
|
||||
class TestObjectListObjects(TestObject):
|
||||
|
||||
def test_list_objects_no_options(self):
|
||||
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(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
fake_url,
|
||||
fake_container,
|
||||
)
|
||||
|
||||
# Check expected values
|
||||
self.app.restapi.list.assert_called_with(
|
||||
self.app.client_manager.session.get.assert_called_with(
|
||||
fake_url + '/' + fake_container,
|
||||
params={
|
||||
'format': 'json',
|
||||
}
|
||||
)
|
||||
self.assertEqual(data, resp)
|
||||
self.assertEqual(resp, data)
|
||||
|
||||
def test_list_objects_marker(self):
|
||||
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(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
fake_url,
|
||||
fake_container,
|
||||
marker='next',
|
||||
)
|
||||
|
||||
# Check expected values
|
||||
self.app.restapi.list.assert_called_with(
|
||||
self.app.client_manager.session.get.assert_called_with(
|
||||
fake_url + '/' + fake_container,
|
||||
params={
|
||||
'format': 'json',
|
||||
'marker': 'next',
|
||||
}
|
||||
)
|
||||
self.assertEqual(data, resp)
|
||||
self.assertEqual(resp, data)
|
||||
|
||||
def test_list_objects_limit(self):
|
||||
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(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
fake_url,
|
||||
fake_container,
|
||||
limit=5,
|
||||
)
|
||||
|
||||
# Check expected values
|
||||
self.app.restapi.list.assert_called_with(
|
||||
self.app.client_manager.session.get.assert_called_with(
|
||||
fake_url + '/' + fake_container,
|
||||
params={
|
||||
'format': 'json',
|
||||
'limit': 5,
|
||||
}
|
||||
)
|
||||
self.assertEqual(data, resp)
|
||||
self.assertEqual(resp, data)
|
||||
|
||||
def test_list_objects_end_marker(self):
|
||||
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(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
fake_url,
|
||||
fake_container,
|
||||
end_marker='last',
|
||||
)
|
||||
|
||||
# Check expected values
|
||||
self.app.restapi.list.assert_called_with(
|
||||
self.app.client_manager.session.get.assert_called_with(
|
||||
fake_url + '/' + fake_container,
|
||||
params={
|
||||
'format': 'json',
|
||||
'end_marker': 'last',
|
||||
}
|
||||
)
|
||||
self.assertEqual(data, resp)
|
||||
self.assertEqual(resp, data)
|
||||
|
||||
def test_list_objects_delimiter(self):
|
||||
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(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
fake_url,
|
||||
fake_container,
|
||||
delimiter='|',
|
||||
@ -142,85 +142,86 @@ class TestObjectListObjects(TestObject):
|
||||
# NOTE(dtroyer): requests handles the URL encoding and we're
|
||||
# mocking that so use the otherwise-not-legal
|
||||
# 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,
|
||||
params={
|
||||
'format': 'json',
|
||||
'delimiter': '|',
|
||||
}
|
||||
)
|
||||
self.assertEqual(data, resp)
|
||||
self.assertEqual(resp, data)
|
||||
|
||||
def test_list_objects_prefix(self):
|
||||
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(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
fake_url,
|
||||
fake_container,
|
||||
prefix='foo/',
|
||||
)
|
||||
|
||||
# Check expected values
|
||||
self.app.restapi.list.assert_called_with(
|
||||
self.app.client_manager.session.get.assert_called_with(
|
||||
fake_url + '/' + fake_container,
|
||||
params={
|
||||
'format': 'json',
|
||||
'prefix': 'foo/',
|
||||
}
|
||||
)
|
||||
self.assertEqual(data, resp)
|
||||
self.assertEqual(resp, data)
|
||||
|
||||
def test_list_objects_path(self):
|
||||
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(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
fake_url,
|
||||
fake_container,
|
||||
path='next',
|
||||
)
|
||||
|
||||
# Check expected values
|
||||
self.app.restapi.list.assert_called_with(
|
||||
self.app.client_manager.session.get.assert_called_with(
|
||||
fake_url + '/' + fake_container,
|
||||
params={
|
||||
'format': 'json',
|
||||
'path': 'next',
|
||||
}
|
||||
)
|
||||
self.assertEqual(data, resp)
|
||||
self.assertEqual(resp, data)
|
||||
|
||||
def test_list_objects_full_listing(self):
|
||||
sess = self.app.client_manager.session
|
||||
|
||||
def side_effect(*args, **kwargs):
|
||||
rv = self.app.restapi.list.return_value
|
||||
self.app.restapi.list.return_value = []
|
||||
self.app.restapi.list.side_effect = None
|
||||
rv = sess.get().json.return_value
|
||||
sess.get().json.return_value = []
|
||||
sess.get().json.side_effect = None
|
||||
return rv
|
||||
|
||||
resp = [{'name': 'is-name'}]
|
||||
self.app.restapi.list.return_value = resp
|
||||
self.app.restapi.list.side_effect = side_effect
|
||||
sess.get().json.return_value = resp
|
||||
sess.get().json.side_effect = side_effect
|
||||
|
||||
data = lib_object.list_objects(
|
||||
self.app.restapi,
|
||||
sess,
|
||||
fake_url,
|
||||
fake_container,
|
||||
full_listing=True,
|
||||
)
|
||||
|
||||
# Check expected values
|
||||
self.app.restapi.list.assert_called_with(
|
||||
sess.get.assert_called_with(
|
||||
fake_url + '/' + fake_container,
|
||||
params={
|
||||
'format': 'json',
|
||||
'marker': 'is-name',
|
||||
}
|
||||
)
|
||||
self.assertEqual(data, resp)
|
||||
self.assertEqual(resp, data)
|
||||
|
||||
|
||||
class TestObjectShowObjects(TestObject):
|
||||
@ -228,19 +229,20 @@ class TestObjectShowObjects(TestObject):
|
||||
def test_object_show_no_options(self):
|
||||
resp = {
|
||||
'content-type': 'text/alpha',
|
||||
'x-container-meta-owner': fake_account,
|
||||
}
|
||||
self.app.restapi.head.return_value = \
|
||||
restapi.FakeResponse(headers=resp)
|
||||
self.app.client_manager.session.head.return_value = \
|
||||
fakes.FakeResponse(headers=resp)
|
||||
|
||||
data = lib_object.show_object(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
fake_url,
|
||||
fake_container,
|
||||
fake_object,
|
||||
)
|
||||
|
||||
# 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),
|
||||
)
|
||||
|
||||
@ -250,7 +252,7 @@ class TestObjectShowObjects(TestObject):
|
||||
'object': fake_object,
|
||||
'content-type': 'text/alpha',
|
||||
}
|
||||
self.assertEqual(data, data_expected)
|
||||
self.assertEqual(data_expected, data)
|
||||
|
||||
def test_object_show_all_options(self):
|
||||
resp = {
|
||||
@ -258,22 +260,23 @@ class TestObjectShowObjects(TestObject):
|
||||
'content-length': 577,
|
||||
'last-modified': '20130101',
|
||||
'etag': 'qaz',
|
||||
'x-container-meta-owner': fake_account,
|
||||
'x-object-manifest': None,
|
||||
'x-object-meta-wife': 'Wilma',
|
||||
'x-tra-header': 'yabba-dabba-do',
|
||||
}
|
||||
self.app.restapi.head.return_value = \
|
||||
restapi.FakeResponse(headers=resp)
|
||||
self.app.client_manager.session.head.return_value = \
|
||||
fakes.FakeResponse(headers=resp)
|
||||
|
||||
data = lib_object.show_object(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
fake_url,
|
||||
fake_container,
|
||||
fake_object,
|
||||
)
|
||||
|
||||
# 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),
|
||||
)
|
||||
|
||||
@ -286,7 +289,7 @@ class TestObjectShowObjects(TestObject):
|
||||
'last-modified': '20130101',
|
||||
'etag': 'qaz',
|
||||
'x-object-manifest': None,
|
||||
'Wife': 'Wilma',
|
||||
'X-Tra-Header': 'yabba-dabba-do',
|
||||
'wife': 'Wilma',
|
||||
'x-tra-header': 'yabba-dabba-do',
|
||||
}
|
||||
self.assertEqual(data, data_expected)
|
||||
self.assertEqual(data_expected, data)
|
||||
|
@ -77,7 +77,7 @@ class TestContainerList(TestObject):
|
||||
kwargs = {
|
||||
}
|
||||
c_mock.assert_called_with(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
AUTH_URL,
|
||||
**kwargs
|
||||
)
|
||||
@ -113,7 +113,7 @@ class TestContainerList(TestObject):
|
||||
'prefix': 'bit',
|
||||
}
|
||||
c_mock.assert_called_with(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
AUTH_URL,
|
||||
**kwargs
|
||||
)
|
||||
@ -148,7 +148,7 @@ class TestContainerList(TestObject):
|
||||
'marker': object_fakes.container_name,
|
||||
}
|
||||
c_mock.assert_called_with(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
AUTH_URL,
|
||||
**kwargs
|
||||
)
|
||||
@ -183,7 +183,7 @@ class TestContainerList(TestObject):
|
||||
'end_marker': object_fakes.container_name_3,
|
||||
}
|
||||
c_mock.assert_called_with(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
AUTH_URL,
|
||||
**kwargs
|
||||
)
|
||||
@ -218,7 +218,7 @@ class TestContainerList(TestObject):
|
||||
'limit': 2,
|
||||
}
|
||||
c_mock.assert_called_with(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
AUTH_URL,
|
||||
**kwargs
|
||||
)
|
||||
@ -252,7 +252,7 @@ class TestContainerList(TestObject):
|
||||
kwargs = {
|
||||
}
|
||||
c_mock.assert_called_with(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
AUTH_URL,
|
||||
**kwargs
|
||||
)
|
||||
@ -296,7 +296,7 @@ class TestContainerList(TestObject):
|
||||
'full_listing': True,
|
||||
}
|
||||
c_mock.assert_called_with(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
AUTH_URL,
|
||||
**kwargs
|
||||
)
|
||||
@ -341,7 +341,7 @@ class TestContainerShow(TestObject):
|
||||
}
|
||||
# lib.container.show_container(api, url, container)
|
||||
c_mock.assert_called_with(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
AUTH_URL,
|
||||
object_fakes.container_name,
|
||||
**kwargs
|
||||
|
@ -71,7 +71,7 @@ class TestObjectList(TestObject):
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
o_mock.assert_called_with(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
AUTH_URL,
|
||||
object_fakes.container_name,
|
||||
)
|
||||
@ -107,7 +107,7 @@ class TestObjectList(TestObject):
|
||||
'prefix': 'floppy',
|
||||
}
|
||||
o_mock.assert_called_with(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
AUTH_URL,
|
||||
object_fakes.container_name_2,
|
||||
**kwargs
|
||||
@ -143,7 +143,7 @@ class TestObjectList(TestObject):
|
||||
'delimiter': '=',
|
||||
}
|
||||
o_mock.assert_called_with(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
AUTH_URL,
|
||||
object_fakes.container_name_2,
|
||||
**kwargs
|
||||
@ -179,7 +179,7 @@ class TestObjectList(TestObject):
|
||||
'marker': object_fakes.object_name_2,
|
||||
}
|
||||
o_mock.assert_called_with(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
AUTH_URL,
|
||||
object_fakes.container_name_2,
|
||||
**kwargs
|
||||
@ -215,7 +215,7 @@ class TestObjectList(TestObject):
|
||||
'end_marker': object_fakes.object_name_2,
|
||||
}
|
||||
o_mock.assert_called_with(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
AUTH_URL,
|
||||
object_fakes.container_name_2,
|
||||
**kwargs
|
||||
@ -251,7 +251,7 @@ class TestObjectList(TestObject):
|
||||
'limit': 2,
|
||||
}
|
||||
o_mock.assert_called_with(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
AUTH_URL,
|
||||
object_fakes.container_name_2,
|
||||
**kwargs
|
||||
@ -287,7 +287,7 @@ class TestObjectList(TestObject):
|
||||
kwargs = {
|
||||
}
|
||||
o_mock.assert_called_with(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
AUTH_URL,
|
||||
object_fakes.container_name,
|
||||
**kwargs
|
||||
@ -337,7 +337,7 @@ class TestObjectList(TestObject):
|
||||
'full_listing': True,
|
||||
}
|
||||
o_mock.assert_called_with(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
AUTH_URL,
|
||||
object_fakes.container_name,
|
||||
**kwargs
|
||||
@ -384,7 +384,7 @@ class TestObjectShow(TestObject):
|
||||
}
|
||||
# lib.container.show_container(api, url, container)
|
||||
c_mock.assert_called_with(
|
||||
self.app.restapi,
|
||||
self.app.client_manager.session,
|
||||
AUTH_URL,
|
||||
object_fakes.container_name,
|
||||
object_fakes.object_name_1,
|
||||
|
Loading…
Reference in New Issue
Block a user