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()
Ejemplo n.º 2
0
 def test_fixture_logger(self):
     loggers._BUILD_ID_REGISTRY[32] = 29
     loggers._get_buildlogger_handler_info.return_value = True
     mock_handler = MagicMock()
     loggers.BUILDLOGGER_SERVER.get_global_handler.return_value = mock_handler
     logger = loggers.new_fixture_logger("dummy_class", 32)
     self.assertEqual(logger.handlers[0], mock_handler)