Skip to content

Commit

Permalink
Merge pull request #136 from ktbyers/py3_support
Browse files Browse the repository at this point in the history
PY3 support
  • Loading branch information
ktbyers authored Jul 9, 2018
2 parents c0e5c00 + 25ef406 commit 8e8639b
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ language: python

python:
- 2.7
- 3.5
- 3.6

env:
- ANSIBLE_VERSION=2.2
- ANSIBLE_VERSION=2.3
- ANSIBLE_VERSION=2.4
- ANSIBLE_VERSION=2.5
- ANSIBLE_VERSION=2.6

install:
- pip install pylama
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
develop
=====

- Add Python3 support
- Add support for saving `candidate_file` during the config install
- Fix issue with an exception in napalm_install_config

Expand Down
1 change: 1 addition & 0 deletions napalm_ansible/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals, print_function
import os
import ansible
from distutils.version import LooseVersion
Expand Down
1 change: 1 addition & 0 deletions napalm_ansible/modules/napalm_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals, print_function
from ansible.module_utils.basic import AnsibleModule, return_values


Expand Down
2 changes: 1 addition & 1 deletion napalm_ansible/modules/napalm_diff_yang.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
(c) 2017 David Barroso <[email protected]>
Expand All @@ -19,6 +18,7 @@
You should have received a copy of the GNU General Public License
along with Ansible. If not, see <http://www.gnu.org/licenses/>.
"""
from __future__ import unicode_literals, print_function
from ansible.module_utils.basic import AnsibleModule

try:
Expand Down
1 change: 1 addition & 0 deletions napalm_ansible/modules/napalm_get_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with Ansible. If not, see <http://www.gnu.org/licenses/>.
"""
from __future__ import unicode_literals, print_function
from ansible.module_utils.basic import AnsibleModule, return_values


Expand Down
8 changes: 3 additions & 5 deletions napalm_ansible/modules/napalm_install_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
You should have received a copy of the GNU General Public License
along with Ansible. If not, see <http://www.gnu.org/licenses/>.
"""
from __future__ import unicode_literals, print_function
from ansible.module_utils.basic import AnsibleModule, return_values


Expand Down Expand Up @@ -175,11 +176,8 @@


def save_to_file(content, filename):
f = open(filename, 'w')
try:
with open(filename, 'w') as f:
f.write(content)
finally:
f.close()


def main():
Expand Down Expand Up @@ -288,7 +286,7 @@ def main():

try:
if get_diffs:
diff = device.compare_config().encode('utf-8')
diff = device.compare_config()
changed = len(diff) > 0
else:
changed = True
Expand Down
2 changes: 1 addition & 1 deletion napalm_ansible/modules/napalm_parse_yang.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
You should have received a copy of the GNU General Public License
along with Ansible. If not, see <http://www.gnu.org/licenses/>.
"""
# standard ansible module imports
from __future__ import unicode_literals, print_function
from ansible.module_utils.basic import AnsibleModule, return_values
import json

Expand Down
5 changes: 3 additions & 2 deletions napalm_ansible/modules/napalm_ping.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from ansible.module_utils.basic import AnsibleModule, return_values

"""
(c) 2017 Jason Edelman <[email protected]>
Expand All @@ -15,6 +13,9 @@
You should have received a copy of the GNU General Public License
along with Ansible. If not, see <http://www.gnu.org/licenses/>.
"""
from __future__ import unicode_literals, print_function
from ansible.module_utils.basic import AnsibleModule, return_values


DOCUMENTATION = '''
---
Expand Down
3 changes: 1 addition & 2 deletions napalm_ansible/modules/napalm_translate_yang.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
(c) 2017 David Barroso <[email protected]>
Expand All @@ -19,7 +18,7 @@
You should have received a copy of the GNU General Public License
along with Ansible. If not, see <http://www.gnu.org/licenses/>.
"""
# standard ansible module imports
from __future__ import unicode_literals, print_function
from ansible.module_utils.basic import AnsibleModule

try:
Expand Down
1 change: 1 addition & 0 deletions napalm_ansible/modules/napalm_validate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals, print_function
from ansible.module_utils.basic import AnsibleModule, return_values

napalm_found = False
Expand Down
2 changes: 1 addition & 1 deletion napalm_ansible/plugins/action/napalm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import (absolute_import, division, print_function)
from __future__ import absolute_import, division, print_function, unicode_literals
__metaclass__ = type

from ansible.plugins.action.normal import ActionModule as _ActionModule
Expand Down
3 changes: 2 additions & 1 deletion tests/napalm_get_facts/get_facts_error.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@
var: ansible_failed_result.msg
- assert:
that:
- "{{ ansible_failed_result.msg == \"[interfaces] cannot retrieve device data: u'Key blah is not present'\" }}"
- "{{ '[interfaces] cannot retrieve device data' in ansible_failed_result.msg }}"
- "{{ 'Key blah is not present' in ansible_failed_result.msg }}"

0 comments on commit 8e8639b

Please sign in to comment.