Skip to content

Commit

Permalink
Merge pull request #3486 from garlick/flux_resource_fixes
Browse files Browse the repository at this point in the history
flux resource: allow drain, undrain, and status to work on any rank
  • Loading branch information
mergify[bot] authored Jan 26, 2021
2 parents 4ca5702 + 7b8b17e commit cbb77bd
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/cmd/flux-resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ def drain(args):
flux.Flux(),
"resource.drain",
{"targets": args.targets, "reason": " ".join(args.reason)},
nodeid=0,
).get()


def undrain(args):
"""
Send an "undrain" request to resource module for args.targets
"""
RPC(flux.Flux(), "resource.undrain", {"targets": args.targets}).get()
RPC(flux.Flux(), "resource.undrain", {"targets": args.targets}, nodeid=0).get()


class StatusLine:
Expand Down Expand Up @@ -273,7 +274,7 @@ def status(args):
if args.from_stdin:
resp = sys.stdin.read()
else:
resp = RPC(flux.Flux(), "resource.status").get()
resp = RPC(flux.Flux(), "resource.status", nodeid=0).get()

rstat = ResourceStatus.from_status_response(resp, fmt)

Expand Down
23 changes: 16 additions & 7 deletions src/modules/resource/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,18 @@ static void status_cb (flux_t *h,
void *arg)
{
struct resource_ctx *ctx = arg;
const struct idset *online = monitor_get_up (ctx->monitor);
const struct idset *offline = monitor_get_down (ctx->monitor);
const struct idset *exclude = exclude_get (ctx->exclude);
json_t *drain;
const json_t *R;
json_t *o = NULL;
const char *errstr = NULL;

if (flux_request_decode (msg, NULL, NULL) < 0)
goto error;
if (ctx->rank != 0) {
errno = EPROTO;
errstr = "this RPC only works on rank 0";
goto error;
}
if (!(R = inventory_get (ctx->inventory)))
goto error;
if (!(drain = drain_get_info (ctx->drain)))
Expand All @@ -174,19 +177,25 @@ static void status_cb (flux_t *h,
errno = ENOMEM;
goto error;
}
if (rutil_set_json_idset (o, "online", online) < 0)
if (rutil_set_json_idset (o,
"online",
monitor_get_up (ctx->monitor)) < 0)
goto error;
if (rutil_set_json_idset (o, "offline", offline) < 0)
if (rutil_set_json_idset (o,
"offline",
monitor_get_down (ctx->monitor)) < 0)
goto error;
if (rutil_set_json_idset (o, "exclude", exclude) < 0)
if (rutil_set_json_idset (o,
"exclude",
exclude_get (ctx->exclude)) < 0)
goto error;
if (flux_respond_pack (h, msg, "o", o) < 0) {
flux_log_error (h, "error responding to resource.status request");
json_decref (o);
}
return;
error:
if (flux_respond_error (h, msg, errno, NULL) < 0)
if (flux_respond_error (h, msg, errno, errstr) < 0)
flux_log_error (h, "error responding to resource.status request");
json_decref (o);
}
Expand Down
19 changes: 16 additions & 3 deletions t/t2310-resource-module.t
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ test_expect_success 'flux resource reload fails on nonexistent XML directory' '
'

test_expect_success 'flux resource reload fails on empty XML directory' '
mkdir empty &&
test_must_fail flux resource reload -x $(pwd)/empty
mkdir empty &&
test_must_fail flux resource reload -x $(pwd)/empty
'

test_expect_success HAVE_JQ 'extract hwloc XML from JSON object' '
Expand Down Expand Up @@ -192,7 +192,20 @@ test_expect_success HAVE_JQ 'all ranks were drained' '
'

test_expect_success 'resource.get-xml blocks until all ranks are up' '
flux python ${SHARNESS_TEST_SRCDIR}/resource/get-xml-test.py
flux python ${SHARNESS_TEST_SRCDIR}/resource/get-xml-test.py
'

test_expect_success 'flux resource status works on rank > 0' '
flux exec -r 1 flux resource status
'

status_onrank() {
flux python -c "import flux; print(flux.Flux().rpc(\"resource.status\",nodeid=$1).get())"
}

test_expect_success 'resource.status RPC fails on rank > 0' '
test_must_fail status_onrank 1 2>status.err &&
grep "only works on rank 0" status.err
'

test_expect_success 'unload resource module' '
Expand Down
23 changes: 23 additions & 0 deletions t/t2311-resource-drain.t
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,27 @@ test_expect_success 'drain with no args lists currently drained targets' '
grep "happy happy, joy joy" drain.out
'

test_expect_success 'drain/undrain works on rank > 0' '
flux exec -r 1 flux resource undrain 0 &&
flux exec -r 1 flux resource drain 0 whee drained again
'

drain_onrank() {
local op=$1
local nodeid=$2
local target=$3
flux python -c "import flux; print(flux.Flux().rpc(\"resource.$op\",{\"targets\":$target, \"reason\":\"\"}, nodeid=$nodeid).get())"
}

test_expect_success 'resource.drain RPC fails on rank > 0' '
test_must_fail drain_onrank drain 1 0 2>drain1.err &&
grep -i "unknown service method" drain1.err
'

test_expect_success 'resource.undrain RPC fails on rank > 0' '
test_must_fail drain_onrank undrain 1 0 2>undrain1.err &&
grep -i "unknown service method" undrain1.err
'


test_done

0 comments on commit cbb77bd

Please sign in to comment.