From 64a60dd040c2f9985104143153add69a21a2c0fd Mon Sep 17 00:00:00 2001 From: kaz_shinohara Date: Mon, 9 Jul 2018 11:46:47 +0900 Subject: [PATCH] Add Blazar client plugin to Heat Add a Blazar client plugin which will be used by a couple of Balazar resources under development. Change-Id: I0f68fc0525db3ba299d77019a102f24b9d3cea87 Task: 19754 Story: 2002085 --- README.rst | 1 + heat/engine/clients/os/blazar.py | 42 +++++++++++++++++++ heat/tests/clients/test_blazar_client.py | 42 +++++++++++++++++++ lower-constraints.txt | 1 + ...blazar-client-plugin-e2077e8646ca5f1a.yaml | 4 ++ requirements.txt | 1 + setup.cfg | 1 + 7 files changed, 92 insertions(+) create mode 100644 heat/engine/clients/os/blazar.py create mode 100644 heat/tests/clients/test_blazar_client.py create mode 100644 releasenotes/notes/add-blazar-client-plugin-e2077e8646ca5f1a.yaml diff --git a/README.rst b/README.rst index 0264a6f50e..6add1af7cf 100644 --- a/README.rst +++ b/README.rst @@ -62,3 +62,4 @@ We have integration with * https://git.openstack.org/cgit/openstack/python-zaqarclient (messaging service) * https://git.openstack.org/cgit/openstack/python-monascaclient (monitoring service) * https://git.openstack.org/cgit/openstack/python-zunclient (container management service) +* https://git.openstack.org/cgit/openstack/python-blazarclient (reservation service) diff --git a/heat/engine/clients/os/blazar.py b/heat/engine/clients/os/blazar.py new file mode 100644 index 0000000000..3095d46518 --- /dev/null +++ b/heat/engine/clients/os/blazar.py @@ -0,0 +1,42 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from blazarclient import client as blazar_client +from keystoneauth1.exceptions import http as ks_exc + +from heat.engine.clients import client_plugin + +CLIENT_NAME = 'blazar' + + +class BlazarClientPlugin(client_plugin.ClientPlugin): + + service_types = [RESERVATION] = ['reservation'] + + def _create(self, version=None): + interface = self._get_client_option(CLIENT_NAME, 'endpoint_type') + args = { + 'session': self.context.keystone_session, + 'service_type': self.RESERVATION, + 'interface': interface, + 'region_name': self._get_region_name(), + } + + client = blazar_client.Client(**args) + return client + + def is_not_found(self, exc): + return isinstance(exc, ks_exc.NotFound) + + def has_host(self): + return True if self.client().host.list() else False diff --git a/heat/tests/clients/test_blazar_client.py b/heat/tests/clients/test_blazar_client.py new file mode 100644 index 0000000000..f9410f9fe0 --- /dev/null +++ b/heat/tests/clients/test_blazar_client.py @@ -0,0 +1,42 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from heat.tests import common +from heat.tests import utils +import mock + + +class BlazarClientPluginTest(common.HeatTestCase): + + def setUp(self): + super(BlazarClientPluginTest, self).setUp() + self.blazar_client = mock.MagicMock() + context = utils.dummy_context() + self.blazar_client_plugin = context.clients.client_plugin('blazar') + + def _stub_client(self): + self.blazar_client_plugin.client = lambda: self.blazar_client + + def test_create(self): + client = self.blazar_client_plugin.client() + self.assertEqual(None, client.blazar_url) + + def test_has_host_pass(self): + self._stub_client() + self.blazar_client.host.list.return_value = ['hosta'] + self.assertEqual(True, self.blazar_client_plugin.has_host()) + + def test_has_host_fail(self): + self._stub_client() + self.blazar_client.host.list.return_value = [] + self.assertEqual(False, self.blazar_client_plugin.has_host()) diff --git a/lower-constraints.txt b/lower-constraints.txt index 2fd1f2b519..e3c8facad6 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -101,6 +101,7 @@ pyOpenSSL==17.5.0 pyparsing==2.2.0 pyperclip==1.6.0 python-barbicanclient==4.5.2 +python-blazarclient===1.0.0 python-ceilometerclient==2.5.0 python-cinderclient==3.3.0 python-dateutil==2.7.0 diff --git a/releasenotes/notes/add-blazar-client-plugin-e2077e8646ca5f1a.yaml b/releasenotes/notes/add-blazar-client-plugin-e2077e8646ca5f1a.yaml new file mode 100644 index 0000000000..aafae46727 --- /dev/null +++ b/releasenotes/notes/add-blazar-client-plugin-e2077e8646ca5f1a.yaml @@ -0,0 +1,4 @@ +--- +other: + - | + Introduce a Blazar client plugin module that will be used by Blazar resources. diff --git a/requirements.txt b/requirements.txt index 858a9cfd42..bfb3cbb79f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -31,6 +31,7 @@ oslo.versionedobjects>=1.31.2 # Apache-2.0 PasteDeploy>=1.5.0 # MIT aodhclient>=0.9.0 # Apache-2.0 python-barbicanclient>=4.5.2 # Apache-2.0 +python-blazarclient>=1.0.0 # Apache-2.0 python-ceilometerclient>=2.5.0 # Apache-2.0 python-cinderclient>=3.3.0 # Apache-2.0 python-designateclient>=2.7.0 # Apache-2.0 diff --git a/setup.cfg b/setup.cfg index 980e631bd1..c43d0a8ce3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -65,6 +65,7 @@ oslo.policy.policies = heat.clients = aodh = heat.engine.clients.os.aodh:AodhClientPlugin barbican = heat.engine.clients.os.barbican:BarbicanClientPlugin + blazar = heat.engine.clients.os.blazar:BlazarClientPlugin ceilometer = heat.engine.clients.os.ceilometer:CeilometerClientPlugin cinder = heat.engine.clients.os.cinder:CinderClientPlugin designate = heat.engine.clients.os.designate:DesignateClientPlugin