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

Replace the use of the function string.replace with the method str.replace #68793

Merged
merged 3 commits into from Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/bsd_rcconf_string_replace.yaml
@@ -0,0 +1,2 @@
bugfixes:
- service - Fix for the BSD rcconf code using a Python 2 specific string replace function
9 changes: 4 additions & 5 deletions lib/ansible/modules/service.py
Expand Up @@ -135,7 +135,6 @@
import re
import select
import shlex
import string
import subprocess
import tempfile
import time
Expand Down Expand Up @@ -419,7 +418,7 @@ def service_enable_rcconf(self):

# Write out the contents of the list into our temporary file.
for rcline in new_rc_conf:
os.write(TMP_RCCONF, rcline)
os.write(TMP_RCCONF, rcline.encode())

# Close temporary file.
os.close(TMP_RCCONF)
Expand Down Expand Up @@ -1116,7 +1115,7 @@ def service_enable(self):
if os.path.isfile(rcfile):
self.rcconf_file = rcfile

self.rcconf_key = "%s" % string.replace(self.name, "-", "_")
self.rcconf_key = "%s" % self.name.replace("-", "_")

return self.service_enable_rcconf()

Expand Down Expand Up @@ -1274,7 +1273,7 @@ class NetBsdService(Service):
"""
This is the NetBSD Service manipulation class - it uses the /etc/rc.conf
file for controlling services started at boot, check status and perform
direct service manipulation. Init scripts in /etc/rcd are used for
direct service manipulation. Init scripts in /etc/rc.d are used for
controlling services (start/stop) as well as for controlling the current
state.
"""
Expand Down Expand Up @@ -1304,7 +1303,7 @@ def service_enable(self):
if os.path.isfile(rcfile):
self.rcconf_file = rcfile

self.rcconf_key = "%s" % string.replace(self.name, "-", "_")
self.rcconf_key = "%s" % self.name.replace("-", "_")

return self.service_enable_rcconf()

Expand Down