예제 #1
0
    def _new_configsvr(sharded_cluster: ShardedClusterFixture,
                       is_multiversion: bool,
                       old_bin_version: Optional[str]) -> ReplicaSetFixture:
        """Return a replica set fixture configured as the config server.

        :param sharded_cluster: sharded cluster fixture we are configuring config server for
        :param is_multiversion: whether we are in multiversion mode
        :param old_bin_version: old bin version
        :return: replica set fixture configured as the config server
        """

        configsvr_logger = sharded_cluster.get_configsvr_logger()
        configsvr_kwargs = sharded_cluster.get_configsvr_kwargs()

        mixed_bin_versions = None
        if is_multiversion:
            # Our documented recommended path for upgrading shards lets us assume that config
            # server nodes will always be fully upgraded before shard nodes.
            mixed_bin_versions = [BinVersionEnum.NEW] * 2

        return make_fixture("ReplicaSetFixture",
                            configsvr_logger,
                            sharded_cluster.job_num,
                            mixed_bin_versions=mixed_bin_versions,
                            old_bin_version=old_bin_version,
                            **configsvr_kwargs)
예제 #2
0
    def _new_rs_shard(sharded_cluster: ShardedClusterFixture,
                      mixed_bin_versions: Optional[List[str]],
                      old_bin_version: Optional[str], rs_shard_index: int,
                      num_rs_nodes_per_shard: int) -> ReplicaSetFixture:
        """Return a replica set fixture configured as a shard in a sharded cluster.

        :param sharded_cluster: sharded cluster fixture we are configuring config server for
        :param mixed_bin_versions: the list of bin versions
        :param old_bin_version: old bin version
        :param rs_shard_index: replica set shard index
        :param num_rs_nodes_per_shard: the number of nodes in a replica set per shard
        :return: replica set fixture configured as a shard in a sharded cluster
        """

        rs_shard_logger = sharded_cluster.get_rs_shard_logger(rs_shard_index)
        rs_shard_kwargs = sharded_cluster.get_rs_shard_kwargs(rs_shard_index)

        if mixed_bin_versions is not None:
            start_index = rs_shard_index * num_rs_nodes_per_shard
            mixed_bin_versions = mixed_bin_versions[start_index:start_index +
                                                    num_rs_nodes_per_shard]

        return make_fixture("ReplicaSetFixture",
                            rs_shard_logger,
                            sharded_cluster.job_num,
                            num_nodes=num_rs_nodes_per_shard,
                            mixed_bin_versions=mixed_bin_versions,
                            old_bin_version=old_bin_version,
                            **rs_shard_kwargs)
def list_commands_for_api(api_version: str, mongod_or_mongos: str, install_dir: str) -> Set[str]:
    """Get a list of commands in a given API version by calling listCommands."""
    assert mongod_or_mongos in ("mongod", "mongos")
    logging.info("Calling listCommands on %s", mongod_or_mongos)
    dbpath = TemporaryDirectory()
    mongod_executable = os.path.join(install_dir, "mongod")
    mongos_executable = os.path.join(install_dir, "mongos")
    if mongod_or_mongos == "mongod":
        logger = loggers.new_fixture_logger("MongoDFixture", 0)
        logger.parent = LOGGER
        fixture: interface.Fixture = MongoDFixture(logger, 0, dbpath_prefix=dbpath.name,
                                                   mongod_executable=mongod_executable)
    else:
        logger = loggers.new_fixture_logger("ShardedClusterFixture", 0)
        logger.parent = LOGGER
        fixture = ShardedClusterFixture(logger, 0, dbpath_prefix=dbpath.name,
                                        mongos_executable=mongos_executable,
                                        mongod_executable=mongod_executable, mongod_options={})

    fixture.setup()
    fixture.await_ready()

    try:
        client = MongoClient(fixture.get_driver_connection_url())
        reply = client.admin.command('listCommands')
        commands = {
            name
            for name, info in reply['commands'].items() if api_version in info['apiVersions']
        }
        logging.info("Found %s commands in API Version %s on %s", len(commands), api_version,
                     mongod_or_mongos)
        return commands
    finally:
        fixture.teardown()
예제 #4
0
    def _new_mongos(sharded_cluster: ShardedClusterFixture,
                    executables: Dict[str, str], classes: Dict[str, str],
                    mongos_index: int, total: int,
                    is_multiversion: bool) -> FixtureContainer:
        """Make a fixture container with configured mongos fixture(s) in it.

        In non-multiversion mode only a new mongos fixture will be in the fixture container.
        In multiversion mode a new mongos and the old mongos fixtures will be in the container.

        :param sharded_cluster: sharded cluster fixture we are configuring mongos for
        :param executables: dict with a new and the old (if multiversion) mongos executable names
        :param classes: dict with a new and the old (if multiversion) mongos fixture names
        :param mongos_index: the index of mongos
        :param total: total number of mongos
        :param is_multiversion: whether we are in multiversion mode
        :return: fixture container with configured mongos fixture(s) in it
        """

        mongos_logger = sharded_cluster.get_mongos_logger(mongos_index, total)
        mongos_kwargs = sharded_cluster.get_mongos_kwargs()

        old_fixture = None

        if is_multiversion:
            old_fixture = make_fixture(
                classes[BinVersionEnum.OLD],
                mongos_logger,
                sharded_cluster.job_num,
                mongos_executable=executables[BinVersionEnum.OLD],
                **mongos_kwargs)

        # We can't restart mongos since explicit ports are not supported.
        new_fixture_mongos_kwargs = sharded_cluster.get_mongos_kwargs()
        new_fixture = make_fixture(
            classes[BinVersionEnum.NEW],
            mongos_logger,
            sharded_cluster.job_num,
            mongos_executable=executables[BinVersionEnum.NEW],
            **new_fixture_mongos_kwargs)

        # Always spin up an old mongos if in multiversion mode given mongos is the last thing in the update path.
        return FixtureContainer(
            new_fixture, old_fixture,
            BinVersionEnum.OLD if is_multiversion else BinVersionEnum.NEW)