From 7f3d4310fb009ab47d3f50b803d1fc0dca0c74f6 Mon Sep 17 00:00:00 2001 From: yanyanhu Date: Fri, 25 Mar 2016 04:26:06 -0400 Subject: [PATCH] Add basic support for Senlin service This patch adds basic support for Senlin service including consts of Senlin service name, type and Senlin client implementation in osclients module. Change-Id: I94fa1143553b5ac815087820b6bb5ec54db2f3b0 Partial-bp: add-support-for-clustering-service-senlin --- optional-requirements.txt | 1 + rally/consts.py | 4 ++++ rally/osclients.py | 11 +++++++++++ tests/unit/fakes.py | 13 +++++++++++++ tests/unit/test_osclients.py | 16 ++++++++++++++++ 5 files changed, 45 insertions(+) diff --git a/optional-requirements.txt b/optional-requirements.txt index 8c551168ca..94222b99c4 100644 --- a/optional-requirements.txt +++ b/optional-requirements.txt @@ -3,3 +3,4 @@ python-fuelclient==6.1.0 python-muranoclient>=0.5.5 python-monascaclient>=1.0.22 python-cueclient>=1.0.0 +python-senlinclient>=0.3.0 # Apache-2.0 diff --git a/rally/consts.py b/rally/consts.py index 78ce89ccca..e2c54c59ef 100644 --- a/rally/consts.py +++ b/rally/consts.py @@ -26,6 +26,7 @@ from rally.common import utils class _TempestTestsAPI(utils.ImmutableMixin, utils.EnumMixin): BAREMETAL = "baremetal" + CLUSTERING = "clustering" COMPUTE = "compute" DATA_PROCESSING = "data_processing" DATABASE = "database" @@ -103,6 +104,7 @@ class _Service(utils.ImmutableMixin, utils.EnumMixin): CEILOMETER = "ceilometer" MONASCA = "monasca" S3 = "s3" + SENLIN = "senlin" TROVE = "trove" SAHARA = "sahara" SWIFT = "swift" @@ -121,6 +123,7 @@ class _ServiceType(utils.ImmutableMixin, utils.EnumMixin): CLOUD = "cloudformation" ORCHESTRATION = "orchestration" IDENTITY = "identity" + CLUSTERING = "clustering" COMPUTE = "compute" NETWORK = "network" DNS = "dns" @@ -137,6 +140,7 @@ class _ServiceType(utils.ImmutableMixin, utils.EnumMixin): def __init__(self): self.__names = { + self.CLUSTERING: _Service.SENLIN, self.COMPUTE: _Service.NOVA, self.VOLUME: _Service.CINDER, self.SHARE: _Service.MANILA, diff --git a/rally/osclients.py b/rally/osclients.py index 20fd910d09..b25723c735 100644 --- a/rally/osclients.py +++ b/rally/osclients.py @@ -691,6 +691,17 @@ class Cue(OSClient): return cue.Client(session=session, interface=endpoint_type[0]) +@configure("senlin", default_version="1", default_service_type="clustering", + supported_versions=["1"]) +class Senlin(OSClient): + def create_client(self, version=None, service_type=None): + """Return senlin client.""" + from senlinclient import client as senlin + return senlin.Client( + self.choose_version(version), + **self._get_auth_info(project_name_key="project_name")) + + 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 f234960b48..80e8ad2859 100644 --- a/tests/unit/fakes.py +++ b/tests/unit/fakes.py @@ -1457,6 +1457,13 @@ class FakeCueClient(object): pass +class FakeSenlinClient(object): + + def __init__(self): + # TODO(Yanyan Hu):Fake interfaces of senlinclient. + pass + + class FakeClients(object): def __init__(self, credential_=None): @@ -1476,6 +1483,7 @@ class FakeClients(object): self._murano = None self._monasca = None self._ec2 = None + self._senlin = None self._credential = credential_ or objects.Credential( "http://fake.example.org:5000/v2.0/", "fake_username", @@ -1565,6 +1573,11 @@ class FakeClients(object): self._ec2 = FakeEC2Client() return self._ec2 + def senlin(self): + if not self._senlin: + self._senlin = FakeSenlinClient() + return self._senlin + class FakeRunner(object): diff --git a/tests/unit/test_osclients.py b/tests/unit/test_osclients.py index 2a34bd6225..84388b4720 100644 --- a/tests/unit/test_osclients.py +++ b/tests/unit/test_osclients.py @@ -782,3 +782,19 @@ class OSClientsTestCase(test.TestCase): interface=consts.EndpointType.PUBLIC, session=self.fake_keystone.session) self.assertEqual(fake_cue, self.clients.cache["cue"]) + + def test_senlin(self): + mock_senlin = mock.MagicMock() + self.assertNotIn("senlin", self.clients.cache) + with mock.patch.dict("sys.modules", {"senlinclient": mock_senlin}): + client = self.clients.senlin() + self.assertEqual(mock_senlin.client.Client.return_value, client) + mock_senlin.client.Client.assert_called_once_with( + "1", + username=self.credential.username, + password=self.credential.password, + project_name=self.credential.tenant_name, + auth_url=self.credential.auth_url) + self.assertEqual( + mock_senlin.client.Client.return_value, + self.clients.cache["senlin"])