Skip to content

Commit

Permalink
Update troveclient to 1.0.0
Browse files Browse the repository at this point in the history
Closes-Bug: #1238121

Author: Robert Myers <robert.myers@rackspace.com>

Change-Id: I03d3d95602f4009c97d37fdf8e241ec8ab82389d
  • Loading branch information
Robert Myers authored and Steve Leon committed Nov 25, 2013
1 parent dfbafa5 commit 8bca2eb
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 190 deletions.
67 changes: 22 additions & 45 deletions openstack_dashboard/api/trove.py
Expand Up @@ -14,56 +14,33 @@
# License for the specific language governing permissions and limitations
# under the License.

import logging

from django.conf import settings # noqa
from troveclient.v1 import client

from openstack_dashboard.api import base


try:
from troveclient.compat import auth
from troveclient.compat import client
with_trove = True
except ImportError:
try:
from troveclient import auth
from troveclient import client
with_trove = True
except ImportError:
with_trove = False


class TokenAuth(object):
"""Simple Token Authentication handler for trove api."""

def __init__(self, client, auth_strategy, auth_url, username, password,
tenant, region, service_type, service_name, service_url):
# TODO(rmyers): handle some of these other args
self.username = username
self.service_type = service_type
self.service_name = service_name
self.region = region

def authenticate(self):
catalog = {
'access': {
'serviceCatalog': self.username.service_catalog,
'token': {
'id': self.username.token.id,
}
}
}
if not with_trove:
return None
return auth.ServiceCatalog(catalog,
service_type=self.service_type,
service_name=self.service_name,
region=self.region)
LOG = logging.getLogger(__name__)


def troveclient(request):
if not with_trove:
return None
return client.Dbaas(username=request.user,
api_key=None,
auth_strategy=TokenAuth,
region_name=request.user.services_region)
insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None)
trove_url = base.url_for(request, 'database')
LOG.debug('troveclient connection created using token "%s" and url "%s"' %
(request.user.token.id, trove_url))
c = client.Client(request.user.username,
request.user.token.id,
project_id=request.user.project_id,
auth_url=trove_url,
insecure=insecure,
cacert=cacert,
http_log_debug=settings.DEBUG)
c.client.auth_token = request.user.token.id
c.client.management_url = trove_url
return c


def instance_list(request, marker=None):
Expand Down
Expand Up @@ -27,11 +27,6 @@


class DatabasesBackupsTests(test.TestCase):
def setUp(self):
if not api.trove.with_trove:
self.skipTest('Skip trove related tests.')
super(DatabasesBackupsTests, self).setUp()

@test.create_stubs({api.trove: ('backup_list', )})
def test_index(self):
api.trove.backup_list(IsA(http.HttpRequest))\
Expand Down
14 changes: 1 addition & 13 deletions openstack_dashboard/dashboards/project/databases/tests.py
Expand Up @@ -23,14 +23,7 @@
from openstack_dashboard import api
from openstack_dashboard.test import helpers as test

if api.trove.with_trove:
try:
from troveclient.compat import common
except ImportError:
try:
from troveclient import common
except ImportError:
pass
from troveclient import common


INDEX_URL = reverse('horizon:project:databases:index')
Expand All @@ -39,11 +32,6 @@


class DatabaseTests(test.TestCase):
def setUp(self):
if not api.trove.with_trove:
self.skipTest('Skip trove related tests.')
super(DatabaseTests, self).setUp()

@test.create_stubs(
{api.trove: ('instance_list', 'flavor_list')})
def test_index(self):
Expand Down
96 changes: 47 additions & 49 deletions openstack_dashboard/exceptions.py
Expand Up @@ -25,57 +25,55 @@
from neutronclient.common import exceptions as neutronclient
from novaclient import exceptions as novaclient
from swiftclient import client as swiftclient
try:
from troveclient.compat import exceptions as troveclient
with_trove = True
except ImportError:
try:
from troveclient import exceptions as troveclient
with_trove = True
except ImportError:
with_trove = False
from troveclient import exceptions as troveclient


UNAUTHORIZED = (keystoneclient.Unauthorized,
keystoneclient.Forbidden,
cinderclient.Unauthorized,
cinderclient.Forbidden,
novaclient.Unauthorized,
novaclient.Forbidden,
glanceclient.Unauthorized,
neutronclient.Unauthorized,
neutronclient.Forbidden,
heatclient.HTTPUnauthorized,
heatclient.HTTPForbidden,)
UNAUTHORIZED = (
keystoneclient.Unauthorized,
keystoneclient.Forbidden,
cinderclient.Unauthorized,
cinderclient.Forbidden,
novaclient.Unauthorized,
novaclient.Forbidden,
glanceclient.Unauthorized,
neutronclient.Unauthorized,
neutronclient.Forbidden,
heatclient.HTTPUnauthorized,
heatclient.HTTPForbidden,
troveclient.Unauthorized,
)

NOT_FOUND = (keystoneclient.NotFound,
cinderclient.NotFound,
novaclient.NotFound,
glanceclient.NotFound,
neutronclient.NetworkNotFoundClient,
neutronclient.PortNotFoundClient,
heatclient.HTTPNotFound,)

# NOTE(gabriel): This is very broad, and may need to be dialed in.
RECOVERABLE = (keystoneclient.ClientException,
# AuthorizationFailure is raised when Keystone is "unavailable".
keystoneclient.AuthorizationFailure,
cinderclient.ClientException,
cinderclient.ConnectionError,
novaclient.ClientException,
glanceclient.ClientException,
# NOTE(amotoki): Neutron exceptions other than the first one
# are recoverable in many cases (e.g., NetworkInUse is not
# raised once VMs which use the network are terminated).
neutronclient.NeutronClientException,
neutronclient.NetworkInUseClient,
neutronclient.PortInUseClient,
neutronclient.AlreadyAttachedClient,
neutronclient.StateInvalidClient,
swiftclient.ClientException,
heatclient.HTTPException,)
NOT_FOUND = (
keystoneclient.NotFound,
cinderclient.NotFound,
novaclient.NotFound,
glanceclient.NotFound,
neutronclient.NetworkNotFoundClient,
neutronclient.PortNotFoundClient,
heatclient.HTTPNotFound,
troveclient.NotFound,
)


if with_trove:
UNAUTHORIZED += (troveclient.Unauthorized,)
NOT_FOUND += (troveclient.NotFound,)
RECOVERABLE += (troveclient.ClientException,)
# NOTE(gabriel): This is very broad, and may need to be dialed in.
RECOVERABLE = (
keystoneclient.ClientException,
# AuthorizationFailure is raised when Keystone is "unavailable".
keystoneclient.AuthorizationFailure,
cinderclient.ClientException,
cinderclient.ConnectionError,
novaclient.ClientException,
glanceclient.ClientException,
# NOTE(amotoki): Neutron exceptions other than the first one
# are recoverable in many cases (e.g., NetworkInUse is not
# raised once VMs which use the network are terminated).
neutronclient.NeutronClientException,
neutronclient.NetworkInUseClient,
neutronclient.PortInUseClient,
neutronclient.AlreadyAttachedClient,
neutronclient.StateInvalidClient,
swiftclient.ClientException,
heatclient.HTTPException,
troveclient.ClientException
)
31 changes: 10 additions & 21 deletions openstack_dashboard/test/helpers.py
Expand Up @@ -38,15 +38,8 @@
from neutronclient.v2_0 import client as neutron_client
from novaclient.v1_1 import client as nova_client
from swiftclient import client as swift_client
try:
from troveclient.compat import client as trove_client
with_trove = True
except ImportError:
try:
from troveclient import client as trove_client
with_trove = True
except ImportError:
with_trove = False
from troveclient import client as trove_client


import httplib2
import mox
Expand Down Expand Up @@ -266,8 +259,7 @@ def fake_keystoneclient(request, admin=False):
self._original_cinderclient = api.cinder.cinderclient
self._original_heatclient = api.heat.heatclient
self._original_ceilometerclient = api.ceilometer.ceilometerclient
if with_trove:
self._original_troveclient = api.trove.troveclient
self._original_troveclient = api.trove.troveclient

# Replace the clients with our stubs.
api.glance.glanceclient = lambda request: self.stub_glanceclient()
Expand All @@ -278,8 +270,7 @@ def fake_keystoneclient(request, admin=False):
api.heat.heatclient = lambda request: self.stub_heatclient()
api.ceilometer.ceilometerclient = lambda request: \
self.stub_ceilometerclient()
if with_trove:
api.trove.troveclient = lambda request: self.stub_troveclient()
api.trove.troveclient = lambda request: self.stub_troveclient()

