Skip to content
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

Questions about switch rules in config.ini and override mechanism (thru <plugin_name>.ini in /etc/metwork_config.d/mfdata/plugin) #383

Open
dearith opened this issue Feb 18, 2021 · 2 comments
Assignees

Comments

@dearith
Copy link
Contributor

dearith commented Feb 18, 2021

Hi,

I'm facing a issue about override mechanism for switch rules.

I'm trying to explain with a simple example/use case.

I build a plugin foo with a step name fooa.

I created a python switch_rules script with 2 functions : rule and rule2 because sometimes, depending on a context I want to apply rule, sometimes rule2.
(My real use case is : a same plugin with 2 different configurations (sections [switch rule] and [custom]), so 2 instances of the same plugin by applying the Mework concepts :
https://metwork-framework.org/pub/metwork/releases/docs/release_1.0/mfdata/350-plugin_guide/#25-advanced-installing-several-times-the-same-plugin and
https://metwork-framework.org/pub/metwork/releases/docs/release_1.0/mfdata/350-plugin_guide/#26-advanced-repackaging-a-plugin)

Here is the simple example/use case to illustrate my issue.

My config.ini plugin file is :

[switch_rules:python]
switch_rules.rule = fooa

Now for some reasons (in production environnement), I don't to use rule anymore but rule2.

To do that, I created a foo.ini file beside my foo3-xxxxx.plugin in the /etc/metwork.config.d/mfdata/plugins directory :

[switch_rules:python]
switch_rules.rule2 = fooa

In fact, I see the rule and rule2 function will be called and rule is not replaced by rule2 : ./tmp/config_auto/plugin_switch_rules.ini is :

# <CONTRIBUTION OF foo3 PLUGIN>
[switch_rules_foo:python]
/home/dearith10/metwork/mfdata/var/plugins/foo:switch_rules.rule = foo/fooa
/home/dearith10/metwork/mfdata/var/plugins/foo:switch_rules.rule2 = foo/fooa
# </CONTRIBUTION OF foo3 PLUGIN>

I'm aware that all switch rules (regexp, python , etc...) defined in config.ini are aggregated in switch. That's Ok.
But also the switch rules defined in foo.ini in the /etc/metwork.config.d/mfdata/plugins directory.
Could your confirm this is the expected behavior ?

My workaround is as follow:

In the config.ini : don't define any switch rule, just define them in the foo.ini (when deploying my plugin in production env.).

Thanks for your answer.

@thefab thefab self-assigned this Mar 1, 2021
@thefab
Copy link
Member

thefab commented Mar 1, 2021

yes this is "normal"

configuration overrides values if the key (and the group) are the same

here, the key is switch_rules.rule2 so it's a different key than switch_rules.rule

but I agree this is not great for your use case

another way would be to have a kind of rule proxy (in python) with something like that:

def rule(*args, **kwargs):
    if os.environ.get("MFCONFIG").startswith("DEV_"):
        return rule_dev(*args, **kwargs)
    else:
        return rule_prod(*args, **kwargs)

@dearith
Copy link
Contributor Author

dearith commented Mar 1, 2021

@thefab OK. Thanks for your answer.

My use case doesn't concern 'dev' or 'prod' environnement. All is 'prod' environnement. We use the same plugin source to create 2 (or more) instances of the same plugin (by 'repackaging' the plugin) with different configuration including switch rules.

So we will use the workaround : in the config.ini : don't define any switch rule, just define them in the <plugin_name>.ini (in the /etc/metwork.config.d/mfdata/plugins when deploying the plugin in a production env.).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants