From: Michael Fritch Date: Tue, 28 Jul 2020 19:57:17 +0000 (-0600) Subject: mgr/orch: allow for multiline OrchestratorEvent message X-Git-Tag: v17.0.0~1611^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=a10861255087b1122f69b6a863d5374ec113bb58;p=ceph.git mgr/orch: allow for multiline OrchestratorEvent message Signed-off-by: Michael Fritch --- diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index d7230b320613e..b3f2c10bd656e 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -1604,7 +1604,7 @@ class OrchestratorEvent: """ INFO = 'INFO' ERROR = 'ERROR' - regex_v1 = re.compile(r'^([^ ]+) ([^:]+):([^ ]+) \[([^\]]+)\] "(.*)"$') + regex_v1 = re.compile(r'^([^ ]+) ([^:]+):([^ ]+) \[([^\]]+)\] "((?:.|\n)*)"$', re.MULTILINE) def __init__(self, created: Union[str, datetime.datetime], kind, subject, level, message): if isinstance(created, str): @@ -1633,7 +1633,6 @@ class OrchestratorEvent: created = self.created.strftime(DATEFMT) return f'{created} {self.kind_subject()} [{self.level}] "{self.message}"' - @classmethod @handle_type_error def from_json(cls, data) -> "OrchestratorEvent": @@ -1649,6 +1648,13 @@ class OrchestratorEvent: return cls(*match.groups()) raise ValueError(f'Unable to match: "{data}"') + def __eq__(self, other): + if not isinstance(other, OrchestratorEvent): + return False + + return self.created == other.created and self.kind == other.kind \ + and self.subject == other.subject and self.message == other.message + def _mk_orch_methods(cls): # Needs to be defined outside of for. diff --git a/src/pybind/mgr/orchestrator/tests/test_orchestrator.py b/src/pybind/mgr/orchestrator/tests/test_orchestrator.py index 1dd6a964a9007..cc1e6e401fc28 100644 --- a/src/pybind/mgr/orchestrator/tests/test_orchestrator.py +++ b/src/pybind/mgr/orchestrator/tests/test_orchestrator.py @@ -1,5 +1,6 @@ from __future__ import absolute_import +import datetime import json import pytest @@ -278,4 +279,13 @@ events: assert to_format([object], 'yaml', True, cls) == y j = json.loads(to_format(object, 'json', False, cls)) - assert to_format(cls.from_json(j), 'yaml', False, cls) == y \ No newline at end of file + assert to_format(cls.from_json(j), 'yaml', False, cls) == y + + +def test_event_multiline(): + from .._interface import OrchestratorEvent + e = OrchestratorEvent(datetime.datetime.utcnow(), 'service', 'subject', 'ERROR', 'message') + assert OrchestratorEvent.from_json(e.to_json()) == e + + e = OrchestratorEvent(datetime.datetime.utcnow(), 'service', 'subject', 'ERROR', 'multiline\nmessage') + assert OrchestratorEvent.from_json(e.to_json()) == e