def tearDown(self):
super(APITestCase, self).tearDown()
Expand All @@ -290,8 +281,7 @@ def tearDown(self):
api.cinder.cinderclient = self._original_cinderclient
api.heat.heatclient = self._original_heatclient
api.ceilometer.ceilometerclient = self._original_ceilometerclient
if with_trove:
api.trove.troveclient = self._original_troveclient
api.trove.troveclient = self._original_troveclient

def stub_novaclient(self):
if not hasattr(self, "novaclient"):
Expand Down Expand Up @@ -357,12 +347,11 @@ def stub_ceilometerclient(self):
CreateMock(ceilometer_client.Client)
return self.ceilometerclient

if with_trove:
def stub_troveclient(self):
if not hasattr(self, "troveclient"):
self.mox.StubOutWithMock(trove_client, 'Client')
self.troveclient = self.mox.CreateMock(trove_client.Client)
return self.troveclient
def stub_troveclient(self):
if not hasattr(self, "troveclient"):
self.mox.StubOutWithMock(trove_client, 'Client')
self.troveclient = self.mox.CreateMock(trove_client.Client)
return self.troveclient


@unittest.skipUnless(os.environ.get('WITH_SELENIUM', False),
Expand Down
21 changes: 6 additions & 15 deletions openstack_dashboard/test/test_data/exceptions.py
Expand Up @@ -19,15 +19,7 @@
from neutronclient.common import exceptions as neutron_exceptions
from novaclient import exceptions as nova_exceptions
from swiftclient import client as swift_exceptions
try:
from troveclient.compat import exceptions as trove_exceptions
with_trove = True
except ImportError:
try:
from troveclient import exceptions as trove_exceptions
with_trove = True
except ImportError:
with_trove = False
from troveclient import exceptions as trove_exceptions

from openstack_dashboard.test.test_data import utils

Expand Down Expand Up @@ -82,10 +74,9 @@ def data(TEST):
cinder_exception = cinder_exceptions.BadRequest
TEST.exceptions.cinder = create_stubbed_exception(cinder_exception)

if with_trove:
trove_exception = trove_exceptions.ClientException
TEST.exceptions.trove = create_stubbed_exception(trove_exception)
trove_exception = trove_exceptions.ClientException
TEST.exceptions.trove = create_stubbed_exception(trove_exception)

trove_auth = trove_exceptions.Unauthorized
TEST.exceptions.trove_unauthorized = \
create_stubbed_exception(trove_auth)
trove_auth = trove_exceptions.Unauthorized
TEST.exceptions.trove_unauthorized = \
create_stubbed_exception(trove_auth)
33 changes: 12 additions & 21 deletions openstack_dashboard/test/test_data/trove_data.py
Expand Up @@ -14,17 +14,8 @@
# License for the specific language governing permissions and limitations
# under the License.

try:
from troveclient.v1 import backups
from troveclient.v1 import instances
with_trove = True
except ImportError:
try:
from troveclient import backups
from troveclient import instances
with_trove = True
except ImportError:
with_trove = False
from troveclient.v1 import backups
from troveclient.v1 import instances

from openstack_dashboard.test.test_data import utils

Expand Down Expand Up @@ -75,14 +66,14 @@
"description": "Longer description of backup"
}

if with_trove:
def data(TEST):
database = instances.Instance(instances.Instances(None), DATABASE_DATA)
bkup1 = backups.Backup(backups.Backups(None), BACKUP_ONE)
bkup2 = backups.Backup(backups.Backups(None), BACKUP_TWO)

TEST.databases = utils.TestDataContainer()
TEST.database_backups = utils.TestDataContainer()
TEST.databases.add(database)
TEST.database_backups.add(bkup1)
TEST.database_backups.add(bkup2)
def data(TEST):
database = instances.Instance(instances.Instances(None), DATABASE_DATA)
bkup1 = backups.Backup(backups.Backups(None), BACKUP_ONE)
bkup2 = backups.Backup(backups.Backups(None), BACKUP_TWO)

TEST.databases = utils.TestDataContainer()
TEST.database_backups = utils.TestDataContainer()
TEST.databases.add(database)
TEST.database_backups.add(bkup1)
TEST.database_backups.add(bkup2)

0 comments on commit 8bca2eb

Please sign in to comment.