diff --git a/resource/libjobspec/jobspec.cpp b/resource/libjobspec/jobspec.cpp index 064f313cd..16539bacf 100644 --- a/resource/libjobspec/jobspec.cpp +++ b/resource/libjobspec/jobspec.cpp @@ -45,7 +45,7 @@ parse_error::parse_error(const YAML::Node &node, const char *msg) namespace { void parse_yaml_count (Resource& res, const YAML::Node &cnode) { - /* count can have an unsigned interger value */ + /* count can have an unsigned integer value */ if (cnode.IsScalar()) { res.count.min = cnode.as(); res.count.max = res.count.min; @@ -57,41 +57,40 @@ void parse_yaml_count (Resource& res, const YAML::Node &cnode) throw parse_error (cnode, "count is not a mapping"); } - /* Verify existance of required entries */ + /* Verify existence of required entries */ if (!cnode["min"]) { throw parse_error (cnode, "Key \"min\" missing from count"); } if (!cnode["min"].IsScalar()) { throw parse_error (cnode["min"], "Value of \"min\" must be a scalar"); } - if (!cnode["max"]) { - throw parse_error (cnode, "Key \"max\" missing from count"); - } - if (!cnode["max"].IsScalar()) { + if (cnode["max"] && !cnode["max"].IsScalar()) { throw parse_error (cnode["max"], "Value of \"max\" must be a scalar"); } - if (!cnode["operator"]) { - throw parse_error (cnode, "Key \"operator\" missing from count"); - } - if (!cnode["operator"].IsScalar()) { + if (cnode["operator"] && !cnode["operator"].IsScalar()) { throw parse_error (cnode["operator"], "Value of \"operator\" must be a scalar"); } - if (!cnode["operand"]) { - throw parse_error (cnode, "Key \"operand\" missing from count"); - } - if (!cnode["operand"].IsScalar()) { + if (cnode["operand"] && !cnode["operand"].IsScalar()) { throw parse_error (cnode["operand"], "Value of \"operand\" must be a scalar"); } /* Validate values of entries */ res.count.min = cnode["min"].as(); + if (cnode["max"]) { + res.count.max = cnode["max"].as(); + } + if (cnode["operator"]) { + res.count.oper = cnode["operator"].as(); + } + if (cnode["operand"]) { + res.count.operand = cnode["operand"].as(); + } + if (res.count.min < 1) { throw parse_error (cnode["min"], "\"min\" must be greater than zero"); } - - res.count.max = cnode["max"].as(); if (res.count.max < 1) { throw parse_error (cnode["max"], "\"max\" must be greater than zero"); } @@ -99,8 +98,6 @@ void parse_yaml_count (Resource& res, const YAML::Node &cnode) throw parse_error (cnode["max"], "\"max\" must be greater than or equal to \"min\""); } - - res.count.oper = cnode["operator"].as(); switch (res.count.oper) { case '+': case '*': @@ -109,8 +106,6 @@ void parse_yaml_count (Resource& res, const YAML::Node &cnode) default: throw parse_error (cnode["operator"], "Invalid count operator"); } - - res.count.operand = cnode["operand"].as(); } } diff --git a/resource/libjobspec/jobspec.hpp b/resource/libjobspec/jobspec.hpp index c06dfd1fe..7a0a67d71 100644 --- a/resource/libjobspec/jobspec.hpp +++ b/resource/libjobspec/jobspec.hpp @@ -34,6 +34,7 @@ #include #include #include +#include #include namespace Flux { @@ -55,7 +56,7 @@ class Resource { std::string type; struct { unsigned min; - unsigned max; + unsigned max = std::numeric_limits::max(); char oper = '+'; int operand = 1; } count; diff --git a/t/data/resource/jobspecs/validation/invalid/resource_count_missing_max.yaml b/t/data/resource/jobspecs/validation/valid/resource_count_missing_max.yaml similarity index 100% rename from t/data/resource/jobspecs/validation/invalid/resource_count_missing_max.yaml rename to t/data/resource/jobspecs/validation/valid/resource_count_missing_max.yaml diff --git a/t/data/resource/jobspecs/validation/invalid/resource_count_missing_operand.yaml b/t/data/resource/jobspecs/validation/valid/resource_count_missing_operand.yaml similarity index 100% rename from t/data/resource/jobspecs/validation/invalid/resource_count_missing_operand.yaml rename to t/data/resource/jobspecs/validation/valid/resource_count_missing_operand.yaml diff --git a/t/data/resource/jobspecs/validation/invalid/resource_count_missing_operator.yaml b/t/data/resource/jobspecs/validation/valid/resource_count_missing_operator.yaml similarity index 100% rename from t/data/resource/jobspecs/validation/invalid/resource_count_missing_operator.yaml rename to t/data/resource/jobspecs/validation/valid/resource_count_missing_operator.yaml