CFE-4686: Add cancel attribute to classes promises to undefine a class#6175
Open
nickanderson wants to merge 2 commits into
Open
CFE-4686: Add cancel attribute to classes promises to undefine a class#6175nickanderson wants to merge 2 commits into
nickanderson wants to merge 2 commits into
Conversation
Covers undefining a defined class when the cancel expression is true, retaining the class when the expression is false, function-based triggers, the no-op case for an undefined class, refusal to cancel reserved hard classes, and mutual exclusion with the class-defining attributes. Ticket: CFE-4686 Changelog: None Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Until now a classes promise could only define a class; the only way to undefine one from policy was a cancel_* classes body attached to another promise's outcome. This adds a 'cancel' attribute to the classes promise itself: when its class expression (a string, or a function returning a boolean) evaluates true, the promiser class is undefined if it is defined. The class-skipping optimization in ExpandDeRefPromise() normally excludes a classes promise whose promiser is already defined. A cancel promise must run precisely in that case, so the skip now makes an exception when the 'cancel' attribute is present. 'cancel' is mutually exclusive with the class-defining attributes (expression, and, or, xor, not, dist, select_class) via the existing "Irreconcilable constraints" check, since it is counted like any other class-body attribute. Reserved hard classes cannot be cancelled. The evaluation and undefine path mirrors the cancel_* classes body behaviour (DeleteAllClasses). Ticket: CFE-4686 Changelog: Title Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Member
Author
|
@cf-bottom jenkins please |
| boolean. Shared by the class-defining attributes (expression, not, and, or, | ||
| xor, select_class, dist) and by the class-cancelling 'cancel' attribute, | ||
| whose trigger is evaluated exactly like 'expression'. This deliberately does | ||
| NOT consider whether the promiser class is already defined; that skip logic |
| " ?> Cancelling cached persistent class %s", | ||
| pp->promiser); | ||
| EvalContextHeapPersistentRemove(pp->promiser); | ||
| } |
| pp->promiser); | ||
| EvalContextHeapPersistentRemove(pp->promiser); | ||
| } | ||
| return false; |
|
Alright, I triggered a build: Jenkins: https://ci.cfengine.com/job/pr-pipeline/13945/ Packages: http://buildcache.cfengine.com/packages/testing-pr/jenkins-pr-pipeline-13945/ |
Contributor
|
Thanks nice addition!! Much needed |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds a
cancelattribute toclassespromises so policy can undefine aclass. Until now a classes promise could only define a class; the only way
to undefine one from policy was a
cancel_*classes body attached to anotherpromise's outcome. With
cancel, the classes promise can undefine its ownpromiser directly:
When the cancel expression (a class expression — string or a function
returning a boolean) evaluates true, the promiser class is undefined if it is
currently defined. False trigger, or an already-undefined class, is a no-op.
Key detail: the class-skipping exception
ExpandDeRefPromise()normally excludes a classes promise whose promiser isalready defined (an optimization). A
cancelpromise must run precisely inthat case, so the skip now makes an exception when the
cancelattribute ispresent. This is the crux of the change — without it the promise would never
actuate.
Behaviour
expression,and,or,xor,not,dist,select_class) via the existing "Irreconcilableconstraints" check —
cancelis counted like any other class-body attribute.consistent with the
cancel_*classes body attributes (ENT-7718 / CFE-3647).cancel_*classes body(
DeleteAllClasses): persistent removal +EvalContextClassRemove+bundle-frame removal.
Tests
New acceptance tests in
tests/acceptance/02_classes/01_basic/:cancel_attribute.cf,cancel_attribute_hardclass.cf,cancel_attribute_mutex.cf(+.sub).Full
02_classessuite: 117 passed, 0 failed (3 staging-skipped, 3pre-existing soft failures).
Docs
Documentation PR: cfengine/documentation (CFE-4686) adds the
cancelreferencesection.
Ticket: https://northerntech.atlassian.net/browse/CFE-4686
🤖 Generated with Claude Code