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

Should be able to define variables from non null keys in data

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Evaluation
    • Labels:
      None

      Description

      It seems that null handling is a bit aggressive. I seem to be unable to define variables for non null keys in data that does contain null keys by iterating over them.

      <pre>
      bundle agent main
      {
      methods:
      "ec2";

      vars:
      "test_state" data => bundlestate(ec2);
      "test_string" string => storejson(test_state);

      reports:
      "$(this.bundle): state of things = $(test_string)";
      }

      bundle agent ec2
      {
      vars:
      "data" data => '{
      "instanceId" : "i-f444554e",
      "billingProducts" : null,
      "instanceType" : "m3.large",
      "accountId" : "444444444444",
      "pendingTime" : "2015-12-02T19:47:57Z",
      "imageId" : "ami-44444444",
      "kernelId" : "aki-44444444",
      "ramdiskId" : null,
      "architecture" : "x86_64",
      "region" : "eu-west-1",
      "version" : "2010-08-31",
      "availabilityZone" : "eu-west-1c",
      "privateIp" : "10.44.44.4",
      "devpayProductCodes" : null
      }';

      1. This data has nulls in it
        "keys" slist => getindices("data");
        "data_$(keys)" string => "$(data[$(keys)])";

      "data2" data => '{
      "instanceId" : "i-f444554e",
      "instanceType" : "m3.large",
      "accountId" : "444444444444",
      "pendingTime" : "2015-12-02T19:47:57Z",
      "imageId" : "ami-44444444",
      "kernelId" : "aki-44444444",
      "architecture" : "x86_64",
      "region" : "eu-west-1",
      "version" : "2010-08-31",
      "availabilityZone" : "eu-west-1c",
      "privateIp" : "10.44.44.4",
      }';

      1. This data has no nulls in it.
        "keys2" slist => getindices("data2");
        "data2_$(keys2)" string => "$(data2[$(keys2)])";

      reports:
      "Index of data with nulls: $(keys)";
      "Index of data without nulls: $(keys2)";
      "data of individual key with nulls: $(data_$(keys)) = $(data[$(keys)])";
      "data of individual key without nulls: $(data_$(keys2)) = $(data2[$(keys2)])";
      }
      </pre>

      Note in this output (run on 3.8.0) the data of individual keys with nulls. None of them are able to expand when any null value is present.

      <pre>

      > $ cf-agent -KIf ./test_json_with_and_without_nulls.cf [±master ●▴]
      R: Index of data with nulls: instanceId
      R: Index of data with nulls: billingProducts
      R: Index of data with nulls: instanceType
      R: Index of data with nulls: accountId
      R: Index of data with nulls: pendingTime
      R: Index of data with nulls: imageId
      R: Index of data with nulls: kernelId
      R: Index of data with nulls: ramdiskId
      R: Index of data with nulls: architecture
      R: Index of data with nulls: region
      R: Index of data with nulls: version
      R: Index of data with nulls: availabilityZone
      R: Index of data with nulls: privateIp
      R: Index of data with nulls: devpayProductCodes
      R: Index of data without nulls: instanceId
      R: Index of data without nulls: instanceType
      R: Index of data without nulls: accountId
      R: Index of data without nulls: pendingTime
      R: Index of data without nulls: imageId
      R: Index of data without nulls: kernelId
      R: Index of data without nulls: architecture
      R: Index of data without nulls: region
      R: Index of data without nulls: version
      R: Index of data without nulls: availabilityZone
      R: Index of data without nulls: privateIp
      R: data of individual key without nulls: $(data_instanceId) = i-f444554e
      R: data of individual key without nulls: $(data_instanceType) = m3.large
      R: data of individual key without nulls: $(data_accountId) = 444444444444
      R: data of individual key without nulls: $(data_pendingTime) = 2015-12-02T19:47:57Z
      R: data of individual key without nulls: $(data_imageId) = ami-44444444
      R: data of individual key without nulls: $(data_kernelId) = aki-44444444
      R: data of individual key without nulls: $(data_architecture) = x86_64
      R: data of individual key without nulls: $(data_region) = eu-west-1
      R: data of individual key without nulls: $(data_version) = 2010-08-31
      R: data of individual key without nulls: $(data_availabilityZone) = eu-west-1c
      R: data of individual key without nulls: $(data_privateIp) = 10.44.44.4
      R: main: state of things = {
      "data":

      { "accountId": "444444444444", "architecture": "x86_64", "availabilityZone": "eu-west-1c", "billingProducts": null, "devpayProductCodes": null, "imageId": "ami-44444444", "instanceId": "i-f444554e", "instanceType": "m3.large", "kernelId": "aki-44444444", "pendingTime": "2015-12-02T19:47:57Z", "privateIp": "10.44.44.4", "ramdiskId": null, "region": "eu-west-1", "version": "2010-08-31" }

      ,
      "data2":

      { "accountId": "444444444444", "architecture": "x86_64", "availabilityZone": "eu-west-1c", "imageId": "ami-44444444", "instanceId": "i-f444554e", "instanceType": "m3.large", "kernelId": "aki-44444444", "pendingTime": "2015-12-02T19:47:57Z", "privateIp": "10.44.44.4", "region": "eu-west-1", "version": "2010-08-31" }

      ,
      "data2_accountId": "444444444444",
      "data2_architecture": "x86_64",
      "data2_availabilityZone": "eu-west-1c",
      "data2_imageId": "ami-44444444",
      "data2_instanceId": "i-f444554e",
      "data2_instanceType": "m3.large",
      "data2_kernelId": "aki-44444444",
      "data2_pendingTime": "2015-12-02T19:47:57Z",
      "data2_privateIp": "10.44.44.4",
      "data2_region": "eu-west-1",
      "data2_version": "2010-08-31",
      "keys": [
      "instanceId",
      "billingProducts",
      "instanceType",
      "accountId",
      "pendingTime",
      "imageId",
      "kernelId",
      "ramdiskId",
      "architecture",
      "region",
      "version",
      "availabilityZone",
      "privateIp",
      "devpayProductCodes"
      ],
      "keys2": [
      "instanceId",
      "instanceType",
      "accountId",
      "pendingTime",
      "imageId",
      "kernelId",
      "architecture",
      "region",
      "version",
      "availabilityZone",
      "privateIp"
      ]
      }
      </pre>

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                a10003 Eystein Maloy Stenberg
                Reporter:
                a10042 Nick Anderson
              • Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Summary Panel

                    Time Tracking

                    Estimated:
                    Original Estimate - 2 days, 5 hours
                    2d 5h
                    Remaining:
                    Not Specified
                    Logged:
                    Time Not Required
                    Not Specified