Bug #7459
closedArchitecture #7155: Stable class identifier
Architecture #7156: Modify generic methods to define and use the new class_prefix
Reporting is broken for several ncf generic methods because the new class_prefix is not computed without this.callers_promisers, and any conditions using class_prefix are incorrectly evaluated
Description
For example, in command_execution.cf:
vars: "old_class_prefix" string => canonify("command_execution_${command_name}"); "class_prefix" string => canonify(join("_", "this.callers_promisers")); "args" slist => { "${command_name}" }; methods: "report" usebundle => _log("Execute the command ${command_name}", "${old_class_prefix}", "${class_prefix}", @{args}), ifvarclass => "(!has_promiser_stack.${old_class_prefix}_reached)|(has_promiser_stack.${class_prefix}_reached)";
In this case, the last ifvarclass will evaluate to FALSE because ${class_prefix} is an undefined variable, because "this.callers_promisers" does not exist. This obvisouly breaks reporting, since "_log" is never called.
Updated by Jonathan CLARKE almost 9 years ago
The best solution we have found for this is to slightly change the boiler plate lines at the top of each generic method as follows:
vars: "old_class_prefix" string => canonify("command_execution_${command_name}"); "promisers" slist => { @{this.callers_promisers}, cf_null }, policy => "ifdefined"; "class_prefix" string => canonify(join("_", "promisers")); "args" slist => { "${command_name}" };
The change is the second line (whose result is used in the 3rd line, instead of using "this.callers_promisers" directly). This line uses several CFEngine tricks:
- It uses 'policy => "ifdefined"' to include the values of @{this.callers_promisers} if and only if that list exists.
- It uses the special value "cf_null" to avoid this new list from being empty, in case @{this.callers_promisers} does not exist
- "promisers" becomes an empty list (when "this.callers_promisers", as currently it does not)
Updated by Jonathan CLARKE almost 9 years ago
- Status changed from New to In progress
- Assignee set to Jonathan CLARKE
Updated by Jonathan CLARKE almost 9 years ago
- Status changed from In progress to Pending technical review
- Assignee changed from Jonathan CLARKE to Benoît PECCATTE
- Pull Request set to https://github.com/Normation/ncf/pull/271
Updated by Jonathan CLARKE almost 9 years ago
- Related to Bug #7461: classes_* methods should refuse to copy classes to a prefix which is an empty string added
Updated by Jonathan CLARKE almost 9 years ago
- Status changed from Pending technical review to Pending release
- % Done changed from 0 to 100
Applied in changeset commit:76e71537af4933abfec22e38ba46f5b8ea57eec6.
Updated by Benoît PECCATTE almost 9 years ago
Applied in changeset commit:c427961f26fa97cf2fc4fa8cd272f210ac28647f.
Updated by Benoît PECCATTE almost 9 years ago
- Subject changed from Reporting is broken for several ncf generic methods because the new class_prefix is not computer without this.callers_promisers, and any conditions using class_prefix are incorrectly evaluated to Reporting is broken for several ncf generic methods because the new class_prefix is not computed without this.callers_promisers, and any conditions using class_prefix are incorrectly evaluated
Updated by Vincent MEMBRÉ about 8 years ago
- Status changed from Pending release to Released