Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #7157: Use the new class_prefix in reporting #229

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 0 additions & 31 deletions tree/30_generic_methods/_bundle_caller.cf

This file was deleted.

35 changes: 0 additions & 35 deletions tree/30_generic_methods/_bundle_caller_four.cf

This file was deleted.

33 changes: 0 additions & 33 deletions tree/30_generic_methods/_bundle_caller_one.cf

This file was deleted.

35 changes: 0 additions & 35 deletions tree/30_generic_methods/_bundle_caller_three.cf

This file was deleted.

34 changes: 0 additions & 34 deletions tree/30_generic_methods/_bundle_caller_two.cf

This file was deleted.

17 changes: 9 additions & 8 deletions tree/30_generic_methods/_logger.cf
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@
# @name Logger
# @description Standard logging output
#
# @parameter message The common part of the message to display
# @parameter class_prefix The prefix of the class for different states
# @parameter message The common part of the message to display
# @parameter old_class_prefix The prefix of the class for different states
# @parameter class_prefix The prefix of the class for different states
# @parameter args The arguments used to call the generic method (slist)
#
# @class_prefix
# @class_parameter
# The three states are kept, repaired and not_ok
# (as defined in the classes_generic of the cfengine_stdlib)

bundle agent _logger(message, class_prefix)
{

bundle agent _logger(message, old_class_prefix, class_prefix, args)
{
methods:

# Report using the appropriate bundle(s)
"logging" usebundle => _bundle_caller_two("${configuration.enabled_loggers}", "${message}" , "${class_prefix}");

"${configuration.enabled_loggers}"
usebundle => ${configuration.enabled_loggers}("${message}", "${old_class_prefix}", "${class_prefix}", "${args}"),
comment => "Call the ${method} bundle with arguments ${old_class_prefix}, ${args}";
}
43 changes: 35 additions & 8 deletions tree/30_generic_methods/_logger_default.cf
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,56 @@
# @name Logger default
# @description Standard default logging output
#
# @parameter message The common part of the message to display
# @parameter class_prefix The prefix of the class for different states
# @parameter message The common part of the message to display
# @parameter old_class_prefix The prefix of the class for different states
# @parameter class_prefix The prefix of the class for different states
# @parameter args The arguments used to call the generic method (slist)
#
# @class_prefix
# @class_parameter
# The three states are kept, repaired and not_ok
# (as defined in the classes_generic of the cfengine_stdlib)

bundle agent _logger_default(message, class_prefix)
bundle agent _logger_default(message, old_class_prefix, class_prefix, args)
{
vars:
"canonified_prefix" string => canonify("${class_prefix}");
"canonified_prefix" string => canonify("${old_class_prefix}");

"promiser_count" int => length("this.callers_promisers");

# head(length-2) -> remove logger call stack (_logger + _logger_default)
"nologger_len" int => eval("${promiser_count}-2", "math", "infix");
"promisers_list_nologger" slist => sublist("this.callers_promisers", "head", "${nologger_len}");

"promisers" string => join("/", "promisers_list_nologger");

"arg_list" string => join(",", "args");

reports:
debug::
"${configuration.debug} Promise called ${promisers) with ${arg_list}"; # full debug information

debug.!has_promiser_stack::
"${configuration.debug} Promise kept, not doing anything: ${message}"
ifvarclass => "${canonified_prefix}_kept.!${canonified_prefix}_repaired.!${canonified_prefix}_not_ok";

debug|info::
debug.has_promiser_stack::
"${configuration.debug} Promise kept, not doing anything: ${message}"
ifvarclass => "${class_prefix}_kept.!${class_prefix}_repaired.!${class_prefix}_not_ok";

(debug|info).!has_promiser_stack::
"${configuration.info} Promise repaired, made a change: ${message}"
ifvarclass => "${class_prefix}_repaired.!${canonified_prefix}_not_ok";
ifvarclass => "${canonified_prefix}_repaired.!${canonified_prefix}_not_ok";

cfengine:: # We always want to log errors
(debug|info).has_promiser_stack::
"${configuration.info} Promise repaired, made a change: ${message}"
ifvarclass => "${class_prefix}_repaired.!${class_prefix}_not_ok";

!has_promiser_stack:: # We always want to log errors
"${configuration.error} Promise could not be repaired, error encountered: ${message}"
ifvarclass => canonify("${class_prefix}_not_ok");
ifvarclass => "${canonified_prefix}_not_ok";

has_promiser_stack:: # We always want to log errors
"${configuration.error} Promise could not be repaired, error encountered: ${message}"
ifvarclass => "${class_prefix}_not_ok";
}
3 changes: 2 additions & 1 deletion tree/30_generic_methods/command_execution.cf
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ bundle agent command_execution(command_name)
vars:
"old_class_prefix" string => canonify("command_execution_${command_name}");
"class_prefix" string => canonify(join("_", "this.callers_promisers"));
"args" slist => { "${command_name}" };

methods:
"report"
usebundle => _logger("Execute the command ${command_name}", "${old_class_prefix}"),
usebundle => _logger("Execute the command ${command_name}", "${old_class_prefix}", "${class_prefix}", @{args} ),
ifvarclass => "(!has_promiser_stack.${old_class_prefix}_reached)|(has_promiser_stack.${class_prefix}_reached)";

commands:
Expand Down
3 changes: 2 additions & 1 deletion tree/30_generic_methods/directory_check_exists.cf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ bundle agent directory_check_exists(directory_name)
vars:
"old_class_prefix" string => canonify("directory_check_exists_${directory_name}");
"class_prefix" string => canonify(join("_", "this.callers_promisers"));
"args" slist => { "${directory_name}" };

classes:
"directory_exists" expression => isdir("${directory_name}");
Expand All @@ -46,5 +47,5 @@ bundle agent directory_check_exists(directory_name)
"directory_doesnt_exists" usebundle => _classes_failure("${class_prefix}");

any::
"report" usebundle => _logger("Check if directory ${directory_name} exists", "${old_class_prefix}");
"report" usebundle => _logger("Check if directory ${directory_name} exists", "${old_class_prefix}", "${class_prefix}", @{args});
}
3 changes: 2 additions & 1 deletion tree/30_generic_methods/directory_create.cf
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ bundle agent directory_create(target)
vars:
"old_class_prefix" string => canonify("directory_create_${target}");
"class_prefix" string => canonify(join("_", "this.callers_promisers"));
"args" slist => { "${target}" };

