Merge "Add base for Swift API Benchmarks - Patch-1"

This commit is contained in:
Jenkins 2015-02-25 07:46:22 +00:00 committed by Gerrit Code Review
commit 02c7872e9d
4 changed files with 93 additions and 0 deletions

View File

@ -29,6 +29,7 @@ from neutronclient.neutron import client as neutron
from novaclient import client as nova
from oslo_config import cfg
from saharaclient import client as sahara
from swiftclient import client as swift
from troveclient import client as trove
from zaqarclient.queues import client as zaqar
@ -331,7 +332,21 @@ class Clients(object):
client = client.client(mistral_url=mistral_url,
service_type="workflowv2",
auth_token=kc.auth_token)
return client
@cached
def swift(self):
"""Return swift client."""
kc = self.keystone()
object_api_url = kc.service_catalog.url_for(
service_type="object-store",
endpoint_type=self.endpoint.endpoint_type,
region_name=self.endpoint.region_name)
client = swift.Connection(retries=1,
preauthurl=object_api_url,
preauthtoken=kc.auth_token,
insecure=CONF.https_insecure,
cacert=CONF.https_cacert)
return client
@cached

View File

@ -31,6 +31,7 @@ python-ironicclient>=0.2.1
python-saharaclient>=0.7.6
python-troveclient>=1.0.7
python-zaqarclient>=0.0.3
python-swiftclient>=2.2.0
python-subunit>=0.0.18
requests>=2.2.0,!=2.4.0
SQLAlchemy>=0.9.7,<=0.9.99

View File

@ -25,6 +25,7 @@ import mock
from neutronclient.common import exceptions as neutron_exceptions
from novaclient import exceptions as nova_exceptions
import six
from swiftclient import exceptions as swift_exceptions
from rally.benchmark.context import base as base_ctx
from rally.benchmark.scenarios import base
@ -285,6 +286,10 @@ class FakeWorkbook(FakeResource):
self.workbook = mock.MagicMock()
class FakeObject(FakeResource):
pass
class FakeManager(object):
def __init__(self):
@ -824,6 +829,49 @@ class FakeWorkbookManager(FakeManager):
return [self.workbook]
class FakeObjectManager(FakeManager):
def get_account(self, **kwargs):
containers = self.list()
return (mock.MagicMock(), [{"name": con.name} for con in containers])
def get_container(self, name, **kwargs):
container = self.find(name=name)
if container is None:
raise swift_exceptions.ClientException("Container GET failed")
return (mock.MagicMock(), [{"name": obj} for obj in container.items])
def put_container(self, name, **kwargs):
if self.find(name=name):
raise swift_exceptions.ClientException("Container PUT failed")
self._cache(FakeObject(name=name))
def delete_container(self, name, **kwargs):
container = self.find(name=name)
if container is None or len(container.items.keys()) > 0:
raise swift_exceptions.ClientException("Container DELETE failed")
self.delete(container.uuid)
def get_object(self, container_name, object_name, **kwargs):
container = self.find(name=container_name)
if container is None or object_name not in container.items:
raise swift_exceptions.ClientException("Object GET failed")
return (mock.MagicMock(), container.items[object_name])
def put_object(self, container_name, object_name, content, **kwargs):
container = self.find(name=container_name)
if container is None or object_name in container.items:
raise swift_exceptions.ClientException("Object PUT failed")
container.items[object_name] = content
return mock.MagicMock()
def delete_object(self, container_name, object_name, **kwargs):
container = self.find(name=container_name)
if container is None or object_name not in container.items:
raise swift_exceptions.ClientException("Object DELETE failed")
del container.items[object_name]
class FakeServiceCatalog(object):
def get_endpoints(self):
return {"image": [{"publicURL": "http://fake.to"}],
@ -1212,6 +1260,10 @@ class FakeMistralClient(object):
self.workbook = FakeWorkbookManager()
class FakeSwiftClient(FakeObjectManager):
pass
class FakeClients(object):
def __init__(self, endpoint_=None):
@ -1227,6 +1279,7 @@ class FakeClients(object):
self._zaqar = None
self._trove = None
self._mistral = None
self._swift = None
self._endpoint = endpoint_ or objects.Endpoint(
"http://fake.example.org:5000/v2.0/",
"fake_username",
@ -1296,6 +1349,11 @@ class FakeClients(object):
self._mistral = FakeMistralClient()
return self._mistral
def swift(self):
if not self._swift:
self._swift = FakeSwiftClient()
return self._swift
class FakeRunner(object):

View File

@ -301,6 +301,25 @@ class OSClientsTestCase(test.TestCase):
)
self.assertEqual(fake_mistral, self.clients.cache["mistral"])
def test_swift(self):
with mock.patch("rally.osclients.swift") as mock_swift:
fake_swift = fakes.FakeSwiftClient()
mock_swift.Connection = mock.MagicMock(return_value=fake_swift)
self.assertNotIn("swift", self.clients.cache)
client = self.clients.swift()
self.assertEqual(client, fake_swift)
self.service_catalog.url_for.assert_called_once_with(
service_type="object-store",
endpoint_type=consts.EndpointType.PUBLIC,
region_name=self.endpoint.region_name)
kw = {"retries": 1,
"preauthurl": self.service_catalog.url_for.return_value,
"preauthtoken": self.fake_keystone.auth_token,
"insecure": False,
"cacert": None}
mock_swift.Connection.assert_called_once_with(**kw)
self.assertEqual(self.clients.cache["swift"], fake_swift)
@mock.patch("rally.osclients.Clients.keystone")
def test_services(self, mock_keystone):
available_services = {consts.ServiceType.IDENTITY: {},