Assign os_region_name a default value

Leaving os_region_name is unspecified leads to RegionAmbiguity errors.
Defaulting to RegionOne (DevStacks default) allows Trove working
out-of-the-box with DevStack and, in the more common case of not being
in a DevStack environment, it will fail with a NoServiceEndpoint error.

Change-Id: I772e6698566c4c8e43ec5aebea5ac9362ce01ee7
Closes-Bug: #1361377
This commit is contained in:
Victoria Martinez de la Cruz 2014-12-08 16:00:23 -03:00
parent 80dde965f0
commit 0220e1cd5a
4 changed files with 8 additions and 24 deletions

View File

@ -57,7 +57,7 @@ common_opts = [
help='Set the service and instance task statuses to ERROR '
'when an instance fails to become active within the '
'configured usage_timeout.'),
cfg.StrOpt('os_region_name',
cfg.StrOpt('os_region_name', default='RegionOne',
help='Region name of this node. Used when searching catalog.'),
cfg.StrOpt('nova_compute_url', help='URL without the tenant segment.'),
cfg.StrOpt('nova_compute_service_type', default='compute',

View File

@ -439,13 +439,6 @@ class InvalidInstanceState(TroveError):
"the instance status is currently: %(status)s.")
class RegionAmbiguity(TroveError):
"""Found more than one matching endpoint in Service Catalog."""
message = _("Multiple matches for service_type=%(service_type)s and "
"endpoint_region=%(endpoint_region)s. This generally means "
"that a region is required and you have not supplied one.")
class NoServiceEndpoint(TroveError):
"""Could not find requested endpoint in Service Catalog."""
message = _("Endpoint not found for service_type=%(service_type)s, "

View File

@ -39,16 +39,16 @@ def normalize_url(url):
return url
def get_endpoint(service_catalog, service_type=None, endpoint_region=None,
def get_endpoint(service_catalog, service_type=None,
endpoint_region=CONF.os_region_name,
endpoint_type='publicURL'):
"""
Select an endpoint from the service catalog
We search the full service catalog for services
matching both type and region. If the client
supplied no region then any endpoint matching service_type
is considered a match. There must be one -- and
only one -- successful match in the catalog,
matching both type and region. The client is expected to
supply the region matching the service_type. There must
be one -- and only one -- successful match in the catalog,
otherwise we will raise an exception.
Some parts copied from glance/common/auth.py.
@ -69,10 +69,6 @@ def get_endpoint(service_catalog, service_type=None, endpoint_region=None,
endpoint_region=endpoint_region,
endpoint_type=endpoint_type)
if len(urls) > 1:
raise exception.RegionAmbiguity(service_type=service_type,
endpoint_region=endpoint_region)
return urls[0]

View File

@ -45,7 +45,8 @@ class TestRemote(testtools.TestCase):
mock_resp = MagicMock()
swiftclient.client.Connection.get_container = MagicMock(
return_value=["text", mock_resp])
service_catalog = [{'endpoints': [{'publicURL': 'example.com'}],
service_catalog = [{'endpoints': [{'region': 'RegionOne',
'publicURL': 'example.com'}],
'type': 'object-store'}]
client = remote.create_swift_client(TroveContext(
tenant='123',
@ -581,12 +582,6 @@ class TestEndpoints(testtools.TestCase):
endpoint_region='RegionOne')
self.assertEqual('http://internalURL/', endpoint)
def test_get_endpoint_raises_with_ambiguous_endpoint_region(self):
self.assertRaises(exception.RegionAmbiguity,
remote.get_endpoint,
self.service_catalog,
service_type='object-store')
def test_get_endpoint_raises_with_invalid_service_type(self):
self.assertRaises(exception.NoServiceEndpoint,
remote.get_endpoint,