From 92fb44ce720806b3a34b743cafa1ab27a116927a Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Wed, 19 Apr 2023 12:17:06 +0100 Subject: [PATCH] tests: Disable policy deprecation warnings Change-Id: I8d2710ac7275916bedf186131e5b0f88743c37c1 Signed-off-by: Stephen Finucane --- barbican/common/policy.py | 18 +++++++++++++++++- barbican/tests/api/test_resources_policy.py | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/barbican/common/policy.py b/barbican/common/policy.py index 06bdd8d96..ac872bb3c 100644 --- a/barbican/common/policy.py +++ b/barbican/common/policy.py @@ -37,12 +37,28 @@ def reset(): ENFORCER = None -def init(): +def init(suppress_deprecation_warnings=False): + """Init an Enforcer class. + + :param suppress_deprecation_warnings: Whether to suppress the deprecation + warnings. + """ global ENFORCER global saved_file_rules if not ENFORCER: ENFORCER = policy.Enforcer(CONF) + + # NOTE(gmann): Explictly disable the warnings for policies + # changing their default check_str. During policy-defaults-refresh + # work, all the policy defaults have been changed and warning for + # each policy started filling the logs limit for various tool. + # Once we move to new defaults only world then we can enable these + # warning again. + ENFORCER.suppress_default_change_warnings = True + if suppress_deprecation_warnings: + ENFORCER.suppress_deprecation_warnings = True + register_rules(ENFORCER) ENFORCER.load_rules() diff --git a/barbican/tests/api/test_resources_policy.py b/barbican/tests/api/test_resources_policy.py index 37bab3be4..ca1237175 100644 --- a/barbican/tests/api/test_resources_policy.py +++ b/barbican/tests/api/test_resources_policy.py @@ -42,7 +42,7 @@ TEST_VAR_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), CONF = config.new_config() -policy.init() +policy.init(suppress_deprecation_warnings=True) ENFORCER = policy.ENFORCER