Skip to content

Commit

Permalink
Merge pull request #6460 from grondo/issue#6275
Browse files Browse the repository at this point in the history
skip "empty" lines of output in `flux resource list` with `--skip-empty` or `--include`
  • Loading branch information
mergify[bot] authored Dec 3, 2024
2 parents 3acf1d8 + c2e7203 commit d61eccb
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
9 changes: 9 additions & 0 deletions doc/man1/flux-resource.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 2 additions & 0 deletions etc/completions/flux.pre
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,8 @@ _flux_resource()
-n --no-header \
-q --queue= \
-i --include= \
--skip-empty \
--no-skip-empty \
"
local status_OPTS="\
${list_OPTS} \
Expand Down
21 changes: 21 additions & 0 deletions src/cmd/flux-resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 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)


Expand Down Expand Up @@ -901,6 +903,16 @@ def main():
metavar="QUEUE,...",
help="Include only specified queues in output",
)
list_parser.add_argument(
"--skip-empty",
action="store_true",
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"
)
Expand Down Expand Up @@ -939,6 +951,15 @@ 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.add_argument(
"--no-skip-empty", action="store_true", help=argparse.SUPPRESS
)
info_parser.set_defaults(func=info)

reload_parser = subparsers.add_parser(
Expand Down
21 changes: 18 additions & 3 deletions t/t2350-resource-list.t
Original file line number Diff line number Diff line change
Expand Up @@ -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" &&
Expand All @@ -96,12 +103,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
Expand Down Expand Up @@ -172,13 +180,19 @@ 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 <list-include.output) -eq 1
'
INPUT=${SHARNESS_TEST_SRCDIR}/flux-resource/list/normal-new.json
test_expect_success 'flux-resource list --include skips empty lines by default' '
flux resource list -s all -ni 0 --from-stdin < $INPUT >skip-empty.out &&
test_debug "cat skip-empty.out" &&
test $(wc -l <skip-empty.out) -eq 1
'
test_expect_success 'flux-resource list: --include works with ranks' '
flux resource list -s all -o "{nnodes} {ranks}" -ni 0,3 --from-stdin \
--no-skip-empty \
< $INPUT >include-ranks.out &&
test_debug "cat include-ranks.out" &&
grep "^2 0,3" include-ranks.out
Expand Down Expand Up @@ -270,7 +284,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
'
Expand Down

0 comments on commit d61eccb

Please sign in to comment.