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

ifvarclass expressions don't evaluate as expected

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Rejected
    • Priority: Higher
    • Resolution: Done
    • Affects Version/s: 3.15.1, 3.16.0
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Story Points:
      13

      Description

      Given test.json:

      {
        "things": [
          {
            "Title": "DEBIAN",
            "classexpr": "debian"
          },
          {
            "Title": "UBUNTU",
            "classexpr": "ubuntu"
          }
        ]
      }
      

      and test.cf:

      bundle agent main
      {
        vars:
          "d" data => readjson("/home/craig/test.json");
          "di" slist => getindices( "d[things]" );
      
        reports:
          "di is $(di)";
          "$(d[things][$(di)][Title]) has classexpr $(d[things][$(di)][classexpr])" if => concat("$([things][$(di)][classexpr])");
      }
      

      The expression `concat("$([things][$(di)][classexpr])")` doesn't seem to evaluate properly. This concat() expression was introduced when the "things" in json/cf was something with a space in it like "thing s". Without the concat() a Syntax error will be given for the report line such as this:

      ./test.cf:8:48: error: Syntax error in context string
          "has $(d[thing s]) class" if => "$(d[thing s])";
                                                     ^
         error: There are syntax errors in policy files
         error: Policy failed validation with command '"/home/craig/.cfagent/bin/cf-promises" -c "./test.cf"'
         error: Failsafe condition triggered. Interactive session detected, skipping failsafe.cf execution.
         error: Error reading CFEngine policy. Exiting...
      

      If the "things" is without a space the ifvarclass expression without concat works as expected.

      So it seems there is a problem in either the parser or the evaluator or both.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                a10042 Nick Anderson
                Reporter:
                a10042 Nick Anderson
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Summary Panel