Skip to content

Commit

Permalink
dws: drop FLUX_LOCAL_RABBIT env var from shell
Browse files Browse the repository at this point in the history
Problem: the `flux rabbitmapping` utility makes the FLUX_LOCAL_RABBIT
environment variable obsolete.

Drop it.
  • Loading branch information
jameshcorbett committed Jan 24, 2025
1 parent 8fa4474 commit 4b8480c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 51 deletions.
47 changes: 7 additions & 40 deletions src/shell/plugins/dws_environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,10 @@
* Apply a JSON object defining environment variables to the job's environment
*/
static int set_environment (flux_shell_t *shell,
json_t *env_object,
json_t *rabbit_mapping)
json_t *env_object)
{
const char *key, *value_string;
json_t *value;
struct hostlist *h;
char hostname[HOST_NAME_MAX + 1];

if (gethostname (hostname, HOST_NAME_MAX + 1) < 0)
return -1;
hostname[HOST_NAME_MAX] = '\0';

json_object_foreach (env_object, key, value) {
if (!(value_string = json_string_value (value))) {
Expand All @@ -57,30 +50,7 @@ static int set_environment (flux_shell_t *shell,
return -1;
}
}

json_object_foreach (rabbit_mapping, key, value) {
if (!(value_string = json_string_value (value))) {
shell_log_error (
"variables in dws_environment event must have string values");
return -1;
}
if (!(h = hostlist_decode (value_string))){
shell_log_error ("Failed initializing hostlist");
return -1;
}
if (hostlist_find (h, hostname) >= 0){
if (flux_shell_setenvf (shell, 1, "FLUX_LOCAL_RABBIT", "%s", key) < 0){
shell_log_error ("Failed setting FLUX_LOCAL_RABBIT");
hostlist_destroy (h);
return -1;
}
hostlist_destroy (h);
return 0;
}
hostlist_destroy (h);
}
shell_log_error ("Failed to find current node in rabbit mapping");
return -1;
return 0;
}

/*
Expand All @@ -90,7 +60,7 @@ static int read_future (flux_shell_t *shell, flux_future_t *fut)
{
json_t *o = NULL;
json_t *context = NULL;
json_t *env, *rabbit_mapping;
json_t *env;
const char *name, *event = NULL;

while (flux_future_wait_for (fut, 30.0) == 0
Expand All @@ -112,19 +82,16 @@ static int read_future (flux_shell_t *shell, flux_future_t *fut)
}
else if (!strcmp (name, "dws_environment")) {
if (json_unpack (context,
"{s:o, s:o}",
"{s:o}",
"variables",
&env,
"rabbits",
&rabbit_mapping)
&env)
< 0) {
shell_log_error (
"No 'variables' or 'rabbits' context "
"in dws_environment event");
"No 'variables' context in dws_environment event");
json_decref (o);
return -1;
}
if (set_environment (shell, env, rabbit_mapping) < 0) {
if (set_environment (shell, env) < 0) {
json_decref (o);
return -1;
}
Expand Down
17 changes: 6 additions & 11 deletions t/t1004-dws-environment.t
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,24 @@ test_expect_success 'shell: plugin sets env vars properly' '
--setattr=dw="foo" --dependency=afterany:$depend_job env) &&
kvsdir=$(flux job id --to=kvs $jobid) &&
flux kvs eventlog append ${kvsdir}.eventlog dws_environment \
"{\"variables\":{\"DWS_TEST_VAR1\": \"foo\", \"DWS_TEST_VAR2\": \"bar\"}, \
\"rabbits\":{\"rabbit1\": \"$(hostname)\"}}" &&
"{\"variables\":{\"DWS_TEST_VAR1\": \"foo\", \"DWS_TEST_VAR2\": \"bar\"}}" &&
flux cancel $depend_job &&
environment=$(flux job attach ${jobid}) &&
echo "$environment" | grep DWS_TEST_VAR1=foo &&
echo "$environment" | grep DWS_TEST_VAR2=bar &&
echo "$environment" | grep FLUX_LOCAL_RABBIT=rabbit1
'
echo "$environment" | grep DWS_TEST_VAR2=bar
'

test_expect_success 'shell: plugin sets env vars properly with multiple rabbits' '
depend_job=$(flux submit sleep 10) &&
jobid=$(flux submit -o userrc=$(pwd)/$USERRC_NAME \
--setattr=dw="foo" --dependency=afterany:$depend_job env) &&
kvsdir=$(flux job id --to=kvs $jobid) &&
flux kvs eventlog append ${kvsdir}.eventlog dws_environment \
"{\"variables\":{\"DWS_TEST_VAR1\": \"foo\", \"DWS_TEST_VAR2\": \"bar\"}, \
\"rabbits\":{\"rabbit96\": \"compute[265-1056]\", \"rabbit7\": \"compute[01-72]\", \
\"rabbit15\": \"$(hostname)\"}}" &&
"{\"variables\":{\"DWS_TEST_VAR1\": \"foo\", \"DWS_TEST_VAR2\": \"bar\"}}" &&
flux cancel $depend_job &&
environment=$(flux job attach ${jobid}) &&
echo "$environment" | grep DWS_TEST_VAR1=foo &&
echo "$environment" | grep DWS_TEST_VAR2=bar &&
echo "$environment" | grep FLUX_LOCAL_RABBIT=rabbit15
'
echo "$environment" | grep DWS_TEST_VAR2=bar
'

test_done

0 comments on commit 4b8480c

Please sign in to comment.