Skip to content

pybind/mgr/status: drop asserts that fight the defaultdict defaults - #68743

Merged
tchaikov merged 2 commits into
ceph:mainfrom
tchaikov:mgr-get_metadata
May 16, 2026
Merged

tchaikov merged 2 commits into
ceph:mainfrom
tchaikov:mgr-get_metadata

Conversation

@tchaikov

@tchaikov tchaikov commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

The 'assert metadata' checks in the status module were actually fighting
against our own defaults. Since an empty defaultdict is falsy, these
asserts would blow up the whole command if a single daemon was down
after a mgr restart.

This drops those four grumpy asserts. Now, instead of a traceback,
ceph osd status and ceph fs status will just show a blank hostname
or "unknown" version as intended.

The trigger is common in practice: any mgr restart leaves daemons
that are currently down without metadata in daemon_state, since
they never reconnect via MMgrOpen to repopulate it. After such a
restart, ceph osd status and ceph fs status blow up:

  Error EINVAL: Traceback (most recent call last):
    ...
    File ".../status/module.py", line 340, in handle_osd_status
      assert metadata
  AssertionError

The bug was introduced in 5ac2901

Fixes: https://tracker.ceph.com/issues/76416
Reported-by: Maximiliano Sandoval [email protected]
Signed-off-by: Kefu Chai [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.

@github-actions github-actions Bot added cephfs Ceph File System mgr pybind labels May 5, 2026
@tchaikov

tchaikov commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

cc @A6GibKm

@tchaikov
tchaikov force-pushed the mgr-get_metadata branch 3 times, most recently from d64cdbb to ac9734e Compare May 6, 2026 01:05
@tchaikov

tchaikov commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

1 similar comment
@tchaikov

tchaikov commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@tchaikov
tchaikov requested a review from a team May 7, 2026 02:22
@tchaikov

tchaikov commented May 8, 2026

Copy link
Copy Markdown
Contributor Author

the test failure on arm64 should be addressed by #68816

@tchaikov

tchaikov commented May 8, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@NitzanMordhai NitzanMordhai 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.

@tchaikov LGTM, just a few questions

svc_id: str) -> Optional[Dict[str, str]]:
...

@overload

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.

Missing default=None overload ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

indeed. added in the latest revision.

def get_metadata(self,
svc_type: str,
svc_id: str,
default: Dict[str, str]) -> Dict[str, str]:

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.

Should default accept Mapping[str, str] to be more permissive about what callers can pass in?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i am afraid we should not. if default is typed Mapping[str, str] but the return type is Dict[str, str], that would be a lie. because a Mapping is not necessarily a Dict. as, if the metadata does not have a matching key, the default is used for the return value.

tchaikov added 2 commits May 13, 2026 15:55
Enable type narrowing for get_metadata() when a non-None default is
provided. Previously, the return type was always `Optional[Dict[str, str]]`,
forcing callers to use defensive `assert metadata` checks even when
a result was guaranteed.

The wrapper returns either the metadata from `_ceph_get_metadata()` or the
caller-supplied default. Providing an `@overload` allows type checkers to
prove the result is non-None, avoiding invalid assertions for falsy
defaults (like an empty defaultdict).

This is a hygienic change with no runtime impact.

Signed-off-by: Kefu Chai <[email protected]>
The 'assert metadata' checks in the status module were actually fighting
against our own defaults. Since an empty defaultdict is falsy, these
asserts would blow up the whole command if a single daemon was down
after a mgr restart.

This drops those four grumpy asserts. Now, instead of a traceback,
`ceph osd status` and `ceph fs status` will just show a blank hostname
 or "unknown" version as intended.

The trigger is common in practice: any mgr restart leaves daemons
that are currently down without metadata in daemon_state, since
they never reconnect via MMgrOpen to repopulate it. After such a
restart, `ceph osd status` and `ceph fs status` blow up:
```
  Error EINVAL: Traceback (most recent call last):
    ...
    File ".../status/module.py", line 340, in handle_osd_status
      assert metadata
  AssertionError
```

The bug was introduced in 5ac2901

Fixes: https://tracker.ceph.com/issues/76416
Reported-by: Maximiliano Sandoval <[email protected]>
Signed-off-by: Kefu Chai <[email protected]>
@tchaikov
tchaikov force-pushed the mgr-get_metadata branch from ac9734e to 1c5a739 Compare May 13, 2026 07:56
@tchaikov

Copy link
Copy Markdown
Contributor Author

changelog:

  • added the missing overload where the default is None.

@tchaikov

Copy link
Copy Markdown
Contributor Author

jenkins test pr

@tchaikov

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@tchaikov

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@tchaikov

Copy link
Copy Markdown
Contributor Author

jenkins test windows

1 similar comment
@tchaikov

Copy link
Copy Markdown
Contributor Author

jenkins test windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cephfs Ceph File System mgr pybind

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants