Update troveclient to 1.0.0
Closes-Bug: #1238121 Author: Robert Myers <robert.myers@rackspace.com> Change-Id: I03d3d95602f4009c97d37fdf8e241ec8ab82389d
This commit is contained in:
parent
dfbafa51cc
commit
8bca2eb363
@ -14,56 +14,33 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
from django.conf import settings # noqa
|
from django.conf import settings # noqa
|
||||||
|
from troveclient.v1 import client
|
||||||
|
|
||||||
try:
|
from openstack_dashboard.api import base
|
||||||
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):
|
LOG = logging.getLogger(__name__)
|
||||||
"""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)
|
|
||||||
|
|
||||||
|
|
||||||
def troveclient(request):
|
def troveclient(request):
|
||||||
if not with_trove:
|
insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
|
||||||
return None
|
cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None)
|
||||||
return client.Dbaas(username=request.user,
|
trove_url = base.url_for(request, 'database')
|
||||||
api_key=None,
|
LOG.debug('troveclient connection created using token "%s" and url "%s"' %
|
||||||
auth_strategy=TokenAuth,
|
(request.user.token.id, trove_url))
|
||||||
region_name=request.user.services_region)
|
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):
|
def instance_list(request, marker=None):
|
||||||
|
@ -27,11 +27,6 @@ DETAILS_URL = reverse('horizon:project:database_backups:detail', args=['id'])
|
|||||||
|
|
||||||
|
|
||||||
class DatabasesBackupsTests(test.TestCase):
|
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', )})
|
@test.create_stubs({api.trove: ('backup_list', )})
|
||||||
def test_index(self):
|
def test_index(self):
|
||||||
api.trove.backup_list(IsA(http.HttpRequest))\
|
api.trove.backup_list(IsA(http.HttpRequest))\
|
||||||
|
@ -23,14 +23,7 @@ from mox import IsA # noqa
|
|||||||
from openstack_dashboard import api
|
from openstack_dashboard import api
|
||||||
from openstack_dashboard.test import helpers as test
|
from openstack_dashboard.test import helpers as test
|
||||||
|
|
||||||
if api.trove.with_trove:
|
from troveclient import common
|
||||||
try:
|
|
||||||
from troveclient.compat import common
|
|
||||||
except ImportError:
|
|
||||||
try:
|
|
||||||
from troveclient import common
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
INDEX_URL = reverse('horizon:project:databases:index')
|
INDEX_URL = reverse('horizon:project:databases:index')
|
||||||
@ -39,11 +32,6 @@ DETAILS_URL = reverse('horizon:project:databases:detail', args=['id'])
|
|||||||
|
|
||||||
|
|
||||||
class DatabaseTests(test.TestCase):
|
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(
|
@test.create_stubs(
|
||||||
{api.trove: ('instance_list', 'flavor_list')})
|
{api.trove: ('instance_list', 'flavor_list')})
|
||||||
def test_index(self):
|
def test_index(self):
|
||||||
|
@ -25,57 +25,55 @@ from keystoneclient import exceptions as keystoneclient
|
|||||||
from neutronclient.common import exceptions as neutronclient
|
from neutronclient.common import exceptions as neutronclient
|
||||||
from novaclient import exceptions as novaclient
|
from novaclient import exceptions as novaclient
|
||||||
from swiftclient import client as swiftclient
|
from swiftclient import client as swiftclient
|
||||||
try:
|
from troveclient import exceptions as troveclient
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
UNAUTHORIZED = (keystoneclient.Unauthorized,
|
UNAUTHORIZED = (
|
||||||
keystoneclient.Forbidden,
|
keystoneclient.Unauthorized,
|
||||||
cinderclient.Unauthorized,
|
keystoneclient.Forbidden,
|
||||||
cinderclient.Forbidden,
|
cinderclient.Unauthorized,
|
||||||
novaclient.Unauthorized,
|
cinderclient.Forbidden,
|
||||||
novaclient.Forbidden,
|
novaclient.Unauthorized,
|
||||||
glanceclient.Unauthorized,
|
novaclient.Forbidden,
|
||||||
neutronclient.Unauthorized,
|
glanceclient.Unauthorized,
|
||||||
neutronclient.Forbidden,
|
neutronclient.Unauthorized,
|
||||||
heatclient.HTTPUnauthorized,
|
neutronclient.Forbidden,
|
||||||
heatclient.HTTPForbidden,)
|
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.
|
# NOTE(gabriel): This is very broad, and may need to be dialed in.
|
||||||
RECOVERABLE = (keystoneclient.ClientException,
|
RECOVERABLE = (
|
||||||
# AuthorizationFailure is raised when Keystone is "unavailable".
|
keystoneclient.ClientException,
|
||||||
keystoneclient.AuthorizationFailure,
|
# AuthorizationFailure is raised when Keystone is "unavailable".
|
||||||
cinderclient.ClientException,
|
keystoneclient.AuthorizationFailure,
|
||||||
cinderclient.ConnectionError,
|
cinderclient.ClientException,
|
||||||
novaclient.ClientException,
|
cinderclient.ConnectionError,
|
||||||
glanceclient.ClientException,
|
novaclient.ClientException,
|
||||||
# NOTE(amotoki): Neutron exceptions other than the first one
|
glanceclient.ClientException,
|
||||||
# are recoverable in many cases (e.g., NetworkInUse is not
|
# NOTE(amotoki): Neutron exceptions other than the first one
|
||||||
# raised once VMs which use the network are terminated).
|
# are recoverable in many cases (e.g., NetworkInUse is not
|
||||||
neutronclient.NeutronClientException,
|
# raised once VMs which use the network are terminated).
|
||||||
neutronclient.NetworkInUseClient,
|
neutronclient.NeutronClientException,
|
||||||
neutronclient.PortInUseClient,
|
neutronclient.NetworkInUseClient,
|
||||||
neutronclient.AlreadyAttachedClient,
|
neutronclient.PortInUseClient,
|
||||||
neutronclient.StateInvalidClient,
|
neutronclient.AlreadyAttachedClient,
|
||||||
swiftclient.ClientException,
|
neutronclient.StateInvalidClient,
|
||||||
heatclient.HTTPException,)
|
swiftclient.ClientException,
|
||||||
|
heatclient.HTTPException,
|
||||||
if with_trove:
|
troveclient.ClientException
|
||||||
UNAUTHORIZED += (troveclient.Unauthorized,)
|
)
|
||||||
NOT_FOUND += (troveclient.NotFound,)
|
|
||||||
RECOVERABLE += (troveclient.ClientException,)
|
|
||||||
|
@ -38,15 +38,8 @@ from keystoneclient.v2_0 import client as keystone_client
|
|||||||
from neutronclient.v2_0 import client as neutron_client
|
from neutronclient.v2_0 import client as neutron_client
|
||||||
from novaclient.v1_1 import client as nova_client
|
from novaclient.v1_1 import client as nova_client
|
||||||
from swiftclient import client as swift_client
|
from swiftclient import client as swift_client
|
||||||
try:
|
from troveclient import client as trove_client
|
||||||
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
|
|
||||||
|
|
||||||
import httplib2
|
import httplib2
|
||||||
import mox
|
import mox
|
||||||
@ -266,8 +259,7 @@ class APITestCase(TestCase):
|
|||||||
self._original_cinderclient = api.cinder.cinderclient
|
self._original_cinderclient = api.cinder.cinderclient
|
||||||
self._original_heatclient = api.heat.heatclient
|
self._original_heatclient = api.heat.heatclient
|
||||||
self._original_ceilometerclient = api.ceilometer.ceilometerclient
|
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.
|
# Replace the clients with our stubs.
|
||||||
api.glance.glanceclient = lambda request: self.stub_glanceclient()
|
api.glance.glanceclient = lambda request: self.stub_glanceclient()
|
||||||
@ -278,8 +270,7 @@ class APITestCase(TestCase):
|
|||||||
api.heat.heatclient = lambda request: self.stub_heatclient()
|
api.heat.heatclient = lambda request: self.stub_heatclient()
|
||||||
api.ceilometer.ceilometerclient = lambda request: \
|
api.ceilometer.ceilometerclient = lambda request: \
|
||||||
self.stub_ceilometerclient()
|
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):
|
def tearDown(self):
|
||||||
super(APITestCase, self).tearDown()
|
super(APITestCase, self).tearDown()
|
||||||
@ -290,8 +281,7 @@ class APITestCase(TestCase):
|
|||||||
api.cinder.cinderclient = self._original_cinderclient
|
api.cinder.cinderclient = self._original_cinderclient
|
||||||
api.heat.heatclient = self._original_heatclient
|
api.heat.heatclient = self._original_heatclient
|
||||||
api.ceilometer.ceilometerclient = self._original_ceilometerclient
|
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):
|
def stub_novaclient(self):
|
||||||
if not hasattr(self, "novaclient"):
|
if not hasattr(self, "novaclient"):
|
||||||
@ -357,12 +347,11 @@ class APITestCase(TestCase):
|
|||||||
CreateMock(ceilometer_client.Client)
|
CreateMock(ceilometer_client.Client)
|
||||||
return self.ceilometerclient
|
return self.ceilometerclient
|
||||||
|
|
||||||
if with_trove:
|
def stub_troveclient(self):
|
||||||
def stub_troveclient(self):
|
if not hasattr(self, "troveclient"):
|
||||||
if not hasattr(self, "troveclient"):
|
self.mox.StubOutWithMock(trove_client, 'Client')
|
||||||
self.mox.StubOutWithMock(trove_client, 'Client')
|
self.troveclient = self.mox.CreateMock(trove_client.Client)
|
||||||
self.troveclient = self.mox.CreateMock(trove_client.Client)
|
return self.troveclient
|
||||||
return self.troveclient
|
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(os.environ.get('WITH_SELENIUM', False),
|
@unittest.skipUnless(os.environ.get('WITH_SELENIUM', False),
|
||||||
|
@ -19,15 +19,7 @@ from keystoneclient import exceptions as keystone_exceptions
|
|||||||
from neutronclient.common import exceptions as neutron_exceptions
|
from neutronclient.common import exceptions as neutron_exceptions
|
||||||
from novaclient import exceptions as nova_exceptions
|
from novaclient import exceptions as nova_exceptions
|
||||||
from swiftclient import client as swift_exceptions
|
from swiftclient import client as swift_exceptions
|
||||||
try:
|
from troveclient import exceptions as trove_exceptions
|
||||||
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 openstack_dashboard.test.test_data import utils
|
from openstack_dashboard.test.test_data import utils
|
||||||
|
|
||||||
@ -82,10 +74,9 @@ def data(TEST):
|
|||||||
cinder_exception = cinder_exceptions.BadRequest
|
cinder_exception = cinder_exceptions.BadRequest
|
||||||
TEST.exceptions.cinder = create_stubbed_exception(cinder_exception)
|
TEST.exceptions.cinder = create_stubbed_exception(cinder_exception)
|
||||||
|
|
||||||
if with_trove:
|
trove_exception = trove_exceptions.ClientException
|
||||||
trove_exception = trove_exceptions.ClientException
|
TEST.exceptions.trove = create_stubbed_exception(trove_exception)
|
||||||
TEST.exceptions.trove = create_stubbed_exception(trove_exception)
|
|
||||||
|
|
||||||
trove_auth = trove_exceptions.Unauthorized
|
trove_auth = trove_exceptions.Unauthorized
|
||||||
TEST.exceptions.trove_unauthorized = \
|
TEST.exceptions.trove_unauthorized = \
|
||||||
create_stubbed_exception(trove_auth)
|
create_stubbed_exception(trove_auth)
|
||||||
|
@ -14,17 +14,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
try:
|
from troveclient.v1 import backups
|
||||||
from troveclient.v1 import backups
|
from troveclient.v1 import instances
|
||||||
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 openstack_dashboard.test.test_data import utils
|
from openstack_dashboard.test.test_data import utils
|
||||||
|
|
||||||
@ -75,14 +66,14 @@ BACKUP_TWO = {
|
|||||||
"description": "Longer description of backup"
|
"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()
|
def data(TEST):
|
||||||
TEST.database_backups = utils.TestDataContainer()
|
database = instances.Instance(instances.Instances(None), DATABASE_DATA)
|
||||||
TEST.databases.add(database)
|
bkup1 = backups.Backup(backups.Backups(None), BACKUP_ONE)
|
||||||
TEST.database_backups.add(bkup1)
|
bkup2 = backups.Backup(backups.Backups(None), BACKUP_TWO)
|
||||||
TEST.database_backups.add(bkup2)
|
|
||||||
|
TEST.databases = utils.TestDataContainer()
|
||||||
|
TEST.database_backups = utils.TestDataContainer()
|
||||||
|
TEST.databases.add(database)
|
||||||
|
TEST.database_backups.add(bkup1)
|
||||||
|
TEST.database_backups.add(bkup2)
|
||||||
|
@ -11,12 +11,6 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
try:
|
|
||||||
import troveclient
|
|
||||||
with_trove = True
|
|
||||||
assert troveclient
|
|
||||||
except ImportError:
|
|
||||||
with_trove = False
|
|
||||||
|
|
||||||
|
|
||||||
def load_test_data(load_onto=None):
|
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 neutron_data
|
||||||
from openstack_dashboard.test.test_data import nova_data
|
from openstack_dashboard.test.test_data import nova_data
|
||||||
from openstack_dashboard.test.test_data import swift_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.
|
# The order of these loaders matters, some depend on others.
|
||||||
loaders = (exceptions.data,
|
loaders = (
|
||||||
keystone_data.data,
|
exceptions.data,
|
||||||
glance_data.data,
|
keystone_data.data,
|
||||||
nova_data.data,
|
glance_data.data,
|
||||||
cinder_data.data,
|
nova_data.data,
|
||||||
neutron_data.data,
|
cinder_data.data,
|
||||||
swift_data.data,
|
neutron_data.data,
|
||||||
heat_data.data,
|
swift_data.data,
|
||||||
ceilometer_data.data,)
|
heat_data.data,
|
||||||
if with_trove:
|
ceilometer_data.data,
|
||||||
loaders += (trove_data.data,)
|
trove_data.data,
|
||||||
|
)
|
||||||
if load_onto:
|
if load_onto:
|
||||||
for data_func in loaders:
|
for data_func in loaders:
|
||||||
data_func(load_onto)
|
data_func(load_onto)
|
||||||
|
@ -16,7 +16,7 @@ python-novaclient>=2.15.0
|
|||||||
python-neutronclient>=2.3.0,<3
|
python-neutronclient>=2.3.0,<3
|
||||||
python-swiftclient>=1.5
|
python-swiftclient>=1.5
|
||||||
python-ceilometerclient>=1.0.6
|
python-ceilometerclient>=1.0.6
|
||||||
python-troveclient<1
|
python-troveclient>=1.0.0
|
||||||
pytz>=2010h
|
pytz>=2010h
|
||||||
# Horizon Utility Requirements
|
# Horizon Utility Requirements
|
||||||
# for SECURE_KEY generation
|
# for SECURE_KEY generation
|
||||||
|
@ -6,7 +6,7 @@ set -o errexit
|
|||||||
# Increment me any time the environment should be rebuilt.
|
# Increment me any time the environment should be rebuilt.
|
||||||
# This includes dependncy changes, directory renames, etc.
|
# This includes dependncy changes, directory renames, etc.
|
||||||
# Simple integer secuence: 1, 2, 3...
|
# Simple integer secuence: 1, 2, 3...
|
||||||
environment_version=40
|
environment_version=41
|
||||||
#--------------------------------------------------------#
|
#--------------------------------------------------------#
|
||||||
|
|
||||||
function usage {
|
function usage {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user