From 34c5178c11747df719d1f6a7e9f9d3a509ed3f84 Mon Sep 17 00:00:00 2001 From: Al Bailey Date: Mon, 23 Jan 2023 17:52:11 +0000 Subject: [PATCH] Replace SafeConfigParser with ConfigParser 'SafeConfigParser' is a deprecated class. Replace the reference to it with its non-deprecated counterpart called 'ConfigParser' This change only affects how the debug.ini file is loaded, which is a file used for setting log levels within NFV. The change is not meant to affect any runtime behaviour. The intention of this code change is for this to behave the same as using SafeConfigParser. pylint was reporting this as a deprecated class (W4904) Test Plan: PASS: added a new unit test to verify coverage PASS: build ISO and unlock AIO-SX and verify vim working and startup logs appear unchanged Story: 2010531 Task: 47215 Signed-off-by: Al Bailey Change-Id: Id0c22f9847489b171c28c11f8d8215902d444241 --- .../nfv_common/debug/_debug_config.py | 6 +-- .../nfv_unit_tests/tests/test_debug_config.py | 50 +++++++++++++++++++ nfv/pylint.rc | 1 - 3 files changed, 53 insertions(+), 4 deletions(-) create mode 100755 nfv/nfv-tests/nfv_unit_tests/tests/test_debug_config.py 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