-
Type:
Bug
-
Status: Done
-
Priority:
Low
-
Resolution: Fixed
-
Affects Version/s: 3.10.1
-
Fix Version/s: 3.17.0
-
Component/s: Evaluation
-
Labels:
I had long ago (3.6.6) noted several oddities in the way boolean expressions were handled; sometimes functions appeared to return strings (class expressions) and sometimes booleans, and the two weren't always handled the same way.
I've just stumbled across an instance of this in CFEngine 3.10.1:
[root@ip-172-31-16-223 ~]# cat test1.cf bundle agent main { classes: "myclass" and => { isvariable("sys.flavor") }; reports: myclass:: "myclass is set"; } [root@ip-172-31-16-223 ~]# cf-agent -KIC -f ./test1.cf R: myclass is set [root@ip-172-31-16-223 ~]# cat test2.cf bundle agent main { classes: "myotherclass" and => { isvariable("sys.fqhost"), not( isvariable("nosuchvar") ) }; reports: myotherclass:: "myotherclass is set"; } [root@ip-172-31-16-223 ~]# cf-agent -KIC -f ./test2.cf ./test2.cf:5:47: error: Function does not return the required type not( isvariable("nosuchvar") ) }; ^ error: There are syntax errors in policy files error: Policy failed validation with command '"/var/cfengine/bin/cf-promises" -c "./test2.cf"' error: Failsafe condition triggered. Interactive session detected, skipping failsafe.cf execution. error: Error reading CFEngine policy. Exiting... [root@ip-172-31-16-223 ~]# cat test3.cf bundle agent main { classes: "athirdclass" expression => not( isvariable("nosuchvar") ); reports: athirdclass:: "The class got set"; } [root@ip-172-31-16-223 ~]# cf-agent -KIC -f ./test3.cf R: The class got set [root@ip-172-31-16-223 ~]# cat test4.cf bundle agent main { classes: "lastclass" expression => and( isvariable("sys.fqhost"), not( isvariable("nosuchvar") ) ); reports: lastclass:: "This class got set"; } [root@ip-172-31-16-223 ~]# cf-agent -KIC -f ./test4.cf R: This class got set [root@ip-172-31-16-223 ~]#
The above tests demonstrate that the return type of the not() function is not acceptable as input in the and => {}; attribute of a classes promise, though the return type of the not() function IS acceptable as input for the and() function, and is likewise acceptable as input directly in an expression attribute of a classes promise.