Use ansible.module_utils.six in inventory scripts (#55000)

* Use six from ansible.module_utils for inventory scripts

Remove skips from sanity test

* Change all imports of ConfigParser to use module_utils.six.moves

* Remove commented out lines

* Fix six imports
This commit is contained in:
Sam Doran 2019-04-09 13:17:59 -04:00 committed by Sloane Hertel
parent 97f706810c
commit 3cd98a9fcc
33 changed files with 48 additions and 109 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- use ansible.module_utils.six for all scripts in contrib/inventory

View file

@ -44,10 +44,10 @@ imagetemplate: Creates a host group for each image template containing all hosts
import os import os
import sys import sys
import time import time
import ConfigParser
import json import json
from ansible.module_utils.six.moves import configparser as ConfigParser
from ansible.module_utils.urls import open_url from ansible.module_utils.urls import open_url

View file

@ -35,9 +35,9 @@ import os
import argparse import argparse
import re import re
from time import time from time import time
import ConfigParser
from six import iteritems, string_types from ansible.module_utils.six import iteritems, string_types
from ansible.module_utils.six.moves import configparser as ConfigParser
from libcloud.compute.types import Provider from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver from libcloud.compute.providers import get_driver
import libcloud.security as sec import libcloud.security as sec

View file

@ -201,14 +201,8 @@ import re
import sys import sys
import inspect import inspect
try:
# python2
import ConfigParser as cp
except ImportError:
# python3
import configparser as cp
from os.path import expanduser from os.path import expanduser
from ansible.module_utils.six.moves import configparser as cp
import ansible.module_utils.six.moves.urllib.parse as urlparse import ansible.module_utils.six.moves.urllib.parse as urlparse
HAS_AZURE = True HAS_AZURE = True

View file

@ -79,10 +79,7 @@ Version: 0.2
import sys import sys
import os import os
try: from ansible.module_utils.six.moves.configparser import SafeConfigParser as ConfigParser
from ConfigParser import SafeConfigParser as ConfigParser
except ImportError:
from configparser import ConfigParser
import json import json

View file

@ -59,7 +59,6 @@ Changelog:
###################################################################### ######################################################################
import argparse import argparse
import ConfigParser
import os import os
import re import re
from time import time from time import time
@ -67,7 +66,8 @@ import xmlrpclib
import json import json
from six import iteritems from ansible.module_utils.six import iteritems
from ansible.module_utils.six.moves import configparser as ConfigParser
# NOTE -- this file assumes Ansible is being accessed FROM the cobbler # NOTE -- this file assumes Ansible is being accessed FROM the cobbler
# server, so it does not attempt to login with a username and password. # server, so it does not attempt to login with a username and password.

View file

@ -67,7 +67,6 @@ Tested against Ansible 1.8.2 and Collins 1.3.0.
import argparse import argparse
import ConfigParser
import logging import logging
import os import os
import re import re
@ -77,8 +76,9 @@ import traceback
import json import json
from six import iteritems from ansible.module_utils.six import iteritems
from six.moves.urllib.parse import urlencode from ansible.module_utils.six.moves import configparser as ConfigParser
from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.module_utils.urls import open_url from ansible.module_utils.urls import open_url

View file

@ -136,10 +136,7 @@ import re
import argparse import argparse
import sys import sys
try: from ansible.module_utils.six.moves import configparser
import configparser
except ImportError:
import ConfigParser as configparser
def get_log_filename(): def get_log_filename():
@ -201,7 +198,7 @@ except ImportError as e:
sys.exit("""failed=True msg='python-consul required for this module. sys.exit("""failed=True msg='python-consul required for this module.
See https://python-consul.readthedocs.io/en/latest/#installation'""") See https://python-consul.readthedocs.io/en/latest/#installation'""")
from six import iteritems from ansible.module_utils.six import iteritems
class ConsulInventory(object): class ConsulInventory(object):

View file

@ -166,9 +166,10 @@ from boto import rds
from boto import elasticache from boto import elasticache
from boto import route53 from boto import route53
from boto import sts from boto import sts
import six
from ansible.module_utils import six
from ansible.module_utils import ec2 as ec2_utils from ansible.module_utils import ec2 as ec2_utils
from ansible.module_utils.six.moves import configparser
HAS_BOTO3 = False HAS_BOTO3 = False
try: try:
@ -177,7 +178,6 @@ try:
except ImportError: except ImportError:
pass pass
from six.moves import configparser
from collections import defaultdict from collections import defaultdict
import json import json

View file

@ -22,12 +22,6 @@
# Stdlib imports # Stdlib imports
# __future__ imports must occur at the beginning of file # __future__ imports must occur at the beginning of file
from __future__ import print_function from __future__ import print_function
try:
# Python 2 version
import ConfigParser
except ImportError:
# Python 3 version
import configparser as ConfigParser
import json import json
import argparse import argparse
import copy import copy
@ -47,6 +41,7 @@ if LooseVersion(requests.__version__) < LooseVersion('1.1.0'):
from requests.auth import HTTPBasicAuth from requests.auth import HTTPBasicAuth
from ansible.module_utils._text import to_text from ansible.module_utils._text import to_text
from ansible.module_utils.six.moves import configparser as ConfigParser
def json_format_dict(data, pretty=False): def json_format_dict(data, pretty=False):

View file

@ -8,7 +8,7 @@ import json
import os import os
import sys import sys
from ipalib import api, errors, __version__ as IPA_VERSION from ipalib import api, errors, __version__ as IPA_VERSION
from six import u from ansible.module_utils.six import u
def initialize(): def initialize():

View file

@ -80,10 +80,7 @@ import argparse
from time import time from time import time
if sys.version_info >= (3, 0): from ansible.module_utils.six.moves import configparser
import configparser
else:
import ConfigParser as configparser
import logging import logging
logging.getLogger('libcloud.common.google').addHandler(logging.NullHandler()) logging.getLogger('libcloud.common.google').addHandler(logging.NullHandler())

View file

@ -108,7 +108,7 @@ except Exception:
load_chube_config() load_chube_config()
# Imports for ansible # Imports for ansible
import ConfigParser from ansible.module_utils.six.moves import configparser as ConfigParser
class LinodeInventory(object): class LinodeInventory(object):

View file

@ -27,10 +27,8 @@ from subprocess import Popen, PIPE
import distutils.spawn import distutils.spawn
import sys import sys
import json import json
try:
import configparser from ansible.module_utils.six.moves import configparser
except Exception:
from six.moves import configparser
# Set up defaults # Set up defaults
resource = 'local:' resource = 'local:'

View file

@ -27,10 +27,7 @@ maintainer: J Barnett (github @jbarnett1981)
import argparse import argparse
import json import json
import pymssql import pymssql
try: from ansible.module_utils.six.moves import configparser
import configparser
except ImportError:
import ConfigParser as configparser
class MDTInventory(object): class MDTInventory(object):

View file

@ -36,11 +36,7 @@ import re
import argparse import argparse
import sys import sys
try: from ansible.module_utils.six.moves import configparser
import configparser
except ImportError:
import ConfigParser
configparser = ConfigParser
import json import json
try: try:

View file

@ -29,11 +29,7 @@ Configuration is read from `nagios_ndo.ini`.
import os import os
import argparse import argparse
import sys import sys
try: from ansible.module_utils.six.moves import configparser
import configparser
except ImportError:
import ConfigParser
configparser = ConfigParser
import json import json
try: try:

View file

@ -148,7 +148,7 @@ from pynsot.client import get_api_client
from pynsot.app import HttpServerError from pynsot.app import HttpServerError
from click.exceptions import UsageError from click.exceptions import UsageError
from six import string_types from ansible.module_utils.six import string_types
def warning(*objs): def warning(*objs):

View file

@ -32,10 +32,10 @@ import json
import os import os
import os.path import os.path
import sys import sys
import ConfigParser
import StringIO import StringIO
from ansible.module_utils.urls import open_url from ansible.module_utils.urls import open_url
from ansible.module_utils.six.moves import configparser as ConfigParser
configparser = None configparser = None

View file

@ -68,8 +68,8 @@ USER_AGENT_VERSION = "v1"
import sys import sys
import os import os
import argparse import argparse
import ConfigParser
from collections import defaultdict from collections import defaultdict
from ansible.module_utils.six.moves import configparser as ConfigParser
import json import json

View file

@ -65,10 +65,7 @@ import sys
from collections import defaultdict from collections import defaultdict
try: from ansible.module_utils.six.moves import configparser
import ConfigParser as configparser
except ImportError:
import configparser
import json import json

View file

@ -43,9 +43,9 @@ import os
import argparse import argparse
import re import re
from time import time from time import time
import six
from six.moves import configparser from ansible.module_utils import six
from ansible.module_utils.six.moves import configparser
try: try:
import packet import packet

View file

@ -30,8 +30,8 @@ import os
import sys import sys
from optparse import OptionParser from optparse import OptionParser
from six import iteritems from ansible.module_utils.six import iteritems
from six.moves.urllib.parse import urlencode from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.module_utils.urls import open_url from ansible.module_utils.urls import open_url

View file

@ -151,9 +151,9 @@ import sys
import argparse import argparse
import warnings import warnings
import collections import collections
import ConfigParser
from six import iteritems from ansible.module_utils.six import iteritems
from ansible.module_utils.six.moves import configparser as ConfigParser
import json import json

View file

@ -53,9 +53,9 @@ import sys
import os import os
import re import re
import argparse import argparse
import six
import httplib2 as http import httplib2 as http
from time import time from time import time
from ansible.module_utils import six
from ansible.module_utils.six.moves import configparser from ansible.module_utils.six.moves import configparser
from ansible.module_utils.six.moves.urllib.parse import urlparse from ansible.module_utils.six.moves.urllib.parse import urlparse

View file

@ -41,8 +41,8 @@ all: Contains all hosts defined in Scaleway.
import copy import copy
import os import os
import requests import requests
import six from ansible.module_utils import six
from six.moves import configparser from ansible.module_utils.six.moves import configparser
import sys import sys
import time import time
import traceback import traceback

View file

@ -47,10 +47,10 @@ import os
import time import time
from optparse import OptionParser from optparse import OptionParser
import subprocess import subprocess
import ConfigParser
import json import json
from six import iteritems from ansible.module_utils.six import iteritems
from ansible.module_utils.six.moves import configparser as ConfigParser
base_dir = os.path.dirname(os.path.realpath(__file__)) base_dir = os.path.dirname(os.path.realpath(__file__))

View file

@ -38,10 +38,9 @@ import ssl
import sys import sys
import time import time
from six import integer_types, text_type, string_types
from six.moves import configparser
from ansible.module_utils.common._collections_compat import MutableMapping from ansible.module_utils.common._collections_compat import MutableMapping
from ansible.module_utils.six import integer_types, text_type, string_types
from ansible.module_utils.six.moves import configparser
# Disable logging message trigged by pSphere/suds. # Disable logging message trigged by pSphere/suds.
try: try:

View file

@ -39,8 +39,9 @@ import uuid
from time import time from time import time
from jinja2 import Environment from jinja2 import Environment
from six import integer_types, PY3
from six.moves import configparser from ansible.module_utils.six import integer_types, PY3
from ansible.module_utils.six.moves import configparser
try: try:
import argparse import argparse

View file

@ -38,10 +38,7 @@ from __future__ import print_function
import os import os
import sys import sys
import argparse import argparse
try: from ansible.module_utils.six.moves import configparser
import ConfigParser as configparser
except ImportError:
import configparser
try: try:
from zabbix_api import ZabbixAPI from zabbix_api import ZabbixAPI

View file

@ -122,12 +122,7 @@ import sys
import inspect import inspect
from azure.keyvault import KeyVaultClient from azure.keyvault import KeyVaultClient
try: from ansible.module_utils.six.moves import configparser as cp
# python2
import ConfigParser as cp
except ImportError:
# python3
import configparser as cp
from os.path import expanduser from os.path import expanduser
import ansible.module_utils.six.moves.urllib.parse as urlparse import ansible.module_utils.six.moves.urllib.parse as urlparse

View file

@ -35,12 +35,12 @@ import jinja2
import yaml import yaml
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
from jinja2.runtime import Undefined from jinja2.runtime import Undefined
from six import iteritems, string_types
from ansible.errors import AnsibleError from ansible.errors import AnsibleError
from ansible.module_utils._text import to_bytes, to_text from ansible.module_utils._text import to_bytes, to_text
from ansible.module_utils.common.collections import is_sequence from ansible.module_utils.common.collections import is_sequence
from ansible.module_utils.parsing.convert_bool import boolean from ansible.module_utils.parsing.convert_bool import boolean
from ansible.module_utils.six import iteritems, string_types
from ansible.plugins.loader import fragment_loader from ansible.plugins.loader import fragment_loader
from ansible.utils import plugin_docs from ansible.utils import plugin_docs
from ansible.utils.display import Display from ansible.utils.display import Display

View file

@ -11,25 +11,6 @@ def main():
# digital_ocean is checking for six because dopy doesn't specify the # digital_ocean is checking for six because dopy doesn't specify the
# requirement on six so it needs to try importing six to give the correct error message # requirement on six so it needs to try importing six to give the correct error message
'lib/ansible/modules/cloud/digital_ocean/digital_ocean.py', 'lib/ansible/modules/cloud/digital_ocean/digital_ocean.py',
# correct imports in the following files and remove them from this list
'contrib/inventory/apache-libcloud.py',
'contrib/inventory/cobbler.py',
'contrib/inventory/collins.py',
'contrib/inventory/consul_io.py',
'contrib/inventory/ec2.py',
'contrib/inventory/freeipa.py',
'contrib/inventory/lxd.py',
'contrib/inventory/nova.py',
'contrib/inventory/nsot.py',
'contrib/inventory/packet_net.py',
'contrib/inventory/proxmox.py',
'contrib/inventory/rax.py',
'contrib/inventory/rudder.py',
'contrib/inventory/scaleway.py',
'contrib/inventory/spacewalk.py',
'contrib/inventory/vmware.py',
'contrib/inventory/vmware_inventory.py',
'docs/bin/plugin_formatter.py',
]) ])
for path in sys.argv[1:] or sys.stdin.read().splitlines(): for path in sys.argv[1:] or sys.stdin.read().splitlines():