diff --git a/t/Makefile.am b/t/Makefile.am index 6e90f8364444..6aa915d2d1b2 100644 --- a/t/Makefile.am +++ b/t/Makefile.am @@ -423,6 +423,7 @@ check_PROGRAMS = \ job-manager/list-jobs \ job-manager/print-constants \ job-manager/events_journal_stream \ + job-info/info_lookup \ job-info/update_lookup \ job-info/update_watch_stream \ ingest/submitbench \ @@ -770,6 +771,11 @@ job_manager_events_journal_stream_CPPFLAGS = $(test_cppflags) job_manager_events_journal_stream_LDADD = $(test_ldadd) job_manager_events_journal_stream_LDFLAGS = $(test_ldflags) +job_info_info_lookup_SOURCES = job-info/info_lookup.c +job_info_info_lookup_CPPFLAGS = $(test_cppflags) +job_info_info_lookup_LDADD = $(test_ldadd) +job_info_info_lookup_LDFLAGS = $(test_ldflags) + job_info_update_lookup_SOURCES = job-info/update_lookup.c job_info_update_lookup_CPPFLAGS = $(test_cppflags) job_info_update_lookup_LDADD = $(test_ldadd) diff --git a/t/job-info/info_lookup.c b/t/job-info/info_lookup.c new file mode 100644 index 000000000000..d0a7ab77c854 --- /dev/null +++ b/t/job-info/info_lookup.c @@ -0,0 +1,81 @@ +/************************************************************\ + * Copyright 2023 Lawrence Livermore National Security, LLC + * (c.f. AUTHORS, NOTICE.LLNS, COPYING) + * + * This file is part of the Flux resource manager framework. + * For details, see https://github.com/flux-framework. + * + * SPDX-License-Identifier: LGPL-3.0 +\************************************************************/ + +#if HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include +#include +#include + +#include "src/common/libutil/log.h" + +int main (int argc, char *argv[]) +{ + flux_t *h; + flux_future_t *f; + flux_jobid_t id; + json_t *keys; + int i; + + if (argc < 3) { + fprintf (stderr, "Usage: info_lookup ...\n"); + exit (1); + } + + if (!(h = flux_open (NULL, 0))) + log_err_exit ("flux_open"); + + if (flux_job_id_parse (argv[1], &id) < 0) + log_msg_exit ("error parsing jobid: %s", argv[1]); + + if (!(keys = json_array ())) + log_err_exit ("json_array"); + + for (i = 2; i < argc; i++) { + json_t *key = json_string (argv[i]); + if (!key) + log_err_exit ("json_string_value"); + if (json_array_append_new (keys, key) < 0) + log_err_exit ("json_array_append_new"); + } + + if (!(f = flux_rpc_pack (h, + "job-info.lookup", + FLUX_NODEID_ANY, + 0, + "{s:I s:O s:i}", + "id", id, + "keys", keys, + "flags", 0))) + log_err_exit ("flux_rpc_pack"); + + for (i = 2; i < argc; i++) { + json_t *value; + char *s; + if (flux_rpc_get_unpack (f, "{s:o}", argv[i], &value) < 0) + log_msg_exit ("job-info.lookup: %s", + future_strerror (f, errno)); + if (!(s = json_dumps (value, JSON_ENCODE_ANY))) + log_msg_exit ("invalid json result"); + printf ("%s\n", s); + fflush (stdout); + free (s); + } + + flux_future_destroy (f); + flux_close (h); + return (0); +} + +/* + * vi:tabstop=4 shiftwidth=4 expandtab + */ diff --git a/t/t2230-job-info-lookup.t b/t/t2230-job-info-lookup.t index 2beb099bdb3c..067b3ecf364a 100755 --- a/t/t2230-job-info-lookup.t +++ b/t/t2230-job-info-lookup.t @@ -7,6 +7,7 @@ test_description='Test flux job info lookup service' test_under_flux 4 job RPC=${FLUX_BUILD_DIR}/t/request/rpc +INFOLOOKUP=${FLUX_BUILD_DIR}/t/job-info/info_lookup fj_wait_event() { flux job wait-event --timeout=20 "$@" @@ -204,6 +205,34 @@ test_expect_success 'flux job eventlog -p fails on invalid path' ' test_must_fail flux job eventlog -p "foobar" $jobid ' +# +# job info lookup tests (multiple keys in info request) +# + +test_expect_success 'job-info.lookup multiple keys works (different keys)' ' + jobid=$(submit_job) && + ${INFOLOOKUP} $jobid eventlog jobspec J > all_info_a.out && + grep submit all_info_a.out && + grep sleep all_info_a.out +' + +test_expect_success 'job-info.lookup multiple keys works (same key)' ' + jobid=$(submit_job) && + ${INFOLOOKUP} $jobid eventlog eventlog eventlog > eventlog_3.out && + test $(grep submit eventlog_3.out | wc -l) -eq 3 +' + +test_expect_success 'job-info.lookup multiple keys fails on bad id' ' + test_must_fail ${INFOLOOKUP} 12345 eventlog jobspec J +' + +test_expect_success 'job-info.lookup multiple keys fails on 1 bad entry' ' + jobid=$(submit_job) && + kvsdir=$(flux job id --to=kvs $jobid) && + flux kvs unlink ${kvsdir}.jobspec && + test_must_fail ${INFOLOOKUP} $jobid eventlog jobspec J > all_info_b.out +' + # # stats & corner cases #