service: Remove py2 specific code (#85191)

Signed-off-by: Abhijeet Kasurde <Akasurde@redhat.com>
(cherry picked from commit 068157618c)
pull/85255/head
Abhijeet Kasurde 6 months ago committed by Matt Davis
parent df60504b93
commit 2d800e1a4c

@ -36,7 +36,7 @@ import select
import shlex
import subprocess
from ansible.module_utils.six import PY2, b
from ansible.module_utils.six import b
from ansible.module_utils.common.text.converters import to_bytes, to_text
@ -187,11 +187,7 @@ def daemonize(module, cmd):
if pid == 0:
os.close(pipe[0])
# if command is string deal with py2 vs py3 conversions for shlex
if not isinstance(cmd, list):
if PY2:
cmd = shlex.split(to_bytes(cmd, errors=errors))
else:
cmd = shlex.split(to_text(cmd, errors=errors))
# make sure we always use byte strings
@ -247,9 +243,6 @@ def daemonize(module, cmd):
break
return_data += to_bytes(data, errors=errors)
# Note: no need to specify encoding on py3 as this module sends the
# pickle to itself (thus same python interpreter so we aren't mixing
# py2 and py3)
return pickle.loads(to_bytes(return_data, errors=errors))

@ -180,7 +180,7 @@ from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.locale import get_best_parsable_locale
from ansible.module_utils.common.sys_info import get_platform_subclass
from ansible.module_utils.service import fail_if_missing, is_systemd_managed
from ansible.module_utils.six import PY2, b
from ansible.module_utils.six import b
class Service(object):
@ -285,12 +285,6 @@ class Service(object):
os._exit(0)
# Start the command
if PY2:
# Python 2.6's shlex.split can't handle text strings correctly
cmd = to_bytes(cmd, errors='surrogate_or_strict')
cmd = shlex.split(cmd)
else:
# Python3.x shex.split text strings.
cmd = to_text(cmd, errors='surrogate_or_strict')
cmd = [to_bytes(c, errors='surrogate_or_strict') for c in shlex.split(cmd)]
# In either of the above cases, pass a list of byte strings to Popen

Loading…
Cancel
Save