From e247c291ed5c38a9dfeecbda462e949b92c88ab1 Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Wed, 4 Jun 2014 15:25:24 +1200 Subject: [PATCH] Implement trove client plugin This moves the client creation code out of Clients._trove() into its own client plugin. Trove is an integrated project, and python-troveclient is a dependency, so the import is now mandatory. Change-Id: I89d290f6a38488779e77ff11bdfdd64c159a57e8 --- heat/engine/clients/__init__.py | 24 ---------------- heat/engine/clients/os/trove.py | 42 ++++++++++++++++++++++++++++ heat/engine/resources/os_database.py | 3 +- heat/tests/test_os_database.py | 12 ++++---- setup.cfg | 1 + 5 files changed, 50 insertions(+), 32 deletions(-) create mode 100644 heat/engine/clients/os/trove.py diff --git a/heat/engine/clients/__init__.py b/heat/engine/clients/__init__.py index 0341a8642..d685c25cf 100644 --- a/heat/engine/clients/__init__.py +++ b/heat/engine/clients/__init__.py @@ -15,7 +15,6 @@ from ceilometerclient import client as ceilometerclient from heatclient import client as heatclient from oslo.config import cfg from stevedore import extension -from troveclient import client as troveclient import warnings from heat.common import heat_keystoneclient as hkc @@ -120,29 +119,6 @@ class OpenStackClients(object): 'Replace with calls to client("trove")') return self.client('trove') - def _trove(self): - - con = self.context - endpoint_type = self._get_client_option('trove', 'endpoint_type') - args = { - 'service_type': 'database', - 'auth_url': con.auth_url, - 'proxy_token': con.auth_token, - 'username': None, - 'password': None, - 'cacert': self._get_client_option('trove', 'ca_file'), - 'insecure': self._get_client_option('trove', 'insecure'), - 'endpoint_type': endpoint_type - } - - client = troveclient.Client('1.0', **args) - management_url = self.url_for(service_type='database', - endpoint_type=endpoint_type) - client.client.auth_token = con.auth_token - client.client.management_url = management_url - - return client - def ceilometer(self): warnings.warn('ceilometer() is deprecated. ' 'Replace with calls to client("ceilometer")') diff --git a/heat/engine/clients/os/trove.py b/heat/engine/clients/os/trove.py new file mode 100644 index 000000000..1a5eb9b76 --- /dev/null +++ b/heat/engine/clients/os/trove.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 troveclient import client as tc + +from heat.engine.clients import client_plugin + + +class TroveClientPlugin(client_plugin.ClientPlugin): + + def _create(self): + + con = self.context + endpoint_type = self._get_client_option('trove', 'endpoint_type') + args = { + 'service_type': 'database', + 'auth_url': con.auth_url, + 'proxy_token': con.auth_token, + 'username': None, + 'password': None, + 'cacert': self._get_client_option('trove', 'ca_file'), + 'insecure': self._get_client_option('trove', 'insecure'), + 'endpoint_type': endpoint_type + } + + client = tc.Client('1.0', **args) + management_url = self.url_for(service_type='database', + endpoint_type=endpoint_type) + client.client.auth_token = con.auth_token + client.client.management_url = management_url + + return client diff --git a/heat/engine/resources/os_database.py b/heat/engine/resources/os_database.py index dcf54863a..bf6e2e960 100644 --- a/heat/engine/resources/os_database.py +++ b/heat/engine/resources/os_database.py @@ -15,7 +15,6 @@ from troveclient.openstack.common.apiclient import exceptions as troveexc from heat.common import exception from heat.engine import attributes -from heat.engine.clients import troveclient from heat.engine import constraints from heat.engine import properties from heat.engine import resource @@ -265,7 +264,7 @@ class OSDBInstance(resource.Resource): def _refresh_instance(self, instance): try: instance.get() - except troveclient.exceptions.RequestEntityTooLarge as exc: + except troveexc.RequestEntityTooLarge as exc: msg = _("Stack %(name)s (%(id)s) received an OverLimit " "response during instance.get(): %(exception)s") LOG.warning(msg % {'name': self.stack.name, diff --git a/heat/tests/test_os_database.py b/heat/tests/test_os_database.py index c1c6b0304..290e5150f 100644 --- a/heat/tests/test_os_database.py +++ b/heat/tests/test_os_database.py @@ -11,13 +11,13 @@ # License for the specific language governing permissions and limitations # under the License. +from troveclient.openstack.common.apiclient import exceptions as troveexc import uuid import six from heat.common import exception from heat.common import template_format -from heat.engine.clients import troveclient from heat.engine import parser from heat.engine.resources import os_database from heat.engine import scheduler @@ -181,7 +181,7 @@ class OSDBInstanceTest(HeatTestCase): # Simulate an OverLimit exception self.m.StubOutWithMock(fake_dbinstance, 'get') fake_dbinstance.get().AndRaise( - troveclient.exceptions.RequestEntityTooLarge) + troveexc.RequestEntityTooLarge) self.m.ReplayAll() @@ -211,7 +211,7 @@ class OSDBInstanceTest(HeatTestCase): fake_dbinstance.delete().AndReturn(None) self.m.StubOutWithMock(fake_dbinstance, 'get') fake_dbinstance.get().AndReturn(None) - fake_dbinstance.get().AndRaise(troveclient.exceptions.NotFound(404)) + fake_dbinstance.get().AndRaise(troveexc.NotFound(404)) self.m.ReplayAll() scheduler.TaskRunner(instance.delete)() @@ -232,9 +232,9 @@ class OSDBInstanceTest(HeatTestCase): # Simulate an OverLimit exception self.m.StubOutWithMock(fake_dbinstance, 'get') fake_dbinstance.get().AndRaise( - troveclient.exceptions.RequestEntityTooLarge) + troveexc.RequestEntityTooLarge) fake_dbinstance.get().AndReturn(None) - fake_dbinstance.get().AndRaise(troveclient.exceptions.NotFound(404)) + fake_dbinstance.get().AndRaise(troveexc.NotFound(404)) self.m.ReplayAll() scheduler.TaskRunner(instance.delete)() @@ -262,7 +262,7 @@ class OSDBInstanceTest(HeatTestCase): scheduler.TaskRunner(instance.create)() self.m.StubOutWithMock(self.fc.instances, 'get') self.fc.instances.get(12345).AndRaise( - troveclient.exceptions.NotFound(404)) + troveexc.NotFound(404)) self.m.ReplayAll() scheduler.TaskRunner(instance.delete)() diff --git a/setup.cfg b/setup.cfg index a2dbf0689..7776a4e53 100644 --- a/setup.cfg +++ b/setup.cfg @@ -43,6 +43,7 @@ heat.clients = nova = heat.engine.clients.os.nova:NovaClientPlugin neutron = heat.engine.clients.os.neutron:NeutronClientPlugin swift = heat.engine.clients.os.swift:SwiftClientPlugin + trove = heat.engine.clients.os.trove:TroveClientPlugin heat.constraints = nova.flavor = heat.engine.resources.server:FlavorConstraint