[FIX] sentry: enable use of "sentry_odoo_dir" config parameter
Allow using `sentry_release` or `sentry_odoo_dir` in the Odoo configuration file. Previously, the `sentry_odoo_dir` was never actually respected. It would always be overridden by `sentry_release`. Even if `sentry_release` is not set, it will use an empty value instead of using `sentry_odoo_dir` to find the Git commit hash. After this commit, the `sentry_release` parameter still takes precedence. However, if `sentry_release` is not set and `sentry_odoo_dir` is set, then `sentry_odoo_dir` will be used to find the appropriate Git commit hash, which will be used as the `release` value. Both cases are covered by the added unit tests.pull/2516/head
parent
d4cab37f13
commit
93b758bf11
|
@ -46,11 +46,7 @@ def initialize_raven(config, client_cls=None):
|
||||||
_logger.debug(
|
_logger.debug(
|
||||||
"Both sentry_odoo_dir and sentry_release defined, choosing sentry_release"
|
"Both sentry_odoo_dir and sentry_release defined, choosing sentry_release"
|
||||||
)
|
)
|
||||||
options = {
|
options = {}
|
||||||
"release": config.get(
|
|
||||||
"sentry_release", get_odoo_commit(config.get("sentry_odoo_dir"))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
for option in const.get_sentry_options():
|
for option in const.get_sentry_options():
|
||||||
value = config.get("sentry_%s" % option.key, option.default)
|
value = config.get("sentry_%s" % option.key, option.default)
|
||||||
if isinstance(option.converter, abc.Callable):
|
if isinstance(option.converter, abc.Callable):
|
||||||
|
@ -64,6 +60,11 @@ def initialize_raven(config, client_cls=None):
|
||||||
if level not in const.LOG_LEVEL_MAP:
|
if level not in const.LOG_LEVEL_MAP:
|
||||||
level = const.DEFAULT_LOG_LEVEL
|
level = const.DEFAULT_LOG_LEVEL
|
||||||
|
|
||||||
|
if not options.get("release"):
|
||||||
|
options["release"] = config.get(
|
||||||
|
"sentry_release", get_odoo_commit(config.get("sentry_odoo_dir"))
|
||||||
|
)
|
||||||
|
|
||||||
client_cls = client_cls or raven.Client
|
client_cls = client_cls or raven.Client
|
||||||
client = client_cls(**options)
|
client = client_cls(**options)
|
||||||
handler = OdooSentryHandler(
|
handler = OdooSentryHandler(
|
||||||
|
|
|
@ -6,12 +6,16 @@ import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import raven
|
import raven
|
||||||
|
from mock import patch
|
||||||
|
|
||||||
from odoo import exceptions
|
from odoo import exceptions
|
||||||
|
|
||||||
from .. import initialize_raven
|
from .. import initialize_raven
|
||||||
from ..logutils import OdooSentryHandler
|
from ..logutils import OdooSentryHandler
|
||||||
|
|
||||||
|
GIT_SHA = "d670460b4b4aece5915caf5c68d12f560a9fe3e4"
|
||||||
|
RELEASE = "test@1.2.3"
|
||||||
|
|
||||||
|
|
||||||
def log_handler_by_class(logger, handler_cls):
|
def log_handler_by_class(logger, handler_cls):
|
||||||
for handler in logger.handlers:
|
for handler in logger.handlers:
|
||||||
|
@ -117,3 +121,32 @@ class TestClientSetup(unittest.TestCase):
|
||||||
record = logging.LogRecord(__name__, level, __file__, 42, msg, (), exc_info)
|
record = logging.LogRecord(__name__, level, __file__, 42, msg, (), exc_info)
|
||||||
handler.emit(record)
|
handler.emit(record)
|
||||||
self.assertEventNotCaptured(client, level, msg)
|
self.assertEventNotCaptured(client, level, msg)
|
||||||
|
|
||||||
|
@patch("odoo.addons.sentry.get_odoo_commit", return_value=GIT_SHA)
|
||||||
|
def test_config_odoo_dir(self, get_odoo_commit):
|
||||||
|
config = {
|
||||||
|
"sentry_enabled": True,
|
||||||
|
"sentry_dsn": "http://public:secret@example.com/1",
|
||||||
|
"sentry_odoo_dir": "/opt/odoo/core",
|
||||||
|
}
|
||||||
|
client = initialize_raven(config, client_cls=InMemoryClient)
|
||||||
|
self.assertEqual(
|
||||||
|
client.release,
|
||||||
|
GIT_SHA,
|
||||||
|
"Failed to use 'sentry_odoo_dir' parameter appropriately",
|
||||||
|
)
|
||||||
|
|
||||||
|
@patch("odoo.addons.sentry.get_odoo_commit", return_value=GIT_SHA)
|
||||||
|
def test_config_release(self, get_odoo_commit):
|
||||||
|
config = {
|
||||||
|
"sentry_enabled": True,
|
||||||
|
"sentry_dsn": "http://public:secret@example.com/1",
|
||||||
|
"sentry_odoo_dir": "/opt/odoo/core",
|
||||||
|
"sentry_release": RELEASE,
|
||||||
|
}
|
||||||
|
client = initialize_raven(config, client_cls=InMemoryClient)
|
||||||
|
self.assertEqual(
|
||||||
|
client.release,
|
||||||
|
RELEASE,
|
||||||
|
"Failed to use 'sentry_release' parameter appropriately",
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue