Bundle parameters are optional.
Both in the sense of implementation, but also from the perspective of use.
I did not know (or if I did, i don’t even remember forgetting) that bundle parameters, if present are optional. In that, a bundle that has parameters can be called without parameters . However, if you call with non-zero parameters you must supply all (that part I knew).
bundle agent __main__
{
meta:
"description"
string => "Bundle parameters are optional!",
comment => "But, if you supply one, you must supply all.";
methods:
"A bundle without params called via usebundle"
usebundle => a_bundle_without_params;
"A bundle without params called via usebundle" -> { "People who like parens" }
usebundle => a_bundle_without_params();
"A bundle with 2 params called without params"
usebundle => a_bundle_with_2_params;
# This is not syntactically valid.
# "A bundle with 2 params called without params" -> { "People who like parens" }
# usebundle => a_bundle_with_2_params();
"A bundle with 2 params called with 2 params"
usebundle => a_bundle_with_2_params( "1", "2" );
# This is not syntactically valid.
# "A bundle with 2 params called with 1 param"
# usebundle => a_bundle_with_2_params( "1" );
# Shortened syntax for calling bundles without parameters.
"a_bundle_without_params";
"a_bundle_with_2_params" comment => "Called without params";
}
bundle agent a_bundle_without_params
{
}
bundle agent a_bundle_with_2_params( p1, p2 )
{
}
Is there prior art for this in the cfengine/core source examples or tests?
Old examples show as I recalled about the case of wanting to supply some parameters. Here though they did supply the parameter, just an empty string.
# More useful, defaults if parameters are passed to a param bundle
"example" usebundle => mymethod("","bbb");
Here a bundle is called dynamically:
"dragon visits"
comment => "One off activity that the nodes carry out while the dragon visits",
usebundle => $(method)("$(satellite)"),
classes => if_repaired("send_the_dragon_back_from_$(satellite)"),
if => "cue_action_on_$(satellite)";
More dynamic bundle calling …
methods:
"b" usebundle => $(bundles)("z"); # runs 2x
"bv" usebundle => $(bundles)($(values)); # runs 4x
}
Notably checkN
is not tested without parms here:
methods:
"check1";
"check2" usebundle => check2;
"bad_check3" usebundle => check3;
#"checkN(4)"; # Not currently working.
"checkN(5)" usebundle => checkN(5);
"bad_checkN(6)" usebundle => checkN(6);
"checkN(bad)" usebundle => checkN(good);
"check$(test_var7)";
#"checkN($(test_var8))"; # Not currently working.
}
None of the other tests with usebundle
in the path did either.