From 8bca2eb3633cc95d1bb22025ef5e89696c641c40 Mon Sep 17 00:00:00 2001 From: Robert Myers Date: Thu, 17 Oct 2013 08:50:32 -0500 Subject: [PATCH] Update troveclient to 1.0.0 Closes-Bug: #1238121 Author: Robert Myers Change-Id: I03d3d95602f4009c97d37fdf8e241ec8ab82389d --- openstack_dashboard/api/trove.py | 63 ++++-------- .../project/database_backups/tests.py | 5 - .../dashboards/project/databases/tests.py | 14 +-- openstack_dashboard/exceptions.py | 96 +++++++++---------- openstack_dashboard/test/helpers.py | 31 ++---- .../test/test_data/exceptions.py | 21 ++-- .../test/test_data/trove_data.py | 33 +++---- openstack_dashboard/test/test_data/utils.py | 32 +++---- requirements.txt | 2 +- run_tests.sh | 2 +- 10 files changed, 111 insertions(+), 188 deletions(-) diff --git a/openstack_dashboard/api/trove.py b/openstack_dashboard/api/trove.py index b6fc56866d..c677f3124a 100644 --- a/openstack_dashboard/api/trove.py +++ b/openstack_dashboard/api/trove.py @@ -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 -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 +from openstack_dashboard.api import base -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): diff --git a/openstack_dashboard/dashboards/project/database_backups/tests.py b/openstack_dashboard/dashboards/project/database_backups/tests.py index 62f1a6926c..ccff48d1c4 100644 --- a/openstack_dashboard/dashboards/project/database_backups/tests.py +++ b/openstack_dashboard/dashboards/project/database_backups/tests.py @@ -27,11 +27,6 @@ DETAILS_URL = reverse('horizon:project:database_backups:detail', args=['id']) 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))\ diff --git a/openstack_dashboard/dashboards/project/databases/tests.py b/openstack_dashboard/dashboards/project/databases/tests.py index 318115f620..a73067d9ee 100644 --- a/openstack_dashboard/dashboards/project/databases/tests.py +++ b/openstack_dashboard/dashboards/project/databases/tests.py @@ -23,14 +23,7 @@ from mox import IsA # noqa 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') @@ -39,11 +32,6 @@ DETAILS_URL = reverse('horizon:project:databases:detail', args=['id']) 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): diff --git a/openstack_dashboard/exceptions.py b/openstack_dashboard/exceptions.py index 78e677f4f2..949a0ea589 100644 --- a/openstack_dashboard/exceptions.py +++ b/openstack_dashboard/exceptions.py @@ -25,57 +25,55 @@ from keystoneclient import exceptions as keystoneclient 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, + troveclient.NotFound, +) -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,) - -if with_trove: - UNAUTHORIZED += (troveclient.Unauthorized,) - NOT_FOUND += (troveclient.NotFound,) - RECOVERABLE += (troveclient.ClientException,) +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 +) diff --git a/openstack_dashboard/test/helpers.py b/openstack_dashboard/test/helpers.py index 22603332d1..806c30be9d 100644 --- a/openstack_dashboard/test/helpers.py +++ b/openstack_dashboard/test/helpers.py @@ -38,15 +38,8 @@ from keystoneclient.v2_0 import client as keystone_client 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 @@ -266,8 +259,7 @@ class APITestCase(TestCase): 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() @@ -278,8 +270,7 @@ class APITestCase(TestCase): 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() @@ -290,8 +281,7 @@ class APITestCase(TestCase): 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"): @@ -357,12 +347,11 @@ class APITestCase(TestCase): 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), diff --git a/openstack_dashboard/test/test_data/exceptions.py b/openstack_dashboard/test/test_data/exceptions.py index ae8e83145c..1432b590e3 100644 --- a/openstack_dashboard/test/test_data/exceptions.py +++ b/openstack_dashboard/test/test_data/exceptions.py @@ -19,15 +19,7 @@ from keystoneclient import exceptions as keystone_exceptions 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 @@ -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) diff --git a/openstack_dashboard/test/test_data/trove_data.py b/openstack_dashboard/test/test_data/trove_data.py index 134cacb464..0bb1e4bc33 100644 --- a/openstack_dashboard/test/test_data/trove_data.py +++ b/openstack_dashboard/test/test_data/trove_data.py @@ -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 @@ -75,14 +66,14 @@ BACKUP_TWO = { "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) diff --git a/openstack_dashboard/test/test_data/utils.py b/openstack_dashboard/test/test_data/utils.py index 5f8ac13ceb..211054ef95 100644 --- a/openstack_dashboard/test/test_data/utils.py +++ b/openstack_dashboard/test/test_data/utils.py @@ -11,12 +11,6 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -try: - import troveclient - with_trove = True - assert troveclient -except ImportError: - with_trove = False def load_test_data(load_onto=None): @@ -29,21 +23,21 @@ def load_test_data(load_onto=None): from openstack_dashboard.test.test_data import neutron_data from openstack_dashboard.test.test_data import nova_data from openstack_dashboard.test.test_data import swift_data - if with_trove: - from openstack_dashboard.test.test_data import trove_data + from openstack_dashboard.test.test_data import trove_data # The order of these loaders matters, some depend on others. - loaders = (exceptions.data, - keystone_data.data, - glance_data.data, - nova_data.data, - cinder_data.data, - neutron_data.data, - swift_data.data, - heat_data.data, - ceilometer_data.data,) - if with_trove: - loaders += (trove_data.data,) + loaders = ( + exceptions.data, + keystone_data.data, + glance_data.data, + nova_data.data, + cinder_data.data, + neutron_data.data, + swift_data.data, + heat_data.data, + ceilometer_data.data, + trove_data.data, + ) if load_onto: for data_func in loaders: data_func(load_onto) diff --git a/requirements.txt b/requirements.txt index aa4163e046..4f4841a854 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,7 +16,7 @@ python-novaclient>=2.15.0 python-neutronclient>=2.3.0,<3 python-swiftclient>=1.5 python-ceilometerclient>=1.0.6 -python-troveclient<1 +python-troveclient>=1.0.0 pytz>=2010h # Horizon Utility Requirements # for SECURE_KEY generation diff --git a/run_tests.sh b/run_tests.sh index aa2454ea72..e6e124a81e 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -6,7 +6,7 @@ set -o errexit # Increment me any time the environment should be rebuilt. # This includes dependncy changes, directory renames, etc. # Simple integer secuence: 1, 2, 3... -environment_version=40 +environment_version=41 #--------------------------------------------------------# function usage {