From 2ceebb04e6c6e3d97bd019112c104fc8abbbb564 Mon Sep 17 00:00:00 2001 From: zhiyuan_cai Date: Mon, 26 Dec 2016 16:25:19 +0800 Subject: [PATCH] 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 --- tricircle/common/client.py | 21 +++++++++++++++++---- tricircle/tests/unit/common/test_client.py | 13 ++++++++----- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/tricircle/common/client.py b/tricircle/common/client.py index 5e338104..fb79e9cc 100644 --- a/tricircle/common/client.py +++ b/tricircle/common/client.py @@ -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 diff --git a/tricircle/tests/unit/common/test_client.py b/tricircle/tests/unit/common/test_client.py index 58a0f588..15fdea73 100644 --- a/tricircle/tests/unit/common/test_client.py +++ b/tricircle/tests/unit/common/test_client.py @@ -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