From 0220e1cd5ade19a54c708fb565fa432e2d7be053 Mon Sep 17 00:00:00 2001 From: Victoria Martinez de la Cruz Date: Mon, 8 Dec 2014 16:00:23 -0300 Subject: [PATCH] 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 --- trove/common/cfg.py | 2 +- trove/common/exception.py | 7 ------- trove/common/remote.py | 14 +++++--------- trove/tests/unittests/common/test_remote.py | 9 ++------- 4 files changed, 8 insertions(+), 24 deletions(-) diff --git a/trove/common/cfg.py b/trove/common/cfg.py index 4782047451..3bd3f9aae7 100644 --- a/trove/common/cfg.py +++ b/trove/common/cfg.py @@ -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', diff --git a/trove/common/exception.py b/trove/common/exception.py index 4b123773df..d92955d5ee 100644 --- a/trove/common/exception.py +++ b/trove/common/exception.py @@ -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, " diff --git a/trove/common/remote.py b/trove/common/remote.py index ce8164213d..ae3536747d 100644 --- a/trove/common/remote.py +++ b/trove/common/remote.py @@ -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] diff --git a/trove/tests/unittests/common/test_remote.py b/trove/tests/unittests/common/test_remote.py index cae9596db0..a5a5512a5c 100644 --- a/trove/tests/unittests/common/test_remote.py +++ b/trove/tests/unittests/common/test_remote.py @@ -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,