From d3a2263ec975370e26bd945c88cae9cbe8fd13c1 Mon Sep 17 00:00:00 2001 From: dagnello Date: Wed, 9 Dec 2015 16:31:36 -0800 Subject: [PATCH] Adding Cue client to osclients Including Cue client unit tests Change-Id: I957fb50f496f6dd2be2c0499f67eb86b983e5d20 --- optional-requirements.txt | 1 + rally/osclients.py | 16 ++++++++++++++++ tests/unit/fakes.py | 6 ++++++ tests/unit/test_osclients.py | 18 ++++++++++++++++++ 4 files changed, 41 insertions(+) diff --git a/optional-requirements.txt b/optional-requirements.txt index b93ebc514d..8c551168ca 100644 --- a/optional-requirements.txt +++ b/optional-requirements.txt @@ -2,3 +2,4 @@ python-mistralclient python-fuelclient==6.1.0 python-muranoclient>=0.5.5 python-monascaclient>=1.0.22 +python-cueclient>=1.0.0 diff --git a/rally/osclients.py b/rally/osclients.py index f0f3ff8d90..fccc5d55d3 100644 --- a/rally/osclients.py +++ b/rally/osclients.py @@ -619,6 +619,22 @@ class Monasca(OSClient): return client +@configure("cue", default_version="1", default_service_type="message-broker") +class Cue(OSClient): + def create_client(self, service_type=None): + """Return cue client.""" + from cueclient.v1 import client as cue + + version = self.choose_version() + api_url = self._get_endpoint(service_type) + api_url += "v%s" % version + + session = self._get_session(endpoint=api_url) + endpoint_type = self.credential.endpoint_type, + + return cue.Client(session=session, interface=endpoint_type[0]) + + class Clients(object): """This class simplify and unify work with OpenStack python clients.""" diff --git a/tests/unit/fakes.py b/tests/unit/fakes.py index bddea629f5..b6a110323a 100644 --- a/tests/unit/fakes.py +++ b/tests/unit/fakes.py @@ -1449,6 +1449,12 @@ class FakeEC2Client(object): pass +class FakeCueClient(object): + + def __init__(self): + pass + + class FakeClients(object): def __init__(self, endpoint_=None): diff --git a/tests/unit/test_osclients.py b/tests/unit/test_osclients.py index d451f9e9f3..9bca577a3f 100644 --- a/tests/unit/test_osclients.py +++ b/tests/unit/test_osclients.py @@ -680,3 +680,21 @@ class OSClientsTestCase(test.TestCase): if version is not None: key += "%s" % {"version": version} self.assertEqual(fake_designate, self.clients.cache[key]) + + @mock.patch("rally.osclients.Cue._get_session") + def test_cue(self, mock_cue__get_session): + fake_cue = fakes.FakeCueClient() + mock_cue = mock.MagicMock() + mock_cue.client.Client = mock.MagicMock(return_value=fake_cue) + + mock_cue__get_session.return_value = self.fake_keystone.session + + self.assertNotIn("cue", self.clients.cache) + with mock.patch.dict("sys.modules", {"cueclient": mock_cue, + "cueclient.v1": mock_cue}): + client = self.clients.cue() + self.assertEqual(fake_cue, client) + mock_cue.client.Client.assert_called_once_with( + interface=consts.EndpointType.PUBLIC, + session=self.fake_keystone.session) + self.assertEqual(fake_cue, self.clients.cache["cue"])