From f7daeb6f09b3865b257e941bd0f121207a600e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Peccatte?= Date: Thu, 15 Sep 2022 10:29:40 +0200 Subject: [PATCH] fixup! fixup! Fixes #21763: Add an audit command generic method Fixes #21763: Add an audit command generic method --- .../30_generic_methods/command_execution.cf | 4 ++-- .../command_execution_result.cf | 12 ++++++------ tests/acceptance/default_ncf.cf.sub | 17 +++++++++-------- tests/acceptance/testall | 6 ++++-- tree/30_generic_methods/command_execution.cf | 1 + .../command_execution_result.cf | 1 + 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/tests/acceptance/30_generic_methods/command_execution.cf b/tests/acceptance/30_generic_methods/command_execution.cf index 983fbbec..2245c00c 100644 --- a/tests/acceptance/30_generic_methods/command_execution.cf +++ b/tests/acceptance/30_generic_methods/command_execution.cf @@ -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"); diff --git a/tests/acceptance/30_generic_methods/command_execution_result.cf b/tests/acceptance/30_generic_methods/command_execution_result.cf index 5a45fb91..ea347cbf 100644 --- a/tests/acceptance/30_generic_methods/command_execution_result.cf +++ b/tests/acceptance/30_generic_methods/command_execution_result.cf @@ -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"); diff --git a/tests/acceptance/default_ncf.cf.sub b/tests/acceptance/default_ncf.cf.sub index a81db381..050074a3 100644 --- a/tests/acceptance/default_ncf.cf.sub +++ b/tests/acceptance/default_ncf.cf.sub @@ -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}})"; @@ -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 @@ -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 @@ -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"); diff --git a/tests/acceptance/testall b/tests/acceptance/testall index ea328f52..f9c39bfd 100755 --- a/tests/acceptance/testall +++ b/tests/acceptance/testall @@ -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 diff --git a/tree/30_generic_methods/command_execution.cf b/tree/30_generic_methods/command_execution.cf index f6b42d72..68d97083 100644 --- a/tree/30_generic_methods/command_execution.cf +++ b/tree/30_generic_methods/command_execution.cf @@ -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: diff --git a/tree/30_generic_methods/command_execution_result.cf b/tree/30_generic_methods/command_execution_result.cf index e22d21ff..6890b290 100644 --- a/tree/30_generic_methods/command_execution_result.cf +++ b/tree/30_generic_methods/command_execution_result.cf @@ -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}");