Merge "Replace SafeConfigParser with ConfigParser"

This commit is contained in:
Zuul 2023-01-30 17:43:15 +00:00 committed by Gerrit Code Review
commit 2debfbc72a
3 changed files with 53 additions and 4 deletions

View File

@ -1,10 +1,10 @@
#
# Copyright (c) 2015-2016 Wind River Systems, Inc.
# Copyright (c) 2015-2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import configparser
import six
from six.moves import configparser
from nfv_common.debug._debug_defs import DEBUG_LEVEL
@ -65,7 +65,7 @@ class DebugConfig(object):
Load debug configuration
"""
if self._config is None:
self._config = configparser.SafeConfigParser()
self._config = configparser.ConfigParser()
self._config.read(self._filename)
@property

View File

@ -0,0 +1,50 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import os
from nfv_common import debug
from nfv_common.debug._debug_defs import DEBUG_LEVEL
from nfv_common.debug._debug_module import Debug
from nfv_unit_tests.tests import testcase
class TestDebugConfig(testcase.NFVTestCase):
def setUp(self):
"""Setup for testing."""
super(TestDebugConfig, self).setUp()
def tearDown(self):
"""Cleanup testing setup."""
super(TestDebugConfig, self).tearDown()
def test_create_debug_config(self):
# Debug is a singleton. Its default value is VERBOSE
self.assertEqual(Debug()._debug_level, DEBUG_LEVEL.VERBOSE)
# Parse a debug.ini and see if it changes
dirname = os.path.dirname(__file__)
debug_ini = os.path.join(dirname, '../../../nfv-vim/nfv_vim/debug.ini')
CONF = dict()
CONF['debug'] = dict()
CONF['debug']['config_file'] = debug_ini
debug.debug_initialize(CONF['debug'])
config = debug.debug_get_config()
# assert that the debug CONF was populated
self.assertEqual(CONF['debug']['config_file'], config.get('config_file'))
# assert that the _debug_level has changed
self.assertNotEqual(Debug()._debug_level, DEBUG_LEVEL.VERBOSE)
# locally modify the debug_level
Debug()._debug_level = DEBUG_LEVEL.VERBOSE
self.assertEqual(Debug()._debug_level, DEBUG_LEVEL.VERBOSE)
# call reload_config to undo the local modification
config = debug.debug_reload_config()
self.assertNotEqual(Debug()._debug_level, DEBUG_LEVEL.VERBOSE)

View File

@ -97,7 +97,6 @@ disable=
W1505, # deprecated-method
W1514, # unspecified-encoding
W0237, # arguments-renamed
W4904, # deprecated-class
W4905, # deprecated-decorator
E1101, # no-member
E1111, # assignment-from-no-return