Skip to content

Commit

Permalink
fixup! fixup! Fixes #21763: Add an audit command generic method
Browse files Browse the repository at this point in the history
Fixes #21763: Add an audit command generic method
  • Loading branch information
peckpeck committed Sep 15, 2022
1 parent 9bbf823 commit f7daeb6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 18 deletions.
4 changes: 2 additions & 2 deletions tests/acceptance/30_generic_methods/command_execution.cf
Expand Up @@ -38,10 +38,10 @@ bundle agent init

# Audit mode
"command[5]" string => "unknown audit command";
"result[5]" string => "error";
"result[5]" string => "na";

"command[6]" string => "/bin/touch ${tmp}/my_file";
"result[6]" string => "error";
"result[6]" string => "na";


"indices" slist => getindices("command");
Expand Down
12 changes: 6 additions & 6 deletions tests/acceptance/30_generic_methods/command_execution_result.cf
Expand Up @@ -46,22 +46,22 @@ bundle agent init

# Audit
"command[6]" string => "/bin/touch ${tmp}/6";
"result[6]" string => "error";
"result[6]" string => "na";

"command[7]" string => "/bin/touch ${tmp}/7";
"result[7]" string => "error";
"result[7]" string => "na";

"command[8]" string => "/bin/touch ${tmp}/8";
"result[8]" string => "error";
"result[8]" string => "na";

"command[9]" string => "/bin/touch ${tmp}/9";
"result[9]" string => "error";
"result[9]" string => "na";

"command[10]" string => "/bin/touch ${tmp}/10";
"result[10]" string => "error";
"result[10]" string => "na";

"command[11]" string => "/bin/touch ${tmp}/11";
"result[11]" string => "error";
"result[11]" string => "na";

"indices" slist => getindices("command");

Expand Down
17 changes: 9 additions & 8 deletions tests/acceptance/default_ncf.cf.sub
Expand Up @@ -46,12 +46,13 @@ bundle common test_utils {
bundle agent define_expected_classes(class_prefix, status, id)
{
vars:
"complete_suffix" slist => {"not_kept", "kept", "not_ok", "ok", "not_repaired", "repaired", "failed", "error"};
"error_suffix" slist => {"not_kept", "not_ok", "not_repaired", "failed", "error"};
"repaired_suffix" slist => { "ok", "repaired", "not_kept" };
"success_suffix" slist => { "ok", "kept", "not_repaired" };
"complete_suffix" slist => {"not_kept", "kept", "not_ok", "ok", "not_repaired", "repaired", "failed", "error", "reached"};
"error_suffix" slist => {"not_kept", "not_ok", "not_repaired", "failed", "error", "reached"};
"repaired_suffix" slist => { "ok", "repaired", "not_kept", "reached" };
"success_suffix" slist => { "ok", "kept", "not_repaired", "reached" };
"na_suffix" slist => { "noop" };

"expected_string_${id}" string => concat(join(".", maplist("${class_prefix}_${this}", "@{${status}_suffix}")), ".${class_prefix}_reached");
"expected_string_${id}" string => join(".", maplist("${class_prefix}_${this}", "@{${status}_suffix}"));
"unexpected_string_${id}" string => join("|", maplist("${class_prefix}_${this}", difference(complete_suffix, "${status}_suffix")));

"report_string_${id}" string => "(${expected_string_${id}}).!(${unexpected_string_${id}})";
Expand All @@ -72,7 +73,7 @@ bundle agent execute_testinfra(test_name, class_name, comment)
# a global class "${result_class}_ok" if everything succeed.
#
# name: name of the target bundle
# args: slist containing the target bundle parameter, in
# args: slist containing the target bundle parameter, in
# correct order.
# status: expected result status, can be: success, error, repaired
# result_class: prefix of the resulting class
Expand Down Expand Up @@ -172,7 +173,7 @@ bundle agent apply_gm(name, args, status, result_class, mode)
# a global class "${result_class}_ok" if everything succeed.
#
# name: name of the target bundle
# args: slist containing the target bundle parameter, in
# args: slist containing the target bundle parameter, in
# correct order.
# status: expected result status, can be: success, error, repaired
# result_class: prefix of the resulting class
Expand All @@ -189,7 +190,7 @@ bundle agent apply_gm_v4(name, args, status, result_class, mode)
"arg5" string => nth("args", "5");

"class_prefix" string => "${${name}.class_prefix}";

"report_param" string => join("_", args);
pass1:: # need to be guarded by a class, and need an extra parameter to be executed at each call
"uuid" string => execresult("/usr/bin/uuidgen #${result_class}", "useshell");
Expand Down
6 changes: 4 additions & 2 deletions tests/acceptance/testall
Expand Up @@ -469,10 +469,12 @@ if [ $# -gt 0 ]; then
fi

if [ -f $test ]; then
TESTS="$TESTS${TESTS:+ }$test"
TESTS="$TESTS${TESTS:+
}$test"
elif [ -d $test ]; then
ADDTESTS=`${NCF_COMPATIBLE_INPUTS} --capability-file ${CAPABILITY_FILE} --agent-version ${AGENT_VERSION} --ncf-path "${NCF_TESTS_ACCEPTANCE}/${test}" . | awk -v path="${test}" '{ print path"/"$0 }' | sort`
TESTS="$TESTS${TESTS:+ }$ADDTESTS"
TESTS="$TESTS${TESTS:+
}$ADDTESTS"
else
echo "Unable to open test file/directory: $test"
fi
Expand Down
1 change: 1 addition & 0 deletions tree/30_generic_methods/command_execution.cf
Expand Up @@ -74,6 +74,7 @@ bundle agent command_execution(command)
methods:
pass3.dry_run::
"${report_data.method_id}" usebundle => _classes_noop("${report_data.method_id}");
"${report_data.method_id}" usebundle => _classes_noop("${class_prefix}");
pass3::
"${report_data.method_id}" usebundle => log_rudder_v4("${command}", "Execute command", "${command}");
commands:
Expand Down
1 change: 1 addition & 0 deletions tree/30_generic_methods/command_execution_result.cf
Expand Up @@ -48,6 +48,7 @@ bundle agent command_execution_result(command, kept_codes, repaired_codes)
methods:
pass3.dry_run::
"${report_data.method_id}" usebundle => _classes_noop("${report_data.method_id}");
"${report_data.method_id}" usebundle => _classes_noop("${class_prefix}");
pass3::
"${report_data.method_id}" usebundle => log_rudder_v4("${command}", "Execute command", "${command}");

Expand Down

0 comments on commit f7daeb6

Please sign in to comment.