Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add set-status command to flux ion-resource
Browse files Browse the repository at this point in the history
Problem: there is no convenient testing interface to the set-status
resource service.

Add a command to the flux-ion-resource script for sending a
set-status RPC.
jameshcorbett committed Dec 12, 2023
1 parent e37be53 commit bec401a
Showing 2 changed files with 42 additions and 15 deletions.
29 changes: 14 additions & 15 deletions resource/modules/resource_match.cpp
Original file line number Diff line number Diff line change
@@ -2648,47 +2648,46 @@ static void set_status_request_cb (flux_t *h, flux_msg_handler_t *w,
std::string resource_path = "", status = "", errmsg = "";
std::shared_ptr<resource_ctx_t> ctx = getctx ((flux_t *)arg);
resource_pool_t::string_to_status sts = resource_pool_t::str_to_status;
std::map<std::string, std::vector<vtx_t>>::const_iterator it {};
resource_pool_t::string_to_status::iterator status_it {};

if (flux_request_unpack (msg, NULL, "{s:s, s:s}",
"resource_path", &rp,
"status", &st) < 0){
if (flux_respond_error (h, msg, EINVAL, "malformed RPC") < 0)
flux_log_error (h, "%s: flux_respond_error", __FUNCTION__);
return;
errmsg = "malformed RPC";
goto error;
}
resource_path = rp;
status = st;
// check that the path/vertex exists
std::map<std::string, std::vector<vtx_t>>::const_iterator it =
ctx->db->metadata.by_path.find (resource_path);
it = ctx->db->metadata.by_path.find (resource_path);
if (it == ctx->db->metadata.by_path.end ()) {
errmsg = "could not find path '" + resource_path + "' in resource graph";
if (flux_respond_error (h, msg, EINVAL, errmsg.c_str()) < 0)
flux_log_error (h, "%s: flux_respond_error", __FUNCTION__);
return;
goto error;
}
// check that the status given is valid ('up' or 'down')
auto status_it = sts.find (status);
status_it = sts.find (status);
if (status_it == sts.end ()) {
errmsg = "unrecognized status '" + status + "'";
if (flux_respond_error (h, msg, EINVAL, errmsg.c_str()) < 0)
flux_log_error (h, "%s: flux_respond_error", __FUNCTION__);
return;
goto error;
}
// mark the vertex
if (ctx->traverser->mark (resource_path, status_it->second) < 0) {
flux_log_error (h, "%s: traverser::mark: %s", __FUNCTION__,
ctx->traverser->err_message ().c_str ());
ctx->traverser->clear_err_message ();
errmsg = "Failed to set status of resource vertex";
if (flux_respond_error (h, msg, EINVAL, errmsg.c_str()) < 0)
flux_log_error (h, "%s: flux_respond_error", __FUNCTION__);
return;
goto error;
}
if (flux_respond (h, msg, NULL) < 0) {
flux_log_error (h, "%s: flux_respond", __FUNCTION__);
}
return;

error:
if (flux_respond_error (h, msg, EINVAL, errmsg.c_str ()) < 0)
flux_log_error (h, "%s: flux_respond_error", __FUNCTION__);
return;
}

/******************************************************************************
28 changes: 28 additions & 0 deletions t/scripts/flux-ion-resource.py
Original file line number Diff line number Diff line change
@@ -94,6 +94,10 @@ def rpc_find(self, criteria, find_format=None):
def rpc_status(self):
return self.f.rpc("sched-fluxion-resource.status").get()

def rpc_set_status(self, resource_path, status):
payload = {"resource_path": resource_path, "status": status}
return self.f.rpc("sched-fluxion-resource.set_status", payload).get()

def rpc_namespace_info(self, rank, type_name, identity):
payload = {"rank": rank, "type-name": type_name, "id": identity}
return self.f.rpc("sched-fluxion-resource.ns-info", payload).get()
@@ -288,6 +292,16 @@ def status_action(args):
print(json.dumps(resp))


"""
Action for set-status sub-command
"""


def set_status_action(args):
r = ResourceModuleInterface()
r.rpc_set_status(args.resource_path, args.status)


"""
Action for ns-info sub-command
"""
@@ -341,6 +355,7 @@ def main():
cstr = "Cancel an allocated or reserved job."
fstr = "Find resources matching with a crieria."
ststr = "Display resource status."
ssstr = "Set up/down status of a resource vertex."
pstr = "Set property-key=value for specified resource."
gstr = "Get value for specified resource and property-key."
nstr = "Get remapped ID given raw ID seen by the reader."
@@ -352,6 +367,7 @@ def main():
parser_c = subpar.add_parser("cancel", help=cstr, description=cstr)
parser_f = subpar.add_parser("find", help=fstr, description=fstr)
parser_st = subpar.add_parser("status", help=ststr, description=ststr)
parser_ss = subpar.add_parser("set-status", help=ssstr, description=ssstr)
parser_sp = subpar.add_parser("set-property", help=pstr, description=pstr)
parser_gp = subpar.add_parser("get-property", help=gstr, description=gstr)
parser_n = subpar.add_parser("ns-info", help=nstr, description=nstr)
@@ -419,6 +435,18 @@ def main():
st_help = "Resource status"
parser_st.set_defaults(func=status_action)

# Positional argument for set-status sub-command
#
parser_ss.add_argument(
"resource_path",
help="path to vertex",
)
parser_ss.add_argument(
"status",
help="status of vertex",
)
parser_ss.set_defaults(func=set_status_action)

#
# Positional argument for match allocate sub-command
#

0 comments on commit bec401a

Please sign in to comment.