Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
amousset committed Oct 5, 2016
1 parent 5b2fa93 commit 524654f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tree/10_ncf_internals/configuration.cf
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ bundle agent configuration
"cfengine_port" string => "${ncf_config[cfengine_port][1]}";

# Constants
"fatal" string => "[FATAL]";
"error" string => "[ERROR]";
"info" string => "[INFO] ";
"info" string => "[INFO]";
"debug" string => "[DEBUG]";
"trace" string => "[TRACE]";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ bundle agent set_dry_run_mode(mode)

pass2.!unset_mode::
"dry_run" expression => "any", scope => "namespace";

reports:
pass2.debug.unset_mode::
"${configuration.debug} Disabling dry-run mode";
pass2.debug.!unset_mode::
"${configuration.debug} Enabling dry-run mode";
}

###############################################################################
Expand Down
57 changes: 57 additions & 0 deletions tree/20_cfe_basics/dry_run_lib.unsupported.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#####################################################################################
# Copyright 2016 Normation SAS
#####################################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#####################################################################################

# There is 3 ways to have a promise dry-runned:
# - set the global_dry_run class (this one is not set by ncf)
# - call set_dry_run_mode()
# - set a <promise_type>_dry_run class to make only this promise type to be dry-runned

# @parameter mode The dry-run mode, "true" to enable dry-run-mode and "false" to disable it
#
# WARNING:
# WARNING: Be carefull to have a different promiser content for each call to this method!
# WARNING:
# WARNING: The bodies defined here are used when no action body is specified in a promise.
# WARNING: All ncf action bodies check the two global dry-run classes and prevent any modification
# WARNING: when one of them if defined. This also means that:
# WARNING:
# WARNING: * You need to check for them in all of your custom bodies
# WARNING: * promise type specific dry-run is NOT considered by action bodies, and will be overriden
# WARNING: when using any action body.
# WARNING:
bundle agent set_dry_run_mode(mode)
{
classes:
# double negation, so that the default is dry_run (in case of error)
"unset_mode" expression => strcmp("${mode}", "false");
"pass3" expression => "pass2";
"pass2" expression => "pass1";
"pass1" expression => "any";

pass3.!unset_mode
# wait for pass3 to be able to display the report before
# then abort agent execution
"abort_agent_run" expression => "any";

reports:
pass2.!unset_mode::
"${configuration.fatal} Dry-run mode is not compatible with this agent. Stopping immediately not to prevent any unwanted change."
action => immediate;
pass2.debug.unset_mode::
"${configuration.debug} Dry-run mode is not compatible with this agent, but only a disabling of dry-run has been requested. Ignoring.";
}

0 comments on commit 524654f

Please sign in to comment.