def _new_configsvr(self): """Return a replicaset.ReplicaSetFixture configured as the config server.""" shard_logging_prefix = "configsvr" mongod_logger = logging.loggers.new_fixture_node_logger(self.__class__.__name__, self.job_num, shard_logging_prefix) configsvr_options = self.configsvr_options.copy() auth_options = configsvr_options.pop("auth_options", self.auth_options) preserve_dbpath = configsvr_options.pop("preserve_dbpath", self.preserve_dbpath) num_nodes = configsvr_options.pop("num_nodes", 1) replset_config_options = configsvr_options.pop("replset_config_options", {}) replset_config_options["configsvr"] = True mongod_options = self.mongod_options.copy() mongod_options.update(make_historic(configsvr_options.pop("mongod_options", {}))) mongod_options["configsvr"] = "" mongod_options["dbpath"] = os.path.join(self._dbpath_prefix, "config") mongod_options["replSet"] = ShardedClusterFixture._CONFIGSVR_REPLSET_NAME mongod_options["storageEngine"] = "wiredTiger" return replicaset.ReplicaSetFixture( mongod_logger, self.job_num, mongod_options=mongod_options, mongod_executable=self.mongod_executable, preserve_dbpath=preserve_dbpath, num_nodes=num_nodes, auth_options=auth_options, mixed_bin_versions=None, replset_config_options=replset_config_options, shard_logging_prefix=shard_logging_prefix, **configsvr_options)
def _new_rs_shard(self, index, num_rs_nodes_per_shard): """Return a replicaset.ReplicaSetFixture configured as a shard in a sharded cluster.""" shard_logging_prefix = f"shard{index}" mongod_logger = logging.loggers.new_fixture_node_logger(self.__class__.__name__, self.job_num, shard_logging_prefix) shard_options = self.shard_options.copy() auth_options = shard_options.pop("auth_options", self.auth_options) preserve_dbpath = shard_options.pop("preserve_dbpath", self.preserve_dbpath) replset_config_options = make_historic(shard_options.pop("replset_config_options", {})) replset_config_options["configsvr"] = False mixed_bin_versions = self.mixed_bin_versions if mixed_bin_versions is not None: start_index = index * num_rs_nodes_per_shard mixed_bin_versions = mixed_bin_versions[start_index:start_index + num_rs_nodes_per_shard] mongod_options = self.mongod_options.copy() mongod_options.update(make_historic(shard_options.pop("mongod_options", {}))) mongod_options["shardsvr"] = "" mongod_options["dbpath"] = os.path.join(self._dbpath_prefix, "shard{}".format(index)) mongod_options["replSet"] = ShardedClusterFixture._SHARD_REPLSET_NAME_PREFIX + str(index) return replicaset.ReplicaSetFixture( mongod_logger, self.job_num, mongod_executable=self.mongod_executable, mongod_options=mongod_options, preserve_dbpath=preserve_dbpath, num_nodes=num_rs_nodes_per_shard, auth_options=auth_options, replset_config_options=replset_config_options, mixed_bin_versions=mixed_bin_versions, shard_logging_prefix=shard_logging_prefix, **shard_options)
def setup(self): """Set up the replica sets.""" if not self.replica_sets: for i in range(self.num_replica_sets): rs_name = f"rs{i}" mongod_options = self.common_mongod_options.copy() mongod_options.update(self.per_mongod_options[i]) mongod_options["dbpath"] = os.path.join(self._dbpath_prefix, rs_name) mongod_options["replSet"] = rs_name self.replica_sets.append( replicaset.ReplicaSetFixture( self.logger, self.job_num, mongod_options=mongod_options, preserve_dbpath=self.preserve_dbpath, num_nodes=self.num_nodes_per_replica_set, auth_options=self.auth_options, replset_config_options=self.replset_config_options, mixed_bin_versions=self.mixed_bin_versions, replicaset_logging_prefix=rs_name, use_replica_set_connection_string=self.use_replica_set_connection_string)) self.replica_set_with_tenant = self.replica_sets[0] # Start up each of the replica sets for replica_set in self.replica_sets: replica_set.setup()