From eb98dd9313b1c0dfc2428a0cac7ad05c421f5f37 Mon Sep 17 00:00:00 2001 From: "Mark A. Grondona" Date: Fri, 22 Nov 2024 08:57:52 -0800 Subject: [PATCH 1/5] cmd: add `--skip-empty` option to `flux resource list` Problem: There is no way to skip lines of empty resource sets in `flux resource list`. Add a `--skip-empty` option to suppress empty lines. --- src/cmd/flux-resource.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/cmd/flux-resource.py b/src/cmd/flux-resource.py index 1835a3f02470..bcc5ef2d42a8 100755 --- a/src/cmd/flux-resource.py +++ b/src/cmd/flux-resource.py @@ -693,6 +693,8 @@ def list_handler(args): resources, args.states, formatter, config, queues=args.queue ) items = sort_output(args, lines.values()) + if args.skip_empty: + items = [x for x in items if x.ranks] formatter.print_items(items, no_header=args.no_header) @@ -901,6 +903,11 @@ def main(): metavar="QUEUE,...", help="Include only specified queues in output", ) + list_parser.add_argument( + "--skip-empty", + action="store_true", + help="Skip empty lines", + ) list_parser.add_argument( "-n", "--no-header", action="store_true", help="Suppress header output" ) @@ -939,6 +946,13 @@ def main(): "--from-stdin", action="store_true", help=argparse.SUPPRESS ) info_parser.add_argument("--config-file", help=argparse.SUPPRESS) + # Options required in `info` because they are also present in `list`: + info_parser.add_argument( + "--skip-empty", + action="store_true", + help=argparse.SUPPRESS, + ) + info_parser.set_defaults(func=info) reload_parser = subparsers.add_parser( From 5da7b4473e18817de370c41af5f9ef1ab492b502 Mon Sep 17 00:00:00 2001 From: "Mark A. Grondona" Date: Fri, 22 Nov 2024 09:04:39 -0800 Subject: [PATCH 2/5] cmd: skip empty lines with `flux resource list --include` Problem: When using `flux resource list --include=TARGETS`, a set of empty resource sets are generated for all configured queues. This is probably not desired behavior. Take the simple approach for now and skip empty lines if `--include` is used. In order to preserve the current behavior, also add a hidden `--no-skip-empty` option which prevents skipping empty lines. Use `--no-skip-empty` where necessary in t2350-resource-list.t to avoid breaking existing tests. --- src/cmd/flux-resource.py | 13 ++++++++++--- t/t2350-resource-list.t | 9 ++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/cmd/flux-resource.py b/src/cmd/flux-resource.py index bcc5ef2d42a8..984f30e96d24 100755 --- a/src/cmd/flux-resource.py +++ b/src/cmd/flux-resource.py @@ -693,7 +693,7 @@ def list_handler(args): resources, args.states, formatter, config, queues=args.queue ) items = sort_output(args, lines.values()) - if args.skip_empty: + if args.skip_empty or (args.include and not args.no_skip_empty): items = [x for x in items if x.ranks] formatter.print_items(items, no_header=args.no_header) @@ -906,7 +906,12 @@ def main(): list_parser.add_argument( "--skip-empty", action="store_true", - help="Skip empty lines", + help="Skip empty lines. This is the default with -i, --include.", + ) + list_parser.add_argument( + "--no-skip-empty", + action="store_true", + help="Do not skip empty lines, even with --include.", ) list_parser.add_argument( "-n", "--no-header", action="store_true", help="Suppress header output" @@ -952,7 +957,9 @@ def main(): action="store_true", help=argparse.SUPPRESS, ) - + info_parser.add_argument( + "--no-skip-empty", action="store_true", help=argparse.SUPPRESS + ) info_parser.set_defaults(func=info) reload_parser = subparsers.add_parser( diff --git a/t/t2350-resource-list.t b/t/t2350-resource-list.t index 4c510bb050b1..6970b9353573 100755 --- a/t/t2350-resource-list.t +++ b/t/t2350-resource-list.t @@ -96,12 +96,13 @@ for input in ${SHARNESS_TEST_SRCDIR}/flux-resource/list/*.json; do name=$(basename $base) && test_expect_success "flux-resource list input --include check: $name" ' flux resource list -o "{ranks} {nodelist}" --include=0 \ + --no-skip-empty \ --from-stdin < $input >$name-include.output 2>&1 && test_debug "cat $name-include.output" && grep "^0[^,-]" $name-include.output ' test_expect_success "flux-resource info input --include check: $testname" ' - flux resource info --from-stdin -i0 < $input \ + flux resource info --from-stdin --no-skip-empty -i0 < $input \ > ${name}-info-include.output 2>&1 && test_debug "cat ${name}-info-include.output" && grep "1 Node" ${name}-info-include.output @@ -172,13 +173,14 @@ test_expect_success 'flux-resource -q, --queue reports invalid queue' ' grep "foo: no such queue" badqueue.err ' test_expect_success 'flux-resource list supports --include' ' - flux resource list -s all -ni 0 >list-include.output && + flux resource list -s all -ni 0 --no-skip-empty >list-include.output && test_debug "cat list-include.output" && test $(wc -l include-ranks.out && test_debug "cat include-ranks.out" && grep "^2 0,3" include-ranks.out @@ -270,7 +272,8 @@ test_expect_success 'flux-resource list: -i works with excluded hosts #5266' ' ' test_expect_success 'flux-resource list: --include works with invalid host' ' flux resource list -s all -o "{nnodes} {nodelist}" -ni pi7 \ - --from-stdin < $INPUT >include-invalid-hosts.out && + --from-stdin --no-skip-empty \ + < $INPUT >include-invalid-hosts.out && test_debug "cat include-invalid-hosts.out" && grep "^0" include-invalid-hosts.out ' From 3ba4a19ce41d9f7ef12bf6e039867cb233fa4a69 Mon Sep 17 00:00:00 2001 From: "Mark A. Grondona" Date: Fri, 22 Nov 2024 11:02:46 -0800 Subject: [PATCH 3/5] testsuite: test flux-resource skip-empty behavior Problem: t2350-resource-list.t doesn't explicitly test that `flux resource list` skips empty lines by default with `--include`, and that `--skip-empty` skips empty lines without `--include`. Add a couple explicit tests of this behavior. --- t/t2350-resource-list.t | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/t/t2350-resource-list.t b/t/t2350-resource-list.t index 6970b9353573..9e9bb23571c9 100755 --- a/t/t2350-resource-list.t +++ b/t/t2350-resource-list.t @@ -76,6 +76,13 @@ for input in ${SHARNESS_TEST_SRCDIR}/flux-resource/list/*.json; do test_debug "cat $name.output" && test_cmp ${base}.expected $name.output ' + test_expect_success "flux-resource list --skip-empty: $testname" ' + awk "\$3!=0 {print}" ${base}.expected > skip-empty.${name}.expected && + flux resource list -o "$FORMAT" \ + --skip-empty \ + --from-stdin < $input > skip-empty.${name}.output 2>&1 && + test_cmp skip-empty.${name}.expected skip-empty.${name}.output + ' test_expect_success "flux-resource info input check: $testname" ' flux resource info --from-stdin < $input > ${name}-info.output 2>&1 && test_debug "cat ${name}-info.output" && @@ -178,6 +185,11 @@ test_expect_success 'flux-resource list supports --include' ' test $(wc -l skip-empty.out && + test_debug "cat skip-empty.out" && + test $(wc -l Date: Fri, 22 Nov 2024 11:06:47 -0800 Subject: [PATCH 4/5] etc: update bash completions for flux-resource Problem: The bash tab completions for `flux resource list` do not include the `--[no-]skip-empty` flags. Add them. --- etc/completions/flux.pre | 2 ++ 1 file changed, 2 insertions(+) diff --git a/etc/completions/flux.pre b/etc/completions/flux.pre index 6fde69315d34..5faca2b7d044 100644 --- a/etc/completions/flux.pre +++ b/etc/completions/flux.pre @@ -543,6 +543,8 @@ _flux_resource() -n --no-header \ -q --queue= \ -i --include= \ + --skip-empty \ + --no-skip-empty \ " local status_OPTS="\ ${list_OPTS} \ From c2e7203412b3741a39d6653880e8aa06c63defc9 Mon Sep 17 00:00:00 2001 From: "Mark A. Grondona" Date: Fri, 22 Nov 2024 11:15:37 -0800 Subject: [PATCH 5/5] doc: update flux-resource(1) Problem: The `--[no-]skip-empty` `flux resource list` options are undocumented. Add them to the flux-resource(1) manual. --- doc/man1/flux-resource.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/man1/flux-resource.rst b/doc/man1/flux-resource.rst index 357bcf549ee1..fab5c39a6b94 100644 --- a/doc/man1/flux-resource.rst +++ b/doc/man1/flux-resource.rst @@ -106,6 +106,15 @@ all hostlist form. It is not an error to specify ranks, nodes, or hosts which do not exist. +.. option:: --skip-empty + + Skip lines with empty resource sets in output. This is the default when + `-i, --include` is used. + +.. options:: --no-skip-empty + + Do not skip empty resource sets in output, even with `-i, --include`. + .. option:: -o, --format=FORMAT Customize the output format (See the `OUTPUT FORMAT`_ section below).