-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from peckpeck/ust_7171/add_methods_to_help_cr…
…eating_new_generic_methods Fixes #7171: Add methods to help creating new generic methods
- Loading branch information
Showing
13 changed files
with
529 additions
and
38 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
tests/acceptance/30_generic_methods/classes_combine_ifthenelse.cf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
####################################################### | ||
# | ||
# This will check that result classes are copied | ||
# | ||
####################################################### | ||
|
||
bundle common acc_path | ||
{ | ||
vars: | ||
"root" string => getenv("NCF_TESTS_ACCEPTANCE", 1024); | ||
} | ||
|
||
body common control | ||
{ | ||
inputs => { "${acc_path.root}/default.cf.sub", "${acc_path.root}/default_ncf.cf.sub", "@{ncf_inputs.default_files}" }; | ||
bundlesequence => { default("$(this.promise_filename)") }; | ||
version => "1.0"; | ||
} | ||
|
||
####################################################### | ||
|
||
bundle agent init | ||
{ | ||
vars: | ||
"tmp" string => getenv("TEMP", 1024); | ||
} | ||
|
||
####################################################### | ||
|
||
bundle agent test | ||
{ | ||
classes: | ||
"global_true_true" expression => "any", | ||
scope => "namespace"; | ||
|
||
"global_false_false" expression => "any", | ||
scope => "namespace"; | ||
|
||
methods: | ||
|
||
"ok" usebundle => _classes_success("global_success"); | ||
"ko" usebundle => _classes_failure("global_failure"); | ||
|
||
"test1" usebundle => _classes_combine_ifthenelse("global_true", "success", "failure", "global_classA"); # success | ||
"test1" usebundle => _classes_combine_ifthenelse("global_true", "failure", "success", "global_classB"); # failure | ||
"test1" usebundle => _classes_combine_ifthenelse("global_false", "success", "failure", "global_classC"); # failure | ||
"test1" usebundle => _classes_combine_ifthenelse("global_false", "failure", "success", "global_classD"); # success | ||
|
||
"test1" usebundle => _classes_combine_ifthenelse("global_true", "global_success", "global_failure", "global_classE"); # success | ||
"test1" usebundle => _classes_combine_ifthenelse("global_true", "global_failure", "global_success", "global_classF"); # failure | ||
"test1" usebundle => _classes_combine_ifthenelse("global_false", "global_success", "global_failure", "global_classG"); # failure | ||
"test1" usebundle => _classes_combine_ifthenelse("global_false", "global_failure", "global_success", "global_classH"); # success | ||
|
||
"test1" usebundle => _classes_combine_ifthenelse("global_failure", "invalid", "invalid", "global_classI"); # failure | ||
} | ||
|
||
####################################################### | ||
|
||
bundle agent check | ||
{ | ||
classes: | ||
"ok_success" expression => "global_success_kept.global_classA_kept.global_classD_kept.global_classE_kept.global_classH_kept"; | ||
"ok_failure" expression => "global_failure_failed.global_classB_failed.global_classC_failed.global_classF_failed.global_classG_failed.global_classI_failed"; | ||
"ok" expression => "ok_success.ok_failure"; | ||
|
||
reports: | ||
ok:: | ||
"$(this.promise_filename) Pass"; | ||
!ok:: | ||
"$(this.promise_filename) FAIL"; | ||
} |
60 changes: 60 additions & 0 deletions
60
tests/acceptance/30_generic_methods/classes_combine_two.cf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
####################################################### | ||
# | ||
# This will check that result classes are copied | ||
# | ||
####################################################### | ||
|
||
bundle common acc_path | ||
{ | ||
vars: | ||
"root" string => getenv("NCF_TESTS_ACCEPTANCE", 1024); | ||
} | ||
|
||
body common control | ||
{ | ||
inputs => { "${acc_path.root}/default.cf.sub", "${acc_path.root}/default_ncf.cf.sub", "@{ncf_inputs.default_files}" }; | ||
bundlesequence => { default("$(this.promise_filename)") }; | ||
version => "1.0"; | ||
} | ||
|
||
####################################################### | ||
|
||
bundle agent init | ||
{ | ||
vars: | ||
"tmp" string => getenv("TEMP", 1024); | ||
"file" string => "${tmp}/test"; | ||
"file_canon" string => canonify("${file}"); | ||
} | ||
|
||
####################################################### | ||
|
||
bundle agent test | ||
{ | ||
|
||
methods: | ||
"ph1" usebundle => file_ensure_lines_present("${init.file}", "sample two"); # should get repaired | ||
"ph2" usebundle => file_ensure_lines_absent("${init.file}", "sample one"); # should get success | ||
"ph3" usebundle => file_ensure_lines_absent("/dev/zero", "sample three"); # should get failed | ||
|
||
"test1" usebundle => _classes_combine_two("file_ensure_lines_absent_${init.file_canon}", "file_ensure_lines_absent_${init.file_canon}", "global_classA"); # success | ||
"test2" usebundle => _classes_combine_two("file_ensure_lines_absent_${init.file_canon}", "file_ensure_lines_present_${init.file_canon}", "global_classB"); # repaired | ||
"test3" usebundle => _classes_combine_two("file_ensure_lines_absent_${init.file_canon}", "file_ensure_lines_absent__dev_zero", "global_classC"); # error | ||
} | ||
|
||
####################################################### | ||
|
||
bundle agent check | ||
{ | ||
classes: | ||
"ok_repaired" expression => "(global_classA_ok.global_classA_reached.global_classA_kept.global_classA_not_repaired.promise_kept_global_classA).!(global_classA_repaired|promise_repaired_global_classA)"; | ||
"ok_success" expression => "(global_classB_ok.global_classB_reached.global_classB_repaired.promise_repaired_global_classB).!(global_classB_kept|global_classB_not_repaired|promise_kept_global_classB)"; | ||
"ok_error" expression => "(global_classC_failed.repair_failed_global_classC.global_classC_not_ok.global_classC_not_kept.global_classC_not_repaired.global_classC_reached).!(global_classC_kept|promise_kept_global_classC|global_classC_repaired|promise_repaired_global_classC)"; | ||
"ok" expression => "ok_success.ok_repaired.ok_error"; | ||
|
||
reports: | ||
ok:: | ||
"$(this.promise_filename) Pass"; | ||
!ok:: | ||
"$(this.promise_filename) FAIL"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
##################################################################################### | ||
# Copyright 2015 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 Class combine two | ||
# @description Aggregate 2 class prefix into a new one | ||
# | ||
# @parameter first_prefix The first prefix of the source class to combine | ||
# @parameter second_prefix The second prefix of the source class to combine | ||
# @parameter third_prefix The third prefix of the source class to combine | ||
# @parameter fourth_prefix The fourth prefix of the source class to combine | ||
# @parameter destination_prefix The prefix of the destination class | ||
# | ||
# @class_prefix | ||
# @class_parameter destination_prefix | ||
# This bundle will define a class ${destination_prefix}_{kept,repaired,not_ok,ok,reached} | ||
# based on ${first_prefix}_{kept,repaired,not_ok,ok,reached} and ${second_prefix}_{kept,repaired,not_ok,ok,reached} | ||
# keeping the worst outcome | ||
|
||
bundle agent _classes_combine_four(first_prefix, second_prefix, third_prefix, fourth_prefix, destination_prefix) | ||
{ | ||
classes: | ||
"first_reached" expression => "${first_prefix}_reached"; | ||
"second_reached" expression => "${second_prefix}_reached"; | ||
"third_reached" expression => "${third_prefix}_reached"; | ||
"fourth_reached" expression => "${fourth_prefix}_reached"; | ||
|
||
first_reached.second_reached.third_reached.fourth_reached:: | ||
"${destination_prefix}_ok" expression => "${first_prefix}_ok.${second_prefix}_ok.${third_prefix}_ok.${fourth_prefix}_ok", | ||
scope => "namespace"; | ||
|
||
"${destination_prefix}_kept" expression => "${first_prefix}_kept.${second_prefix}_kept.${third_prefix}_kept.${fourth_prefix}_kept", | ||
scope => "namespace"; | ||
|
||
"promise_kept_${destination_prefix}" expression => "${destination_prefix}_kept", | ||
scope => "namespace"; | ||
|
||
"${destination_prefix}_repaired" expression => "(${first_prefix}_repaired.${second_prefix}_ok.${third_prefix}_ok.${fourth_prefix}_ok)|(${first_prefix}_ok.${second_prefix}_repaired.${third_prefix}_ok.${fourth_prefix}_ok)|(${first_prefix}_ok.${second_prefix}_ok.${third_prefix}_repaired.${fourth_prefix}_ok)|(${first_prefix}_ok.${second_prefix}_ok.${third_prefix}_ok.${fourth_prefix}_repaired)", | ||
scope => "namespace"; | ||
|
||
"promise_repaired_${destination_prefix}" expression => "${destination_prefix}_repaired", | ||
scope => "namespace"; | ||
|
||
"${destination_prefix}_reached" expression => "${first_prefix}_reached|${second_prefix}_reached|${third_prefix}_reached|${fourth_prefix}_reached", | ||
scope => "namespace"; | ||
|
||
"${destination_prefix}_failed" expression => "${first_prefix}_failed|${second_prefix}_failed|${third_prefix}_failed|${fourth_prefix}_failed", | ||
scope => "namespace"; | ||
|
||
"repair_failed_${destination_prefix}" expression => "${destination_prefix}_failed", | ||
scope => "namespace"; | ||
|
||
"${destination_prefix}_denied" expression => "${first_prefix}_denied|${second_prefix}_denied|${third_prefix}_denied|${fourth_prefix}_denied", | ||
scope => "namespace"; | ||
|
||
"repair_denied_${destination_prefix}" expression => "${destination_prefix}_denied", | ||
scope => "namespace"; | ||
|
||
"${destination_prefix}_timeout" expression => "${first_prefix}_timeout|${second_prefix}_timeout|${third_prefix}_timeout|${fourth_prefix}_timeout", | ||
scope => "namespace"; | ||
|
||
"repair_timeout_${destination_prefix}" expression => "${destination_prefix}_timeout", | ||
scope => "namespace"; | ||
|
||
"${destination_prefix}_error" expression => "${first_prefix}_error|${second_prefix}_error|${third_prefix}_error|${fourth_prefix}_error", | ||
scope => "namespace"; | ||
|
||
"${destination_prefix}_not_ok" expression => "!${destination_prefix}_ok", | ||
scope => "namespace"; | ||
|
||
"${destination_prefix}_not_kept" expression => "!${destination_prefix}_kept", | ||
scope => "namespace"; | ||
|
||
"${destination_prefix}_not_repaired" expression => "!${destination_prefix}_repaired", | ||
scope => "namespace"; | ||
methods: | ||
!first_reached:: | ||
"no first" usebundle => _classes_combine_three("${second_prefix}", "${third_prefix}", "${fourth_prefix}", "${destination_prefix}"); | ||
|
||
first_reached.!second_reached:: | ||
"no second" usebundle => _classes_combine_three("${first_prefix}", "${third_prefix}", "${fourth_prefix}", "${destination_prefix}"); | ||
|
||
first_reached.second_reached.!third_reached:: | ||
"no third" usebundle => _classes_combine_three("${first_prefix}", "${second_prefix}", "${fourth_prefix}", "${destination_prefix}"); | ||
|
||
first_reached.second_reached.third_reached.!fourth_reached:: | ||
"no fourth" usebundle => _classes_combine_three("${first_prefix}", "${second_prefix}", "${third_prefix}", "${destination_prefix}"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
##################################################################################### | ||
# Copyright 2015 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 Class combine ifthenelse | ||
# @description Aggregate class outcomes within an if then else structure | ||
# | ||
# @parameter test_prefix The prefix of classes comming from the test method | ||
# @parameter then_outcome The prefix of classes comming from the method called in the 'then' case (or the litteral 'success' or 'failure') | ||
# @parameter else_outcome The prefix of classes comming from the method called in the 'else' case (or the litteral 'success' or 'failure') | ||
# @parameter destination_prefix The prefix of the destination class | ||
# | ||
# @class_prefix | ||
# @class_parameter destination_prefix | ||
# This bundle will define a class ${destination_prefix}_{kept,repaired,not_ok,ok,reached} | ||
# based on the test result and the method called afterwards. | ||
# | ||
# If the 'test' call has a '_true' outcome then the 'then' result is copied to destination | ||
# If the 'test' call has a '_false' outcome then the 'else' result is copied to destination | ||
# | ||
# 'then_outcome' and 'else_outcome' can be replaced by the litteral string "success" or "failure" | ||
# In such case, the outcome is respectively replaced by a call to _classes_success or _classes_failure | ||
|
||
bundle agent _classes_combine_ifthenelse(test_prefix, then_outcome, else_outcome, destination_prefix) | ||
{ | ||
classes: | ||
"test_true" expression => "${test_prefix}_true"; | ||
"test_false" expression => "${test_prefix}_false"; | ||
|
||
"then_success" expression => strcmp("success", "${then_outcome}"); | ||
"then_failure" expression => strcmp("failure", "${then_outcome}"); | ||
|
||
"else_success" expression => strcmp("success", "${else_outcome}"); | ||
"else_failure" expression => strcmp("failure", "${else_outcome}"); | ||
|
||
methods: | ||
test_true.then_success:: | ||
"success" usebundle => _classes_success("${destination_prefix}"); | ||
|
||
test_true.then_failure:: | ||
"failure" usebundle => _classes_failure("${destination_prefix}"); | ||
|
||
test_true.!then_success.!then_failure:: | ||
"copy then" usebundle => _classes_copy("${then_outcome}", "${destination_prefix}"); | ||
|
||
test_false.else_success:: | ||
"success" usebundle => _classes_success("${destination_prefix}"); | ||
|
||
test_false.else_failure:: | ||
"failure" usebundle => _classes_failure("${destination_prefix}"); | ||
|
||
test_false.!else_success.!else_failure:: | ||
"copy else" usebundle => _classes_copy("${else_outcome}", "${destination_prefix}"); | ||
|
||
!test_true.!test_false:: | ||
# this will copy if_prefix which contains a failure | ||
"failure" usebundle => _classes_copy("${test_prefix}", "${destination_prefix}"); | ||
} |
Oops, something went wrong.