Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mysql source: handle ssh timeout exception #20593

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -22,9 +22,11 @@
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.keyverifier.AcceptAllServerKeyVerifier;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.util.net.SshdSocketAddress;
import org.apache.sshd.common.util.security.SecurityUtils;
import org.apache.sshd.core.CoreModuleProperties;
Expand Down Expand Up @@ -364,7 +366,13 @@ ClientSession openTunnel(final SshClient client) {
remoteServiceHost, remoteServicePort, address.toInetSocketAddress()));
return session;
} catch (final IOException | GeneralSecurityException e) {
throw new RuntimeException(e);
if (e instanceof SshException && e.getMessage()
.toLowerCase(Locale.ROOT)
.contains("failed to get operation result within specified timeout")) {
throw new ConfigErrorException(e.getMessage(), e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the expected message should be something like:
"Timed out while opening a SSH Tunnel. Please double check the given SSH configurations and try again."

} else {
throw new RuntimeException(e);
}
}
}

Expand Down
Expand Up @@ -28,7 +28,7 @@ public abstract class AbstractSshMySqlSourceAcceptanceTest extends SourceAccepta
private static final String STREAM_NAME = "id_and_name";
private static final String STREAM_NAME2 = "starships";

private JsonNode config;
protected static JsonNode config;

public abstract Path getConfigFilePath();

Expand Down
Expand Up @@ -4,10 +4,22 @@

package io.airbyte.integrations.io.airbyte.integration_tests.sources;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import io.airbyte.commons.exceptions.ConfigErrorException;
import io.airbyte.commons.features.EnvVariableFeatureFlags;
import io.airbyte.integrations.base.Source;
import io.airbyte.integrations.base.ssh.SshBastionContainer;
import io.airbyte.integrations.base.ssh.SshTunnel;
import io.airbyte.integrations.source.mysql.MySqlSource;
import io.airbyte.integrations.standardtest.source.TestDestinationEnv;
import java.nio.file.Path;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.containers.Network;
import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;
import uk.org.webcompere.systemstubs.jupiter.SystemStub;
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
Expand All @@ -29,4 +41,32 @@ public Path getConfigFilePath() {
return Path.of("secrets/ssh-pwd-repl-config.json");
}

@Test
public void sshTimeoutExceptionMarkAsConfigErrorTest() throws Exception {
SshBastionContainer bastion = new SshBastionContainer();
final Network network = Network.newNetwork();
// set up env
MySQLContainer<?> db = startTestContainers(bastion, network);
config = bastion.getTunnelConfig(SshTunnel.TunnelMethod.SSH_PASSWORD_AUTH, bastion.getBasicDbConfigBuider(db, List.of("public")));
bastion.stopAndClose();
Source sshWrappedSource = MySqlSource.sshWrappedSource();
Exception exception = assertThrows(ConfigErrorException.class, () -> sshWrappedSource.discover(config));

String expectedMessage = "Failed to get operation result within specified timeout";
String actualMessage = exception.getMessage();

assertTrue(actualMessage.contains(expectedMessage));
}

private MySQLContainer startTestContainers(SshBastionContainer bastion, Network network) {
bastion.initAndStartBastion(network);
return initAndStartJdbcContainer(network);
}

private MySQLContainer initAndStartJdbcContainer(Network network) {
MySQLContainer<?> db = new MySQLContainer<>("mysql:8.0").withNetwork(network);
db.start();
return db;
}

}