Skip to content

Commit 7879439

Browse files
committed
flux-R: add from-config subcommand
Problem: The flux-R command has support for generating Rv1 from arguments and other sources for testing etc., but does not include a way to generate R from configuration as provided by the librlist function rlist_from_config(). Add a from-config subcommand to test reading R from resource.config array. This can be used to validate configuration or drive testing of the underlying API.
1 parent bf33139 commit 7879439

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/cmd/flux-R.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "src/common/libutil/read_all.h"
3030
#include "src/common/librlist/rlist.h"
3131
#include "src/common/librlist/rhwloc.h"
32+
#include "src/common/libtomlc99/toml.h"
3233

3334
#define RSET_DOC "\
3435
Read, generate, and process RFC 20 Resource Set objects.\n\
@@ -43,6 +44,7 @@ int cmd_rerank (optparse_t *p, int argc, char **argv);
4344
int cmd_decode (optparse_t *p, int argc, char **argv);
4445
int cmd_verify (optparse_t *p, int argc, char **argv);
4546
int cmd_set_property (optparse_t *p, int argc, char **argv);
47+
int cmd_parse_config (optparse_t *p, int argc, char **argv);
4648

4749
static struct optparse_option global_opts[] = {
4850
OPTPARSE_TABLE_END
@@ -145,6 +147,11 @@ static struct optparse_option decode_opts[] = {
145147
OPTPARSE_TABLE_END
146148
};
147149

150+
static struct optparse_option parse_config_opts[] = {
151+
OPTPARSE_TABLE_END
152+
};
153+
154+
148155
static struct optparse_subcommand subcommands[] = {
149156
{ "encode",
150157
"[OPTIONS]...",
@@ -218,6 +225,13 @@ static struct optparse_subcommand subcommands[] = {
218225
0,
219226
set_property_opts,
220227
},
228+
{ "parse-config",
229+
"PATH",
230+
"Read config from resource.config array",
231+
cmd_parse_config,
232+
0,
233+
parse_config_opts,
234+
},
221235
OPTPARSE_SUBCMD_END
222236
};
223237

@@ -828,6 +842,33 @@ int cmd_set_property (optparse_t *p, int argc, char **argv)
828842
return 0;
829843
}
830844

845+
int cmd_parse_config (optparse_t *p, int argc, char **argv)
846+
{
847+
flux_error_t error;
848+
json_t *o = NULL;
849+
struct rlist *rl = NULL;
850+
flux_conf_t *conf;
851+
852+
if (!(conf = flux_conf_parse (argv[1], &error)))
853+
log_msg_exit ("flux_conf_parse: %s", error.text);
854+
855+
if (flux_conf_unpack (conf, &error,
856+
"{s:{s:o}}",
857+
"resource",
858+
"config", &o) < 0)
859+
log_msg_exit ("Config file error: %s", error.text);
860+
861+
if (!(rl = rlist_from_config (o, &error)))
862+
log_msg_exit ("Config file error: %s", error.text);
863+
864+
rlist_puts (rl);
865+
866+
flux_conf_decref (conf);
867+
rlist_destroy (rl);
868+
869+
return 0;
870+
}
871+
831872
/*
832873
* vi:tabstop=4 shiftwidth=4 expandtab
833874
*/

0 commit comments

Comments
 (0)