def setup_package(): print_('Using Cassandra version: %s' % CASSANDRA_VERSION) try: try: cluster = CCMCluster.load(path, CLUSTER_NAME) log.debug("Found existing ccm test cluster, clearing") cluster.clear() if CASSANDRA_DIR: cluster.set_cassandra_dir(cassandra_dir=CASSANDRA_DIR) else: cluster.set_cassandra_dir(cassandra_version=CASSANDRA_VERSION) except Exception: if CASSANDRA_DIR: log.debug("Creating new ccm test cluster with cassandra dir %s", CASSANDRA_DIR) cluster = CCMCluster(path, CLUSTER_NAME, cassandra_dir=CASSANDRA_DIR) else: log.debug("Creating new ccm test cluster with version %s", CASSANDRA_VERSION) cluster = CCMCluster(path, CLUSTER_NAME, cassandra_version=CASSANDRA_VERSION) cluster.set_configuration_options({'start_native_transport': True}) common.switch_cluster(path, CLUSTER_NAME) cluster.populate(3) log.debug("Starting ccm test cluster") cluster.start(wait_for_binary_proto=True, wait_other_notice=True) except Exception: log.exception("Failed to start ccm cluster:") raise global CCM_CLUSTER CCM_CLUSTER = cluster setup_test_keyspace()
def setUp(self): # cleaning up if a previous execution didn't trigger tearDown (which # can happen if it is interrupted by KeyboardInterrupt) # TODO: move that part to a generic fixture if os.path.exists(LAST_TEST_DIR): with open(LAST_TEST_DIR) as f: self.test_path = f.readline().strip('\n') name = f.readline() try: self.cluster = Cluster.load(self.test_path, name) # Avoid waiting too long for node to be marked down self.__cleanup_cluster() except IOError: # after a restart, /tmp will be emptied so we'll get an IOError when loading the old cluster here pass self.cluster = self.__get_cluster() # the failure detector can be quite slow in such tests with quick start/stop self.cluster.set_configuration_options( values={'phi_convict_threshold': 5}) self.cluster.set_configuration_options( values={'rpc_timeout_in_ms': 2000}) with open(LAST_TEST_DIR, 'w') as f: f.write(self.test_path + '\n') f.write(self.cluster.name) self.connections = [] self.runners = []
def setUp(self): # cleaning up if a previous execution didn't trigger tearDown (which # can happen if it is interrupted by KeyboardInterrupt) # TODO: move that part to a generic fixture if os.path.exists(LAST_TEST_DIR): with open(LAST_TEST_DIR) as f: self.test_path = f.readline().strip("\n") name = f.readline() try: self.cluster = Cluster.load(self.test_path, name) # Avoid waiting too long for node to be marked down self.__cleanup_cluster() except IOError: # after a restart, /tmp will be emptied so we'll get an IOError when loading the old cluster here pass self.cluster = self.__get_cluster() # the failure detector can be quite slow in such tests with quick start/stop self.cluster.set_configuration_options(values={"phi_convict_threshold": 5}) self.cluster.set_configuration_options(values={"rpc_timeout_in_ms": 15000}) with open(LAST_TEST_DIR, "w") as f: f.write(self.test_path + "\n") f.write(self.cluster.name) if DEBUG: self.cluster.set_log_level("DEBUG") self.connections = [] self.runners = []
def use_multidc(dc_list): teardown_package() try: try: cluster = CCMCluster.load(path, MULTIDC_CLUSTER_NAME) log.debug("Found existing ccm test multi-dc cluster, clearing") cluster.clear() except Exception: log.debug("Creating new ccm test multi-dc cluster") if CASSANDRA_DIR: cluster = CCMCluster(path, MULTIDC_CLUSTER_NAME, cassandra_dir=CASSANDRA_DIR) else: cluster = CCMCluster(path, MULTIDC_CLUSTER_NAME, cassandra_version=CASSANDRA_VERSION) cluster.set_configuration_options({'start_native_transport': True}) common.switch_cluster(path, MULTIDC_CLUSTER_NAME) cluster.populate(dc_list) log.debug("Starting ccm test cluster") cluster.start(wait_for_binary_proto=True, wait_other_notice=True) except Exception: log.exception("Failed to start ccm cluster:") raise global CCM_CLUSTER CCM_CLUSTER = cluster setup_test_keyspace() log.debug("Switched to multidc cluster")
def setup_package(): print_('Using Cassandra version: %s' % CASSANDRA_VERSION) try: try: cluster = CCMCluster.load(path, CLUSTER_NAME) log.debug("Found existing ccm test cluster, clearing") cluster.clear() cluster.set_cassandra_dir(cassandra_version=CASSANDRA_VERSION) except Exception: log.debug("Creating new ccm test cluster with version %s", CASSANDRA_VERSION) cluster = CCMCluster(path, CLUSTER_NAME, cassandra_version=CASSANDRA_VERSION) cluster.set_configuration_options({'start_native_transport': True}) common.switch_cluster(path, CLUSTER_NAME) cluster.populate(3) log.debug("Starting ccm test cluster") cluster.start(wait_for_binary_proto=True) except Exception: log.exception("Failed to start ccm cluster:") raise global CCM_CLUSTER CCM_CLUSTER = cluster setup_test_keyspace()
def setup_module(cls): validate_ccm_viable() validate_host_viable() cls.ccm_cluster = object() teardown_package() try: try: ccm_cluster = CCMCluster.load(path, IPV6_CLUSTER_NAME) log.debug("Found existing ccm test ipv6 cluster, clearing") ccm_cluster.clear() except Exception: log.debug("Creating new ccm test ipv6 cluster") if CASSANDRA_DIR: ccm_cluster = CCMCluster(path, IPV6_CLUSTER_NAME, cassandra_dir=CASSANDRA_DIR) else: ccm_cluster = CCMCluster(path, IPV6_CLUSTER_NAME, cassandra_version=CASSANDRA_VERSION) ccm_cluster.set_configuration_options( {'start_native_transport': True}) common.switch_cluster(path, IPV6_CLUSTER_NAME) ccm_cluster.populate(1, ipformat='::%d') log.debug("Starting ccm test cluster") ccm_cluster.start(wait_for_binary_proto=True) except Exception: log.exception("Failed to start ccm cluster:") raise log.debug("Switched to ipv6 cluster") cls.ccm_cluster = ccm_cluster
def setup_module(cls): validate_ccm_viable() validate_host_viable() cls.ccm_cluster = object() teardown_package() try: try: ccm_cluster = CCMCluster.load(path, IPV6_CLUSTER_NAME) log.debug("Found existing ccm test ipv6 cluster, clearing") ccm_cluster.clear() except Exception: log.debug("Creating new ccm test ipv6 cluster") if CASSANDRA_DIR: ccm_cluster = CCMCluster(path, IPV6_CLUSTER_NAME, cassandra_dir=CASSANDRA_DIR) else: ccm_cluster = CCMCluster(path, IPV6_CLUSTER_NAME, cassandra_version=CASSANDRA_VERSION) ccm_cluster.set_configuration_options({'start_native_transport': True}) common.switch_cluster(path, IPV6_CLUSTER_NAME) ccm_cluster.populate(1, ipformat='::%d') log.debug("Starting ccm test cluster") ccm_cluster.start(wait_for_binary_proto=True) except Exception: log.exception("Failed to start ccm cluster:") raise log.debug("Switched to ipv6 cluster") cls.ccm_cluster = ccm_cluster
def clear_and_use_multidc(dc_list): teardown_package() try: try: cluster = CCMCluster.load(path, MULTIDC_CLUSTER_NAME) log.debug("Found existing ccm test multi-dc cluster, clearing") cluster.clear() except Exception: log.debug("Creating new ccm test multi-dc cluster") if CASSANDRA_DIR: cluster = CCMCluster(path, MULTIDC_CLUSTER_NAME, cassandra_dir=CASSANDRA_DIR) else: cluster = CCMCluster(path, MULTIDC_CLUSTER_NAME, cassandra_version=CASSANDRA_VERSION) cluster.set_configuration_options({'start_native_transport': True}) common.switch_cluster(path, MULTIDC_CLUSTER_NAME) cluster.populate(dc_list) log.debug("Starting ccm test cluster") cluster.start(wait_for_binary_proto=True, wait_other_notice=True) except Exception: log.exception("Failed to start ccm cluster:") raise global CCM_CLUSTER CCM_CLUSTER = cluster setup_test_keyspace() log.debug("Switched to multidc cluster")
def _load_current_cluster(self): name = common.current_cluster_name(self.path) if name is None: print_('No currently active cluster (use ccm cluster switch)') exit(1) try: return Cluster.load(self.path, name) except common.LoadError as e: print_(str(e)) exit(1)
def setup_class(cls): """ Class-level fixture. Called once for all tests. We create a cluster object here and save it in the provided class instance Create 2 regular users and a new superuser. Enable authentication by setting 'authenticator': 'PasswordAuthenticator'. If invoked from authorization class enable authorization by setting 'authorizer': 'CassandraAuthorizer'. """ try: ccm_cluster = CCMCluster.load(tests.integration.path, AUTH_CLUSTER_NAME) log.debug("Found existing ccm test authentication cluster, removing") ccm_cluster.remove() except Exception: log.debug("Can not load cluster %s ....." % AUTH_CLUSTER_NAME) log.debug("Creating new ccm test authentication cluster") if tests.integration.CASSANDRA_DIR: ccm_cluster = CCMCluster(tests.integration.path, AUTH_CLUSTER_NAME, cassandra_dir=tests.integration.CASSANDRA_DIR) else: ccm_cluster = CCMCluster(tests.integration.path, AUTH_CLUSTER_NAME, cassandra_version=tests.integration.CASSANDRA_VERSION) ccm_cluster.set_configuration_options({'start_native_transport': True}) ccm_cluster.set_configuration_options({'authenticator': 'PasswordAuthenticator'}) # # This method is called either with AuthenticationTests class or with AuthorizedAuthenticationTests class. # In the second case we enable CassandraAuthorizer # if cls.__name__ == 'AuthorizedAuthenticationTests': print "Running tests with Cassandra Authorizer Enabled" log.info("Running tests with Cassandra Authorizer Enabled") ccm_cluster.set_configuration_options({'authorizer': 'CassandraAuthorizer'}) else: print "Running tests with Cassandra Authorizer Disabled" log.info("Running tests with Cassandra Authorizer Disabled") common.switch_cluster(tests.integration.path, AUTH_CLUSTER_NAME) ccm_cluster.populate(1) log.debug("Starting ccm test authentication cluster") ccm_cluster.start(wait_for_binary_proto=True) if not wait_for_cassandra() or not try_connecting('cassandra', 'cassandra'): log.exception("Can not talk to cassandra") raise Exception('Can not talk to cassandra') log.debug("Switched to AUTH_CLUSTER_NAME cluster") cls.ccm_cluster = ccm_cluster cls.root_cluster = cls.cluster_as('cassandra', 'cassandra') cls.root_session = cls.root_cluster.connect() cls.create_user(cls.root_cluster, cls.test_user, cls.password) cls.create_user(cls.root_cluster, cls.test_other_user, cls.password) cls.create_user(cls.root_cluster, cls.suser, cls.password, su=True)
def run(self): if self.other_cluster: # Remove the specified cluster: cluster = Cluster.load(self.path, self.other_cluster) cluster.remove() # Remove CURRENT flag if the specified cluster is the current cluster: if self.other_cluster == common.current_cluster_name(self.path): os.remove(os.path.join(self.path, 'CURRENT')) else: # Remove the current cluster: self.cluster.remove() os.remove(os.path.join(self.path, 'CURRENT'))
def teardown_package(): for cluster_name in [CLUSTER_NAME, MULTIDC_CLUSTER_NAME]: try: cluster = CCMCluster.load(path, cluster_name) try: cluster.clear() cluster.remove() log.info('Cleared cluster: %s' % cluster_name) except Exception: log.exception('Failed to clear cluster: %s' % cluster_name) except Exception: log.warn('Did not find cluster: %s' % cluster_name)
def setUp(self): global CURRENT_TEST CURRENT_TEST = self.id() + self._testMethodName # cleaning up if a previous execution didn't trigger tearDown (which # can happen if it is interrupted by KeyboardInterrupt) # TODO: move that part to a generic fixture if os.path.exists(LAST_TEST_DIR): with open(LAST_TEST_DIR) as f: self.test_path = f.readline().strip('\n') name = f.readline() try: self.cluster = Cluster.load(self.test_path, name) # Avoid waiting too long for node to be marked down self.__cleanup_cluster() except IOError: # after a restart, /tmp will be emptied so we'll get an IOError when loading the old cluster here pass self.cluster = self._get_cluster() self.__setup_cobertura() # the failure detector can be quite slow in such tests with quick start/stop self.cluster.set_configuration_options( values={'phi_convict_threshold': 5}) timeout = 10000 if self.cluster_options is not None: self.cluster.set_configuration_options(values=self.cluster_options) elif self.cluster.version() < "1.2": self.cluster.set_configuration_options( values={'rpc_timeout_in_ms': timeout}) else: self.cluster.set_configuration_options( values={ 'read_request_timeout_in_ms': timeout, 'range_request_timeout_in_ms': timeout, 'write_request_timeout_in_ms': timeout, 'truncate_request_timeout_in_ms': timeout, 'request_timeout_in_ms': timeout }) with open(LAST_TEST_DIR, 'w') as f: f.write(self.test_path + '\n') f.write(self.cluster.name) if DEBUG: self.cluster.set_log_level("DEBUG") if TRACE: self.cluster.set_log_level("TRACE") self.connections = [] self.runners = []
def setUp(self): global CURRENT_TEST CURRENT_TEST = self.id() + self._testMethodName # cleaning up if a previous execution didn't trigger tearDown (which # can happen if it is interrupted by KeyboardInterrupt) # TODO: move that part to a generic fixture if os.path.exists(LAST_TEST_DIR): with open(LAST_TEST_DIR) as f: self.test_path = f.readline().strip('\n') name = f.readline() try: self.cluster = Cluster.load(self.test_path, name) # Avoid waiting too long for node to be marked down self.__cleanup_cluster() except IOError: # after a restart, /tmp will be emptied so we'll get an IOError when loading the old cluster here pass self.cluster = self._get_cluster() self.__setup_cobertura() # the failure detector can be quite slow in such tests with quick start/stop self.cluster.set_configuration_options(values={'phi_convict_threshold': 5}) timeout = 10000 if self.cluster_options is not None: self.cluster.set_configuration_options(values=self.cluster_options) elif self.cluster.version() < "1.2": self.cluster.set_configuration_options(values={'rpc_timeout_in_ms': timeout}) else: self.cluster.set_configuration_options(values={ 'read_request_timeout_in_ms' : timeout, 'range_request_timeout_in_ms' : timeout, 'write_request_timeout_in_ms' : timeout, 'truncate_request_timeout_in_ms' : timeout, 'request_timeout_in_ms' : timeout }) with open(LAST_TEST_DIR, 'w') as f: f.write(self.test_path + '\n') f.write(self.cluster.name) if DEBUG: self.cluster.set_log_level("DEBUG") if TRACE: self.cluster.set_log_level("TRACE") self.connections = [] self.runners = []
def setup_package(): try: try: cluster = CCMCluster.load(path, CLUSTER_NAME) log.debug("Found existing ccm test cluster, clearing") cluster.clear() except Exception: log.debug("Creating new ccm test cluster") cluster = CCMCluster(path, CLUSTER_NAME, cassandra_version='1.2.6') cluster.set_configuration_options({'start_native_transport': True}) common.switch_cluster(path, CLUSTER_NAME) cluster.populate(3) log.debug("Starting ccm test cluster") cluster.start(wait_for_binary_proto=True) except Exception: log.exception("Failed to start ccm cluster:") raise global CCM_CLUSTER CCM_CLUSTER = cluster
def setup_package(): version = os.getenv("CASSANDRA_VERSION", DEFAULT_CASSANDRA_VERSION) try: try: cluster = CCMCluster.load(path, CLUSTER_NAME) log.debug("Found existing ccm test cluster, clearing") cluster.clear() cluster.set_cassandra_dir(cassandra_version=version) except Exception: log.debug("Creating new ccm test cluster with version %s", version) cluster = CCMCluster(path, CLUSTER_NAME, cassandra_version=version) cluster.set_configuration_options({'start_native_transport': True}) common.switch_cluster(path, CLUSTER_NAME) cluster.populate(3) log.debug("Starting ccm test cluster") cluster.start(wait_for_binary_proto=True) except Exception: log.exception("Failed to start ccm cluster:") raise global CCM_CLUSTER CCM_CLUSTER = cluster setup_test_keyspace()
def setup_class(cls): """ Class-level fixture. Called once for all tests. We create a cluster object here and save it in the provided class instance Create 2 regular users and a new superuser. Enable authentication by setting 'authenticator': 'PasswordAuthenticator'. If invoked from authorization class enable authorization by setting 'authorizer': 'CassandraAuthorizer'. """ try: ccm_cluster = CCMCluster.load(tests.integration.path, AUTH_CLUSTER_NAME) log.debug( "Found existing ccm test authentication cluster, removing") ccm_cluster.remove() except Exception: log.debug("Can not load cluster %s ....." % AUTH_CLUSTER_NAME) log.debug("Creating new ccm test authentication cluster") if tests.integration.CASSANDRA_DIR: ccm_cluster = CCMCluster( tests.integration.path, AUTH_CLUSTER_NAME, cassandra_dir=tests.integration.CASSANDRA_DIR) else: ccm_cluster = CCMCluster( tests.integration.path, AUTH_CLUSTER_NAME, cassandra_version=tests.integration.CASSANDRA_VERSION) ccm_cluster.set_configuration_options({'start_native_transport': True}) ccm_cluster.set_configuration_options( {'authenticator': 'PasswordAuthenticator'}) # # This method is called either with AuthenticationTests class or with AuthorizedAuthenticationTests class. # In the second case we enable CassandraAuthorizer # if cls.__name__ == 'AuthorizedAuthenticationTests': print "Running tests with Cassandra Authorizer Enabled" log.info("Running tests with Cassandra Authorizer Enabled") ccm_cluster.set_configuration_options( {'authorizer': 'CassandraAuthorizer'}) else: print "Running tests with Cassandra Authorizer Disabled" log.info("Running tests with Cassandra Authorizer Disabled") common.switch_cluster(tests.integration.path, AUTH_CLUSTER_NAME) ccm_cluster.populate(1) log.debug("Starting ccm test authentication cluster") ccm_cluster.start(wait_for_binary_proto=True) if not wait_for_cassandra() or not try_connecting( 'cassandra', 'cassandra'): log.exception("Can not talk to cassandra") raise Exception('Can not talk to cassandra') log.debug("Switched to AUTH_CLUSTER_NAME cluster") cls.ccm_cluster = ccm_cluster cls.root_cluster = cls.cluster_as('cassandra', 'cassandra') cls.root_session = cls.root_cluster.connect() cls.create_user(cls.root_cluster, cls.test_user, cls.password) cls.create_user(cls.root_cluster, cls.test_other_user, cls.password) cls.create_user(cls.root_cluster, cls.suser, cls.password, su=True)