]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/orch: allow for multiline OrchestratorEvent message 36334/head
authorMichael Fritch <mfritch@suse.com>
Tue, 28 Jul 2020 19:57:17 +0000 (13:57 -0600)
committerMichael Fritch <mfritch@suse.com>
Wed, 29 Jul 2020 17:50:55 +0000 (11:50 -0600)
Signed-off-by: Michael Fritch <mfritch@suse.com>
src/pybind/mgr/orchestrator/_interface.py
src/pybind/mgr/orchestrator/tests/test_orchestrator.py

index d7230b320613e43f905f72052c43a51b98c5dd90..b3f2c10bd656e4939b833b571f2de799fdc9979d 100644 (file)
@@ -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.
index 1dd6a964a9007f0b7898cb43dbf72912fba732cd..cc1e6e401fc289ef7293ecc0d7333b187c6285aa 100644 (file)
@@ -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