use of org.jenkinsci.test.acceptance.Ssh in project acceptance-test-harness by jenkinsci.
the class PluginDownloader method materialize.
@Override
public void materialize(Machine machine, String path) {
try (Ssh ssh = machine.connect()) {
if (!JenkinsDownloader.remoteFileExists(ssh.getConnection(), path, null)) {
ssh.executeRemoteCommand("mkdir -p " + Ssh.escape(FileUtils.dirname(path)));
ssh.executeRemoteCommand(String.format("wget -q -O %s %s", Ssh.escape(path), Ssh.escape(pluginPath)));
}
}
}
use of org.jenkinsci.test.acceptance.Ssh in project acceptance-test-harness by jenkinsci.
the class Ec2Provider method postStartupSetup.
@Override
public void postStartupSetup(NodeMetadata node) {
String host = node.getPublicAddresses().iterator().next();
try (Ssh ssh = new Ssh(host)) {
authenticator().authenticate(ssh.getConnection());
ssh.getConnection().exec(String.format("pkill -u $(id -u %s)", config.getUser()), System.out);
// set instance initiated shutdown behavior to terminate. This means any shutdown will result in to instance
// termination
EC2Api client = contextBuilder.buildApi(EC2Api.class);
client.getInstanceApi().get().setInstanceInitiatedShutdownBehaviorForInstanceInRegion(config.getRegion(), node.getProviderId(), Volume.InstanceInitiatedShutdownBehavior.TERMINATE);
copyAutoterminateScript(host);
} catch (IOException | InterruptedException e) {
logger.error(e.getMessage());
throw new RuntimeException(e);
}
}
use of org.jenkinsci.test.acceptance.Ssh in project acceptance-test-harness by jenkinsci.
the class JcloudsMachine method close.
@Override
public void close() throws IOException {
logger.info("Destroying node: " + nodeMetadata);
try (Ssh ssh = connect()) {
ssh.getConnection().exec(String.format("pkill -u $(id -u %s)", getUser()), System.out);
} catch (InterruptedException e) {
// ignore
logger.error(e.getMessage());
}
machineProvider.offer(this);
}
use of org.jenkinsci.test.acceptance.Ssh in project acceptance-test-harness by jenkinsci.
the class JcloudsMachine method connect.
@Override
public Ssh connect() {
Ssh ssh = null;
try {
ssh = new Ssh(getPublicIpAddress());
machineProvider.authenticator().authenticate(ssh.getConnection());
return ssh;
} catch (IOException e) {
if (ssh != null) {
ssh.close();
}
throw new AssertionError("Failed to create ssh connection", e);
}
}
use of org.jenkinsci.test.acceptance.Ssh in project acceptance-test-harness by jenkinsci.
the class JcloudsMachineProvider method waitForSsh.
private void waitForSsh(String user, String host) {
// 2 minute
int timeout = 120000;
long startTime = System.currentTimeMillis();
while (true) {
logger.info(String.format("Making sure sshd is up on host: %s ", host));
try {
if (System.currentTimeMillis() - startTime > timeout) {
throw new RuntimeException(String.format("ssh failed to work within %s seconds.", timeout / 1000));
}
try (Ssh ssh = new Ssh(host)) {
authenticator().authenticate(ssh.getConnection());
logger.info("sshd is ready on host: " + host);
}
return;
} catch (IOException e) {
try {
// sleep 10 sec
Thread.sleep(10000);
} catch (InterruptedException e1) {
logger.error(e.getMessage(), e);
// exit from this loop
return;
}
}
}
}
Aggregations