-
Notifications
You must be signed in to change notification settings - Fork 1.7k
dconf: add feature to populate a subpath from file #10432
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
base: main
Are you sure you want to change the base?
Conversation
* Simplify check of changes
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution!
Co-authored-by: Felix Fontein <[email protected]>
This comment was marked as outdated.
This comment was marked as outdated.
* Mutual exclusion of 'path' and 'value'
plugins/modules/dconf.py
Outdated
# NOTE: This case shouldn't happen yet as 'key' and 'path' are | ||
# required with 'state=present' | ||
# TODO: if 'key' ends with '/' then 'dconf list' should be used | ||
# else, 'dconf read' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this TODO be part of dconf.load()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't thing so.
The architecture defined by the original author suggests that:
dconf.read
handlesdconf read [key]
dconf.write
handlesdconf write [key] [value]
dconf.load
handlesdconf load [key] < [path]
(this contribution)
If key
ends with '/', it means that it's a directory. If value
is set, it should be illegal. If path
is set, we're in the case of the contribution. If none of them is set, user tries to read a directory. It cannot be handled neither by dconf read
nor dconf dump
instead, dconf list
must be used. In the future, dconf.list
must be created to by compliant.
As you said, state=read
is a mistake. As I understand, it means that reading key
(whatever the meaning - a key or a directory) should have been handled by state=present
. That's why I added this TODO here.
Are you agree with that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you said,
state=read
is a mistake. As I understand, it means that readingkey
(whatever the meaning - a key or a directory) should have been handled bystate=present
. That's why I added this TODO here.
What do you mean that read is a mistake? The read
state is meant to read the key value without making changes to it - the present
state will/might change the value. Or have I misunderstood something here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
Felix wrote the following sentence:
Note that
load
is not a state. (Not thatread
is one, but that mistake has already been made in the past.)
I understand that state=read
shouldn't be valid. If it's a valid state, that's fine with me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
state=read
should not be there, it should be moved to a separate _info
module. Since that state has been added a long time ago (together with the module in 2017), it's still there until someone invests some work to move it to a separate module though. But if someone tries to add a similar "state" again to a module nowadays, it would be rejected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway, this comment has been removed to follow the guidance of russoz!
|
||
# Run the command and fetch standard return code, stdout, and stderr. | ||
dbus_wrapper = DBusWrapper(self.module) | ||
rc, out, err = dbus_wrapper.run_command(command, data=raw_config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens to keys that already exist, but are not part of raw_config
? Are these kept, or removed?
If the latter, the changed
check above is not correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If keys exist in the database but, are not part of raw_config
then they're kept. changed
check should be correct!
Co-authored-by: Felix Fontein <[email protected]>
Co-authored-by: Felix Fontein <[email protected]>
Co-authored-by: Felix Fontein <[email protected]>
This update allows: * Compatibility between python2 and python3 * To handle IO operation errors Co-authored-by: Felix Fontein <[email protected]>
Co-authored-by: Felix Fontein <[email protected]>
Co-authored-by: Felix Fontein <[email protected]>
Co-authored-by: Felix Fontein <[email protected]>
Co-authored-by: Felix Fontein <[email protected]>
Note that I added a sub-function ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @Sh3idan, thanks for your contribution.
I have some other comments as well.
changed = any( | ||
not self.variants_are_equal(self.read("%s%s/%s" % (root_dir, sub_dir, k)), v) | ||
for sub_dir in config.sections() | ||
for k, v in config[sub_dir].items() | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I presume you are doing this because dconf
will not report whether any value was changed, is that so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's why i'm doing this. Should I also check if the keys have actually been added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only if you have reason to believe that dconf
might not add them and be silent about it. If we can trust them to be added (or receive an error if something goes bad), then there is no need to perform additional checks.
Co-authored-by: Alexei Znamensky <[email protected]>
Co-authored-by: Alexei Znamensky <[email protected]>
* Remove unreachable code
@@ -0,0 +1,2 @@ | |||
minor_changes: | |||
- dconf - adds support of ``load`` to populate a subpath from file (https://github.com/ansible-collections/community.general/pull/10432). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- dconf - adds support of ``load`` to populate a subpath from file (https://github.com/ansible-collections/community.general/pull/10432). | |
- dconf - allow to populate a subpath from a file (https://github.com/ansible-collections/community.general/pull/10432). |
elif module.params['state'] == 'present': | ||
changed = dconf.write(module.params['key'], module.params['value']) | ||
module.exit_json(changed=changed) | ||
if module.params['path']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if module.params['path']: | |
if module.params['path'] is not None: |
# Use 'dconf load' to propagate multiple entries from the root given by 'key' | ||
changed = dconf.load(module.params['key'], module.params['path']) | ||
module.exit_json(changed=changed) | ||
elif module.params['value']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elif module.params['value']: | |
else: |
|
||
# Process based on different states. | ||
if module.params['state'] == 'read': | ||
# TODO: Handle this case when 'state=present' and 'key' is the only one |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what this comment means. Can you please explain it?
@Sh3idan ping needs_info |
SUMMARY
This merge request allows to populate a subpath from file by using
load
sub-command of thedconf
binary. Below the changes that were made:state: load
has been added to address the featurepath
is a new option working with the feature. It points to a file located in node which contains a subpath dump.key
remains unchanged but, here, it refers to a root directory (instead of a dconf key) and must be '/' terminatedISSUE TYPE
COMPONENT NAME
dconf
ADDITIONAL INFORMATION
Below a role using the newly
load
state, followed by the varbatim output:The content of the
path
file is: