Fix check_config_option_in_central_place

Updated check_config_option_in_central_place. All options with one exception
were moved to central location. Added list that tracks these exceptions.

Also nova/tests should be treated as an exception - there is another check
that validates if config options are not registered in tests.

Closes-Bug: #1613411
Blueprint centralize-config-options-ocata

Change-Id: I802aaf61e711eb4cfa206e4a52e969128dee2189
This commit is contained in:
Maciej Szankin 2016-08-15 13:50:19 -05:00
parent c4ce5f1104
commit 8ddf174a30
2 changed files with 25 additions and 17 deletions

View File

@ -647,17 +647,21 @@ def check_config_option_in_central_place(logical_line, filename):
# That's the correct location
if "nova/conf/" in filename:
return
# TODO(markus_z) This is just temporary until all config options are
# moved to the central place. To avoid that a once cleaned up place
# introduces new config options, we do a check here. This array will
# get quite huge over the time, but will be removed at the end of the
# reorganization.
# You can add the full path to a module or folder. It's just a substring
# check, which makes it flexible enough.
cleaned_up = ["nova/console/serial.py",
"nova/cmd/serialproxy.py",
]
if not any(c in filename for c in cleaned_up):
# (macsz) All config options (with exceptions that are clarified
# in the list below) were moved to the central place. List below is for
# all options that were impossible to move without doing a major impact
# on code. Add full path to a module or folder.
conf_exceptions = [
# CLI opts are allowed to be outside of nova/conf directory
'nova/cmd/manage.py',
'nova/cmd/policy_check.py',
# config options should not be declared in tests, but there is
# another checker for it (N320)
'nova/tests',
]
if any(f in filename for f in conf_exceptions):
return
if cfg_opt_re.match(logical_line):

View File

@ -613,18 +613,22 @@ class HackingTestCase(test.NoDBTestCase):
self._assert_has_no_errors(code,
checks.check_config_option_in_central_place,
filename="nova/conf/serial_console.py")
# option at a location which is not in scope right now
# TODO(markus_z): This is temporary until all config options are
# moved to /nova/conf
self._assert_has_no_errors(code,
checks.check_config_option_in_central_place,
filename="nova/dummy/non_existent.py")
# option at the wrong place in the tree
self._assert_has_errors(code,
checks.check_config_option_in_central_place,
filename="nova/cmd/serialproxy.py",
expected_errors=errors)
# option at a location which is marked as an exception
# TODO(macsz) remove testing exceptions as they are removed from
# check_config_option_in_central_place
self._assert_has_no_errors(code,
checks.check_config_option_in_central_place,
filename="nova/cmd/manage.py")
self._assert_has_no_errors(code,
checks.check_config_option_in_central_place,
filename="nova/tests/dummy_test.py")
def test_check_doubled_words(self):
errors = [(1, 0, "N343")]