17
Checks custom cluster metadata decorator.
20
from unittest.mock import Mock
23
from ducktape.cluster.cluster_spec import ClusterSpec, LINUX
24
from ducktape.mark.mark_expander import MarkedFunctionExpander
26
from ignitetest.utils._mark import cluster, ParametrizableClusterMetadata, CLUSTER_SIZE_KEYWORD, CLUSTER_SPEC_KEYWORD
29
def expand_function(*, func, sess_ctx):
31
Inject parameters into function and generate context list.
33
assert hasattr(func, "marks")
34
assert next(filter(lambda x: isinstance(x, ParametrizableClusterMetadata), func.marks), None)
36
return MarkedFunctionExpander(session_context=sess_ctx, function=func).expand()
39
def mock_session_ctx(*, cluster_size=None):
41
Create mock of session context.
44
sess_ctx.globals = {"cluster_size": cluster_size} if cluster_size is not None else {}
49
class CheckClusterParametrization:
51
Checks custom @cluster parametrization.
53
def check_num_nodes(self):
57
@cluster(num_nodes=10)
61
test_context_list = expand_function(func=function, sess_ctx=mock_session_ctx())
62
assert len(test_context_list) == 1
63
assert test_context_list[0].cluster_use_metadata[CLUSTER_SIZE_KEYWORD] == 10
65
test_context_list = expand_function(func=function,
66
sess_ctx=mock_session_ctx(cluster_size="100"))
67
assert len(test_context_list) == 1
68
assert test_context_list[0].cluster_use_metadata[CLUSTER_SIZE_KEYWORD] == 100
70
def check_cluster_spec(self):
74
@cluster(cluster_spec=ClusterSpec.simple_linux(10))
78
test_context_list = expand_function(func=function, sess_ctx=mock_session_ctx())
79
assert len(test_context_list) == 1
80
inserted_spec = test_context_list[0].cluster_use_metadata[CLUSTER_SPEC_KEYWORD]
82
assert inserted_spec.size() == 10
83
for node in inserted_spec.nodes:
84
assert node.operating_system == LINUX
86
test_context_list = expand_function(func=function,
87
sess_ctx=mock_session_ctx(cluster_size="100"))
88
assert len(test_context_list) == 1
89
inserted_spec = test_context_list[0].cluster_use_metadata[CLUSTER_SPEC_KEYWORD]
91
assert inserted_spec.size() == 100
92
for node in inserted_spec.nodes:
93
assert node.operating_system == LINUX
95
def check_invalid_global_param(self):
96
"""Check handle of invalid params."""
97
@cluster(num_nodes=10)
101
invalid_vals = ["abc", "-10", "1.5", "0", 1.6, -7, 0]
103
for val in invalid_vals:
104
with pytest.raises(Exception):
105
expand_function(func=function, sess_ctx=mock_session_ctx(cluster_size=val))