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

Expansion of 'this' variable breaks within parametrized bodies called within bundles which are called with usebundle.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: High
    • Resolution: Unresolved
    • Affects Version/s: 3.9.1, 3.12.1, 3.15.0b1
    • Fix Version/s: None
    • Labels:
      None
    • Environment:
      Centos 7.2

      Description

      Hello,
      I have problems concerning the expansion of the special 'this' variable when it is used inside a parametrized body called from a bundle which is itself called from another bundle with a 'usebundle' directive.

      To illustrate this, consider the autonomous testcase below:

      
      body common control {
      
      bundlesequence => {"a"};
      
      }
      
      
      bundle agent a {
      
      vars:
         "target_path" string => "/d1/d2/d3/my_file";
         "used_bundles" slist => {"b", "c"};
      
      files:
         "/tmp/a/d1/d2/d3/my_file"
         create => "true";
      
         "/tmp/$(used_bundles)/d1/d2/d3/my_file"
         create => "true";
      
          "$(target_path)"
          copy_from => my_copy_with_param("/tmp");
      
      methods:
      
         "XXX" usebundle => $(used_bundles);
      
      }
      
      bundle agent b {
      
       files:
      
          "$(a.target_path)"
          copy_from => my_copy_without_param();
      
      }
      
      bundle agent c {
      
       files:
      
          "$(a.target_path)"
          copy_from => my_copy_with_param("/tmp");
      
      }
      
      body copy_from my_copy_without_param() {
          source  => "/tmp/$(this.bundle)/$(this.promiser)";
          servers => { "localhost" };
          compare => "digest";
      }
      
      body copy_from my_copy_with_param(root) {
          source  => "/$(root)/$(this.bundle)/$(this.promiser)";
          servers => { "localhost" };
          compare => "digest";
      }
      
      

      The verbose logs are inside the attached file 'cf.log'.
      To sum up, three cases are tested:

      1. I use the parametrized body my_copy_with_param directly in the main a bundle
      2. I use the unparametrized body my_copy_without_param wthin the b bundle called from the a bundle with a usebundle directive
      3. I use parametrized body my_copy_with_param wthin the c bundle called from the a bundle with a usebundle directive

      In the two bodies i use the variables this.bundle and this.promiser.

      The two first cases are OK, the 'this' variable is correctly expanded as the calling bundle (a in the first case, b in the second case).
      In the third case, the 'this' variable is not corrctly expanded, as it references the a bundle (the root bundle) whereas it should reference the c bundle, as it is the calling bundle. Il seems that the body parameter muddles in certain way the 'this' variable.

      This bug, if it appears to be one, is potentially very harmful as a bundle (the c bundle in this case) never knows the context of its activation, directly in the bundlesequence or indirectly via a usebundle directive.

        Attachments

        1. cf.log
          24 kB
        2. test1.cf
          0.9 kB

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                yrouxel Yann Rouxel
              • Votes:
                1 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Summary Panel