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

stdin.encode does not properly encode the stdin on python3 #65

Closed
Scronkfinkle opened this issue Jul 13, 2021 · 1 comment
Closed

stdin.encode does not properly encode the stdin on python3 #65

Scronkfinkle opened this issue Jul 13, 2021 · 1 comment

Comments

@Scronkfinkle
Copy link
Contributor

Link to issue: https://tracker.ceph.com/issues/51291

I was getting the following error when trying to use Ceph wih the docker container for 15.2.13:

RuntimeError: Failed to execute command: sudo /usr/bin/cephadm --image docker.io/ceph/ceph:v15 --no-container-init deploy --fsid 85361255-4989-4e27-bdb3-e017b9081911 --name mds.cephfs.athos4.nsevry --config-json -
2021-06-28T12:19:36.468436+0000 mgr.athos2 (mgr.5211678) 1623980 : cephadm [INF] Deploying daemon mds.cephfs.athos2.adupvw on athos2
2021-06-28T12:19:36.504448+0000 mgr.athos2 (mgr.5211678) 1623985 : cephadm [ERR] Traceback (most recent call last):
2021-06-28T12:19:36.504677+0000 mgr.athos2 (mgr.5211678) 1623986 : cephadm [ERR]   File "/lib/python3.6/site-packages/remoto/process.py", line 188, in check
2021-06-28T12:19:36.504883+0000 mgr.athos2 (mgr.5211678) 1623987 : cephadm [ERR]     response = result.receive(timeout)
2021-06-28T12:19:36.505087+0000 mgr.athos2 (mgr.5211678) 1623988 : cephadm [ERR]   File "/lib/python3.6/site-packages/execnet/gateway_base.py", line 749, in receive
2021-06-28T12:19:36.505290+0000 mgr.athos2 (mgr.5211678) 1623989 : cephadm [ERR]     raise self._getremoteerror() or EOFError()
2021-06-28T12:19:36.505525+0000 mgr.athos2 (mgr.5211678) 1623990 : cephadm [ERR] execnet.gateway_base.RemoteError: Traceback (most recent call last):
2021-06-28T12:19:36.505741+0000 mgr.athos2 (mgr.5211678) 1623991 : cephadm [ERR]   File "<string>", line 1088, in executetask
2021-06-28T12:19:36.505951+0000 mgr.athos2 (mgr.5211678) 1623992 : cephadm [ERR]   File "/lib/python3.6/site-packages/remoto/process.py", line 151, in _remote_check
2021-06-28T12:19:36.506161+0000 mgr.athos2 (mgr.5211678) 1623993 : cephadm [ERR]   File "/usr/lib/python3.6/subprocess.py", line 863, in communicate
2021-06-28T12:19:36.506370+0000 mgr.athos2 (mgr.5211678) 1623994 : cephadm [ERR]     stdout, stderr = self._communicate(input, endtime, timeout)
2021-06-28T12:19:36.506579+0000 mgr.athos2 (mgr.5211678) 1623995 : cephadm [ERR]   File "/usr/lib/python3.6/subprocess.py", line 1519, in _communicate
2021-06-28T12:19:36.506785+0000 mgr.athos2 (mgr.5211678) 1623996 : cephadm [ERR]     input_view = memoryview(self._input)
2021-06-28T12:19:36.506993+0000 mgr.athos2 (mgr.5211678) 1623997 : cephadm [ERR] TypeError: memoryview: a bytes-like object is required, not 'str'
2021-06-28T12:19:36.507202+0000 mgr.athos2 (mgr.5211678) 1623998 : cephadm [ERR] 
2021-06-28T12:19:36.507409+0000 mgr.athos2 (mgr.5211678) 1623999 : cephadm [ERR] 
2021-06-28T12:19:36.508516+0000 mgr.athos2 (mgr.5211678) 1624001 : cephadm [ERR] Failed to execute command: sudo /usr/bin/cephadm --image docker.io/ceph/ceph:v15 --no-container-init deploy --fsid 85361255-4989-4e27-bdb3-e017b9081911 --name mds.cephfs.athos2.adupvw --config-json -
Traceback (most recent call last):
  File "/lib/python3.6/site-packages/remoto/process.py", line 188, in check
    response = result.receive(timeout)
  File "/lib/python3.6/site-packages/execnet/gateway_base.py", line 749, in receive
    raise self._getremoteerror() or EOFError()
execnet.gateway_base.RemoteError: Traceback (most recent call last):
  File "<string>", line 1088, in executetask
  File "/lib/python3.6/site-packages/remoto/process.py", line 151, in _remote_check
  File "/usr/lib/python3.6/subprocess.py", line 863, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)
  File "/usr/lib/python3.6/subprocess.py", line 1519, in _communicate
    input_view = memoryview(self._input)
TypeError: memoryview: a bytes-like object is required, not 'str'

I dug into the source code and found this on line 151 of remoto/process.py

  if stdin:
        if not isinstance(stdin, bytes):
            stdin.encode('utf-8', errors='ignore')
        stdout_stream, stderr_stream = process.communicate(stdin)
    else:

In python3.6 (the version shipped with the ceph container) stdin.encode('utf-8', errors='ignore') does not mutate stdin, and instead only returns the modified variable. To verify this, I modified the code like so such that it sets stdin to the encoded value

  if stdin:
        if not isinstance(stdin, bytes):
            stdin = stdin.encode('utf-8', errors='ignore')
        stdout_stream, stderr_stream = process.communicate(stdin)
    else:

Ceph was able to reconfigure and run without issue after this

@Scronkfinkle
Copy link
Contributor Author

Digging deeper, python2.7 doesn't appear to mutate the variable in place either. I'm unsure if this call ever followed expected behavior

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

No branches or pull requests

1 participant