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

actuating bundles by iterating over a list with zero elements produces error about cf_null

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Done
    • Priority: Medium
    • Resolution: Fixed
    • Affects Version/s: 3.7.3, 3.9.1
    • Fix Version/s: 3.10.0
    • Component/s: Evaluation
    • Labels:
      None
    • Steps to reproduce:
      Manual steps provided

      Description

      Resolved for:

      • 3.10.0b1
      • 3.10.0
      • 3.9.x
      • 3.7.x

      When actuating a list of bundles via iteration if the list is empty an error about cf_null not being defined is emitted.

      Here is some example policy to illustrate the case.

      bundle agent main
      {
        methods:
          "" usebundle => roles_dynamic;
          "" usebundle => roles;
      }
      
      bundle common roles_dynamic
      {
        vars:
          "bundles" slist => { };
      }
      bundle agent roles
      {
        classes:
          "have_some_zero_dynamic_role_bundles"
            expression => some( ".*", "roles_dynamic.bundles" );
      
        methods:
      
      # Avoid actuating with an empty list
           have_some_dynamic_role_bundles.use_workaround::
            "" usebundle => $(roles_dynamic.bundles);
          !use_workaround::
            "" usebundle => $(roles_dynamic.bundles);
      
        reports:
            "Running $(sys.cf_version)";
      
      
      }
      

      When run on 3.6.7:

      [root@hub ~]# cf-agent -Kf ./example.cf -b main
      R: Running 3.6.7
      

      When run on 3.7.3:

      [root@hub modules]# cf-agent -Kf ./example.cf -b main
         error: A method attempted to use a bundle 'cf_null' that was apparently not defined
      R: Running 3.7.3
         error: Method 'roles' failed in some repairs
      

      Workarounds:

      • Add bundle common cf_null to policy set.
        bundle common cf_null
        {
          reports:
            !any::
              "This works around an issue iterating over an list of bundles.";
        }
        
      • Guard against iterating over an empty list
      • Turn on ignore_missing_bundles in body common control.

        Attachments

          Activity

            People

            • Assignee:
              a10042 Nick Anderson
              Reporter:
              a10042 Nick Anderson
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Summary Panel