GitHub user ereyes01 opened a pull request:
https://github.com/apache/libcloud/pull/347
Fix ParamikoSSHClient.run() so that it works in Python 3.4.1
I was trying to do the following using apache-libcloud==0.15.1 on Python
3.4.1:
- Run deploy_node to create an EC2 node with a MultiStepDeployment.
- The MultiStepDeployment consists of 2 FileDeployment's followed by 1
ScriptDeployment
The deploy_node would work fine in Python 2.7.6 but failed when I switched
to Python 3,4,1 with the following:
```
DeploymentError Traceback (most recent call last)
<ipython-input-18-79924dc2c1dc> in <module>()
2 ex_security_groups=[SECURITY_GROUP_NAME],
3 ex_keyname=KEY_NAME, deploy=deployment,
ssh_username=USERNAME,
----> 4 ssh_key=PRIVATE_KEY_PATH)
5 print(node)
/home/ereyes/.pyenv/versions/deploy3/lib/python3.4/site-packages/libcloud/compute/base.py
in deploy_node(self, **kwargs)
924 if deploy_error is not None:
925 raise DeploymentError(node=node,
original_exception=deploy_error,
--> 926 driver=self)
927
928 return node
DeploymentError: <DeploymentError: node=i-1ff25335, error=<LibcloudError in
<libcloud.compute.drivers.ec2.EC2NodeDriver object at 0x7f91a0782d68> "Failed
after 3 tries: string argument expected, got 'bytes'">,
driver=<libcloud.compute.drivers.ec2.EC2NodeDriver object at 0x7f91a0782d68>>
```
After instrumenting the code to print more informative stack traces, I
located the source of the Exception, which was in ParamikoSSHClient.run(). The
code where a data chunk is obtained from chan.recv() returns a bytes object in
Python 3, where it presumably returns a descendant of basestring in Python 2.
This object is then passed to stdout.write() (or stderr.write), which blows up
because it's not a stringy value.
My change decodes the bytes into strings as they are passed into those
write() methods.
This change made deploy_node() work in my code for Python 3.4.1. I'm not
sure if the same type of bug exists elsewhere, but this fix is what I needed to
unblock myself.
Thanks for the excellent library, and I hope this helps.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/ereyes01/libcloud ssh_decode
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/libcloud/pull/347.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #347
----
commit 166985fb37f1378e59e6fff2cc086252ec861f3a
Author: Eddy Reyes <[email protected]>
Date: 2014-08-14T18:11:28Z
Fix ParamikoSSHClient.run() so that it works in Python 3.4.1 by decoding
incoming bytes into strings using the bytes decode method.
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---