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
@@ -561,18 +562,23 @@ def use_cluster(cluster_name, nodes, ipformat=None, start=True, workloads=None,
561562
562563 CCM_CLUSTER .set_dse_configuration_options (dse_options )
563564 else :
564- CCM_CLUSTER = CCMCluster (path , cluster_name , ** ccm_options )
565+ ccm_cluster_clz = CCMCluster if Version (cassandra_version ) < Version ('4.1' ) else Cassandra41CCMCluster
566+ CCM_CLUSTER = ccm_cluster_clz (path , cluster_name , ** ccm_options )
565567 CCM_CLUSTER .set_configuration_options ({'start_native_transport' : True })
566568 if Version (cassandra_version ) >= Version ('2.2' ):
567569 CCM_CLUSTER .set_configuration_options ({'enable_user_defined_functions' : True })
568570 if Version (cassandra_version ) >= Version ('3.0' ):
569- CCM_CLUSTER .set_configuration_options ({'enable_scripted_user_defined_functions' : True })
570- if Version (cassandra_version ) >= Version ('4.0-a' ):
571+ # The config.yml option below is deprecated in C* 4.0 per CASSANDRA-17280
572+ if Version (cassandra_version ) < Version ('4.0' ):
573+ CCM_CLUSTER .set_configuration_options ({'enable_scripted_user_defined_functions' : True })
574+ else :
575+ # Cassandra version >= 4.0
571576 CCM_CLUSTER .set_configuration_options ({
572577 'enable_materialized_views' : True ,
573578 'enable_sasi_indexes' : True ,
574579 'enable_transient_replication' : True ,
575580 })
581+
576582 common .switch_cluster (path , cluster_name )
577583 CCM_CLUSTER .set_configuration_options (configuration_options )
578584 CCM_CLUSTER .populate (nodes , ipformat = ipformat , use_single_interface = use_single_interface )
@@ -1011,3 +1017,38 @@ def __new__(cls, **kwargs):
10111017 kwargs ['allow_beta_protocol_version' ] = cls .DEFAULT_ALLOW_BETA
10121018 return Cluster (** kwargs )
10131019
1020+ # Subclass of CCMCluster (i.e. ccmlib.cluster.Cluster) which transparently performs
1021+ # conversion of cassandra.yml directives into something matching the new syntax
1022+ # introduced by CASSANDRA-15234
1023+ class Cassandra41CCMCluster (CCMCluster ):
1024+ __test__ = False
1025+ IN_MS_REGEX = re .compile ('^(\w+)_in_ms$' )
1026+ IN_KB_REGEX = re .compile ('^(\w+)_in_kb$' )
1027+ ENABLE_REGEX = re .compile ('^enable_(\w+)$' )
1028+
1029+ def _get_config_key (self , k , v ):
1030+ if "." in k :
1031+ return k
1032+ m = self .IN_MS_REGEX .match (k )
1033+ if m :
1034+ return m .group (1 )
1035+ m = self .ENABLE_REGEX .search (k )
1036+ if m :
1037+ return "%s_enabled" % (m .group (1 ))
1038+ m = self .IN_KB_REGEX .match (k )
1039+ if m :
1040+ return m .group (1 )
1041+ return k
1042+
1043+ def _get_config_val (self , k , v ):
1044+ m = self .IN_MS_REGEX .match (k )
1045+ if m :
1046+ return "%sms" % (v )
1047+ m = self .IN_KB_REGEX .match (k )
1048+ if m :
1049+ return "%sKiB" % (v )
1050+ return v
1051+
1052+ def set_configuration_options (self , values = None , * args , ** kwargs ):
1053+ new_values = {self ._get_config_key (k , str (v )):self ._get_config_val (k , str (v )) for (k ,v ) in values .items ()}
1054+ super (Cassandra41CCMCluster , self ).set_configuration_options (values = new_values , * args , ** kwargs )
0 commit comments