From 5d58e71fbd2869de0979287ed9f0f2c3cf8a19c3 Mon Sep 17 00:00:00 2001 From: Ben Pope Date: Fri, 22 Nov 2024 15:20:18 +0000 Subject: [PATCH] ducktape: Centralise has_license_nag Signed-off-by: Ben Pope --- tests/rptest/services/redpanda.py | 5 +++++ tests/rptest/tests/audit_log_test.py | 3 ++- tests/rptest/tests/rbac_test.py | 8 ++------ tests/rptest/tests/rbac_upgrade_test.py | 6 +----- tests/rptest/tests/redpanda_kerberos_test.py | 8 ++------ tests/rptest/tests/redpanda_oauth_test.py | 8 ++------ tests/rptest/tests/redpanda_startup_test.py | 8 ++------ tests/rptest/tests/schema_registry_test.py | 8 ++------ tests/rptest/tests/workload_license.py | 3 +-- 9 files changed, 19 insertions(+), 38 deletions(-) diff --git a/tests/rptest/services/redpanda.py b/tests/rptest/services/redpanda.py index 40072eea8d74..cbb641e96476 100644 --- a/tests/rptest/services/redpanda.py +++ b/tests/rptest/services/redpanda.py @@ -2477,6 +2477,8 @@ def copy_from_pod(params): class RedpandaService(RedpandaServiceBase): + ENTERPRISE_LICENSE_NAG = "license is required to use enterprise features" + nodes: list[ClusterNode] def __init__(self, @@ -5414,6 +5416,9 @@ def license_observable(): err_msg="Inserted license not observable in time") self.logger.debug("Enterprise License installed successfully") + def has_license_nag(self): + return self.search_log_any(self.ENTERPRISE_LICENSE_NAG) + def make_redpanda_service(context: TestContext, num_brokers: int | None, diff --git a/tests/rptest/tests/audit_log_test.py b/tests/rptest/tests/audit_log_test.py index f9ab3cf9dac1..ac238b40c6da 100644 --- a/tests/rptest/tests/audit_log_test.py +++ b/tests/rptest/tests/audit_log_test.py @@ -2252,7 +2252,8 @@ def test_sanctioning_mode(self): self.super_rpk.consume(self.audit_log) self.redpanda.search_log_any( - "An enterprise license is required to consume the audit log topic") + f"{self.redpanda.ENTERPRISE_LICENSE_NAG} to consume the audit log topic" + ) self.redpanda.logger.debug( "Install a license to get out of sanctioning mode") diff --git a/tests/rptest/tests/rbac_test.py b/tests/rptest/tests/rbac_test.py index feceb57f195c..9f3b94c022b5 100644 --- a/tests/rptest/tests/rbac_test.py +++ b/tests/rptest/tests/rbac_test.py @@ -633,10 +633,6 @@ def __init__(self, test_ctx, **kwargs): f'{self.LICENSE_CHECK_INTERVAL_SEC}' }) - def _has_license_nag(self): - return self.redpanda.search_log_any( - "license is required to use enterprise features") - def _license_nag_is_set(self): return self.redpanda.search_log_all( f"Overriding default license log annoy interval to: {self.LICENSE_CHECK_INTERVAL_SEC}s" @@ -653,7 +649,7 @@ def test_license_nag(self): time.sleep(self.LICENSE_CHECK_INTERVAL_SEC * 2) # NOTE: This assertion will FAIL if running in FIPS mode because # being in FIPS mode will trigger the license nag - assert not self._has_license_nag() + assert not self.redpanda.has_license_nag() self.logger.debug("Adding a role") self.superuser_admin.create_role(role=self.role_name0) @@ -667,7 +663,7 @@ def test_license_nag(self): err_msg="Failed to set license nag internal") self.logger.debug("Waiting for license nag") - wait_until(self._has_license_nag, + wait_until(self.redpanda.has_license_nag, timeout_sec=self.LICENSE_CHECK_INTERVAL_SEC * 2, err_msg="License nag failed to appear") diff --git a/tests/rptest/tests/rbac_upgrade_test.py b/tests/rptest/tests/rbac_upgrade_test.py index 553fb4b5440f..39b0db115747 100644 --- a/tests/rptest/tests/rbac_upgrade_test.py +++ b/tests/rptest/tests/rbac_upgrade_test.py @@ -41,10 +41,6 @@ def setUp(self): self.installer.install(self.redpanda.nodes, (23, 3)) super().setUp() - def _has_license_nag(self): - return self.redpanda.search_log_any( - "license is required to use enterprise features") - @cluster(num_nodes=3, log_allow_list=RESTART_LOG_ALLOW_LIST) @skip_fips_mode # See NOTE below def test_rbac_migration(self): @@ -84,4 +80,4 @@ def default_role_created(): # NOTE: This assertion will FAIL if running in FIPS mode because # being in FIPS mode will trigger the license nag time.sleep(self.LICENSE_CHECK_INTERVAL_SEC * 2) - assert not self._has_license_nag() + assert not self.redpanda.has_license_nag() diff --git a/tests/rptest/tests/redpanda_kerberos_test.py b/tests/rptest/tests/redpanda_kerberos_test.py index 45fcaea85673..ee56a0864ca4 100644 --- a/tests/rptest/tests/redpanda_kerberos_test.py +++ b/tests/rptest/tests/redpanda_kerberos_test.py @@ -170,10 +170,6 @@ def __init__(self, test_context, num_nodes=3, **kwargs): f'{self.LICENSE_CHECK_INTERVAL_SEC}', }) - def _has_license_nag(self): - return self.redpanda.search_log_any( - "license is required to use enterprise features") - def _license_nag_is_set(self): return self.redpanda.search_log_all( f"Overriding default license log annoy interval to: {self.LICENSE_CHECK_INTERVAL_SEC}s" @@ -190,7 +186,7 @@ def test_license_nag(self): time.sleep(self.LICENSE_CHECK_INTERVAL_SEC * 2) # NOTE: This assertion will FAIL if running in FIPS mode because # being in FIPS mode will trigger the license nag - assert not self._has_license_nag() + assert not self.redpanda.has_license_nag() self.logger.debug("Setting cluster config") self.redpanda.set_cluster_config( @@ -206,7 +202,7 @@ def test_license_nag(self): err_msg="Failed to set license nag internal") self.logger.debug("Waiting for license nag") - wait_until(self._has_license_nag, + wait_until(self.redpanda.has_license_nag, timeout_sec=self.LICENSE_CHECK_INTERVAL_SEC * 2, err_msg="License nag failed to appear") diff --git a/tests/rptest/tests/redpanda_oauth_test.py b/tests/rptest/tests/redpanda_oauth_test.py index 5ebea22093fc..41bcf8c0eaa5 100644 --- a/tests/rptest/tests/redpanda_oauth_test.py +++ b/tests/rptest/tests/redpanda_oauth_test.py @@ -612,10 +612,6 @@ def __init__(self, test_context, num_nodes=3, **kwargs): f'{self.LICENSE_CHECK_INTERVAL_SEC}', }) - def _has_license_nag(self): - return self.redpanda.search_log_any( - "license is required to use enterprise features") - def _license_nag_is_set(self): return self.redpanda.search_log_all( f"Overriding default license log annoy interval to: {self.LICENSE_CHECK_INTERVAL_SEC}s" @@ -634,7 +630,7 @@ def test_license_nag(self, authn_config): time.sleep(self.LICENSE_CHECK_INTERVAL_SEC * 2) # NOTE: This assertion will FAIL if running in FIPS mode because # being in FIPS mode will trigger the license nag - assert not self._has_license_nag() + assert not self.redpanda.has_license_nag() self.logger.debug("Setting cluster config") self.redpanda.set_cluster_config(authn_config) @@ -649,6 +645,6 @@ def test_license_nag(self, authn_config): err_msg="Failed to set license nag internal") self.logger.debug("Waiting for license nag") - wait_until(self._has_license_nag, + wait_until(self.redpanda.has_license_nag, timeout_sec=self.LICENSE_CHECK_INTERVAL_SEC * 2, err_msg="License nag failed to appear") diff --git a/tests/rptest/tests/redpanda_startup_test.py b/tests/rptest/tests/redpanda_startup_test.py index a25bb76c0359..8256adccff9d 100644 --- a/tests/rptest/tests/redpanda_startup_test.py +++ b/tests/rptest/tests/redpanda_startup_test.py @@ -249,10 +249,6 @@ def __init__(self, test_context): True }) - def _has_license_nag(self) -> bool: - return self.redpanda.search_log_any( - "license is required to use enterprise features") - def _license_nag_is_set(self) -> bool: return self.redpanda.search_log_all( f"Overriding default license log annoy interval to: {self.LICENSE_CHECK_INTERVAL_SEC}s" @@ -267,7 +263,7 @@ def test_fips_license_nag(self): self.logger.debug("Ensuring no license nag") sleep(self.LICENSE_CHECK_INTERVAL_SEC * 2) - assert not self._has_license_nag( + assert not self.redpanda.has_license_nag( ), "Should not have license nag yet, FIPS mode not enabled" fips_mode = RedpandaServiceBase.FIPSMode.enabled if in_fips_environment( @@ -282,6 +278,6 @@ def test_fips_license_nag(self): self.redpanda.restart_nodes(self.redpanda.nodes, override_cfg_params=fips_config) - wait_until(self._has_license_nag, + wait_until(self.redpanda.has_license_nag, timeout_sec=30, err_msg="License nag failed to appear") diff --git a/tests/rptest/tests/schema_registry_test.py b/tests/rptest/tests/schema_registry_test.py index 1efcc3abf120..53c57544a1fe 100644 --- a/tests/rptest/tests/schema_registry_test.py +++ b/tests/rptest/tests/schema_registry_test.py @@ -3843,10 +3843,6 @@ def __init__(self, *args, **kwargs): f'{self.LICENSE_CHECK_INTERVAL_SEC}', }) - def _has_license_nag(self): - return self.redpanda.search_log_any( - "license is required to use enterprise features") - def _license_nag_is_set(self): return self.redpanda.search_log_all( f"Overriding default license log annoy interval to: {self.LICENSE_CHECK_INTERVAL_SEC}s" @@ -3865,7 +3861,7 @@ def test_license_nag(self, mode): time.sleep(self.LICENSE_CHECK_INTERVAL_SEC * 2) # NOTE: This assertion will FAIL if running in FIPS mode because # being in FIPS mode will trigger the license nag - assert not self._has_license_nag() + assert not self.redpanda.has_license_nag() self.logger.debug("Setting cluster config") self.redpanda.set_cluster_config({"enable_schema_id_validation": mode}) @@ -3880,7 +3876,7 @@ def test_license_nag(self, mode): err_msg="Failed to set license nag internal") self.logger.debug("Waiting for license nag") - wait_until(self._has_license_nag, + wait_until(self.redpanda.has_license_nag, timeout_sec=self.LICENSE_CHECK_INTERVAL_SEC * 2, err_msg="License nag failed to appear") diff --git a/tests/rptest/tests/workload_license.py b/tests/rptest/tests/workload_license.py index 9a540665dbc5..41c2850305c2 100644 --- a/tests/rptest/tests/workload_license.py +++ b/tests/rptest/tests/workload_license.py @@ -101,8 +101,7 @@ def on_cluster_upgraded(self, version: tuple[int, int, int]) -> int: return PWorkload.NOT_DONE # check for License nag in the log - assert self.ctx.redpanda.search_log_any( - "license is required to use enterprise features" + assert self.ctx.redpanda.has_license_nag( ), "License nag log not found" # Install license