def run(self): try: if self.options.dse or (not self.options.version and common.isDse(self.options.install_dir)): cluster = DseCluster(self.path, self.name, install_dir=self.options.install_dir, version=self.options.version, dse_username=self.options.dse_username, dse_password=self.options.dse_password, opscenter=self.options.opscenter, verbose=True) else: cluster = Cluster(self.path, self.name, install_dir=self.options.install_dir, version=self.options.version, verbose=True) except OSError as e: cluster_dir = os.path.join(self.path, self.name) import traceback print_('Cannot create cluster: %s\n%s' % (str(e), traceback.format_exc()), file=sys.stderr) exit(1) if self.options.partitioner: cluster.set_partitioner(self.options.partitioner) if cluster.cassandra_version() >= "1.2.5": self.options.binary_protocol = True if self.options.binary_protocol: cluster.set_configuration_options({ 'start_native_transport' : True }) if cluster.cassandra_version() >= "1.2" and self.options.vnodes: cluster.set_configuration_options({ 'num_tokens' : 256 }) if not self.options.no_switch: common.switch_cluster(self.path, self.name) print_('Current cluster is now: %s' % self.name) if not (self.options.ipprefix or self.options.ipformat): self.options.ipformat = '127.0.0.%d' if self.options.ssl_path: cluster.enable_ssl(self.options.ssl_path, self.options.require_client_auth) if self.options.node_ssl_path: cluster.enable_internode_ssl(self.options.node_ssl_path) if self.nodes is not None: try: if self.options.debug_log: cluster.set_log_level("DEBUG") if self.options.trace_log: cluster.set_log_level("TRACE") cluster.populate(self.nodes, self.options.debug, use_vnodes=self.options.vnodes, ipprefix=self.options.ipprefix, ipformat=self.options.ipformat) if self.options.start_nodes: profile_options = None if self.options.profile: profile_options = {} if self.options.profile_options: profile_options['options'] = self.options.profile_options if cluster.start(verbose=self.options.debug_log, wait_for_binary_proto=self.options.binary_protocol, jvm_args=self.options.jvm_args, profile_options=profile_options) is None: details = "" if not self.options.debug_log: details = " (you can use --debug-log for more information)" print_("Error starting nodes, see above for details%s" % details, file=sys.stderr) except common.ArgumentError as e: print_(str(e), file=sys.stderr) exit(1)
def restart_test(self): self.cluster = Cluster(CLUSTER_PATH, "restart", cassandra_version='2.0.9') self.cluster.populate(3) self.cluster.start() self.cluster.stop() self.cluster.start() self.cluster.show(True)
def create_ccm_cluster(dtest_setup): logger.info("cluster ccm directory: " + dtest_setup.test_path) version = dtest_setup.dtest_config.cassandra_version if version: cluster = Cluster(dtest_setup.test_path, dtest_setup.cluster_name, cassandra_version=version) else: cluster = Cluster( dtest_setup.test_path, dtest_setup.cluster_name, cassandra_dir=dtest_setup.dtest_config.cassandra_dir) cluster.set_datadir_count(dtest_setup.dtest_config.data_dir_count) cluster.set_environment_variable( 'CASSANDRA_LIBJEMALLOC', dtest_setup.dtest_config.jemalloc_path) return cluster
def test3(self): self.cluster = Cluster(CLUSTER_PATH, "test3", cassandra_version='2.0.3') self.cluster.populate(2) self.cluster.start() self.cluster.cleanup() self.cluster.clear() self.cluster.stop()
def simple_test(self, version='2.0.9'): self.cluster = Cluster(CLUSTER_PATH, "simple", cassandra_version=version) self.cluster.populate(3) self.cluster.start() node1, node2, node3 = self.cluster.nodelist() if version < '2.1': node1.stress() else: node1.stress(['write', 'n=1000000']) self.cluster.flush()
def multi_dc_test(self): self.cluster = Cluster(CLUSTER_PATH, "multi_dc", cassandra_version='2.0.9') self.cluster.populate([1, 2]) self.cluster.start() dcs = [node.data_center for node in self.cluster.nodelist()] self.cluster.set_configuration_options(None, None) self.cluster.stop() self.cluster.start() dcs_2 = [node.data_center for node in self.cluster.nodelist()] self.assertListEqual(dcs, dcs_2)
def create_ccm_cluster(dtest_setup): logger.debug("cluster ccm directory: " + dtest_setup.test_path) version = dtest_setup.dtest_config.cassandra_version if version: cluster = Cluster(dtest_setup.test_path, dtest_setup.cluster_name, cassandra_version=version) else: cluster = Cluster(dtest_setup.test_path, dtest_setup.cluster_name, cassandra_dir=dtest_setup.dtest_config.cassandra_dir) if dtest_setup.dtest_config.use_vnodes: cluster.set_configuration_options(values={'initial_token': None, 'num_tokens': dtest_setup.dtest_config.num_tokens}) else: cluster.set_configuration_options(values={'num_tokens': None}) if dtest_setup.dtest_config.use_off_heap_memtables: cluster.set_configuration_options(values={'memtable_allocation_type': 'offheap_objects'}) cluster.set_datadir_count(dtest_setup.dtest_config.data_dir_count) cluster.set_environment_variable('CASSANDRA_LIBJEMALLOC', dtest_setup.dtest_config.jemalloc_path) return cluster
def create_ccm_cluster(test_path, name): debug("cluster ccm directory: " + test_path) version = os.environ.get('CASSANDRA_VERSION') cdir = CASSANDRA_DIR if version: cluster = Cluster(test_path, name, cassandra_version=version) else: cluster = Cluster(test_path, name, cassandra_dir=cdir) if DISABLE_VNODES: cluster.set_configuration_options(values={'num_tokens': None}) else: cluster.set_configuration_options(values={'initial_token': None, 'num_tokens': NUM_TOKENS}) if OFFHEAP_MEMTABLES: cluster.set_configuration_options(values={'memtable_allocation_type': 'offheap_objects'}) cluster.set_datadir_count(DATADIR_COUNT) cluster.set_environment_variable('CASSANDRA_LIBJEMALLOC', CASSANDRA_LIBJEMALLOC) return cluster
def load(path, name): cluster_path = os.path.join(path, name) filename = os.path.join(cluster_path, 'cluster.conf') with open(filename, 'r') as f: data = yaml.safe_load(f) try: install_dir = None if 'install_dir' in data: install_dir = data['install_dir'] repository.validate(install_dir) if install_dir is None and 'cassandra_dir' in data: install_dir = data['cassandra_dir'] repository.validate(install_dir) if common.isScylla(install_dir): cluster = ScyllaCluster(path, data['name'], install_dir=install_dir, create_directory=False) elif common.isDse(install_dir): cluster = DseCluster(path, data['name'], install_dir=install_dir, create_directory=False) else: cluster = Cluster(path, data['name'], install_dir=install_dir, create_directory=False) node_list = data['nodes'] seed_list = data['seeds'] if 'partitioner' in data: cluster.partitioner = data['partitioner'] if 'config_options' in data: cluster._config_options = data['config_options'] if 'log_level' in data: cluster.__log_level = data['log_level'] if 'use_vnodes' in data: cluster.use_vnodes = data['use_vnodes'] except KeyError as k: raise common.LoadError("Error Loading " + filename + ", missing property:" + str(k)) for node_name in node_list: cluster.nodes[node_name] = Node.load(cluster_path, node_name, cluster) for seed_name in seed_list: cluster.seeds.append(cluster.nodes[seed_name]) return cluster
def test1(self): self.cluster = Cluster(CLUSTER_PATH, "test1", cassandra_version='2.0.3') self.cluster.show(False) self.cluster.populate(2) self.cluster.set_partitioner("Murmur3") self.cluster.start() self.cluster.set_configuration_options(None, None) self.cluster.set_configuration_options({}, True) self.cluster.set_configuration_options({"a": "b"}, False) [node1, node2] = self.cluster.nodelist() node2.compact() self.cluster.flush() self.cluster.stop()
def test3(self): self.cluster = Cluster(CLUSTER_PATH, "test3", version='git:trunk') self.cluster.populate(2) self.cluster.start() node1 = self.cluster.nodelist()[0] self.cluster.stress( ['write', 'n=100', 'no-warmup', '-rate', 'threads=4']) self.cluster.stress([ 'write', 'n=100', 'no-warmup', '-rate', 'threads=4', '-node', node1.ip_addr ]) self.cluster.cleanup() self.cluster.clear() self.cluster.stop()
def issue_150_test(self): self.cluster = Cluster(CLUSTER_PATH, "150", cassandra_version='2.0.9') self.cluster.populate([1, 2], use_vnodes=True) self.cluster.start() dcs = [node.data_center for node in self.cluster.nodelist()] dcs.append('dc2') node4 = Node('node4', self.cluster, True, ('127.0.0.4', 9160), ('127.0.0.4', 7000), '7400', '2000', None) self.cluster.add(node4, False, 'dc2') node4.start() dcs_2 = [node.data_center for node in self.cluster.nodelist()] self.assertListEqual(dcs, dcs_2) node4.nodetool('status')
def load(path, name): cluster_path = os.path.join(path, name) filename = os.path.join(cluster_path, 'cluster.conf') with open(filename, 'r') as f: data = yaml.load(f) try: install_dir = None if 'install_dir' in data: install_dir = data['install_dir'] repository.validate(install_dir) if install_dir is None and 'cassandra_dir' in data: install_dir = data['cassandra_dir'] repository.validate(install_dir) # if common.isDse(install_dir): # cluster = DseCluster(path, data['name'], install_dir=install_dir, create_directory=False) # else: # cluster = Cluster(path, data['name'], install_dir=install_dir, create_directory=False) cluster = Cluster(path, data['name'], install_dir=install_dir, create_directory=False) node_list = data['nodes'] seed_list = data['seeds'] if 'partitioner' in data: cluster.partitioner = data['partitioner'] if 'config_options' in data: cluster._config_options = data['config_options'] if 'dse_config_options' in data: cluster._dse_config_options = data['dse_config_options'] if 'log_level' in data: cluster.__log_level = data['log_level'] if 'use_vnodes' in data: cluster.use_vnodes = data['use_vnodes'] if 'datadirs' in data: cluster.data_dir_count = int(data['datadirs']) extension.load_from_cluster_config(cluster, data) except KeyError as k: raise common.LoadError("Error Loading " + filename + ", missing property:" + k) for node_name in node_list: cluster.nodes[node_name] = Node.load(cluster_path, node_name, cluster) for seed in seed_list: cluster.seeds.append(seed) return cluster
def test_node_start_with_non_default_timeout(self): self.cluster = Cluster(CLUSTER_PATH, "nodestarttimeout", cassandra_version='git:trunk') self.cluster.populate(1) node = self.cluster.nodelist()[0] try: node.start(wait_for_binary_proto=0) self.fail("timeout expected with 0s startup timeout") except ccmlib.node.TimeoutError: pass finally: self.cluster.cleanup() self.cluster.clear() self.cluster.stop()
def test_dc_mandatory_on_multidc(self): self.cluster = Cluster(CLUSTER_PATH, "mandatorydc", cassandra_version='git:trunk') self.cluster.populate([1, 1]) node3 = self.cluster.create_node(name='node3', auto_bootstrap=True, thrift_interface=('127.0.0.3', 9160), storage_interface=('127.0.0.3', 7000), jmx_port='7300', remote_debug_port='0', initial_token=None, binary_interface=('127.0.0.3', 9042)) with self.assertRaisesRegexp( ccmlib.common.ArgumentError, 'Please specify the DC this node should be added to'): self.cluster.add(node3, is_seed=False)
def test_fast_error_on_node_start_failure(self): self.cluster = Cluster(CLUSTER_PATH, 'nodefaststop', cassandra_version='git:trunk') self.cluster.populate(1) self.cluster.set_configuration_options({'invalid_option': 0}) self.check_log_errors = False node = self.cluster.nodelist()[0] start_time = time.time() try: node.start(wait_for_binary_proto=45) self.assertFalse(node.is_running()) self.assertLess(time.time() - start_time, 30) except NodeError: self.assertLess(time.time() - start_time, 30) finally: self.cluster.clear() self.cluster.stop()
def test2(self): self.cluster = Cluster(CLUSTER_PATH, "test2", version='git:trunk') self.cluster.populate(2) self.cluster.start() self.cluster.set_log_level("ERROR") class FakeNode: name = "non-existing node" self.cluster.remove(FakeNode()) node1 = self.cluster.nodelist()[0] self.cluster.remove(node1) self.cluster.show(True) self.cluster.show(False) self.cluster.compact() self.cluster.drain() self.cluster.stop()
def run(self): try: cluster = Cluster(self.path, self.name, cassandra_dir=self.options.cassandra_dir, cassandra_version=self.options.cassandra_version, verbose=True) except OSError as e: cluster_dir = os.path.join(self.path, self.name) import traceback print >> sys.stderr, 'Cannot create cluster: %s\n%s' % ( str(e), traceback.format_exc()) exit(1) if self.options.partitioner: cluster.set_partitioner(self.options.partitioner) if cluster.version() >= "1.2" and self.options.binary_protocol: cluster.set_configuration_options({'start_native_transport': True}) if cluster.version() >= "1.2" and self.options.vnodes: cluster.set_configuration_options({'num_tokens': 256}) if not self.options.no_switch: common.switch_cluster(self.path, self.name) print 'Current cluster is now: %s' % self.name if self.nodes is not None: try: if self.options.debug_log: cluster.set_log_level("DEBUG") if self.options.trace_log: cluster.set_log_level("TRACE") cluster.populate(self.nodes, use_vnodes=self.options.vnodes, ipprefix=self.options.ipprefix) if self.options.start_nodes: cluster.start( verbose=self.options.debug, wait_for_binary_proto=self.options.binary_protocol) except common.ArgumentError as e: print >> sys.stderr, str(e) exit(1)
def test2(self): self.cluster = Cluster(CLUSTER_PATH, "test2", cassandra_version='2.0.3') self.cluster.populate(2) self.cluster.start() self.cluster.set_log_level("ERROR") class FakeNode: name = "non-existing node" self.cluster.remove(FakeNode()) [node1, node2] = self.cluster.nodelist() self.cluster.remove(node1) self.cluster.show(True) self.cluster.show(False) #self.cluster.stress([]) self.cluster.compact() self.cluster.drain() self.cluster.stop()