Architecture #11858
closedAdd common pre- and post- agent run action triggered by technique logic
Description
We would like to have some cfengine code shared between more than one version of a technique. This is needed to be able to "merge" common action like restarting a service if its config file was updated, or execute a command to get a common information.
For example we would have 3 versions of technique A :- A/v1/code.st
- A/v1/common.st
- A/v2/code.st
- A/v2/common.st
- A/v3/code.st
- A/v3/common.st
- A/v1/code.st
- A/v2/code.st
- A/v2/common.st
To generate the final content.
After some thought on it (see comments), the chosen solution is to add a notion of run-hooks implemented like that:
- in metadata.xml, we add an optionnal section in <AGENT> with the following parameters: pre or post hook, hook type (service restart, command, variable from command, package), parameters (a list of k/value), condition (a class expression)
- during generation, on a given node, we:
- accumulate pre (post) hooks which differ on type or parameters
- merge (i.e: accumulate reportid, "or" condition) hooks with same type / parameters
- we add the resulting pre (post) hooks in the bundle sequence by mapping them to the corresponding method calls
Note: reports are for all directive registering for a hook. It makes no sense to have a report for only one directive (because in that case, it is not a common code, it's some code specific to one directive that should be defined in the directive logic)