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

`or` operator for defining classes does not behave as documented

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Done
    • Priority: Low
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.6.x
    • Component/s: Evaluation
    • Labels:
      None

      Description

      Assume we want to implement the following `sh` snippet using CFEngine
      syntax::

      if [ ! -r /etc/aliases.db ] || [ /etc/aliases -nt /etc/aliases.db ]; then
      do_something < /etc/aliases > /etc/aliases.db
      fi

      It would be a simple "or" class: run newaliases if (a) /etc/aliases is
      newer than /etc/aliases.db, or (b) /etc/aliases.db does not exist.

      The documentation for the `or` clause for defining context classes
      states that the LHS class is defined if any one of the class
      expressions on the RHS are defined. However, this is not what
      happens:

      body common control
      {
      inputs =>

      { "lib/cfengine_stdlib.cf" }

      ;
      bundlesequence =>

      { "test" }

      ;
      }

      bundle agent test
      {
      classes:
      "etc_aliases_db_exists"
      expression => fileexists("/etc/aliases.db");

      "etc_aliases_db_does_not_exist"
      not => fileexists("/etc/aliases.db");

        1. does not work
          "rebuild_aliases_db1"
          or => { isnewerthan("/etc/aliases", "/etc/aliases.db"), "!etc_aliases_db_exists" }

          ;

        1. neither does this one:
          "rebuild_aliases_db2"
          or => { "!etc_aliases_db_exists", isnewerthan("/etc/aliases", "/etc/aliases.db") }

          ;

        1. nor this one:
          "rebuild_aliases_db3"
          or => { isnewerthan("/etc/aliases", "/etc/aliases.db"), "etc_aliases_db_does_not_exist" }

          ;

        1. nor this one:
          "rebuild_aliases_db4"
          or => { "etc_aliases_db_does_not_exist", isnewerthan("/etc/aliases", "/etc/aliases.db") }

          ;

      files:
      rebuild_aliases_db1|rebuild_aliases_db2|rebuild_aliases_db3|rebuild_aliases_db4::
      "/etc/aliases.db"
      create => "true",
      classes => if_repaired("rebuilt_aliases_db");

      reports:
      rebuild_aliases_db1|rebuild_aliases_db2|rebuild_aliases_db3|rebuild_aliases_db4::
      "context `rebuild_aliases_db` is set";

      rebuilt_aliases_db::
      "file /etc/aliases.db created";
      }

      With 3.5.0b2.38840ad I get this output (but the problem happens in
      3.4.2 and 3.4.4 as well, though the logs are more verbose so I'm not
      posting them):

      2013-05-24T18:05:58+0200 verbose: Using bundlesequence =>

      {'test'}

      2013-05-24T18:05:58+0200 verbose: Adding local bundle class 'etc_aliases_db_does_not_exist'
      2013-05-24T18:05:58+0200 verbose: Private classes augmented: etc_aliases_db_does_not_exist
      2013-05-24T18:05:58+0200 verbose: Skipping next promise '/etc/aliases.db', as context 'rebuild_aliases_db1|rebuild_aliases_db2|rebuild_aliases_db3|rebuild_aliases_db4' is not relevant
      2013-05-24T18:05:58+0200 verbose: Skipping next promise 'context `rebuild_aliases_db` is set', as context 'rebuild_aliases_db1|rebuild_aliases_db2|rebuild_aliases_db3|rebuild_aliases_db4' is not relevant
      2013-05-24T18:05:58+0200 verbose: Skipping next promise 'file /etc/aliases.db created', as context 'rebuilt_aliases_db' is not relevant
      2013-05-24T18:05:58+0200 verbose: Private classes augmented: etc_aliases_db_does_not_exist
      2013-05-24T18:05:58+0200 verbose: Skipping next promise '/etc/aliases.db', as context
      'rebuild_aliases_db1|rebuild_aliases_db2|rebuild_aliases_db3|rebuild_aliases_db4' is not relevant
      2013-05-24T18:05:58+0200 verbose: Skipping next promise 'context `rebuild_aliases_db` is set', as context
      'rebuild_aliases_db1|rebuild_aliases_db2|rebuild_aliases_db3|rebuild_aliases_db4' is not relevant
      2013-05-24T18:05:58+0200 verbose: Skipping next promise 'file /etc/aliases.db created', as context 'rebuilt_aliases_db' is not relevant
      2013-05-24T18:05:58+0200 verbose: Private classes augmented: etc_aliases_db_does_not_exist
      2013-05-24T18:05:58+0200 verbose: Skipping next promise '/etc/aliases.db', as context
      'rebuild_aliases_db1|rebuild_aliases_db2|rebuild_aliases_db3|rebuild_aliases_db4' is not relevant
      2013-05-24T18:05:58+0200 verbose: Skipping next promise 'context `rebuild_aliases_db` is set', as context
      'rebuild_aliases_db1|rebuild_aliases_db2|rebuild_aliases_db3|rebuild_aliases_db4' is not relevant
      2013-05-24T18:05:58+0200 verbose: Skipping next promise 'file /etc/aliases.db created', as context 'rebuilt_aliases_db' is not relevant
      2013-05-24T18:05:58+0200 verbose: Zero promises executed for bundle "test"
      2013-05-24T18:05:58+0200 verbose: This promise has already been verified
      2013-05-24T18:05:58+0200 verbose: This promise has already been verified
      2013-05-24T18:05:58+0200 verbose: This promise has already been verified
      2013-05-24T18:05:58+0200 verbose: This promise has already been verified
      2013-05-24T18:05:58+0200 verbose: Zero promises executed for bundle "test"

      It seems that the only way of defining the `rebuild_aliases_db` class
      is to use class names instead of class expressions in the `or`
      clause:

      "etc_aliases_db_exists"
      expression => fileexists("/etc/aliases.db");

      "etc_aliases_updated"
      expression => isnewerthan("/etc/aliases", "/etc/aliases.db");

        1. this works
          "rebuild_aliases_db"
          or => { "etc_aliases_updated", "etc_aliases_db_exists" }

          ;

      The behavior of the `or` function should be corrected, or the
      documentation updated to reflect the current behavior.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                a10025 Volker Hilsheimer (Inactive)
                Reporter:
                riccardomurri Riccardo Murri
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Summary Panel