Designate client plugin
Adds the designate client plugin implements blueprint heat-designate-resource Change-Id: I722f90b85ae7bfc91d0a187032bb54158de41d88
This commit is contained in:
parent
1b44bf806a
commit
96ee656ff6
@ -177,3 +177,27 @@ class ClientPlugin(object):
|
||||
return
|
||||
else:
|
||||
raise ex
|
||||
|
||||
def _get_client_args(self,
|
||||
service_name,
|
||||
service_type):
|
||||
endpoint_type = self._get_client_option(service_name,
|
||||
'endpoint_type')
|
||||
endpoint = self.url_for(service_type=service_type,
|
||||
endpoint_type=endpoint_type)
|
||||
args = {
|
||||
'auth_url': self.context.auth_url,
|
||||
'service_type': service_type,
|
||||
'project_id': self.context.tenant_id,
|
||||
'token': lambda: self.auth_token,
|
||||
'endpoint_type': endpoint_type,
|
||||
'os_endpoint': endpoint,
|
||||
'cacert': self._get_client_option(service_name, 'ca_file'),
|
||||
'cert_file': self._get_client_option(service_name, 'cert_file'),
|
||||
'key_file': self._get_client_option(service_name, 'key_file'),
|
||||
'insecure': self._get_client_option(service_name, 'insecure')
|
||||
}
|
||||
|
||||
return args
|
||||
# FIXME(kanagaraj-manickam) Update other client plugins to leverage
|
||||
# this method (bug 1461041)
|
||||
|
31
heat/engine/clients/os/designate.py
Normal file
31
heat/engine/clients/os/designate.py
Normal file
@ -0,0 +1,31 @@
|
||||
#
|
||||
# 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 designateclient import client
|
||||
from designateclient import exceptions
|
||||
|
||||
from heat.engine.clients import client_plugin
|
||||
|
||||
|
||||
class DesignateClientPlugin(client_plugin.ClientPlugin):
|
||||
|
||||
exceptions_module = [exceptions]
|
||||
|
||||
def _create(self):
|
||||
args = self._get_client_args(service_name='designate',
|
||||
service_type='dns')
|
||||
|
||||
return client.client('1', **args)
|
||||
|
||||
def is_not_found(self, ex):
|
||||
return isinstance(ex, exceptions.NotFound)
|
@ -144,6 +144,10 @@ class FooClientsPlugin(client_plugin.ClientPlugin):
|
||||
def _create(self):
|
||||
pass
|
||||
|
||||
@property
|
||||
def auth_token(self):
|
||||
return '5678'
|
||||
|
||||
|
||||
class ClientPluginTest(common.HeatTestCase):
|
||||
|
||||
@ -176,6 +180,69 @@ class ClientPluginTest(common.HeatTestCase):
|
||||
self.assertEqual('/tmp/foo',
|
||||
plugin._get_client_option('foo', 'ca_file'))
|
||||
|
||||
def test_get_client_args(self):
|
||||
plugin = FooClientsPlugin(mock.Mock())
|
||||
|
||||
plugin.url_for = mock.Mock(return_value='sample_endpoint_url')
|
||||
plugin.context = mock.Mock()
|
||||
plugin.context.auth_url = 'sample_auth_url'
|
||||
plugin.context.tenant_id = 'sample_project_id'
|
||||
|
||||
mock_args = {
|
||||
'endpoint_type': 'internalURL',
|
||||
'ca_file': '/tmp/ca_file',
|
||||
'cert_file': '/tmp/cert_file',
|
||||
'key_file': '/tmp/key_file',
|
||||
'insecure': True
|
||||
}
|
||||
|
||||
def _side_effect(service_name, arg_name):
|
||||
return mock_args[arg_name]
|
||||
|
||||
plugin._get_client_option = mock.Mock(side_effect=_side_effect)
|
||||
|
||||
args = plugin._get_client_args('sample_service',
|
||||
'foo_type')
|
||||
|
||||
self.assertEqual('foo_type',
|
||||
args['service_type'],
|
||||
'invalid service_type')
|
||||
|
||||
self.assertEqual('sample_auth_url',
|
||||
args['auth_url'],
|
||||
'invalid auth_url')
|
||||
|
||||
self.assertEqual('sample_project_id',
|
||||
args['project_id'],
|
||||
'invalid project_id')
|
||||
|
||||
self.assertEqual('5678',
|
||||
args['token'](),
|
||||
'invalid auth_token')
|
||||
|
||||
self.assertEqual('sample_endpoint_url',
|
||||
args['os_endpoint'],
|
||||
'invalid os_endpoint')
|
||||
|
||||
self.assertEqual('internalURL',
|
||||
args['endpoint_type'],
|
||||
'invalid endpoint_type')
|
||||
|
||||
self.assertEqual('/tmp/ca_file',
|
||||
args['cacert'],
|
||||
'invalid cacert')
|
||||
|
||||
self.assertEqual('/tmp/cert_file',
|
||||
args['cert_file'],
|
||||
'invalid cert_file')
|
||||
|
||||
self.assertEqual('/tmp/key_file',
|
||||
args['key_file'],
|
||||
'invalid key_file')
|
||||
|
||||
self.assertTrue(args['insecure'],
|
||||
'invalid insecure')
|
||||
|
||||
def test_auth_token(self):
|
||||
con = mock.Mock()
|
||||
con.auth_token = "1234"
|
||||
@ -184,9 +251,6 @@ class ClientPluginTest(common.HeatTestCase):
|
||||
c = clients.Clients(con)
|
||||
con.clients = c
|
||||
|
||||
con.auth_plugin = mock.Mock(name="auth_plugin")
|
||||
con.auth_plugin.get_token = mock.Mock(name="get_token")
|
||||
con.auth_plugin.get_token.return_value = '5678'
|
||||
plugin = FooClientsPlugin(con)
|
||||
|
||||
# assert token is from plugin rather than context
|
||||
|
@ -33,6 +33,7 @@ python-barbicanclient>=3.0.1
|
||||
python-ceilometerclient>=1.0.13
|
||||
python-cinderclient>=1.2.1
|
||||
python-glanceclient>=0.18.0
|
||||
python-designateclient>=1.0.0
|
||||
python-heatclient>=0.3.0
|
||||
python-keystoneclient>=1.6.0
|
||||
python-neutronclient>=2.3.11,<3
|
||||
|
Loading…
x
Reference in New Issue
Block a user