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

var class guard combined with ifvarclass attribute causes incorrect results

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: High
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: cf-agent
    • Labels:
      None
    • Found in version (details):
      3.15 (master)

      Description

      On repeated execution of the two following policies the results seem inconsistent and incorrect.

      It is assumed that "any":: as a class guard results in ifvarclass => and( "any", whatever-ifvarclass-is-already-on-the-promise )

      In the first example touch2 is repeatedly performed even though it seems it should not.

      #+begin_src cfengine3
      bundle agent main
      {
        files:
          "/tmp/craig/"
            create => "true";  commands:
            "/usr/bin/touch"
              handle => "touch-performed",
              args => "/tmp/craig/touch-token",
              if => and( isdir( "/tmp/craig" ), not( fileexists( "/tmp/craig/touch-token" )));    "any"::
            "/usr/bin/touch"
              handle => "touch2-performed",
              args => "/tmp/craig/touch2-token",
              if => and( isdir( "/tmp/craig" ), not( fileexists( "/tmp/craig/touch2-token" )));    "/usr/bin/touch"
              handle => "touch3-performed",
              args => "/tmp/craig/touch3-token",
              if => and( "any", and( isdir( "/tmp/craig" ), not( fileexists( "/tmp/craig/touch3-token" ))));
        reports:
          "touch was performed" depends_on => { "touch-performed" };
          "touch2 was performed" depends_on => { "touch2-performed" };
          "touch3 was performed" depends_on => { "touch3-performed" };
      }
      #+end_src#+RESULTS:
      #+begin_src org
      R: touch2 was performed
      R: touch3 was performed
      #+end_src 

      In this second example it seems a different result happens

      #+NAME: TestVariableAnyClassGuardAndIfRefactor2
      #+BEGIN_SRC cfengine3 :include-stdlib t :log-level info :exports both
         bundle agent main
         {
          files:
            "/tmp/craig/"
              create => "true";
          commands:
              "/usr/bin/touch"
                handle => "touch-performed",
                args => "/tmp/craig/touch-token",
                if => and( isdir( "/tmp/craig" ), not( fileexists( "/tmp/craig/touch-token" )));        "/usr/bin/touch"
                handle => "touch3-performed",
                args => "/tmp/craig/touch3-token",
                if => and( "any", and( isdir( "/tmp/craig" ), not( fileexists( "/tmp/craig/touch3-token" ))));      "any"::
              "/usr/bin/touch"
                handle => "touch2-performed",
                args => "/tmp/craig/touch2-token",
                if => and( isdir( "/tmp/craig" ), not( fileexists( "/tmp/craig/touch2-token" )));
            
             any::
              "/usr/bin/touch"
                handle => "touch4-performed",
                args => "/tmp/craig/touch4-token",
                if => and( isdir( "/tmp/craig" ), not( fileexists( "/tmp/craig/touch4-token" )));    reports:
            "touch was performed" depends_on => { "touch-performed" };
            "touch2 was performed" depends_on => { "touch2-performed" };
            "touch3 was performed" depends_on => { "touch3-performed" };
            "touch4 was performed" depends_on => { "touch4-performed" };
        }
      #+end_src#+RESULTS: TestVariableAnyClassGuardAndIfRefactor2
      #+begin_src org
      R: touch2 was performed
      #+end_src
      

      There may be other permutations based on order of promises, I'm not sure. Some investigation should be performed on variations as well as the code to see where the problem might exist.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              craig.comstock Craig Comstock
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:

                Summary Panel