diff --git a/nfv/nfv-common/nfv_common/debug/_debug_config.py b/nfv/nfv-common/nfv_common/debug/_debug_config.py index 6b8d62b8..72ecf8cd 100755 --- a/nfv/nfv-common/nfv_common/debug/_debug_config.py +++ b/nfv/nfv-common/nfv_common/debug/_debug_config.py @@ -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 diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/test_debug_config.py b/nfv/nfv-tests/nfv_unit_tests/tests/test_debug_config.py new file mode 100755 index 00000000..dc02c9e0 --- /dev/null +++ b/nfv/nfv-tests/nfv_unit_tests/tests/test_debug_config.py @@ -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) diff --git a/nfv/pylint.rc b/nfv/pylint.rc index 020e223f..60d6827e 100755 --- a/nfv/pylint.rc +++ b/nfv/pylint.rc @@ -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