Fix list port failure due to dummy pod entry

1. What is the problem?
If a dummy pod whose region doesn't register any endpoints in Keystone
is created via pod API, port list request to central Neutron server will
fail with EndpointNotFound error.

2. What is the solution to the problem?
Instead of raising EndpointNotFound error, client returns default value
(None or empty list).

3. What the features need to be implemented to the Tricircle
   to realize the solution?
Handle functions in client module return default value when endpoint
url for given service and pod is not found in Keystone.

Change-Id: I3b3667c08cf7a57de35bb49548f41742aeb5e25b
Closes-Bug: #1652588
This commit is contained in:
zhiyuan_cai 2016-12-26 16:25:19 +08:00
parent 639ca707a6
commit 2ceebb04e6
2 changed files with 25 additions and 9 deletions

View File

@ -96,13 +96,26 @@ def _safe_operation(operation_name):
if i == retries:
raise
if cfg.CONF.client.auto_refresh_endpoint:
msg = _LW("%(exception)s, "
"update endpoint and try again") % {
"exception": e.message}
LOG.warning(msg)
LOG.warning(_LW('%(exception)s, '
'update endpoint and try again'),
{'exception': e.message})
instance._update_endpoint_from_keystone(context, True)
else:
raise
except exceptions.EndpointNotFound as e:
# NOTE(zhiyuan) endpoints are not registered in Keystone
# for the given pod and service, we add default behaviours
# for the handle functions
if i < retries and cfg.CONF.client.auto_refresh_endpoint:
LOG.warning(_LW('%(exception)s, '
'update endpoint and try again'),
{'exception': e.message})
instance._update_endpoint_from_keystone(context, True)
continue
if operation_name == 'list':
return []
else:
return None
return handle_args
return handle_func

View File

@ -185,15 +185,18 @@ class ClientTest(unittest.TestCase):
resources = self.client.list_resources(FAKE_RESOURCE, self.context)
self.assertEqual(resources, [{'name': 'res3'}, {'name': 'res2'}])
def test_list_endpoint_not_found(self):
def test_list_create_endpoint_not_found(self):
cfg.CONF.set_override(name='auto_refresh_endpoint', override=False,
group='client')
# delete the configuration so endpoint cannot be found
api.delete_cached_endpoints(self.context, FAKE_SERVICE_ID)
# auto refresh set to False, directly raise exception
self.assertRaises(exceptions.EndpointNotFound,
self.client.list_resources,
FAKE_RESOURCE, self.context, [])
resources = self.client.list_resources(FAKE_RESOURCE, self.context)
# list_resources returns [] by default
self.assertEqual(resources, [])
resource = self.client.create_resources(FAKE_RESOURCE, self.context,
'res3')
# create_resources returns None by default
self.assertEqual(resource, None)
def test_resource_not_supported(self):
# no such resource