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
This commit is contained in:
kaz_shinohara 2018-07-09 11:46:47 +09:00
parent ab55acf43b
commit 64a60dd040
7 changed files with 92 additions and 0 deletions

View File

@ -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)

View File

@ -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

View File

@ -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())

View File

@ -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

View File

@ -0,0 +1,4 @@
---
other:
- |
Introduce a Blazar client plugin module that will be used by Blazar resources.

View File

@ -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

View File

@ -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