Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flux-hostlist: add -F, --find=HOSTS option #6671

Merged
merged 3 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading