-
Notifications
You must be signed in to change notification settings - Fork 200
CFE-4686: Add cancel attribute to classes promises to undefine a class #6175
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
Open
nickanderson
wants to merge
2
commits into
cfengine:master
Choose a base branch
from
nickanderson:CFE-4686/classes-cancel-attribute
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,65 @@ | ||
| ####################################################### | ||
| # | ||
| # Test the 'cancel' attribute of classes promises (CFE-4686). | ||
| # | ||
| # A classes promise using 'cancel' undefines its promiser class when the | ||
| # cancel expression evaluates to true. Unlike the class-defining attributes, | ||
| # it must be evaluated even when the class is already defined. | ||
| # | ||
| ####################################################### | ||
|
|
||
| body common control | ||
| { | ||
| inputs => { "../../default.sub.cf" }; | ||
| bundlesequence => { default("$(this.promise_filename)") }; | ||
| version => "1.0"; | ||
| } | ||
|
|
||
| ####################################################### | ||
|
|
||
| bundle agent init | ||
| { | ||
| } | ||
|
|
||
| ####################################################### | ||
|
|
||
| bundle agent test | ||
| { | ||
| meta: | ||
| "description" -> { "CFE-4686" } | ||
| string => "classes promise 'cancel' attribute undefines a defined class when its expression is true"; | ||
|
|
||
| classes: | ||
| # Define global classes so the check bundle can observe the outcome. | ||
| "to_cancel" expression => "any", scope => "namespace"; | ||
| "to_keep" expression => "any", scope => "namespace"; | ||
| "trigger" expression => "any", scope => "namespace"; | ||
| "func_cancel" expression => "any", scope => "namespace"; | ||
|
|
||
| # trigger is set, so to_cancel must be undefined. | ||
| "to_cancel" cancel => "trigger"; | ||
|
|
||
| # Condition is an undefined class, so to_keep must be retained. | ||
| "to_keep" cancel => "class_that_is_not_defined"; | ||
|
|
||
| # Function-based boolean trigger: the file does not exist, so not(...) | ||
| # is true and func_cancel must be undefined. | ||
| "func_cancel" cancel => not(fileexists("/this/does/not/exist/cfe4686")); | ||
|
|
||
| # Cancelling a class that was never defined is a harmless no-op. | ||
| "never_defined" cancel => "trigger"; | ||
| } | ||
|
|
||
| ####################################################### | ||
|
|
||
| bundle agent check | ||
| { | ||
| classes: | ||
| "ok" expression => "!to_cancel.to_keep.!func_cancel.!never_defined.trigger"; | ||
|
|
||
| reports: | ||
| ok:: | ||
| "$(this.promise_filename) Pass"; | ||
| !ok:: | ||
| "$(this.promise_filename) FAIL"; | ||
| } |
48 changes: 48 additions & 0 deletions
48
tests/acceptance/02_classes/01_basic/cancel_attribute_hardclass.cf
This file contains hidden or 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,48 @@ | ||
| ####################################################### | ||
| # | ||
| # Test that the 'cancel' attribute cannot undefine a hard class (CFE-4686). | ||
| # | ||
| # Cancelling a reserved hard class must be refused (with a warning) and the | ||
| # class left in place, consistent with the cancel_* classes body attributes. | ||
| # | ||
| ####################################################### | ||
|
|
||
| body common control | ||
| { | ||
| inputs => { "../../default.sub.cf" }; | ||
| bundlesequence => { default("$(this.promise_filename)") }; | ||
| version => "1.0"; | ||
| } | ||
|
|
||
| ####################################################### | ||
|
|
||
| bundle agent init | ||
| { | ||
| } | ||
|
|
||
| ####################################################### | ||
|
|
||
| bundle agent test | ||
| { | ||
| meta: | ||
| "description" -> { "CFE-4686" } | ||
| string => "classes promise 'cancel' attribute must not undefine a hard class"; | ||
|
|
||
| classes: | ||
| # cfengine is a reserved hard class - the cancel must be ignored. | ||
| "cfengine" cancel => "any"; | ||
| } | ||
|
|
||
| ####################################################### | ||
|
|
||
| bundle agent check | ||
| { | ||
| classes: | ||
| "ok" expression => "cfengine"; | ||
|
|
||
| reports: | ||
| ok:: | ||
| "$(this.promise_filename) Pass"; | ||
| !ok:: | ||
| "$(this.promise_filename) FAIL"; | ||
| } |
43 changes: 43 additions & 0 deletions
43
tests/acceptance/02_classes/01_basic/cancel_attribute_mutex.cf
This file contains hidden or 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,43 @@ | ||
| ####################################################### | ||
| # | ||
| # Test that 'cancel' is mutually exclusive with the class-defining | ||
| # attributes of a classes promise (CFE-4686). | ||
| # | ||
| # Combining 'cancel' with expression/and/or/xor/not/dist/select_class must be | ||
| # rejected with "Irreconcilable constraints", exactly like combining any two | ||
| # of the defining attributes. The sub-policy exercises every combination; this | ||
| # test asserts the rejection appears in the agent output. | ||
| # | ||
| ####################################################### | ||
|
|
||
| body common control | ||
| { | ||
| inputs => { "../../default.sub.cf" }; | ||
| bundlesequence => { default("$(this.promise_filename)") }; | ||
| version => "1.0"; | ||
| } | ||
|
|
||
| ####################################################### | ||
|
|
||
| bundle agent init | ||
| { | ||
| } | ||
|
|
||
| ####################################################### | ||
|
|
||
| bundle agent test | ||
| { | ||
| meta: | ||
| "description" -> { "CFE-4686" } | ||
| string => "'cancel' must be mutually exclusive with the class-defining attributes"; | ||
| } | ||
|
|
||
| ####################################################### | ||
|
|
||
| bundle agent check | ||
| { | ||
| methods: | ||
| "" usebundle => dcs_passif_output1(".*Irreconcilable constraints in classes.*", | ||
| "$(sys.cf_agent) -Kf $(this.promise_filename).sub 2>&1", | ||
| $(this.promise_filename)); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.