Fixed SafeConfigParser deprecation warning for py3

Using six.PY3 as configparser.SafeConfigParser in py2 got
renamed to configparser.ConfigParser in py3. In order to
keep the codebase running on both version, we are using
it.

Change-Id: I78471e3d0962cda610c22641787d80103eb413b0
This commit is contained in:
Chandan Kumar 2019-01-03 15:06:27 +05:30
parent d376c37fd6
commit 7c355f403e
2 changed files with 18 additions and 4 deletions

View File

@ -37,6 +37,7 @@ obtained by querying the cloud.
import argparse
import logging
import os
import six
import sys
import os_client_config
@ -132,6 +133,9 @@ def read_deployer_input(deployer_input_file, conf):
"""
LOG.info("Adding options from deployer-input file '%s'",
deployer_input_file)
if six.PY3:
deployer_input = configparser.ConfigParser()
else:
deployer_input = configparser.SafeConfigParser()
deployer_input.read(deployer_input_file)
for section in deployer_input.sections():

View File

@ -14,6 +14,7 @@
# under the License.
import os
import six
import sys
from config_tempest import constants as C
@ -34,6 +35,9 @@ class TempestConf(configparser.SafeConfigParser):
def __init__(self, write_credentials=True, **kwargs):
self.write_credentials = write_credentials
if six.PY3:
configparser.ConfigParser.__init__(self, **kwargs)
else:
configparser.SafeConfigParser.__init__(self, **kwargs)
def get_bool_value(self, value):
@ -101,6 +105,9 @@ class TempestConf(configparser.SafeConfigParser):
if priority:
self.priority_sectionkeys.add((section, key))
C.LOG.debug("Setting [%s] %s = %s", section, key, value)
if six.PY3:
configparser.ConfigParser.set(self, section, key, value)
else:
configparser.SafeConfigParser.set(self, section, key, value)
return True
@ -111,6 +118,9 @@ class TempestConf(configparser.SafeConfigParser):
"writing credentials is disabled.")
self.remove_values(C.ALL_CREDENTIALS_KEYS)
with open(out_path, 'w') as f:
if six.PY3:
configparser.ConfigParser.write(self, f)
else:
configparser.SafeConfigParser.write(self, f)
def remove_values(self, to_remove):