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
Refs #4873 - Add bundle command_execution_module() and adapt command_execution() and its tests #58
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
##################################################################################### | ||
# Copyright 2014 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/>. | ||
# | ||
##################################################################################### | ||
|
||
# @name Command execution | ||
# @description Execute a command | ||
# | ||
# @parameter command_name Command name | ||
# @parameter module boolean to know if command should be considered as a CFEngine module (true/false) | ||
# @parameter shell boolean to know if command can be complex or not (true/false) | ||
# | ||
# @class_prefix command_execution_module | ||
# @class_parameter command_name | ||
# This bundle will define a class command_execution_module_${command_name}_{kept,repaired,error,ok,reached} | ||
|
||
bundle agent command_execution_module(command_name, module, shell) | ||
{ | ||
vars: | ||
"class_prefix" | ||
string => canonify("command_execution_module_${command_name}"); | ||
|
||
methods: | ||
"report" | ||
usebundle => _logger("Execute the command ${command_name}", "${class_prefix}"), | ||
ifvarclass => "${class_prefix}_reached"; | ||
|
||
commands: | ||
"${command_name}" | ||
module => "${module}", | ||
contain => command_execution_module_contain("${shell}"), | ||
classes => classes_generic("${class_prefix}"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with this approach, you'll always have repaired status There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose that we should use classes based on ${class_prefix} (i.e ${class_prefix}report{success,repaired,failed} but it would be difficult to incite users to echo in their scripts something like "command_execution_module__usr_share_local_bin_my_script_sh_report_success". |
||
} | ||
|
||
body contain command_execution_module_contain(shell) | ||
{ | ||
useshell => "${shell}"; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. We don't change the contract on existing methods. Ever.