diff --git a/HACKING.rst b/HACKING.rst index b66fa24d7f..0f8a5630a4 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -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 diff --git a/tempest/hacking/checks.py b/tempest/hacking/checks.py index 5943adfce0..d8f25ab5c3 100644 --- a/tempest/hacking/checks.py +++ b/tempest/hacking/checks.py @@ -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) diff --git a/tempest/tests/test_hacking.py b/tempest/tests/test_hacking.py index aba2aabce3..f005c219fb 100644 --- a/tempest/tests/test_hacking.py +++ b/tempest/tests/test_hacking.py @@ -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')))