Closed ktbyers closed 9 years ago
The following components are the main changes needed for the netmiko library to be compatible with Python 2 and Python 3.
if debug:
print("In set_base_prompt")
from netmiko.cisco.cisco_ios_ssh import CiscoIosSSH
or
from . cisco_ios_ssh import CiscoIosSSH
instead of
from cisco_ios_ssh import CiscoIosSSH
output = self.remote_conn.recv(MAX_BUFFER).decode('utf-8')
io
module's open()
method should be used, as it has an encoding
argument just like the builtin open
function in Python 3. This will take care of any input bytes read from disk entering the program.import io
with io.open(config_file, encoding='utf-8') as cfg_file:
return self.send_config_set(cfg_file, **kwargs)
chr(27)
will continue working under Python3 without modification, as ASCII values map directly to the same values in Unicode code points.except IOError as (errno, strerr):
print("I/O Error {0}: {1}".format(errno, strerr))
except IOError as e:
errno, strerr = e.args
print("I/O Error {0}: {1}".format(errno, strerr))
These are the main factors that would need to change in order to be compatible with Python3.
io.open
and the as exc_var
syntax are not supported in Python versions older than 2.6print()
requires a from __future__ import print_function
for Python 2.6.decode('utf-8')
stuff can probably be omitted if you go with from __future__ import unicode_literals
but would have to test that (also only Python 2.6 upwards)@daenney I missed this comment earlier. Let me know if you are interested in working on this Python3 support for netmiko. There is a good chance Pablo and I are going to work on it. I want to look at it some this weekend.
For Python2, we are only going to support Python2.6 and Python2.7.
I've done some porting of codebases to be Python2.6+ compatible so I can certainly help out but I don't have access to any of the hardware to actually test this stuff. Especially the unicode handling makes me a bit nervous.
@plucena24 I think all of the imports use absolute paths now.
@daenney Yes, I should have the ability to test on Cisco IOS, Cisco IOS XE, ASA, HP ProCurve, and Juniper. I think @plucena24 has the ability to test on NX-OS, and IOS-XR as well as some of the same platforms that I have.
I am thinking about setting up Travis-CI so that we could test on PY2.6, 2.7, 3.3 and 3.4 and automate some of the testing.
I assume that we would do a single integrated code that would support PY2.6, 2.7, 3.3, and 3.4?
@ktbyers yes, that would be the preferred route in my opinion - having a single package that works on both.
Created python3_port branch
I have ran unit tests on this using Python 3.4.3 and Python 2.6.9 using Cisco IOS, Juniper, HP ProCurve, and Arista. And Cisco ASA on Python 2.6.9 (still need to test ASA on Python 3.4.3).
These all pass.
It would be good test Cisco NX-OS, IOS-XR, and IOS-XE. I can probably test IOS-XE.
@plucena24 Let me know if you can test on NX-OS, and IOS-XR? I can help getting the tests running if TESTING.md is not clear.
I am working on that at the moment...was having issues installing paramilo for py3.4 on windows, got it sorted out now. On Mon, May 4, 2015 at 3:55 PM Kirk Byers notifications@github.com wrote:
@plucena24 https://github.com/plucena24 Let me know if you can test on NX-OS, and IOS-XR? I can help getting the tests running if TESTING.md is not clear.
— Reply to this email directly or view it on GitHub https://github.com/ktbyers/netmiko/issues/84#issuecomment-98847435.
I've had a look at the python_3 branch, so far so good as far as I can tell. Do network vendors still not provide some kind of virtual lab facility that would allow to (automate) test against a variety of their hardware?
@daenney There are various things available for testing. It seems like virtual devices in your own test environment is probably the easiest way to go, however.
@plucena24 FYI, I have merged this python3_port code back into the master branch.
Time to close the issue then :)
Yep...
Placeholder to figure out the issues involved in doing htis.