Add hacking rule to enfore no config in tempest.lib

This commit adds a hacking rule to enforce that we never add a config
dependency on tempest/lib. Right now we're completely dependent on
reviewers catching this, it is a strong rule so we should ensure we
can't ever land a change that does this.

Change-Id: I1ab1ba52573c6706a50abcd021759c93dd19aa44
This commit is contained in:
Matthew Treinish 2016-05-31 23:42:55 -04:00
parent aff9cc072b
commit 59d9eaabdd
No known key found for this signature in database
GPG Key ID: FD12A0F214C9E177
3 changed files with 32 additions and 0 deletions

View File

@ -21,6 +21,7 @@ Tempest Specific Commandments
- [T111] Check that service client names of DELETE should be consistent
- [T112] Check that tempest.lib should not import local tempest code
- [T113] Check that tests use data_utils.rand_uuid() instead of uuid.uuid4()
- [T114] Check that tempest.lib does not use tempest config
- [N322] Method's default argument shouldn't be mutable
Test Data/Configuration

View File

@ -257,6 +257,23 @@ def use_rand_uuid_instead_of_uuid4(logical_line, filename):
yield (0, msg)
def dont_use_config_in_tempest_lib(logical_line, filename):
"""Check that tempest.lib doesn't use tempest config
T114
"""
if 'tempest/lib/' not in filename:
return
if ('tempest.config' in logical_line
or 'from tempest import config' in logical_line
or 'oslo_config' in logical_line):
msg = ('T114: tempest.lib can not have any dependency on tempest '
'config.')
yield(0, msg)
def factory(register):
register(import_no_clients_in_api_and_scenario_tests)
register(scenario_tests_need_service_tags)
@ -269,4 +286,5 @@ def factory(register):
register(get_resources_on_service_clients)
register(delete_resources_on_service_clients)
register(dont_import_local_tempest_into_lib)
register(dont_use_config_in_tempest_lib)
register(use_rand_uuid_instead_of_uuid4)

View File

@ -167,3 +167,16 @@ class HackingTestCase(base.TestCase):
self.assertEqual(1, len(list(checks.dont_import_local_tempest_into_lib(
"import tempest.exception",
'./tempest/lib/common/compute.py'))))
def test_dont_use_config_in_tempest_lib(self):
self.assertFalse(list(checks.dont_use_config_in_tempest_lib(
'from tempest import config', './tempest/common/compute.py')))
self.assertFalse(list(checks.dont_use_config_in_tempest_lib(
'from oslo_concurrency import lockutils',
'./tempest/lib/auth.py')))
self.assertTrue(list(checks.dont_use_config_in_tempest_lib(
'from tempest import config', './tempest/lib/auth.py')))
self.assertTrue(list(checks.dont_use_config_in_tempest_lib(
'from oslo_config import cfg', './tempest/lib/decorators.py')))
self.assertTrue(list(checks.dont_use_config_in_tempest_lib(
'import tempest.config', './tempest/lib/common/rest_client.py')))