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

logical functions (and(), or(), not()) can't be used with logical class attributes (not,and,or) due to return type mismatch

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Done
    • Priority: Low
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.17.0
    • Component/s: Language
    • Labels:
      None

      Description

      Filing on behalf of customer request to create a class any time a single condition from a list is not met.

      The initial pattern attempted:

      classes:
          "legacy_hostname"
            not => or( regcmp( "$(bias_hostname_regex)", $(sys.uqhost) ),
                   fileexists("$(cliqr_file)") ),
            comment => "hostname is not BIAS-compliant and not a CliQr host.";
      

      But because the logical functions returns strings instead of Booleans the "not" attribute did not like that, we ended up with this:

      classes:
          "legacy_hostname"
            expression => "any",
            ifvarclass => and(
                               not( fileexists("$(flag_file)")),
                               not( regcmp( "$(hostname_regex)", $(sys.uqhost) ) )
                             ),
           comment => "This is a legacy host if it doesnt have a new flag file, and
                       the hostname regex doesnt match the current standard";
      

      Another pattern that also works:

         "legacy_hostname"
            expression => not( or( regcmp( $(reg_match), $(sys.uqhost) ),
                                  fileexists( $(flag_file) ) ) ),
      
            comment => "defined if '$(reg_match)' does not match '$(sys.uqhost)' AND
                        '$(flag_file)' does not exist";
      
      

      Could we have something like this, which would allow our intention to shine through and would have less syntax:

      classes:
          "legacy_hostname"
            nor => { regcmp( "$(bias_hostname_regex)", $(sys.uqhost) ),
                     fileexists("$(cliqr_file)") },
            comment => "hostname is legacy.";
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                olehermanse Ole Herman Schumacher Elgesem
                Reporter:
                a10042 Nick Anderson
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: