Adds trove python client to rally.osclients

Change-Id: Ibac269afdfcc9a0b2b13827cf16dab2c6041f2d4
This commit is contained in:
ravikumar-venkatesan 2014-12-04 13:29:23 +00:00
parent 23d045cf53
commit 662af3dda5
4 changed files with 78 additions and 0 deletions

View File

@ -29,6 +29,7 @@ from neutronclient.neutron import client as neutron
from novaclient import client as nova from novaclient import client as nova
from oslo.config import cfg from oslo.config import cfg
from saharaclient import client as sahara from saharaclient import client as sahara
from troveclient import client as trove
from zaqarclient.queues import client as zaqar from zaqarclient.queues import client as zaqar
from rally import consts from rally import consts
@ -298,6 +299,20 @@ class Clients(object):
insecure=CONF.https_insecure) insecure=CONF.https_insecure)
return client return client
@cached
def trove(self, version='1.0'):
"""Returns trove client."""
client = trove.Client(version,
username=self.endpoint.username,
api_key=self.endpoint.password,
project_id=self.endpoint.tenant_name,
auth_url=self.endpoint.auth_url,
region_name=self.endpoint.region_name,
timeout=CONF.openstack_client_http_timeout,
insecure=CONF.https_insecure,
cacert=CONF.https_cacert)
return client
@cached @cached
def services(self): def services(self):
"""Return available services names and types. """Return available services names and types.

View File

@ -27,6 +27,7 @@ python-heatclient>=0.2.9
python-ceilometerclient>=1.0.6 python-ceilometerclient>=1.0.6
python-ironicclient>=0.2.1 python-ironicclient>=0.2.1
python-saharaclient>=0.7.6 python-saharaclient>=0.7.6
python-troveclient>=1.0.7
python-zaqarclient>=0.0.3 python-zaqarclient>=0.0.3
python-subunit>=0.0.18 python-subunit>=0.0.18
requests>=2.2.0,!=2.4.0 requests>=2.2.0,!=2.4.0

View File

@ -253,6 +253,10 @@ class FakeQueue(FakeResource):
self.messages.create(**msg) self.messages.create(**msg)
class FakeDbInstance(FakeResource):
pass
class FakeMessage(FakeResource): class FakeMessage(FakeResource):
def __init__(self, manager=None, **kwargs): def __init__(self, manager=None, **kwargs):
super(FakeMessage, self).__init__(manager) super(FakeMessage, self).__init__(manager)
@ -741,6 +745,32 @@ class FakeQueuesManager(FakeManager):
del self.__queues[queue.name] del self.__queues[queue.name]
class FakeDbInstanceManager(FakeManager):
def __init__(self):
super(FakeDbInstanceManager, self).__init__()
self.__db_instances = {}
def create(self, name, flavor_id, size):
instance = FakeDbInstance(self)
instance.name = name or instance.name
instance.flavor_id = flavor_id
instance.size = size
return self._cache(instance)
def list(self):
return self.__db_instances.values()
def delete(self, resource):
if not isinstance(resource, basestring):
resource = resource.id
cached = self.get(resource)
if cached is not None:
cached.status = "DELETE_COMPLETE"
del self.cache[resource]
self.resources_order.remove(resource)
class FakeMessagesManager(FakeManager): class FakeMessagesManager(FakeManager):
def __init__(self, queue='myqueue'): def __init__(self, queue='myqueue'):
super(FakeMessagesManager, self).__init__() super(FakeMessagesManager, self).__init__()
@ -1144,6 +1174,12 @@ class FakeZaqarClient(object):
return self.queues.create(name, **kwargs) return self.queues.create(name, **kwargs)
class FakeTroveClient(object):
def __init__(self):
self.instances = FakeDbInstanceManager()
class FakeClients(object): class FakeClients(object):
def __init__(self, endpoint_=None): def __init__(self, endpoint_=None):
@ -1157,6 +1193,7 @@ class FakeClients(object):
self._designate = None self._designate = None
self._ceilometer = None self._ceilometer = None
self._zaqar = None self._zaqar = None
self._trove = None
self._endpoint = endpoint_ or endpoint.Endpoint( self._endpoint = endpoint_ or endpoint.Endpoint(
"http://fake.example.org:5000/v2.0/", "http://fake.example.org:5000/v2.0/",
"fake_username", "fake_username",
@ -1216,6 +1253,11 @@ class FakeClients(object):
self._zaqar = FakeZaqarClient() self._zaqar = FakeZaqarClient()
return self._zaqar return self._zaqar
def trove(self):
if not self._trove:
self._trove = FakeTroveClient()
return self._trove
class FakeRunner(object): class FakeRunner(object):

View File

@ -263,6 +263,26 @@ class OSClientsTestCase(test.TestCase):
conf=conf) conf=conf)
self.assertEqual(self.clients.cache["zaqar"], fake_zaqar) self.assertEqual(self.clients.cache["zaqar"], fake_zaqar)
@mock.patch("rally.osclients.trove")
def test_trove(self, mock_trove):
fake_trove = fakes.FakeTroveClient()
mock_trove.Client = mock.MagicMock(return_value=fake_trove)
self.assertNotIn("trove", self.clients.cache)
client = self.clients.trove()
self.assertEqual(client, fake_trove)
kw = {
"username": self.endpoint.username,
"api_key": self.endpoint.password,
"project_id": self.endpoint.tenant_name,
"auth_url": self.endpoint.auth_url,
"region_name": self.endpoint.region_name,
"timeout": cfg.CONF.openstack_client_http_timeout,
"insecure": cfg.CONF.https_insecure,
"cacert": cfg.CONF.https_cacert
}
mock_trove.Client.assert_called_once_with("1.0", **kw)
self.assertEqual(self.clients.cache["trove"], fake_trove)
@mock.patch("rally.osclients.Clients.keystone") @mock.patch("rally.osclients.Clients.keystone")
def test_services(self, mock_keystone): def test_services(self, mock_keystone):
available_services = {consts.ServiceType.IDENTITY: {}, available_services = {consts.ServiceType.IDENTITY: {},