-
Notifications
You must be signed in to change notification settings - Fork 1.7k
sysrc: refactor #10417
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?
sysrc: refactor #10417
Conversation
I had been sitting on the actual code for a month, and just finished up with the tests this morning. I wanted to get this off my plate before I forgot about it again. Sorry for a PR that competes with another one. |
Never mind, this was my fault on the test for not updating the correct file. |
@vbotka Would you mind checking my logic on the way I'm fairly certain that using |
a9435ae
to
880a640
Compare
Yes, it is. When it is that far, it would be good to understand how sysrc updates rc.conf/rc.conf.d. I'm not sure |
One potential problem is that this is a larger refactoring, which needs a very good reason to be backported to |
(Also please add a changelog fragment :-) ) |
IMO, it is as safe as before. The error handling is missing (as before). For example, insufficient permissions are silently ignored in
As a result, the task is reported I would like to proceed on top of this refactoring. |
IMO, there are no problems. This PR should be merged as is. The error handling may be added later. |
Hopefully the permission check I added works to prevent this. It did locally, but I have molecule using a vagrant and so I can easily create a test that has |
There is no reason to test the parsing. After refactoring, the module uses only "sysrc" to parse the configuration files. The |
I want to propose this patch @@ -152,7 +152,11 @@ class Sysrc(object):
return changed(out.split(' -> ')[1].strip().split(self.delim))
def present(self):
- if self.load_sysrc_value() == self.value:
+ value = self.load_sysrc_value()
+ if value == self.value:
+ return False
+ if self.value is None:
+ self.value = value
return False
if not self.module.check_mode:
@@ -232,6 +236,7 @@ def main():
try:
sysrc = Sysrc(module, name, result['value'], result['path'], result['delim'], result['jail'])
result['changed'] = getattr(sysrc, result['state'])()
+ result['value'] = getattr(sysrc, 'value')
except OSError as err:
module.fail_json(msg=str(err)) The option shell> sysrc k1
k1: v1 Without this patch, the module replaces the current value, e.g. |
Instead of |
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 @dlundgren thanks for the contribution!
Couple of comments on it.
This comment was marked as outdated.
This comment was marked as outdated.
Without the name validity test, the error |
Also use `self.module.fail_json` through out
@vbotka thanks for finding that! I added the check back in and a test for it as well. |
* Fix #10394 Use configparser. * Fix #10394 configparser is in Python3 only. * Fix #10394 return condition. * Fix #10394 Use ConfigParser with Python2. * Fix #10394 import configparser from ansible.module_utils.six.moves * Add changelog fragment. * Update changelogs/fragments/10400-sysrc.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Fix #10394 use shlex instead of configparser. * Update fragment. * Update changelogs/fragments/10400-sysrc.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/sysrc.py Co-authored-by: Felix Fontein <felix@fontein.de> * Apply suggestions from code review. Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> * Copy tests from #10417. --------- Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
* Fix #10394 Use configparser. * Fix #10394 configparser is in Python3 only. * Fix #10394 return condition. * Fix #10394 Use ConfigParser with Python2. * Fix #10394 import configparser from ansible.module_utils.six.moves * Add changelog fragment. * Update changelogs/fragments/10400-sysrc.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Fix #10394 use shlex instead of configparser. * Update fragment. * Update changelogs/fragments/10400-sysrc.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/sysrc.py Co-authored-by: Felix Fontein <felix@fontein.de> * Apply suggestions from code review. Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> * Copy tests from #10417. --------- Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> (cherry picked from commit 0be6e61)
SUMMARY
Refactors the
sysrc
module based on comments from prior PR's. Also fixes #10394.Closes #10400.
ISSUE TYPE
COMPONENT NAME
sysrc
ADDITIONAL INFORMATION
Refactored the
sysrc
module.