Raise exception when failed to get discovery_url

If discovery endpoint is not accessible, magnum returns "ERROR: Timed
out waiting for a reply to message ID a74fe7ec63b34f298c46c9f6659257d7
(HTTP 500)" when we create a bay. The response is misleading.
So we should raise exception when magnum fails to get discovery_url
and make the response easy to understand.

Change-Id: Ia649e55de0878160f42fecf1647d9da7fc954d72
Closes-Bug: #1529200
This commit is contained in:
Hua Wang 2015-12-25 17:22:19 +08:00
parent aa82107e7b
commit c249660f5e
3 changed files with 25 additions and 1 deletions

View File

@ -283,6 +283,10 @@ class InvalidDiscoveryURL(Invalid):
"discovery endpoint '%(discovery_endpoint)s'.")
class GetDiscoveryUrlFailed(MagnumException):
message = _("Fail to get discovery url from %(discovery_endpoint)")
class InvalidUuidOrName(Invalid):
message = _("Expected a name or uuid but received %(uuid)s.")

View File

@ -375,7 +375,12 @@ class BaseTemplateDefinition(TemplateDefinition):
discovery_endpoint = (
cfg.CONF.bay.etcd_discovery_service_endpoint_format %
{'size': bay.master_count})
discovery_url = requests.get(discovery_endpoint).text
try:
discovery_url = requests.get(discovery_endpoint).text
except Exception as err:
LOG.error(six.text_type(err))
raise exception.GetDiscoveryUrlFailed(
discovery_endpoint=discovery_endpoint)
if not discovery_url:
raise exception.InvalidDiscoveryURL(
discovery_url=discovery_url,

View File

@ -288,6 +288,21 @@ class AtomicK8sTemplateDefinitionTestCase(base.TestCase):
self.assertEqual(expected_discovery_url, mock_bay.discovery_url)
self.assertEqual(expected_discovery_url, discovery_url)
@mock.patch('requests.get')
def test_k8s_get_discovery_url_fail(self, mock_get):
cfg.CONF.set_override('etcd_discovery_service_endpoint_format',
'http://etcd/test?size=%(size)d',
group='bay')
mock_get.side_effect = Exception()
mock_bay = mock.MagicMock()
mock_bay.master_count = 10
mock_bay.discovery_url = None
k8s_def = tdef.AtomicK8sTemplateDefinition()
self.assertRaises(exception.GetDiscoveryUrlFailed,
k8s_def.get_discovery_url, mock_bay)
def test_k8s_get_heat_param(self):
k8s_def = tdef.AtomicK8sTemplateDefinition()