Skip to content

Commit

Permalink
Merge pull request redpanda-data#23331 from WillemKauf/skip_fips_mode
Browse files Browse the repository at this point in the history
`rptest`: add `@skip_fips_mode` decorator
  • Loading branch information
WillemKauf authored Sep 17, 2024
2 parents cd0f07c + 6605685 commit dff91ba
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 17 deletions.
15 changes: 1 addition & 14 deletions tests/rptest/services/redpanda.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
from rptest.services.utils import NodeCrash, LogSearchLocal, LogSearchCloud, Stopwatch
from rptest.util import inject_remote_script, ssh_output_stderr, wait_until_result
from rptest.utils.allow_logs_on_predicate import AllowLogsOnPredicate
from rptest.utils.mode_checks import in_fips_environment
import enum

Partition = collections.namedtuple('Partition',
Expand Down Expand Up @@ -366,20 +367,6 @@ def should_compile(allow_list_element: LogAllowListElem) -> bool:
allow_list_element, AllowLogsOnPredicate)


def in_fips_environment() -> bool:
"""
Returns True if the file /proc/sys/crypto/fips_enabled is present and
contains '1', otherwise returns False.
"""
fips_file = "/proc/sys/crypto/fips_enabled"
if os.path.exists(fips_file) and os.path.isfile(fips_file):
with open(fips_file, 'r') as f:
contents = f.read().strip()
return contents == '1'

return False


class ResourceSettings:
"""
Control CPU+memory footprint of Redpanda instances. Pass one
Expand Down
5 changes: 3 additions & 2 deletions tests/rptest/tests/cluster_self_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
# by the Apache License, Version 2.0
import re

from ducktape.mark import parametrize, matrix, ok_to_fail_fips
from ducktape.mark import parametrize, matrix

from rptest.services.admin import Admin
from rptest.services.cluster import cluster
from rptest.services.redpanda import CloudStorageType, SISettings, get_cloud_storage_type
from rptest.tests.end_to_end import EndToEndTest
from rptest.services.utils import LogSearchLocal
from rptest.utils.mode_checks import skip_fips_mode


class ClusterSelfConfigTest(EndToEndTest):
Expand Down Expand Up @@ -86,7 +87,7 @@ def test_s3_self_config(self, cloud_storage_type):
assert self_config_result and self_config_result in self_config_expected_results

# OCI only supports path-style requests, fips mode will always fail.
@ok_to_fail_fips
@skip_fips_mode
@cluster(num_nodes=1)
@matrix(cloud_storage_type=get_cloud_storage_type(
applies_only_on=[CloudStorageType.S3]))
Expand Down
3 changes: 2 additions & 1 deletion tests/rptest/tests/redpanda_startup_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
from ducktape.utils.util import wait_until
from rptest.services.admin import Admin
from rptest.services.cluster import cluster
from rptest.services.redpanda import in_fips_environment, MetricsEndpoint, MetricSamples, RedpandaServiceBase
from rptest.services.redpanda import MetricsEndpoint, MetricSamples, RedpandaServiceBase
from rptest.tests.redpanda_test import RedpandaTest
from rptest.utils.mode_checks import in_fips_environment


class RedpandaStartupTest(RedpandaTest):
Expand Down
44 changes: 44 additions & 0 deletions tests/rptest/utils/mode_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,47 @@ def the_test(...):
return ignore(args, kwargs)
else:
return args[0]


def in_fips_environment() -> bool:
"""
Returns True if the file /proc/sys/crypto/fips_enabled is present and
contains '1', otherwise returns False.
"""
fips_file = "/proc/sys/crypto/fips_enabled"
if os.path.exists(fips_file) and os.path.isfile(fips_file):
with open(fips_file, 'r') as f:
contents = f.read().strip()
return contents == '1'

return False


def skip_fips_mode(*args, **kwargs):
"""
Test method decorator which signals to the test runner to ignore a given test.
Example::
When no parameters are provided to the @ignore decorator, ignore all parametrizations of the test function
@skip_fips_mode # Ignore all parametrizations
@parametrize(x=1, y=0)
@parametrize(x=2, y=3)
def the_test(...):
...
Example::
If parameters are supplied to the @skip_fips_mode decorator, only skip the parametrization with matching parameter(s)
@skip_fips_mode(x=2, y=3)
@parametrize(x=1, y=0) # This test will run as usual
@parametrize(x=2, y=3) # This test will be ignored
def the_test(...):
...
"""
if in_fips_environment():
return ignore(args, kwargs)
else:
return args[0]

0 comments on commit dff91ba

Please sign in to comment.