Skip to content

Instantly share code, notes, and snippets.

@neilhwatson
Created January 14, 2015 15:30
Show Gist options
  • Select an option

  • Save neilhwatson/539cb218a337c96e8938 to your computer and use it in GitHub Desktop.

Select an option

Save neilhwatson/539cb218a337c96e8938 to your computer and use it in GitHub Desktop.
bug in data_readstringarrayindx
The order is mixed up
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";
}
Run it:
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment