Skip to content

mgr/orch: allow for multiline OrchestratorEvent message#36334

Merged
sebastian-philipp merged 1 commit intoceph:masterfrom
mgfritch:cephadm-event-multiline
Jul 30, 2020
Merged

mgr/orch: allow for multiline OrchestratorEvent message#36334
sebastian-philipp merged 1 commit intoceph:masterfrom
mgfritch:cephadm-event-multiline

Conversation

@mgfritch
Copy link
Contributor

Multi-line OrchestratorEvent messages break the output of the ls command:

$ ceph orch ls mon --format yaml
Error EINVAL: Traceback (most recent call last):
  File "/usr/share/ceph/mgr/mgr_module.py", line 1171, in _handle_command
    return self.handle_command(inbuf, cmd)
  File "/usr/share/ceph/mgr/orchestrator/_interface.py", line 131, in handle_command
    return dispatch[cmd['prefix']].call(self, cmd, inbuf)
  File "/usr/share/ceph/mgr/mgr_module.py", line 311, in call
    return self.func(mgr, **kwargs)
  File "/usr/share/ceph/mgr/orchestrator/_interface.py", line 93, in <lambda>
    wrapper_copy = lambda *l_args, **l_kwargs: wrapper(*l_args, **l_kwargs)
  File "/usr/share/ceph/mgr/orchestrator/_interface.py", line 84, in wrapper
    return func(*args, **kwargs)
  File "/usr/share/ceph/mgr/orchestrator/module.py", line 452, in _list_services
    return HandleCommandResult(stdout=to_format(services, format, many=True, cls=ServiceDescription))
  File "/usr/share/ceph/mgr/orchestrator/module.py", line 52, in to_format
    copy = [cls.from_json(o) for o in flat] if many else cls.from_json(flat)
  File "/usr/share/ceph/mgr/orchestrator/module.py", line 52, in <listcomp>
    copy = [cls.from_json(o) for o in flat] if many else cls.from_json(flat)
  File "/usr/share/ceph/mgr/orchestrator/_interface.py", line 1211, in inner
    return method(cls, *args, **kwargs)
  File "/usr/share/ceph/mgr/orchestrator/_interface.py", line 1489, in from_json
    events = [OrchestratorEvent.from_json(e) for e in event_strs]
  File "/usr/share/ceph/mgr/orchestrator/_interface.py", line 1489, in <listcomp>
    events = [OrchestratorEvent.from_json(e) for e in event_strs]
  File "/usr/share/ceph/mgr/orchestrator/_interface.py", line 1211, in inner
    return method(cls, *args, **kwargs)
  File "/usr/share/ceph/mgr/orchestrator/_interface.py", line 1649, in from_json
    raise ValueError(f'Unable to match: "{data}"')
ValueError: Unable to match: "2020-07-28T19:32:27.463735 service:mon [ERROR] "Failed to apply: cephadm exited with an error code: 1, stderr:INFO:cephadm:Deploy daemon mon.host3 ...
INFO:cephadm:Non-zero exit code 1 from /usr/bin/podman run --rm --net=host --ipc=host -e CONTAINER_IMAGE=docker.io/ceph/daemon-base@sha256:481a818ec6ca7b5712670c8a0eaaceb64d5ce8390cd931a540d937043d3baed0 -e NODE_NAME=host3 -v /var/log/ceph/a5fb8148-4d79-44ef-b578-2d46db934808:/var/log/ceph:z -v /var/lib/ceph/a5fb8148-4d79-44ef-b578-2d46db934808/mon.host3:/var/lib/ceph/mon/ceph-host3:z -v /tmp/ceph-tmp_buqrhay:/tmp/keyring:z -v /tmp/ceph-tmps_evysk3:/tmp/config:z --entrypoint /usr/bin/ceph-mon docker.io/ceph/daemon-base@sha256:481a818ec6ca7b5712670c8a0eaaceb64d5ce8390cd931a540d937043d3baed0 --mkfs -i host3 --fsid a5fb8148-4d79-44ef-b578-2d46db934808 -c /tmp/config --keyring /tmp/keyring --setuser ceph --setgroup ceph --default-log-to-file=false --default-log-to-stderr=true --default-log-stderr-prefix="debug " --default-mon-cluster-log-to-file=false --default-mon-cluster-log-to-stderr=true
INFO:cephadm:/usr/bin/ceph-mon:stderr "debug "2020-07-28T19:32:15.661+0000 7fa83bbb8700  0 set uid:gid to 167:167 (ceph:ceph)
INFO:cephadm:/usr/bin/ceph-mon:stderr "debug "2020-07-28T19:32:15.661+0000 7fa83bbb8700 -1 unable to find any IP address in networks '192.168.0.1/24' interfaces ''
Traceback (most recent call last):
  File "<stdin>", line 5048, in <module>
  File "<stdin>", line 1216, in _default_image
  File "<stdin>", line 3000, in command_deploy
  File "<stdin>", line 1879, in deploy_daemon
  File "<stdin>", line 2374, in run
  File "<stdin>", line 877, in call_throws
RuntimeError: Failed command: /usr/bin/podman run --rm --net=host --ipc=host -e CONTAINER_IMAGE=docker.io/ceph/daemon-base@sha256:481a818ec6ca7b5712670c8a0eaaceb64d5ce8390cd931a540d937043d3baed0 -e NODE_NAME=host3 -v /var/log/ceph/a5fb8148-4d79-44ef-b578-2d46db934808:/var/log/ceph:z -v /var/lib/ceph/a5fb8148-4d79-44ef-b578-2d46db934808/mon.host3:/var/lib/ceph/mon/ceph-host3:z -v /tmp/ceph-tmp_buqrhay:/tmp/keyring:z -v /tmp/ceph-tmps_evysk3:/tmp/config:z --entrypoint /usr/bin/ceph-mon docker.io/ceph/daemon-base@sha256:481a818ec6ca7b5712670c8a0eaaceb64d5ce8390cd931a540d937043d3baed0 --mkfs -i host3 --fsid a5fb8148-4d79-44ef-b578-2d46db934808 -c /tmp/config --keyring /tmp/keyring --setuser ceph --setgroup ceph --default-log-to-file=false --default-log-to-stderr=true --default-log-stderr-prefix="debug " --default-mon-cluster-log-to-file=false --default-mon-cluster-log-to-stderr=true""

Signed-off-by: Michael Fritch mfritch@suse.com

Checklist

  • References tracker ticket
  • Updates documentation if necessary
  • Includes tests for new functionality or reproducer for bug

Show available Jenkins commands
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test dashboard backend
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox

@mgfritch
Copy link
Contributor Author

This PR allows for a proper multi-line yaml:

$ ceph orch ls mon --format yaml
service_type: mon
service_name: mon
placement:
  hosts:
  - hostname: host3
    name: ''
    network: ''
status:
  container_image_id: 2f5fdc3dddff3a96da1038eff8de26b7ee5379cfe1d64fb43478ce643bf51a1f
  container_image_name: docker.io/ceph/daemon-base@sha256:481a818ec6ca7b5712670c8a0eaaceb64d5ce8390cd931a540d937043d3baed0
  created: '2020-07-28T20:17:54.486797'
  last_refresh: '2020-07-28T20:17:43.709777'
  running: 1
  size: 1
