-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add a rule-based file editor to CAF #123
Comments
@jouvin quite a long post. i'm not going to comment on all sections at once though a. the disadvantages of filewriter/metaconfig are indeed what you sum up, but at least for metaconfig, extending support for a new option can typically be done by extending the schema, and textrender supports multiversioned templates, but the coupling with the rpm version is indeed manual. b. the way you distribute the rules should not be perl code. similar to TT files, one could ship editor rules like
ofcourse this example format is heavily influenced by the regexptests from TextRender; but this is static data, not code. c. the rules should also indicate where missing data is added (imagine adding a single entry only to the 2nd virtual host in a apache config file) d. i once tought about something similar based on TextRender: make TT files to generate the config for single line values (and than splitting by line and looping over them to apply to the whole text), and provide the conditions in such a way that the regexp pattern for each can also be rendered by the same TT files.
would create the correct configuration |
I understand your points and I don't want to claim that the proposed solution addresses any use cases. The actual added value of what I developed, IMO, is not that this is a powerful templating system (it is clearly not!) but the coupling with a hierarchy of options through this You are right that the Apache case you mentioned is not addressable by the current implementation. I already thought a little bit about it, I think it's doable to add the support for it but as I had no need for it until now, I delayed working on it. At some point it may become too complex and not worth the effort and the metaconfig approach would be a better compromise. Again, I certainly don't want to advocate that this rule-based editor is in any way an alternative to metaconfig. If we agree to put it in CAF, we should probably make it clear that its use should be reserved to cases where the As for the support of new parameters, you are right that if you want to be able to configure them, you need to update the configuration modules managing the files (schema and rules) but what is great in the proposed approach if that if a new configuration parameter is added by a new version of the RPM and the default value is ok for your, at least to start, you can still use the same version of the configuration module to manage the file as it will not break anything. I didn't want to cover everything in my original post so I didn't mention how you update your config file when a new one is provided by a new version of the RPM with extension I hope I made the intention a bit more clear! And that hopefully I convinced you that this is a feature complementary to others we have to manage files that is adding to the power of Quattor. |
BTW, I forgot to give an example of rule hash (this is from
I didn't understand the remark about rules being code rather than data. Rules are Perl hashes which for me are data (the only code used is the string concatenation)... |
Thinking a little bit more at the implementation details, I think that the issue is misworded and that there is no need for a new CAF module. What I propose is in fact just and extension of the FileEditor with a set of new functions to do the rule-based edition. A new module would just inherit from FileEditor and add new functions without modifying anything to the standard behaviour. |
16.2 is unrealistic, please don't set a milestone unless you have code in progress. |
Resolved by #151. |
In some circumstances it is required to edit some files (typically provided by a RPM) to change some configuration parameters and doing it on the template site is impractical or unmaintainable because the file provided by the RPM evolves and you just want to ensure that some critical parameters have a defined value. Doing it on the template site would require to update the templates at each new version of the RPM and would lead to a tricky dependency management between the RPM version and the template version. A typical example are EMI DPM and Xrootd, managed by
ncm-dpmlfc
andncm-xrootd
. Puppet for example is using the "template approach" and this is a nigthmare to express the dependency between the Puppet module version and the RPM version.An approach that has been successfully used for many years in
ncm-dpmlfc
andncm-xrootd
is to use a rule-based editor in the component perl module. The basic idea is that you express the variable/keyword to be edited in your config file with some value from your Quattor configuration if some conditions are met, like a configuration option defined in a certain part of the configuration. This is very flexible and powerful. Currently, this is a (long) piece of Perl code that is inside both configuration modules (this is the same code copied/pasted, thencm-dpmlfc
being slightly more recent with a few additional features.As this is not good to duplicate such a piece of code and because it could also be beneficial for other use cases, I'd like to add it as a new
CAF
module, for exampleFileRuleBasedEditor
. Before going furtther, I'd like to discuss if there is an agreement on the features provided by the current rule-based editor.Let start by describing how rules are constructed (see comments in https://github.com/jouvin/configuration-modules-grid/blob/dpmlfc/ncm-dpmlfc/src/main/perl/dpmlfc.pm around line 147 and the rule examples below):
With:
condition
: an option or an option set that must exist for the rule to be applied. Both option_set and option_name:option_set are accepted (see below). Only one option set is allowed and only existence, not value is tested. In addition, the condition may be negated (option or option_set must not exist) by prepending a '!' to it.option_name
: the name of an option that will be retrieved from the configurationoption_set
: the set of options the option is located in (for example 'dpnsHost:dpm' means 'dpnsHost' option of 'dpm' option set (an option set is a sub-hash of the option hash passed to the rule-based editor). 'GLOBAL' is a special value for 'option_set' indicating that the option is a global option, instead of belonging to a specific option set (a global option is an option at the first level of the option hash).envvar
: a sh shell environment variable definition (export VAR=val
)param
: a sh shell variable definition (VAR=val
)xrdcfg
: akeyword value
line, as used by Xrootd or Apache config files.xrdcfg_setenv
: asetenv
line, as used by Xrootd config files or csh/tcsh script.xrdcfg_set
: aset
line, as used by Xrootd config files.line_fmt
allows to specify how to process lists and nlists. In particular if an option is a pan list, the rule-based editor can display the value of the list separated by the selected separator.allows special formatting of the value. This is mainly used for boolean values to get them printed as
yesor
no`.Inline comments are not supported in
xrdcfg
family of formats whereas every line updated by Quattor receive an inline comment inenvvar
andparam
formats.In addition, if the keyword (hash key) is starting with a
-
, this means that the matching configuration line must be removed/commented out (instead of added/updated) from the configuration file if present. If it is starting with a '?', this means that the matching line must be removed/commented out if the option is undefined (note that this is also possible to specify at the file level, for the whole ruleset, if a line matching one rule but whose condition is not met must removed/commented out).The text was updated successfully, but these errors were encountered: