From 96e48fad49464459ff4fa30f3397ea13f12378bc Mon Sep 17 00:00:00 2001 From: Nir Magnezi Date: Fri, 9 Mar 2018 00:22:10 +0200 Subject: [PATCH] Adds Octavia to OSClient This patch is the foundation for adding Octavia based scenarios. The Octavia is now a top-level project and starting from it's v2 API, No longer works as a neutron-lbaas provider. This means that in order to interact with it, one should use python-octaviaclient instead of python-neutronclient [1] https://developer.openstack.org/api-ref/load-balancer/v2/#service-endpoints Change-Id: Ia7a83ebe37a49e58400620b7ed3dedac209664f8 (cherry picked from commit 0be028b344ba4ec97c8f1a7f9098ad4fa3156922) --- rally_openstack/osclients.py | 22 ++++++++++++++++++++++ requirements.txt | 1 + tests/unit/fakes.py | 12 ++++++++++++ tests/unit/test_osclients.py | 18 ++++++++++++++++++ 4 files changed, 53 insertions(+) diff --git a/rally_openstack/osclients.py b/rally_openstack/osclients.py index 130aeb4e..028793d7 100644 --- a/rally_openstack/osclients.py +++ b/rally_openstack/osclients.py @@ -396,6 +396,28 @@ class Neutron(OSClient): return client +@configure("octavia", default_version="2", + default_service_type="load-balancer", supported_versions=["2"]) +class Octavia(OSClient): + """Wrapper for OctaviaClient which returns an authenticated native client. + + """ + + def create_client(self, version=None, service_type=None): + """Return octavia client.""" + from octaviaclient.api.v2 import octavia + + kw_args = {} + if self.credential.endpoint_type: + kw_args["endpoint_type"] = self.credential.endpoint_type + + client = octavia.OctaviaAPI( + endpoint=self._get_endpoint(service_type), + session=self.keystone.get_session()[0], + **kw_args) + return client + + @configure("glance", default_version="2", default_service_type="image", supported_versions=["1", "2"]) class Glance(OSClient): diff --git a/requirements.txt b/requirements.txt index a2f3d49e..0a4149b6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -24,6 +24,7 @@ python-muranoclient>=0.8.2 # Apache License, Version python-monascaclient>=1.7.0 # Apache Software License python-neutronclient>=6.3.0 # Apache Software License python-novaclient>=9.1.0 # Apache License, Version 2.0 +python-octaviaclient>=1.4.0 # Apache License, Version 2.0 python-saharaclient>=1.4.0 # Apache License, Version 2.0 python-senlinclient>=1.1.0 # Apache Software License python-swiftclient>=3.2.0 # Apache Software License diff --git a/tests/unit/fakes.py b/tests/unit/fakes.py index f1dd70ae..ecb38d82 100644 --- a/tests/unit/fakes.py +++ b/tests/unit/fakes.py @@ -1490,6 +1490,12 @@ class FakeNeutronClient(object): return "" +class FakeOctaviaClient(object): + + def __init__(self): + pass + + class FakeIronicClient(object): def __init__(self): @@ -1590,6 +1596,7 @@ class FakeClients(object): self._keystone = None self._cinder = None self._neutron = None + self._octavia = None self._sahara = None self._heat = None self._designate = None @@ -1637,6 +1644,11 @@ class FakeClients(object): self._neutron = FakeNeutronClient() return self._neutron + def octavia(self): + if not self._octavia: + self._octavia = FakeOctaviaClient() + return self._octavia + def sahara(self): if not self._sahara: self._sahara = FakeSaharaClient() diff --git a/tests/unit/test_osclients.py b/tests/unit/test_osclients.py index 92111599..7c2e51cf 100644 --- a/tests/unit/test_osclients.py +++ b/tests/unit/test_osclients.py @@ -471,6 +471,24 @@ class OSClientsTestCase(test.TestCase): mock_neutron.client.Client.assert_called_once_with("2.0", **kw) self.assertEqual(fake_neutron, self.clients.cache["neutron"]) + @mock.patch("%s.Octavia._get_endpoint" % PATH) + def test_octavia(self, mock_octavia__get_endpoint): + fake_octavia = fakes.FakeOctaviaClient() + mock_octavia__get_endpoint.return_value = "http://fake.to:2/fake" + mock_octavia = mock.MagicMock() + mock_keystoneauth1 = mock.MagicMock() + mock_octavia.octavia.OctaviaAPI.return_value = fake_octavia + self.assertNotIn("octavia", self.clients.cache) + with mock.patch.dict("sys.modules", + {"octaviaclient.api.v2": mock_octavia, + "keystoneauth1": mock_keystoneauth1}): + client = self.clients.octavia() + self.assertEqual(fake_octavia, client) + kw = {"endpoint": mock_octavia__get_endpoint.return_value, + "session": mock_keystoneauth1.session.Session()} + mock_octavia.octavia.OctaviaAPI.assert_called_once_with(**kw) + self.assertEqual(fake_octavia, self.clients.cache["octavia"]) + @mock.patch("%s.Heat._get_endpoint" % PATH) def test_heat(self, mock_heat__get_endpoint): fake_heat = fakes.FakeHeatClient()