DAOS-19122 ddb: Fix flag name collision between global and subcommand parsers#18466
Open
knard38 wants to merge 4 commits into
Open
DAOS-19122 ddb: Fix flag name collision between global and subcommand parsers#18466knard38 wants to merge 4 commits into
knard38 wants to merge 4 commits into
Conversation
|
Ticket title is 'ddb: |
Replace the two-statement var declaration + assignment with a single ':=' short variable declaration, as suggested in code review. Signed-off-by: Cedric Koch-Hofer <cedric.koch-hofer@hpe.com>
… parsers go-flags processes the full argument list before dispatching to grumble. When a subcommand defines a flag with the same name as a global option (e.g. 'rm_pool --db_path', 'open -w', 'feature -s'), go-flags intercepts it as the global option and the subcommand never receives it. This was introduced as a regression by commit 86f31a2 (DAOS-18304), which added a validation that rejected any invocation where --db_path was set (globally, by go-flags) without --vos_path -- even when the user correctly passed --db_path as a subcommand-level argument. Fix: add flags.PassAfterNonOption to the go-flags parser so it stops consuming flags after the first positional argument (the subcommand name). Everything after the subcommand lands in RunCmdArgs and is forwarded to grumble's own flag parser. Also: - Move vosPathMissErr to ddb_commands.go (sole use site after this fix) and add dtxAggrMutuallyExclusiveErr and dtxAggrRequiredOptErr constants to eliminate raw string literals in Go-layer error messages. - Fix a typo in the CLI long description (--vos-path -> --vos_path) and accurately list commands that manage their own pool lifecycle. - Update the two TestDdb_parseOpts cases whose behavior changed with PassAfterNonOption (--help after a subcommand now lands in RunCmdArgs instead of being processed by go-flags). Signed-off-by: Cedric Koch-Hofer <cedric.koch-hofer@hpe.com>
- TestDdb_parseOpts: add two cases verifying PassAfterNonOption behavior:
- flags after the subcommand name are NOT consumed by go-flags (regression case)
- flags before the subcommand name are still consumed globally (validation still fires)
- TestDdb_runDdb: complete noAutoOpen coverage for all 8 commands in the
noAutoOpen list (close, prov_mem, dev_list, dev_replace were missing).
- TestDdb_Cmds: remove the now-obsolete skipCmdLine escape hatch and add
regression coverage for the fixed flag conflicts:
- open: long/short forms of -w/--write_mode and -p/--db_path now work
correctly in command-line mode
- rm_pool: --db_path after subcommand correctly reaches grumble
- prov_mem: -s/--tmpfs_size flag no longer consumed as global VosPath
Also update dtxAggr error assertions to use the new named constants.
Signed-off-by: Cedric Koch-Hofer <cedric.koch-hofer@hpe.com>
- Add Go-layer input validation to the feature command Run handler: - Enforce that exactly one of --enable, --disable, --show is provided - Reject --db_path when no VOS path argument is given - Add featureOnlyOneOptErr constant and onlyOne() helper - Add LongHelp to the feature command documenting the validation rules - Replace featureFnCheckingShow with the more general featureFnChecking factory and add string2FlagsCapturing to verify enable/disable routing - Add full test coverage for all feature flags (short/long enable, disable, show, db_path) and all validation error paths Features: recovery Signed-off-by: Cedric Koch-Hofer <cedric.koch-hofer@hpe.com>
8a13591 to
c101fde
Compare
Collaborator
|
Test stage Functional on EL 9 completed with status FAILURE. https://jenkins-3.daos.hpc.amslabs.hpecorp.net//job/daos-stack/job/daos/view/change-requests/job/PR-18466/1/execution/node/1039/log |
6 tasks
Collaborator
|
Test stage Functional Hardware Medium MD on SSD completed with status FAILURE. https://jenkins-3.daos.hpc.amslabs.hpecorp.net//job/daos-stack/job/daos/view/change-requests/job/PR-18466/2/execution/node/1369/log |
Contributor
Author
|
The two functional test failures of the build #2 are known issues:
|
tanabarr
approved these changes
Jun 10, 2026
| const dtxAggrRequiredOptErr = "'--cmt_time' or '--cmt_date' option has to be defined" | ||
| const featureOnlyOneOptErr = "exactly one of --enable, --disable, --show must be provided" | ||
|
|
||
| func onlyOne(bools ...bool) bool { |
Contributor
There was a problem hiding this comment.
could this go in a generic utility file for reuse?
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Commit 86f31a2 (DAOS-18304) introduced a regression:
ddb rm_pool --db_path ...fails with:This breaks the
recovery/pool_list_consolidation.pytest (test_lost_majority_ps_replicas) on MD-on-SSD clusters, as observed in PR #17965 CI build 22.Root cause: go-flags processes the full command line before dispatching to grumble. Because
--db_pathis registered as a global option incliOptions, go-flags intercepts it — even when the user supplies it as a subcommand-level argument (e.g.ddb rm_pool --db_path ...). The new validation added by86f31a2bd3then rejects the invocation because the global--vos_pathwas not also provided. The same collision affectsopen(-w,-p),feature(-p,-s), andprov_mem(-s).Solution
This PR fixes the regression and improves the
featurecommand with better input validation, all covered by new unit tests. The PR is split into four focused commits, each independently buildable and testable.Commit 1 — Go style: idiomatic logger initialisation
Replace a two-statement
vardeclaration + assignment with a single:=short variable declaration, as suggested in code review of PR #18086.Commit 2 — Fix:
PassAfterNonOptionAdd
flags.PassAfterNonOptionto the go-flags parser. This makes go-flags stop consuming flags after the first positional argument (the subcommand name). Everything after the subcommand lands inRunCmdArgsand is forwarded to grumble's own flag parser, which correctly handles command-level flags.Also includes the two
TestDdb_parseOptscases whose expected behavior changed withPassAfterNonOption(see Side effects below), a doc fix (--vos-path→--vos_path), and error message constants fordtxAggr.Commit 3 — Regression tests
TestDdb_parseOpts: two new cases —--db_pathafter the subcommand is not consumed globally (core regression case);--db_pathbefore the subcommand still triggers thevosPathMissErrvalidation (correct misuse detection preserved).TestDdb_runDdb: completenoAutoOpencoverage for all 8 commands (close,prov_mem,dev_list,dev_replacewere previously missing).TestDdb_Cmds: removeskipCmdLine(now obsolete); add regression tests foropen(-w,--db_path),rm_pool(--db_path), andprov_mem(-s).Commit 4 —
featurecommand improvements--enable/--disable/--showrequired;--db_pathrequires a VOS path argument.featureOnlyOneOptErrconstant andonlyOne()helper.LongHelpdocumenting the validation rules.featureFnCheckingShowwith the more generalfeatureFnCheckingfactory; addstring2FlagsCapturingto verify enable/disable routing.Side effects
PassAfterNonOptionchanges one existing user-visible behavior: flags that appear after the subcommand name are now passed to grumble instead of go-flags. The most visible effect is thatddb <cmd> --helpnow shows the subcommand-specific help rather than the general ddb help:This is a correction of incorrect behavior — users naturally expect
ddb ls --helpto document thelscommand. Flags placed before the subcommand (e.g.ddb --vos_path /foo ls) continue to work as before.Steps for the author:
After all prior steps are complete: