Skip to content

python-common: multi-line for yaml - #68034

Merged
rkachach merged 1 commit into
ceph:mainfrom
timqn22:add-multi-line-to-yaml-representer
Apr 14, 2026
Merged

rkachach merged 1 commit into
ceph:mainfrom
timqn22:add-multi-line-to-yaml-representer

Conversation

@timqn22

@timqn22 timqn22 commented Mar 26, 2026 •

Copy link
Copy Markdown
Contributor

Currently when running the command ceph orch ls --export multi-line strings are processed using default interpretation meaning they could be printed with quotations instead of the expected | . This causes a hassle for users who want to copy their specifications to new yaml files as they have to manually modify the yaml to remove the quotes and add | . My code fixes this by modifying the yaml representer to check for multi-line strings and wrapping them in a as_block class which will mark the multi-line string to be processed with | .

Fixes: https://tracker.ceph.com/issues/75743

Signed-off-by: Timothy Q Nguyen [email protected]

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@timqn22
timqn22 requested a review from a team as a code owner March 26, 2026 19:24
@timqn22
timqn22 force-pushed the add-multi-line-to-yaml-representer branch from dbe51ee to 7d349f3 Compare March 26, 2026 20:45
@phlogistonjohn

Copy link
Copy Markdown
Contributor

How we did something similar for smb resources:

class BigString(str):

@timqn22
timqn22 force-pushed the add-multi-line-to-yaml-representer branch from 7d349f3 to cd1c448 Compare March 27, 2026 17:21
@timqn22

timqn22 commented Mar 27, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@timqn22
timqn22 requested a review from phlogistonjohn April 2, 2026 22:37

@phlogistonjohn phlogistonjohn left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing the formatting, however you now have a new word-choice problem. Typically, classes are named using Nouns and (optionally) Adjectives ("Cache", "FastArray", "SocketStreamer", things like that). AsLiteral does not fit this mold. Something like Literal fits that pattern better, but maybe that's too vague - BlockLiteral?

Also, while I'm not opposed to some level of duplication in the code I would like to have @rkachach or perhaps @adk3798 chime in on the duplication of the class we already created for smb module. Perhaps we should create a common implementation? These classes largely do the same thing after all... but I won't insist on it either.

@rkachach

rkachach commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Thanks for fixing the formatting, however you now have a new word-choice problem. Typically, classes are named using Nouns and (optionally) Adjectives ("Cache", "FastArray", "SocketStreamer", things like that). AsLiteral does not fit this mold. Something like Literal fits that pattern better, but maybe that's too vague - BlockLiteral?

Also, while I'm not opposed to some level of duplication in the code I would like to have @rkachach or perhaps @adk3798 chime in on the duplication of the class we already created for smb module. Perhaps we should create a common implementation? These classes largely do the same thing after all... but I won't insist on it either.

@phlogistonjohn since this new support is being add in a common place, once available we can adjust samba code to make use of it. Wdyt?

Currently when running the command ceph orch ls --export
multi-line strings are processed using default interpretation
meaning they could be printed with quotations instead of
the expected | . This causes a hassle for users who want to
copy their specifications to new yaml files as they have to
manually modify the yaml to remove the quotes and add | .
My code fixes this by modifying the yaml representer to
check for multi-line strings and wrapping them in a
YamlLiteralString class which will mark the multi-line string
to be processed with | . I've also added unit tests.

Signed-off-by: Timothy Q Nguyen <[email protected]>
@timqn22
timqn22 force-pushed the add-multi-line-to-yaml-representer branch from cd1c448 to 0a73f68 Compare April 7, 2026 22:47
@timqn22

timqn22 commented Apr 8, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@rkachach rkachach left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rkachach
rkachach requested a review from phlogistonjohn April 8, 2026 12:34
@phlogistonjohn

Copy link
Copy Markdown
Contributor
  1. I disagree that the location is sufficiently common - this is generic YAML support code, not something specific to service specs - so in the long run I think it would make sense to put it somewhere even more general
    (1a) Plus this implementation is tied directly to ServiceSpec making the implemenation even less generic than it could be
  2. The implementations differ in that BigString will not use literal blocks if it is less than 80 chars (if no newlines are present). This is not a major issue but it is a difference.
  3. Maybe I am being a bit immature but after I pointed out that a similar thing already existed that we would discuss merging them, or reusing the smb one (since it is more generic)... and after all the smb one was "first". Technically, that's not important but hey I'm only human :-)

@timqn22

timqn22 commented Apr 10, 2026

Copy link
Copy Markdown
Contributor Author

@phlogistonjohn @rkachach I think it might be better to keep the classes separate since as John mentioned the implementations differ in the 80 chars condition. I'm not completely sure, but I think that condition could harm the service spec yaml export, since this fix is to allow users to export current specs and reapply them, the formatting is strict.

@rkachach

Copy link
Copy Markdown
Contributor

@timqn22 I've been discussing with @phlogistonjohn offline about how to proceed. We agreed that we can proceed with your changes without modifications and do some refactoring later to put this code in a common place so can be reused easily.

@phlogistonjohn phlogistonjohn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed - this is good enough for now.

@phlogistonjohn
phlogistonjohn dismissed their stale review April 13, 2026 13:54

github's being annoying

@rkachach rkachach added the wip-rkachach-testing-2 rkachach testing label Apr 13, 2026
@rkachach

Copy link
Copy Markdown
Contributor

Teuthology run didn't show any issues that could be related to this PR:

https://pulpito.ceph.com/rkachach-2026-04-14_13:03:43-orch:cephadm-wip-rkachach-testing-2-2026-04-14-1154-distro-default-trial/

Most of the failures are related to NFS and Upgrade.

@rkachach
rkachach merged commit 22f86c4 into ceph:main Apr 14, 2026
6 checks passed
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.

4 participants