Forum: CFEngine Help
Subject: Re: Using dist for random selections
Author: sauer
Link to topic: https://cfengine.com/forum/read.php?3,24500,24503#msg-24503

You can use "50" and "50.0", but the class that gets set is not canonified, and 
the period screws up parsing because it's treated like a boolean "and". :)  For 
example, this:


classes:
  "dtest" dist => {"50", "50.0"};
commands:
  "/bin/grep ^dtest_ $(sys.workdir)/state/allclasses.txt";


results in this:


sauer@midnight:~$ ./test.cf 
Q: ".../bin/grep ^dtes": dtest_50
I: Last 1 quoted lines were generated by promiser "/bin/grep ^dtest_ 
/home/sauer/.cfagent/state/allclasses.txt"
sauer@midnight:~$ ./test.cf 
Q: ".../bin/grep ^dtes": dtest_50.0
I: Last 1 quoted lines were generated by promiser "/bin/grep ^dtest_ 
/home/sauer/.cfagent/state/allclasses.txt"


So, that's a bug (in 3.2.1, anyway).  But it looks like the two are 
equivalently favored in my short testing (exactly 300 out of 600 runs), so you 
could use "dtest&!dtest_50" or possibly set another class using classmatch for 
the 50.0 one.  The same concept works for, say, 25.  Here's that example, and 
an example of using classmatch to work around the bug. :)


sauer@midnight:~$ cat ./test.cf
#!/usr/local/sbin/cf-agent -Kf
body common control { bundlesequence => { "a" }; }
bundle agent a {
classes:
  "dtest" dist => {"25", "25.0", "25.00", "25.000"};
  "dtest_25_0"   expression => classmatch("dtest_25\.0");
  "dtest_25_00"  expression => classmatch("dtest_25\.00");
  "dtest_25_000" expression => classmatch("dtest_25\.000");
reports:
  dtest_25::     "Have dtest_25";
  dtest_25_0::   "Have dtest_25.0";
  dtest_25_00::  "Have dtest_25.00";
  dtest_25_000:: "Have dtest_25.000";
}
sauer@midnight:~$ for I in $(seq 1 10); do ./test.cf; done
R: Have dtest_25.000
R: Have dtest_25.00
R: Have dtest_25.0
R: Have dtest_25.00
R: Have dtest_25.00
R: Have dtest_25.0
R: Have dtest_25.0
R: Have dtest_25.0
R: Have dtest_25.00
R: Have dtest_25.000


_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to