DAOS-19122 ddb: Fix flag name collision between global and subcommand parsers#18466
DAOS-19122 ddb: Fix flag name collision between global and subcommand parsers#18466knard38 wants to merge 9 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
|
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 |
|
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 |
|
The two functional test failures of the build #2 are known issues:
|
| 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 { |
There was a problem hiding this comment.
could this go in a generic utility file for reuse?
…/daos-19122/patch-001 Features: recovery
daltonbohning
left a comment
There was a problem hiding this comment.
This PR seems to have a lot of commits already on master
I think, it is because I have recently merged the target PR with master. |
I think it's because the target branch |
|
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/3/execution/node/1311/log |
…atch-002' into ckochhof/fix/master/daos-19122/patch-001 Features: recovery
Fixed with merging with target pr |
|
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/4/execution/node/1040/log |
|
The tests failure of the latest build #2 are not related to this PR and are known issues:
|
…/fix/master/daos-19122/patch-001 Features: recovery
…atch-002' into ckochhof/fix/master/daos-19122/patch-001 Features: recovery
|
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/6/execution/node/1388/log |
|
Test stage Functional Hardware Medium Verbs Provider 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/6/execution/node/1429/log |
…atch-002' into ckochhof/fix/master/daos-19122/patch-001 Features: recovery
|
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/7/execution/node/1041/log |
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: