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

data_readstringarrayidx returns scrambled index

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Done
    • Priority: High
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.6.5
    • Component/s: Built-in functions
    • Labels:
      None
    • Platform:
      RHEL or CentOS, Debian
    • Steps to reproduce:
      Manual steps provided

      Description

      The order is mixed up

      <pre>
      body common control
      {
      bundlesequence =>

      { "efl_c", "init", "array", "data" }

      ;
      }

      bundle common efl_c
      {
      vars:
      "comment"
      comment => "Comment string in data file.",
      string => "\s*#[^\n]*";

      "array_delimiter"
      comment => "Field delimiter for CSV data files read by data_readstringarrayidx.",
      string => "\s*;;\s*";

      "slist_delimiter"
      comment => "Field delimiter for CSV data files read by readstringlist",
      string => "\s";

      "max_num"
      comment => "Maximum number of lines to read from data file",
      int => "500";

      "max_bytes"
      comment => "Maximum number of bytes to read from data file.",
      string => "1M";
      }

      bundle agent init
      {
      vars:
      "params" slist =>

      { 'any ;; one', 'any ;; two', 'any ;; three', 'any ;; four', 'any ;; five', 'any ;; six', 'any ;; seven', 'any ;; eight', 'any ;; nine', 'any ;; ten', 'any ;; eleven', 'any ;; twelve', 'am_policy_hub.!master_policy_hub ;; thirteen', 'am_policy_hub|atlgit01 ;; fourteen', 'p_fully_managed ;; fifteen', 'any ;; sixteen', 'any ;; seventeen', }

      ;

      files:
      "/tmp/bug.txt"
      create => 'true',
      edit_defaults => empty,
      edit_line => insert_lines( "@

      {params}

      " );

      reports:
      "Expected results: Output order from array and data should be the same";
      "cfengine version: ${sys.cf_version}";
      }

      bundle agent array
      {
      vars:
      "a"
      comment => "Parse csv file",
      int => readstringarrayidx(
      "csv_array",
      "/tmp/bug.txt",
      "${efl_c.comment}",
      "${efl_c.array_delimiter}",
      "${efl_c.max_num}",
      "${efl_c.max_bytes}"
      );

      "i_unsorted"
      comment => "index from array may not be in the correct order",
      slist => getindices( "csv_array" );

      "i"
      comment => "Sort index data",
      slist => sort( "i_unsorted", "int" );

      reports:
      "array: ${csv_array[${i}][1]}";

      }

      bundle agent data
      {
      vars:
      "csv_data"
      comment => "Parse csv file",
      data => data_readstringarrayidx(
      "/tmp/bug.txt",
      "${efl_c.comment}",
      "${efl_c.array_delimiter}",
      "${efl_c.max_num}",
      "${efl_c.max_bytes}"
      );

      "i"
      comment => "index from csv file may not be in the correct order",
      slist => getindices( "csv_data" );

      reports:
      "data: ${csv_data[${i}][1]}";

      }
      body edit_defaults empty
      {
      empty_file_before_editing => "true";
      edit_backup => "false";
      }

      bundle edit_line insert_lines(lines)
      {
      insert_lines:

      "$(lines)"
      comment => "Append lines if they don't exist";
      }

      </pre>
      Run it:
      <pre>
      R: Expected results: Output order from array and data should be the same
      R: cfengine version: 3.6.3
      R: array: one
      R: array: two
      R: array: three
      R: array: four
      R: array: five
      R: array: six
      R: array: seven
      R: array: eight
      R: array: nine
      R: array: ten
      R: array: eleven
      R: array: twelve
      R: array: thirteen
      R: array: fourteen
      R: array: fifteen
      R: array: sixteen
      R: array: seventeen
      R: data: one
      R: data: eight
      R: data: two
      R: data: fourteen
      R: data: fifteen
      R: data: nine
      R: data: eleven
      R: data: five
      R: data: seven
      R: data: three
      R: data: twelve
      R: data: thirteen
      R: data: sixteen
      R: data: six
      R: data: four
      R: data: seventeen
      R: data: ten
      </pre>

        Attachments

          Activity

            People

            • Assignee:
              a10040 Kristian Amlie
              Reporter:
              neilhwatson Neil Watson
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Summary Panel