events:
- 2020-07-28T20:16:42.899135 service:mon [INFO] "service was created"
- "2020-07-28T20:17:19.276721 service:mon [ERROR] \"Failed to apply: cephadm exited\
  \ with an error code: 1, stderr:INFO:cephadm:Deploy daemon mon.host3 ...\nINFO:cephadm:Non-zero\
  \ exit code 1 from /usr/bin/podman run --rm --net=host --ipc=host -e CONTAINER_IMAGE=docker.io/ceph/daemon-base@sha256:481a818ec6ca7b5712670c8a0eaaceb64d5ce8390cd931a540d937043d3baed0\
  \ -e NODE_NAME=host3 -v /var/log/ceph/a5fb8148-4d79-44ef-b578-2d46db934808:/var/log/ceph:z\
  \ -v /var/lib/ceph/a5fb8148-4d79-44ef-b578-2d46db934808/mon.host3:/var/lib/ceph/mon/ceph-host3:z\
  \ -v /tmp/ceph-tmp6ds7nnu2:/tmp/keyring:z -v /tmp/ceph-tmps0ysz3jk:/tmp/config:z\
  \ --entrypoint /usr/bin/ceph-mon docker.io/ceph/daemon-base@sha256:481a818ec6ca7b5712670c8a0eaaceb64d5ce8390cd931a540d937043d3baed0\
  \ --mkfs -i host3 --fsid a5fb8148-4d79-44ef-b578-2d46db934808 -c /tmp/config\
  \ --keyring /tmp/keyring --setuser ceph --setgroup ceph --default-log-to-file=false\
  \ --default-log-to-stderr=true --default-log-stderr-prefix=\"debug \" --default-mon-cluster-log-to-file=false\
  \ --default-mon-cluster-log-to-stderr=true\nINFO:cephadm:/usr/bin/ceph-mon:stderr\
  \ \"debug \"2020-07-28T20:17:12.616+0000 7f31a3548700  0 set uid:gid to 167:167\
  \ (ceph:ceph)\nINFO:cephadm:/usr/bin/ceph-mon:stderr \"debug \"2020-07-28T20:17:12.616+0000\
  \ 7f31a3548700 -1 unable to find any IP address in networks '192.168.0.1/21' interfaces\
  \ ''\nTraceback (most recent call last):\n  File \"<stdin>\", line 5048, in <module>\n\
  \  File \"<stdin>\", line 1216, in _default_image\n  File \"<stdin>\", line 3000,\
  \ in command_deploy\n  File \"<stdin>\", line 1879, in deploy_daemon\n  File \"\
  <stdin>\", line 2374, in run\n  File \"<stdin>\", line 877, in call_throws\nRuntimeError:\
  \ Failed command: /usr/bin/podman run --rm --net=host --ipc=host -e CONTAINER_IMAGE=docker.io/ceph/daemon-base@sha256:481a818ec6ca7b5712670c8a0eaaceb64d5ce8390cd931a540d937043d3baed0\
  \ -e NODE_NAME=host3 -v /var/log/ceph/a5fb8148-4d79-44ef-b578-2d46db934808:/var/log/ceph:z\
  \ -v /var/lib/ceph/a5fb8148-4d79-44ef-b578-2d46db934808/mon.host3:/var/lib/ceph/mon/ceph-host3:z\
  \ -v /tmp/ceph-tmp6ds7nnu2:/tmp/keyring:z -v /tmp/ceph-tmps0ysz3jk:/tmp/config:z\
  \ --entrypoint /usr/bin/ceph-mon docker.io/ceph/daemon-base@sha256:481a818ec6ca7b5712670c8a0eaaceb64d5ce8390cd931a540d937043d3baed0\
  \ --mkfs -i host3 --fsid a5fb8148-4d79-44ef-b578-2d46db934808 -c /tmp/config\
  \ --keyring /tmp/keyring --setuser ceph --setgroup ceph --default-log-to-file=false\
  \ --default-log-to-stderr=true --default-log-stderr-prefix=\"debug \" --default-mon-cluster-log-to-file=false\
  \ --default-mon-cluster-log-to-stderr=true\""

@sebastian-philipp
Copy link
Contributor

sebastian-philipp commented Jul 29, 2020

mind adding something similar to:

--- a/src/pybind/mgr/orchestrator/_interface.py
+++ b/src/pybind/mgr/orchestrator/_interface.py
@@ -1642,6 +1642,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 1dd6a964a9..cc1e6e401f 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

would be great to prevent an regressions here.

@sebastian-philipp sebastian-philipp added the wip-swagner-testing My Teuthology tests label Jul 29, 2020
@mgfritch mgfritch force-pushed the cephadm-event-multiline branch from c5972a0 to 4c50efe Compare July 29, 2020 17:50
Signed-off-by: Michael Fritch <mfritch@suse.com>
@mgfritch mgfritch force-pushed the cephadm-event-multiline branch from 4c50efe to a108612 Compare July 29, 2020 17:51
@mgfritch
Copy link
Contributor Author

jenkins test dashboard backend

@sebastian-philipp
Copy link
Contributor

@sebastian-philipp sebastian-philipp merged commit 244860e into ceph:master Jul 30, 2020
@mgfritch mgfritch deleted the cephadm-event-multiline branch July 30, 2020 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants