async def fixture_rest_async( session_tmpdir: TempDirCreator, kafka_server: Optional[KafkaConfig], registry_async_client: Client ) -> AsyncIterator[KafkaRest]: if not kafka_server: assert REST_URI in os.environ instance, _ = mock_factory("rest")() yield instance else: config_path = os.path.join(session_tmpdir(), "karapace_config.json") kafka_port = kafka_server.kafka_port config = set_config_defaults({ "log_level": "WARNING", "bootstrap_uri": f"127.0.0.1:{kafka_port}", "admin_metadata_max_age": 0 }) write_config(config_path, config) rest = KafkaRest(config_file_path=config_path, config=config) assert rest.serializer.registry_client assert rest.consumer_manager.deserializer.registry_client rest.serializer.registry_client.client = registry_async_client rest.consumer_manager.deserializer.registry_client.client = registry_async_client try: yield rest finally: rest.close() await rest.close_producers()
async def fixture_rest_async( request, tmp_path: Path, kafka_servers: KafkaServers, registry_async_client: Client, ) -> AsyncIterator[Optional[KafkaRest]]: # Do not start a REST api when the user provided an external service. Doing # so would cause this node to join the existing group and participate in # the election process. Without proper configuration for the listeners that # won't work and will cause test failures. rest_url = request.config.getoption("rest_url") if rest_url: yield None return config_path = tmp_path / "karapace_config.json" config = set_config_defaults({ "bootstrap_uri": kafka_servers.bootstrap_servers, "admin_metadata_max_age": 0 }) write_config(config_path, config) rest = KafkaRest(config_file_path=str(config_path), config=config) assert rest.serializer.registry_client assert rest.consumer_manager.deserializer.registry_client rest.serializer.registry_client.client = registry_async_client rest.consumer_manager.deserializer.registry_client.client = registry_async_client try: yield rest finally: rest.close() await rest.close_producers()
async def fixture_rest_async(session_tmpdir, kafka_server, registry_async_client): if REST_URI in os.environ: instance, _ = mock_factory("rest")() yield instance else: config_path = os.path.join(session_tmpdir(), "karapace_config.json") kafka_port = kafka_server["kafka_port"] write_config( config_path, { "log_level": "WARNING", "bootstrap_uri": f"127.0.0.1:{kafka_port}", "admin_metadata_max_age": 0 }) rest = KafkaRest(config_path) rest.serializer.registry_client.client = registry_async_client rest.consumer_manager.deserializer.registry_client.client = registry_async_client try: yield rest finally: rest.close() await rest.close_producers()