Skip to content

Commit

Permalink
fixup! Merge pull request #12 from VinceMacBuche/bug_20603/reports_on…
Browse files Browse the repository at this point in the history
…_method_using_iterator_are_wrong_in_the_cli_output

Fixes #20603: Reports on method using iterator are wrong in the cli output
  • Loading branch information
ncharles committed Jul 7, 2022
1 parent 8505a8a commit 27693ed
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ class ClassicTechniqueWriter(basePath : String, parameterTypeService: ParameterT
case true => "unless"
}

// Get all values

// Reporting argument
val reportingValues = escapeCFEngineString(call.component) ::
escapeCFEngineString(classParameterValue) ::
Expand All @@ -645,21 +645,33 @@ class ClassicTechniqueWriter(basePath : String, parameterTypeService: ParameterT

// Get all bundle argument names
val bundleName = (technique.bundleName.value + "_gm_" + bundleIncrement).replaceAll("-", "_")
bundleIncrement = bundleIncrement +1
bundleIncrement = bundleIncrement + 1

val reportingArgs = "c_name" :: "c_key" :: "report_id" :: Nil
val bundleArgs = params.toList.zipWithIndex.map {
case (_, id) =>
method.flatMap(_.parameters.get(id).map(_.id.value)).getOrElse("arg_" + id)

val (bundleArgs, bundleNameAndArg) = forNaReport match {
case false =>
val args = params.toList.zipWithIndex.map {
case (_, id) =>
method.flatMap(_.parameters.get(id).map(_.id.value)).getOrElse("arg_" + id)
}
(args, s"""${call.methodId.value}(${convertArgsToBundleCall(args)});""")

case true =>
// special case for log_na_rudder; args muse be called with @
val args = "message" :: "class_parameter" :: "unique_prefix" :: "args" :: Nil
(args, """log_na_rudder("${message}","${class_parameter}","${unique_prefix}",@{args});""")
}

val allArgs = reportingArgs ::: bundleArgs

// The bundle that will effectively act
val bundleActing = {
val bundleCall =
s""" "${promiser}" usebundle => ${reportingContextInBundle(reportingArgs)};
| "${promiser}" usebundle => ${call.methodId.value}(${convertArgsToBundleCall(bundleArgs)});""".stripMargin('|')
| "${promiser}" usebundle => ${bundleNameAndArg}""".stripMargin('|')

val allBundles =
val bundleCallWithReportOption =
if (call.disabledReporting) {
s""" "${promiser}" usebundle => disable_reporting;
|${bundleCall}
Expand All @@ -671,7 +683,7 @@ class ClassicTechniqueWriter(basePath : String, parameterTypeService: ParameterT

s"""bundle agent ${bundleName}(${allArgs.mkString(", ")}) {
| methods:
|${allBundles}
|${bundleCallWithReportOption}
|}
|""".stripMargin('|')
}
Expand Down Expand Up @@ -778,7 +790,7 @@ class ClassicTechniqueWriter(basePath : String, parameterTypeService: ParameterT
} yield {
def naReport(condition : String, message : String) = {

val params = message :: escapedClassParameterValue :: classPrefix :: "@{args}" :: Nil
val params = s""""${message}"""" :: s""""${escapedClassParameterValue}"""" :: s""""${classPrefix}"""" :: "@{args}" :: Nil

createCallingBundle(condition, call, classParameterValue, params, true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@ bundle agent technique_by_Rudder_rudder_reporting(technique_parameter)
"class_prefix" string => string_head("${full_class_prefix}", "1000");

methods:
"id1_${report_data.directive_id}" usebundle => technique_by_Rudder_gm_6("Customized component", "${node.properties[apache_package_name]}", "id1", Skipping method 'Package install version' with key parameter '${node.properties[apache_package_name]}' since condition 'any' is not reached, ${node.properties[apache_package_name]}, ${class_prefix}_package_install_version_${node.properties[apache_package_name]}, @{args}),
"id1_${report_data.directive_id}" usebundle => technique_by_Rudder_gm_6("Customized component", "${node.properties[apache_package_name]}", "id1", "Skipping method 'Package install version' with key parameter '${node.properties[apache_package_name]}' since condition 'any' is not reached", "${node.properties[apache_package_name]}", "${class_prefix}_package_install_version_${node.properties[apache_package_name]}", @{args}),
unless => concat("(debian)");
"id2_${report_data.directive_id}" usebundle => technique_by_Rudder_gm_7("Command execution", "Write-Host \"testing special characters ` è &é 'à é \"", "id2", Skipping method 'Command execution' with key parameter 'Write-Host \"testing special characters ` è &é 'à é \"' since condition 'windows' is not reached, Write-Host \"testing special characters ` è &é 'à é \", ${class_prefix}_command_execution_Write-Host \"testing special characters ` è &é 'à é \", @{args}),
"id2_${report_data.directive_id}" usebundle => technique_by_Rudder_gm_7("Command execution", "Write-Host \"testing special characters ` è &é 'à é \"", "id2", "Skipping method 'Command execution' with key parameter 'Write-Host \"testing special characters ` è &é 'à é \"' since condition 'windows' is not reached", "Write-Host \"testing special characters ` è &é 'à é \"", "${class_prefix}_command_execution_Write-Host \"testing special characters ` è &é 'à é \"", @{args}),
unless => concat("(debian.windows)");
"id3_${report_data.directive_id}" usebundle => technique_by_Rudder_gm_8("Customized component", "${node.properties[apache_package_name]}", "id3", Skipping method 'Service start' with key parameter '${node.properties[apache_package_name]}' since condition 'package_install_version_${node.properties[apache_package_name]}_repaired' is not reached, ${node.properties[apache_package_name]}, ${class_prefix}_service_start_${node.properties[apache_package_name]}, @{args}),
"id3_${report_data.directive_id}" usebundle => technique_by_Rudder_gm_8("Customized component", "${node.properties[apache_package_name]}", "id3", "Skipping method 'Service start' with key parameter '${node.properties[apache_package_name]}' since condition 'package_install_version_${node.properties[apache_package_name]}_repaired' is not reached", "${node.properties[apache_package_name]}", "${class_prefix}_service_start_${node.properties[apache_package_name]}", @{args}),
unless => concat("package_install_version_",canonify("${node.properties[apache_package_name]}"),"_repaired");
"id4_${report_data.directive_id}" usebundle => technique_by_Rudder_gm_9("Package install", "openssh-server", "id4", Skipping method 'Package install' with key parameter 'openssh-server' since condition 'redhat' is not reached, openssh-server, ${class_prefix}_package_install_openssh-server, @{args}),
"id4_${report_data.directive_id}" usebundle => technique_by_Rudder_gm_9("Package install", "openssh-server", "id4", "Skipping method 'Package install' with key parameter 'openssh-server' since condition 'redhat' is not reached", "openssh-server", "${class_prefix}_package_install_openssh-server", @{args}),
unless => concat("redhat");

}

bundle agent technique_by_Rudder_gm_6(c_name, c_key, report_id, arg_0, arg_1, arg_2, arg_3) {
bundle agent technique_by_Rudder_gm_6(c_name, c_key, report_id, message, class_parameter, unique_prefix, args) {
methods:
"id1_${report_data.directive_id}" usebundle => _method_reporting_context_v4("${c_name}","${c_key}","${report_id}");
"id1_${report_data.directive_id}" usebundle => log_na_rudder("${arg_0}","${arg_1}","${arg_2}","${arg_3}");
"id1_${report_data.directive_id}" usebundle => log_na_rudder("${message}","${class_parameter}","${unique_prefix}",@{args});
}
bundle agent technique_by_Rudder_gm_7(c_name, c_key, report_id, arg_0, arg_1, arg_2, arg_3) {
bundle agent technique_by_Rudder_gm_7(c_name, c_key, report_id, message, class_parameter, unique_prefix, args) {
methods:
"id2_${report_data.directive_id}" usebundle => disable_reporting;
"id2_${report_data.directive_id}" usebundle => _method_reporting_context_v4("${c_name}","${c_key}","${report_id}");
"id2_${report_data.directive_id}" usebundle => log_na_rudder("${arg_0}","${arg_1}","${arg_2}","${arg_3}");
"id2_${report_data.directive_id}" usebundle => log_na_rudder("${message}","${class_parameter}","${unique_prefix}",@{args});
"id2_${report_data.directive_id}" usebundle => enable_reporting;
}
bundle agent technique_by_Rudder_gm_8(c_name, c_key, report_id, arg_0, arg_1, arg_2, arg_3) {
bundle agent technique_by_Rudder_gm_8(c_name, c_key, report_id, message, class_parameter, unique_prefix, args) {
methods:
"id3_${report_data.directive_id}" usebundle => _method_reporting_context_v4("${c_name}","${c_key}","${report_id}");
"id3_${report_data.directive_id}" usebundle => log_na_rudder("${arg_0}","${arg_1}","${arg_2}","${arg_3}");
"id3_${report_data.directive_id}" usebundle => log_na_rudder("${message}","${class_parameter}","${unique_prefix}",@{args});
}
bundle agent technique_by_Rudder_gm_9(c_name, c_key, report_id, arg_0, arg_1, arg_2, arg_3) {
bundle agent technique_by_Rudder_gm_9(c_name, c_key, report_id, message, class_parameter, unique_prefix, args) {
methods:
"id4_${report_data.directive_id}" usebundle => _method_reporting_context_v4("${c_name}","${c_key}","${report_id}");
"id4_${report_data.directive_id}" usebundle => log_na_rudder("${arg_0}","${arg_1}","${arg_2}","${arg_3}");
"id4_${report_data.directive_id}" usebundle => log_na_rudder("${message}","${class_parameter}","${unique_prefix}",@{args});
}

0 comments on commit 27693ed

Please sign in to comment.