Fix Decode Bug in Py3 (#61691)

* Fix Decode Bug in Py3

* Update fortios.py

* Remove special char from name

* Ensure full compatibility when ansible is install from Py2
pull/61735/head
Miguel Angel Muñoz González 5 years ago committed by Nathaniel Case
parent 411b208147
commit 6cf025425e

@ -25,13 +25,13 @@
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
#
import os
import time
import traceback
from ansible.module_utils._text import to_native
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import env_fallback
import json
@ -117,11 +117,11 @@ class FortiOSHandler(object):
if status == 200:
if vdom == "global":
return json.loads(result_data.decode('utf-8'))[0]['results']
return json.loads(to_text(result_data))[0]['results']
else:
return json.loads(result_data.decode('utf-8'))['results']
return json.loads(to_text(result_data))['results']
else:
return json.loads(result_data.decode('utf-8'))
return json.loads(to_text(result_data))
def get_mkeyname(self, path, name, vdom=None):
schema = self.schema(path, name, vdom=vdom)
@ -200,10 +200,10 @@ class FortiOSHandler(object):
def formatresponse(self, res, vdom=None):
if vdom == "global":
resp = json.loads(res.decode('utf-8'))[0]
resp = json.loads(to_text(res))[0]
resp['vdom'] = "global"
else:
resp = json.loads(res.decode('utf-8'))
resp = json.loads(to_text(res))
return resp
# BEGIN DEPRECATED
@ -253,7 +253,7 @@ class AnsibleFortios(object):
try:
self.forti_device.open()
except Exception as e:
self.module.fail_json(msg='Error connecting device. %s' % to_native(e),
self.module.fail_json(msg='Error connecting device. %s' % to_text(e),
exception=traceback.format_exc())
def load_config(self, path):
@ -266,7 +266,7 @@ class AnsibleFortios(object):
running = f.read()
f.close()
except IOError as e:
self.module.fail_json(msg='Error reading configuration file. %s' % to_native(e),
self.module.fail_json(msg='Error reading configuration file. %s' % to_text(e),
exception=traceback.format_exc())
self.forti_device.load_config(config_text=running, path=path)
@ -276,7 +276,7 @@ class AnsibleFortios(object):
self.forti_device.load_config(path=path)
except Exception as e:
self.forti_device.close()
self.module.fail_json(msg='Error reading running config. %s' % to_native(e),
self.module.fail_json(msg='Error reading running config. %s' % to_text(e),
exception=traceback.format_exc())
# set configs in object
@ -302,7 +302,7 @@ class AnsibleFortios(object):
f.close()
except IOError as e:
self.module.fail_json(msg='Error writing configuration file. %s' %
to_native(e), exception=traceback.format_exc())
to_text(e), exception=traceback.format_exc())
else:
try:
self.forti_device.commit()

@ -33,7 +33,7 @@ __metaclass__ = type
DOCUMENTATION = """
---
author:
- Miguel Angel Muñoz (@magonzalez)
- Miguel Angel Munoz (@magonzalez)
httpapi : fortios
short_description: HttpApi Plugin for Fortinet FortiOS Appliance or VM
description:
@ -43,7 +43,7 @@ version_added: "2.9"
from ansible.plugins.httpapi import HttpApiBase
from ansible.module_utils.basic import to_text
import urllib
from ansible.module_utils.six.moves import urllib
import json
import re

Loading…
Cancel
Save