Skip to content

Commit

Permalink
Merge pull request #6671 from grondo/hostlist-find
Browse files Browse the repository at this point in the history
flux-hostlist: add `-F, --find=HOSTS` option
  • Loading branch information
mergify[bot] authored Feb 28, 2025
2 parents c57d3b1 + 520eae5 commit f15140e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions doc/man1/flux-hostlist.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ OPTIONS
'0-1' will return the first and second, '-1' returns the last host). The
command will fail if any id in *IDS* is not a valid index.

.. option:: -F, --find=HOSTS

Output a list of space-separated indices of *HOSTS* in the result hostlist,
where *HOSTS* should be one or more hosts in hostlist form. The command
will fail if any host in *HOSTS* is not found.

.. option:: -L, --limit=N

Output at most *N* hosts (*-N* to output the last *N* hosts).
Expand Down
12 changes: 11 additions & 1 deletion src/cmd/flux-hostlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ def parse_args():
metavar="[-]IDS",
help="Output hosts at indices in idset IDS (-IDS to index from end)",
)
parser.add_argument(
"-F",
"--find",
type=str,
metavar="HOSTS",
help="Output indices of HOSTS in target in hostlist."
+ " Fails if any host is not found.",
)
parser.add_argument(
"-L",
"--limit",
Expand Down Expand Up @@ -394,7 +402,9 @@ def main():
else:
hl = hl[IDset(args.nth)]

if args.count:
if args.find:
print(" ".join(map(str, hl.index(args.find))))
elif args.count:
print(f"{hl.count()}")
elif args.expand:
# Convert '\n' specified on command line to actual newline char
Expand Down
9 changes: 9 additions & 0 deletions t/t2814-hostlist-cmd.t
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ test_expect_success 'flux-hostlist -n errors with invalid index' '
test_must_fail flux hostlist -n 10 foo[1-10] &&
test_must_fail flux hostlist -n 1,10 foo[1-10]
'
test_expect_success 'flux-hostlist -F, --find=HOSTS works' '
test "$(flux hostlist -F foo1 foo[1-10])" = "0" &&
test "$(flux hostlist -F foo10 foo[1-10])" = "9" &&
test "$(flux hostlist -F foo[1-2] foo[1-10])" = "0 1"
'
test_expect_success 'flux-hostlist -F, --find=HOSTS fails if host not found' '
test_must_fail flux hostlist -F foo1 foo[2-10] &&
test_must_fail flux hostlist -F foo[1-10] foo[2-10]
'
test_expect_success 'flux-hostlist -x, --exclude works' '
test "$(flux hostlist -x foo1 foo[0-10])" = "foo[0,2-10]" &&
test "$(flux hostlist -x foo[0-9] foo[0-10])" = "foo10"
Expand Down

0 comments on commit f15140e

Please sign in to comment.