Uploaded image for project: 'CFEngine Community'
  1. CFEngine Community
  2. CFE-2627

"and" attribute of classes promises doesn't handle booleans correctly

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Done
    • Priority: Low
    • Resolution: Fixed
    • Affects Version/s: 3.10.1
    • Fix Version/s: 3.17.0
    • Component/s: Evaluation
    • Labels:

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                mweilgart Mike Weilgart
              • Votes:
                1 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Summary Panel