Skip to content

rgw/radosgw-admin: extract user commands into a module (2 of 2) - #71578

Open
RaminNietzsche wants to merge 1 commit into
ceph:mainfrom
RaminNietzsche:wip-rgw-admin-user
Open

RaminNietzsche wants to merge 1 commit into
ceph:mainfrom
RaminNietzsche:wip-rgw-admin-user

Conversation

@RaminNietzsche

@RaminNietzsche RaminNietzsche commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

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.

Context (incremental split from #71462)

This is slice 4 in the incremental landing plan for the radosgw-admin modularization work in #71462.

This PR contains only the user module extraction and its exit-code tests. It is based directly on main and does not include the dead-code cleanup (#71569), command-types header split (#71570), or the account module (#71575). The user module uses module-local command enums so it does not depend on a shared radosgw-admin.h.

Note: util.h is identical to the helper added in #71575; after that PR merges I will rebase and drop the duplicate file from this branch.

Summary

  • Add user.h / user.cc with rgw_admin_user_mutate(), rgw_admin_user_query(), and rgw_admin_user_policy() for user/subuser/key/caps commands plus user check/stats/list and managed policy attach/detach/list
  • Add admin_meta.h / admin_meta.cc with rgw_admin_meta_list_keys() for plain user list
  • Add util.h with shared rgw_admin::report_error() for consistent CLI error output
  • Wire dispatch from radosgw-admin.cc through module-local option structs and enums
  • Move user list (including account-filtered list) out of the shared metadata list block into the user module
  • Add user.cc and admin_meta.cc to the radosgw-admin CMake target
  • Add shell exit-code tests: test-user-exit-codes.sh and shared helpers

Supported user commands and flags are unchanged.

Testing

Local build and tests (Release, WITH_RADOSGW_RADOS=ON, vstart cluster):

  • ninja radosgw-admin
  • bash src/test/rgw/radosgw-admin/test-user-exit-codes.sh — 51 passed, 0 failed
  • Manual smoke: user list --max-entries 3, user info --uid …, create/modify/rm lifecycle

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.

@RaminNietzsche
RaminNietzsche requested a review from a team as a code owner September 7, 2026 10:46
@RaminNietzsche

Copy link
Copy Markdown
Member Author

This PR is slice 4 of the incremental radosgw-admin modularization plan spun out of #71462.

It is based directly on current main and contains only the user module slice (2 commits):

  1. rgw/radosgw-admin: extract user commands into a module
  2. test/rgw: add radosgw-admin user exit-code tests

Not included in this branch:

The user module uses module-local command enums (user_mutate_command, user_query_command, user_policy_command) instead of a shared admin header, so this slice can land independently of the earlier PRs. util.h matches the helper in #71575; I will drop the duplicate on rebase after that PR merges.

What this change does:

  • Moves user mutate/query/policy commands into user.cc
  • Routes dispatch through rgw_admin_user_mutate(), rgw_admin_user_query(), and rgw_admin_user_policy()
  • Uses admin_meta.cc for plain user list; account-filtered list stays in the user module via rgw::account::list_users()
  • Adds exit-code tests: test-user-exit-codes.sh and shared helpers wired via add_ceph_test

Local verification on a vstart cluster (WITH_RADOSGW_RADOS=ON):

  • ninja radosgw-admin
  • bash src/test/rgw/radosgw-admin/test-user-exit-codes.sh — 51 passed, 0 failed
  • smoke: user list --max-entries 3, create/modify/rm lifecycle

@RaminNietzsche

Copy link
Copy Markdown
Member Author

Fixed the make check failure in test-user-exit-codes.sh.

Post-init validation cases (e.g. user info with no uid, user modify with no uid) now use check_cluster() instead of check(), matching the account exit-code test pattern. In make check there is no vstart cluster, so those cases skip rather than failing with exit 5 (couldn't init config storage provider).

Simulated CI (no radosgw process): 23 passed, 0 failed, 22 skipped.
With vstart cluster: 51 passed, 0 failed.

@RaminNietzsche

Copy link
Copy Markdown
Member Author

Pushed a follow-up commit addressing review findings:

  • test-user-exit-codes.sh is now gated on WITH_RADOSGW_RADOS (same guard as the radosgw-admin target).
  • user.cc dispatch default: branches use ceph_abort() instead of silent return EINVAL.
  • Documented the user policy list attached exit-code fix (22 vs 234) and the admin_meta pagination loop change.

Local verification on stg-hd1:

  • ninja radosgw-admin
  • test-user-exit-codes.sh — CI sim: 23 passed / 0 failed / 22 skipped; with vstart: 51 passed / 0 failed

@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@RaminNietzsche

Copy link
Copy Markdown
Member Author

Rebased onto current main (169a0fb3a86c). New tip: dcee139663b3.

@RaminNietzsche

Copy link
Copy Markdown
Member Author

jenkins test make check

@RaminNietzsche

Copy link
Copy Markdown
Member Author

@cbodley @ivancich @chardan — slice 4 update (still parallel to #71575 until that merges).

PR text still documents the intentional user policy list attached exit-code difference (22 vs 234). Local tests: test-user-exit-codes.sh, help.t.

@RaminNietzsche

Copy link
Copy Markdown
Member Author

Pushed 0466137c93f0 to fix the build failure.

The series used two files that only exist in #71575 (the account module), which has not merged yet:

  • src/rgw/radosgw-admin/util.h: admin_meta.cc includes it for rgw_admin::report_error(). This was the compile error.
  • src/test/rgw/radosgw-admin/test-radosgw-admin-exit-codes-common.sh: sourced by test-user-exit-codes.sh.

Both are now added to the commits that first use them, byte-identical to the copies in #71575. Whichever of the two PRs merges second rebases with no conflict on those files. Nothing else changed: git diff 2788482b8298 0466137c93f0 shows only those two files.

Verified in a test environment: radosgw-admin builds, and ctest -R test-user-exit-codes passes (23 checks pass; the 22 that need a running cluster are skipped).

@adamemerson
adamemerson requested a review from chardan November 5, 2026 16:45
@adamemerson

Copy link
Copy Markdown
Contributor

@chardan You were restructuring radosgw-admin, could you give this a review?

@chardan

chardan commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

@adamemerson I sure can!

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

This is completely welcome! I think it's a real improvement (and indeed part of giving the tool its own directory was to allow exactly this sort of thing, I'm so pleased to see it being followed through on!).

There are a few tiny things you might peek at which I mentioned in my comments, but I don't think anything that needs to stop the momentum here!

Please note that I reviewed this as a structural change: I did look over the code but I restrained myself from focusing much on implementation. In general I definitely welcome these improvements and don't want to "throw the baby out with the bathwater".

I imagine it belongs in a more general overhaul of command-line handling, but is there any plan with respect to checking that command-line calls still map to the right functionality? We do want to be careful about breaking scripts.


namespace {

constexpr int DEFAULT_MAX_KEYS = 1000;

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.

Ah, macro-free! We're living the dream..!

Comment thread src/rgw/radosgw-admin/admin_meta.cc Outdated
? static_cast<uint64_t>(*opts.max_entries) - count
: static_cast<uint64_t>(DEFAULT_MAX_KEYS);

// NOTE: intentional behavior change vs. the original inline code in

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.

I think you can mention this with a GitHub comment and take it out of the comments.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done. I removed the comment from the code and moved the explanation here: the original inline code looped on while (truncated && left > 0) using the pre-fetch left, which could issue one extra meta_list_keys_next() call with left == 0 once count reached max_entries exactly. The module now breaks before that call, and the loop condition re-checks count after the fetch instead of the stale left.

Comment thread src/rgw/radosgw-admin/radosgw-admin.cc Outdated
case OPT::KEY_RM:
mutate_opts.command = user_mutate_command::key_rm;
break;
default:

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.

Consider moving this to the very top (in the style of a guard, if you're familiar with those).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done: the default: ceph_abort(); label is now the first label of that switch, so the "nothing matched" behaviour is visible without reading the other cases.

Comment thread src/rgw/radosgw-admin/user.cc Outdated
}
return 0;

default:

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.

Same comment (I tend to NOT repeat comments, so this will apply to any similar situation)-- it's fine as-is, but at the top it becomes visible that this is the error behavior if nothing else matches, preventing us from having to read an unknown number of similar clauses only to see the one that's different. YYMV (you do not HAVE to change this).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done for all three switches in user.cc (mutate, query, policy): default now comes first. Thanks for the guard-style suggestion.

#include "common/errno.h"

namespace rgw_admin {
inline int report_error(std::string_view what, int ret,

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.

This is fine as this is an incremental change and fixing errors isn't its main point-- and, indeed, this is a HUGE improvement already! But it would be nice eventually to see this done with dout_fmt() and the <source_location> header.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed, dout_fmt() plus <source_location> would be a good follow-up for util.h. I will keep it out of this change so the extraction stays easy to review, and pick it up in a later slice.

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

@RaminNietzsche Thank you for reviewing this pull request! As a member of the Ceph organization, please add yourself to .githubmap in the main branch if you haven't already.

@adamemerson

Copy link
Copy Markdown
Contributor

@chardan Thank you for the review. The small cleanups are pushed (tip 54eb647464d, folded into the existing review-findings commit): default labels first in the user switches, and the behavior-change note moved out of admin_meta.cc into the thread. The title now carries the series position (2 of 2, with #71575 as 1 of 2). The user exit-code suite passes (51/51) against a vstart cluster.

@adamemerson could this go through QA / merge when convenient? It is approved and CI is re-running on the new tip.

It should be picked up in a QA run soon.

@anrao19

anrao19 commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

This PR has been added to wip-anrao9-testing-2026-11-13-0841-main.

@anrao19

anrao19 commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

This PR has been removed from wip-anrao9-testing-2026-11-13-0842-main.

@anrao19

anrao19 commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

@RaminNietzsche

Copy link
Copy Markdown
Member Author

@anrao19 — thanks for the ping. I looked at the QA thread and Shaman:

What happened with 0842-main: tracker #83138 spun wip-anrao9-testing-2026-11-13-0841-main → 0842-main when this PR was added. ceph-ci does have Merge PR #71578 into wip-anrao9-testing-2026-11-13-0842-main on that branch; Shaman now lists packages for 0842-main. The “build creation failed” note was likely a transient chacra failure while the wip ref was being renamed/rebuilt (some flavor jobs show up empty briefly).

Current queue: The tracker later moved to wip-anrao9-testing-2026-11-13-1450-main (Shaman builds are present). That branch currently includes #72484/#72501/#73055/#73475 but not a merge of #71578 yet — so please re-merge this PR on the active 1450-main testing branch when you refresh the queue.

PR tip: Rebased on current main → 238c6c45e1e (force-pushed). radosgw-admin builds; test-user-exit-codes.sh — 51 passed, 0 failed on vstart.

jenkins test make check

RaminNietzsche added a commit to RaminNietzsche/ceph that referenced this pull request Nov 20, 2026
Move account create/modify/get/stats/rm/list handling from
radosgw-admin.cc into account.cc with shared error reporting via
util.h. Wire dispatch through rgw_admin_account() using a module-local
account_command enum so this slice does not depend on a shared
radosgw-admin header.

Add shell-based exit-code coverage (test-account-exit-codes.sh and
shared helpers). Guard tests with WITH_RADOSGW_RADOS. Use
RGWFormatterFlusher& in the module to match rgw_account.h and the
sibling user slice; ceph_abort() on the outer dispatch default;
document handle_account_list duplication versus admin_meta (ceph#71578).
Indent switch case labels and bodies in account.cc per review.

Behavior of supported account commands and flags is unchanged.

Signed-off-by: ramin.najarbashi <[email protected]>
@RaminNietzsche

Copy link
Copy Markdown
Member Author

Rebased on current main and squashed to one commit (9584f52). chardan already approved; this is ready for QA when you have a slot.

jenkins test make check

@anrao19

anrao19 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

This PR has been added to wip-anrao3-testing-2026-11-26-0631-main.

@anrao19

anrao19 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

shaman build creation is failed, https://shaman.ceph.com/builds/ceph/wip-anrao3-testing-2026-11-26-0631-main/
@RaminNietzsche , could you please check.

@anrao19

anrao19 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

This PR has been removed from wip-anrao3-testing-2026-11-26-0631-main.

@RaminNietzsche

RaminNietzsche commented Nov 26, 2026 •

Copy link
Copy Markdown
Member Author

Thanks for the ping. I checked the Shaman/chacra side for wip-anrao3-testing-2026-11-26-0631-main.

Move user mutate, query, and policy handling from radosgw-admin.cc into
user.cc. Add admin_meta.cc for metadata key listing (user list) and
reuse util.h for shared CLI errors.

Add user exit-code tests (shared helpers, check_cluster for post-init
cases). Guard tests with WITH_RADOSGW_RADOS. Use ceph_abort() on dispatch
default; put default first in mutate/query/policy switches. Fix
admin_meta list pagination and policy list_attached exit code.
Use std::optional<bool> for create generate-key.

Signed-off-by: ramin.najarbashi <[email protected]>
@RaminNietzsche

Copy link
Copy Markdown
Member Author

@anrao19 — follow-up on https://tracker.ceph.com/issues/83592 and the Shaman ping for wip-anrao3-testing-2026-11-26-0631-main.

I rechecked Shaman for 0631-main: package builds are present for multiple distros (tip sha d8937a074071 on that branch). The earlier “build creation failed” note was likely a transient chacra/wip-ref failure while the branch was first spinning up; I do not see an ongoing build blocker on that page now.

This PR was removed from the 0631 batch after that ping — if the queue has moved on (e.g. the current wip-anrao3-testing-2026-11-26-1139-main ticket), please re-add #71578 when you refresh QA.

Code update: rebased onto current ceph/main → tip ce9c7ca1d29c (force-pushed). @chardan approved the prior tip; happy to wait for a quick re-ack if you want that before QA.

@RaminNietzsche

Copy link
Copy Markdown
Member Author

jenkins test make check

@RaminNietzsche

Copy link
Copy Markdown
Member Author

@anrao19 — quick follow-up now that Jenkins is green on the rebased tip ce9c7ca1d29c (make check, arm64, windows, API — https://jenkins.ceph.com/job/ceph-pr-pipeline/11437/).

Ready to be re-added to the active wip-anrao3 QA batch when you have a slot (#83592). Thanks.

formatter->open_array_section("keys");

do {
std::list<std::string> keys;

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.

Just a quick question: is this pre-existing code? If not, I can't think of any reason to use a std::list<> here rather than a std::vector<>.

@chardan chardan 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; please wait for QA approval. Thank you for your work on this, it's a big improvement!

@anrao19

anrao19 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

This PR has been added to wip-anrao14-testing-2026-12-02-0603-main.

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