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

* refactor configparser import to support python3

* change ModuleNotFoundError to ImportError
pull/23568/merge
Thomas Stringer 7 years ago committed by Toshio Kuratomi
parent e859d0da9c
commit cb01f33d1e

@ -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

Loading…
Cancel
Save