files:
"${target}/."
create => "true",
classes => classes_generic_two("${old_class_prefix}", "${class_prefix}");

methods:
"report" usebundle => _logger("Create directory ${target}", "${old_class_prefix}");
"report" usebundle => _logger("Create directory ${target}", "${old_class_prefix}", "${class_prefix}", @{args});
}
3 changes: 2 additions & 1 deletion tree/30_generic_methods/file_check_exists.cf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ bundle agent file_check_exists(file_name)
vars:
"old_class_prefix" string => canonify("file_check_exists_${file_name}");
"class_prefix" string => canonify(join("_", "this.callers_promisers"));
"args" slist => { "${file_name}" };

classes:
"file_exists" expression => fileexists("${file_name}");
Expand All @@ -46,5 +47,5 @@ bundle agent file_check_exists(file_name)
"file_dont_exists" usebundle => _classes_failure("${class_prefix}");

any::
"report" usebundle => _logger("Check if ${file_name} exists", "${old_class_prefix}");
"report" usebundle => _logger("Check if ${file_name} exists", "${old_class_prefix}", "${class_prefix}", @{args});
}
3 changes: 3 additions & 0 deletions tree/30_generic_methods/file_copy_from_local_source.cf
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ bundle agent file_copy_from_local_source(source, destination)
{
vars:
"class_prefix" string => canonify(join("_", "this.callers_promisers"));
"args" slist => { "${source}", "${destination}" };

methods:
"copy without recursion" usebundle => file_copy_from_local_source_recursion("${source}", "${destination}", "0");
"new result classes" usebundle => _classes_copy("${class_prefix}_copy_without_recursion", "${class_prefix}");

"report" usebundle => _logger("Copying ${destination} from ${source}", "", "${class_prefix}", @{args});
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ bundle agent file_copy_from_local_source_recursion(source, destination, recursio
vars:
"old_class_prefix" string => canonify("file_copy_from_local_source_${destination}");
"class_prefix" string => canonify(join("_", "this.callers_promisers"));
"args" slist => { "${source}", "${destination}", "${recursion}" };

classes:
# depth_search prevents from copying file/symlink
Expand Down Expand Up @@ -61,9 +62,9 @@ bundle agent file_copy_from_local_source_recursion(source, destination, recursio
# directory (to apply recursion) or a file
iteration_2.!is_dir_copy::
"report"
usebundle => _logger("Copying ${destination} from ${source}", "${old_class_prefix}");
usebundle => _logger("Copying ${destination} from ${source}", "${old_class_prefix}", "${class_prefix}", @{args});

iteration_2.is_dir_copy::
"report"
usebundle => _logger("Copying ${destination} from ${source}, recursion level ${recursion}", "${old_class_prefix}");
usebundle => _logger("Copying ${destination} from ${source}, recursion level ${recursion}", "${old_class_prefix}", "${class_prefix}", @{args});
}
3 changes: 3 additions & 0 deletions tree/30_generic_methods/file_copy_from_remote_source.cf
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ bundle agent file_copy_from_remote_source(source, destination)
{
vars:
"class_prefix" string => canonify(join("_", "this.callers_promisers"));
"args" slist => { "${source}", "${destination}" };

methods:
"copy without recursion" usebundle => file_copy_from_remote_source_recursion("${source}", "${destination}", "0");
"new result classes" usebundle => _classes_copy("${class_prefix}_copy_without_recursion", "${class_prefix}");

"report" usebundle => _logger("Copying ${destination} from ${source}", "", "${class_prefix}", @{args});
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ bundle agent file_copy_from_remote_source_recursion(source, destination, recursi
vars:
"old_class_prefix" string => canonify("file_copy_from_remote_source_${destination}");
"class_prefix" string => canonify(join("_", "this.callers_promisers"));
"args" slist => { "${source}", "${destination}", "${recursion}" };

classes:
# depth_search prevents from copying file/symlink
Expand Down Expand Up @@ -62,9 +63,9 @@ bundle agent file_copy_from_remote_source_recursion(source, destination, recursi
# directory (to apply recursion) or a file
iteration_2.!is_dir_copy::
"report"
usebundle => _logger("Copying ${destination} from ${source}", "${old_class_prefix}");
usebundle => _logger("Copying ${destination} from ${source}", "${old_class_prefix}", "${class_prefix}", @{args});

iteration_2.is_dir_copy::
"report"
usebundle => _logger("Copying ${destination} from ${source}, recursion level ${recursion}", "${old_class_prefix}");
usebundle => _logger("Copying ${destination} from ${source}, recursion level ${recursion}", "${old_class_prefix}", "${class_prefix}", @{args});
}