1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ import re
1516import os
1617from cassandra .cluster import Cluster
1718
@@ -627,18 +628,24 @@ def use_cluster(cluster_name, nodes, ipformat=None, start=True, workloads=None,
627628 # This allows `test_metadata_with_quoted_identifiers` to run
628629 CCM_CLUSTER .set_configuration_options ({'strict_is_not_null_in_views' : False })
629630 else :
630- CCM_CLUSTER = CCMCluster (path , cluster_name , ** ccm_options )
631+ ccm_cluster_clz = CCMCluster if Version (cassandra_version ) < Version (
632+ '4.1' ) else Cassandra41CCMCluster
633+ CCM_CLUSTER = ccm_cluster_clz (path , cluster_name , ** ccm_options )
631634 CCM_CLUSTER .set_configuration_options ({'start_native_transport' : True })
632635 if Version (cassandra_version ) >= Version ('2.2' ):
633636 CCM_CLUSTER .set_configuration_options ({'enable_user_defined_functions' : True })
634637 if Version (cassandra_version ) >= Version ('3.0' ):
635- CCM_CLUSTER .set_configuration_options ({'enable_scripted_user_defined_functions' : True })
636- if Version (cassandra_version ) >= Version ('4.0-a' ):
638+ # The config.yml option below is deprecated in C* 4.0 per CASSANDRA-17280
639+ if Version (cassandra_version ) < Version ('4.0' ):
640+ CCM_CLUSTER .set_configuration_options ({'enable_scripted_user_defined_functions' : True })
641+ else :
642+ # Cassandra version >= 4.0
637643 CCM_CLUSTER .set_configuration_options ({
638644 'enable_materialized_views' : True ,
639645 'enable_sasi_indexes' : True ,
640646 'enable_transient_replication' : True ,
641647 })
648+
642649 common .switch_cluster (path , cluster_name )
643650 CCM_CLUSTER .set_configuration_options (configuration_options )
644651 # Since scylla CCM doesn't yet support this options, we skip it
@@ -1111,3 +1118,38 @@ def __new__(cls, **kwargs):
11111118 kwargs ['allow_beta_protocol_version' ] = cls .DEFAULT_ALLOW_BETA
11121119 return Cluster (** kwargs )
11131120
1121+ # Subclass of CCMCluster (i.e. ccmlib.cluster.Cluster) which transparently performs
1122+ # conversion of cassandra.yml directives into something matching the new syntax
1123+ # introduced by CASSANDRA-15234
1124+ class Cassandra41CCMCluster (CCMCluster ):
1125+ __test__ = False
1126+ IN_MS_REGEX = re .compile ('^(\w+)_in_ms$' )
1127+ IN_KB_REGEX = re .compile ('^(\w+)_in_kb$' )
1128+ ENABLE_REGEX = re .compile ('^enable_(\w+)$' )
1129+
1130+ def _get_config_key (self , k , v ):
1131+ if "." in k :
1132+ return k
1133+ m = self .IN_MS_REGEX .match (k )
1134+ if m :
1135+ return m .group (1 )
1136+ m = self .ENABLE_REGEX .search (k )
1137+ if m :
1138+ return "%s_enabled" % (m .group (1 ))
1139+ m = self .IN_KB_REGEX .match (k )
1140+ if m :
1141+ return m .group (1 )
1142+ return k
1143+
1144+ def _get_config_val (self , k , v ):
1145+ m = self .IN_MS_REGEX .match (k )
1146+ if m :
1147+ return "%sms" % (v )
1148+ m = self .IN_KB_REGEX .match (k )
1149+ if m :
1150+ return "%sKiB" % (v )
1151+ return v
1152+
1153+ def set_configuration_options (self , values = None , * args , ** kwargs ):
1154+ new_values = {self ._get_config_key (k , str (v )):self ._get_config_val (k , str (v )) for (k ,v ) in values .items ()}
1155+ super (Cassandra41CCMCluster , self ).set_configuration_options (values = new_values , * args , ** kwargs )
0 commit comments