From a10861255087b1122f69b6a863d5374ec113bb58 Mon Sep 17 00:00:00 2001 From: Michael Fritch Date: Tue, 28 Jul 2020 13:57:17 -0600 Subject: [PATCH] mgr/orch: allow for multiline OrchestratorEvent message Signed-off-by: Michael Fritch --- src/pybind/mgr/orchestrator/_interface.py | 10 ++++++++-- .../mgr/orchestrator/tests/test_orchestrator.py | 12 +++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index d7230b32061..b3f2c10bd65 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 1dd6a964a90..cc1e6e401fc 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 -- 2.39.5