Remove use of simplejson throughout code base (#43548)

* Remove use of simplejson throughout code base. Fixes #42761

* Address failing tests

* Remove simplejson from contrib and other outlying files

* Add changelog fragment for simplejson removal
This commit is contained in:
Matt Martz 2018-08-10 11:13:29 -05:00 committed by GitHub
commit c1c229c6d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
55 changed files with 73 additions and 285 deletions

View file

@ -30,10 +30,9 @@ options:
version_added: "1.0"
description:
- Executes a low-down and dirty SSH command, not going through the module
subsystem. This is useful and should only be done in two cases. The
first case is installing C(python-simplejson) on older (Python 2.4 and
before) hosts that need it as a dependency to run modules, since nearly
all core modules require it. Another is speaking to any devices such as
subsystem. This is useful and should only be done in a few cases. A common
case is installing C(python) on a system without python installed by default.
Another is speaking to any devices such as
routers that do not have any Python installed. In any other case, using
the M(shell) or M(command) module is much more appropriate. Arguments
given to C(raw) are run directly through the configured remote shell.
@ -58,9 +57,6 @@ author:
'''
EXAMPLES = '''
- name: Bootstrap a legacy python 2.4 host
raw: yum -y install python-simplejson
- name: Bootstrap a host without python2 installed
raw: dnf install -y python2 python2-dnf libselinux-python
@ -70,5 +66,5 @@ EXAMPLES = '''
executable: /bin/bash
- name: safely use templated variables. Always use quote filter to avoid injection issues.
raw: "{{package_mgr|quote}} {{pkg_flags|quote}} install {{python_simplejson|quote}}"
raw: "{{package_mgr|quote}} {{pkg_flags|quote}} install {{python|quote}}"
'''

View file

@ -497,6 +497,7 @@ EXAMPLES = '''
'''
import datetime
import json
import os
import platform
import socket
@ -508,28 +509,6 @@ from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.module_utils.urls import open_url
HAS_LIB_JSON = True
try:
import json
# Detect the python-json library which is incompatible
# Look for simplejson if that's the case
try:
if (
not isinstance(json.loads, types.FunctionType) or
not isinstance(json.dumps, types.FunctionType)
):
raise ImportError
except AttributeError:
raise ImportError
except ImportError:
try:
import simplejson as json
except ImportError:
HAS_LIB_JSON = False
except SyntaxError:
HAS_LIB_JSON = False
class LogicMonitor(object):
def __init__(self, module, **params):
@ -2148,9 +2127,6 @@ def main():
supports_check_mode=True
)
if HAS_LIB_JSON is not True:
module.fail_json(msg="Unable to load JSON library")
selector(module)

View file

@ -113,30 +113,10 @@ RETURN = '''
...
'''
import json
import socket
import types
HAS_LIB_JSON = True
try:
import json
# Detect the python-json library which is incompatible
# Look for simplejson if that's the case
try:
if (
not isinstance(json.loads, types.FunctionType) or
not isinstance(json.dumps, types.FunctionType)
):
raise ImportError
except AttributeError:
raise ImportError
except ImportError:
try:
import simplejson as json
except ImportError:
HAS_LIB_JSON = False
except SyntaxError:
HAS_LIB_JSON = False
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.module_utils._text import to_native
@ -577,9 +557,6 @@ def main():
supports_check_mode=True
)
if HAS_LIB_JSON is not True:
module.fail_json(msg="Unable to load JSON library")
selector(module)

View file

@ -95,11 +95,7 @@ EXAMPLES = '''
RETURN = '''
'''
try:
import json
except ImportError:
import simplejson as json
import json
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url

View file

@ -64,6 +64,8 @@ EXAMPLES = '''
- name: unsubscribe from common checks
sensu_subscription: name=common state=absent
'''
import json
import traceback
from ansible.module_utils.basic import AnsibleModule
@ -74,11 +76,6 @@ def sensu_subscription(module, path, name, state='present', backup=False):
changed = False
reasons = []
try:
import json
except ImportError:
import simplejson as json
try:
config = json.load(open(path))
except IOError as e:

View file

@ -123,14 +123,7 @@ import re
from ansible.module_utils.basic import AnsibleModule
try:
import json
except ImportError:
try:
import simplejson as json
except ImportError:
# Let snippet from module_utils/basic.py return a proper error in this case
pass
import json
class Npm(object):

View file

@ -114,6 +114,7 @@ EXAMPLES = '''
'''
import glob
import json
import os
import platform
import re
@ -124,11 +125,6 @@ import subprocess
import tempfile
import time
try:
import json
except ImportError:
import simplejson as json
# The distutils module is not shipped with SUNWPython on Solaris.
# It's in the SUNWPython-devel package which also contains development files
# that don't belong on production boxes. Since our Solaris code doesn't

View file

@ -8,10 +8,7 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
try:
import json
except ImportError:
import simplejson as json
import json
import shlex
import shutil
import os