Suppress remaining policy warnings in unit tests
There are few place left in unit tests where policy warnings are still logged. - test_policy which is policy file tests and does policy initialization without suppressing the warnings. - test_serversV21. PolicyFixture takes care of policy setup with no warning things[1] which is used by test base class[2] but test_serversV21 dulicate the policy initialization which leads to log warnings for unit tests. We do not need to initialization policy again and can reply on PolicyFixture setup. From the git history, it was added 7 years ago when no Fixture was available so there is no specific reason of re-initializating the policy in this test. - https://review.opendev.org/#/c/16160/3 [1]4b62c90063/nova/tests/unit/policy_fixture.py (L46)
[2]4b62c90063/nova/test.py (L269)
Change-Id: Ieb3f5510437d38bf2a4c8994d76c7f4001a6c9d8
This commit is contained in:
parent
4b62c90063
commit
324c9b596b
|
@ -256,9 +256,6 @@ class ControllerTest(test.TestCase):
|
|||
|
||||
self.controller = servers.ServersController()
|
||||
self.ips_controller = ips.IPsController()
|
||||
policy.reset()
|
||||
policy.init()
|
||||
self.addCleanup(policy.reset)
|
||||
# Assume that anything that hits the compute API and looks for a
|
||||
# RequestSpec doesn't care about it, since testing logic that deep
|
||||
# should be done in nova.tests.unit.compute.test_compute_api.
|
||||
|
|
|
@ -48,7 +48,9 @@ class PolicyFileTestCase(test.NoDBTestCase):
|
|||
# is_admin or not. As a side-effect, policy reset is needed here
|
||||
# to flush existing policy cache.
|
||||
policy.reset()
|
||||
policy.init()
|
||||
# NOTE(gmann): We do not need to log policy warnings for unit
|
||||
# tests.
|
||||
policy.init(suppress_deprecation_warnings=True)
|
||||
rule = oslo_policy.RuleDefault('example:test', "")
|
||||
policy._ENFORCER.register_defaults([rule])
|
||||
|
||||
|
@ -86,7 +88,9 @@ class PolicyTestCase(test.NoDBTestCase):
|
|||
"role:ADMIN or role:sysadmin"),
|
||||
]
|
||||
policy.reset()
|
||||
policy.init()
|
||||
# NOTE(gmann): We do not need to log policy warnings for unit
|
||||
# tests.
|
||||
policy.init(suppress_deprecation_warnings=True)
|
||||
# before a policy rule can be used, its default has to be registered.
|
||||
policy._ENFORCER.register_defaults(rules)
|
||||
self.context = context.RequestContext('fake', 'fake', roles=['member'])
|
||||
|
@ -232,7 +236,9 @@ class PolicyTestCase(test.NoDBTestCase):
|
|||
class IsAdminCheckTestCase(test.NoDBTestCase):
|
||||
def setUp(self):
|
||||
super(IsAdminCheckTestCase, self).setUp()
|
||||
policy.init()
|
||||
# NOTE(gmann): We do not need to log policy warnings for unit
|
||||
# tests.
|
||||
policy.init(suppress_deprecation_warnings=True)
|
||||
|
||||
def test_init_true(self):
|
||||
check = policy.IsAdminCheck('is_admin', 'True')
|
||||
|
|
Loading…
Reference in New Issue