Skip to content

Commit

Permalink
Fixes #7157: Use the new class_prefix in reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
peckpeck committed Sep 9, 2015
1 parent 3a9cc2d commit 185fcc5
Show file tree
Hide file tree
Showing 67 changed files with 280 additions and 252 deletions.
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.

16 changes: 9 additions & 7 deletions tree/30_generic_methods/_logger.cf
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,22 @@
# @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
#
# @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, args)
{
vars:
"method" string => "${configuration.enabled_loggers}";

methods:

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

"${method}"
usebundle => ${method}("${message}", "${old_class_prefix}", "${args}"),
comment => "Call the ${method} bundle with arguments ${old_class_prefix}, ${args}";
}
42 changes: 33 additions & 9 deletions tree/30_generic_methods/_logger_default.cf
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,53 @@
# @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
#
# @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, 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}");

"class_prefix" string => canonify(join("_", "promisers_list_nologger"));

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

reports:
debug::
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 called ${promisers) with ${args}"; # full debug information

"${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}", @{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}", @{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}", @{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}", @{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}", "", @{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}", @{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}", @{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}", "", @{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}", @{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}", @{args});
}

0 comments on commit 185fcc5

Please sign in to comment.