Change API unexpected exception message

The "API unexpected exception" message can now be configured
by the cloud provider.

By default it continues to display the "launchpad" webpage to
report the nova bug, but it can be configured by the cloud
provider to point to a custom support page.

Change-Id: Ib262b91b57f832cbcc233f24f15572e1ea6803bd
Closes-Bug: #1810342
This commit is contained in:
Belmiro Moreira 2019-01-02 23:20:55 +01:00
parent a7dd1f8881
commit d23cf26ec7
4 changed files with 28 additions and 5 deletions

View File

@ -29,6 +29,7 @@ from nova.api import wsgi
from nova import exception
from nova import i18n
from nova.i18n import _
from nova import version
LOG = logging.getLogger(__name__)
@ -683,9 +684,10 @@ def expected_errors(errors):
raise
LOG.exception("Unexpected exception in API method")
msg = _('Unexpected API Error. Please report this at '
'http://bugs.launchpad.net/nova/ and attach the Nova '
'API log if possible.\n%s') % type(exc)
msg = _("Unexpected API Error. "
"%(support)s\n%(exc)s" % {
'support': version.support_string(),
'exc': type(exc)})
raise webob.exc.HTTPInternalServerError(explanation=msg)
return wrapped

View File

@ -34,7 +34,8 @@ class VersionTestCase(test.NoDBTestCase):
"[Nova]\n"
"vendor = ACME Corporation\n"
"product = ACME Nova\n"
"package = 1337\n")
"package = 1337\n"
"support = Contact ACME support\n")
def test_release_file(self):
version.loaded = False
real_find_file = cfg.CONF.find_file
@ -49,3 +50,4 @@ class VersionTestCase(test.NoDBTestCase):
self.assertEqual(version.vendor_string(), "ACME Corporation")
self.assertEqual(version.product_string(), "ACME Nova")
self.assertEqual(version.package_string(), "1337")
self.assertEqual(version.support_string(), "Contact ACME support")

View File

@ -17,6 +17,9 @@ import pbr.version
NOVA_VENDOR = "OpenStack Foundation"
NOVA_PRODUCT = "OpenStack Nova"
NOVA_PACKAGE = None # OS distro package version suffix
NOVA_SUPPORT = (
"Please report this at http://bugs.launchpad.net/nova/ "
"and attach the Nova API log if possible.")
loaded = False
version_info = pbr.version.VersionInfo('nova')
@ -33,7 +36,7 @@ def _load_config():
from oslo_log import log as logging
global loaded, NOVA_VENDOR, NOVA_PRODUCT, NOVA_PACKAGE
global loaded, NOVA_VENDOR, NOVA_PRODUCT, NOVA_PACKAGE, NOVA_SUPPORT
if loaded:
return
@ -55,6 +58,9 @@ def _load_config():
if cfg.has_option("Nova", "package"):
NOVA_PACKAGE = cfg.get("Nova", "package")
if cfg.has_option("Nova", "support"):
NOVA_SUPPORT = cfg.get("Nova", "support")
except Exception as ex:
LOG = logging.getLogger(__name__)
LOG.error("Failed to load %(cfgfile)s: %(ex)s",
@ -84,3 +90,9 @@ def version_string_with_package():
return version_info.version_string()
else:
return "%s-%s" % (version_info.version_string(), package_string())
def support_string():
_load_config()
return NOVA_SUPPORT

View File

@ -0,0 +1,7 @@
---
features:
- |
The "API unexpected exception" message can now be configured by the cloud
provider to point to a custom support page.
By default it continues to show "http://bugs.launchpad.net/nova/".
It can be configured using the release file.