refactor azure dynamic inventory script configparser import to support python3 (#31370)

* refactor configparser import to support python3

* change ModuleNotFoundError to ImportError
This commit is contained in:
Thomas Stringer 2017-10-05 14:49:35 -04:00 committed by Toshio Kuratomi
parent e859d0da9c
commit cb01f33d1e

View file

@ -187,14 +187,18 @@ Version: 1.0.0
''' '''
import argparse import argparse
import ConfigParser
import json import json
import os import os
import re import re
import sys import sys
import inspect import inspect
import traceback
try:
# python2
import ConfigParser as cp
except ImportError:
# python3
import configparser as cp
from packaging.version import Version from packaging.version import Version
@ -326,7 +330,7 @@ class AzureRM(object):
path = expanduser("~") path = expanduser("~")
path += "/.azure/credentials" path += "/.azure/credentials"
try: try:
config = ConfigParser.ConfigParser() config = cp.ConfigParser()
config.read(path) config.read(path)
except Exception as exc: except Exception as exc:
self.fail("Failed to access {0}. Check that the file exists and you have read " self.fail("Failed to access {0}. Check that the file exists and you have read "
@ -795,7 +799,7 @@ class AzureInventory(object):
config = None config = None
settings = None settings = None
try: try:
config = ConfigParser.ConfigParser() config = cp.ConfigParser()
config.read(path) config.read(path)
except: except:
pass pass