Search in sources :

Example 1 with Ssh

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)));
        }
    }
}
Also used : Ssh(org.jenkinsci.test.acceptance.Ssh)

Example 2 with Ssh

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);
    }
}
Also used : EC2Api(org.jclouds.ec2.EC2Api) Ssh(org.jenkinsci.test.acceptance.Ssh) IOException(java.io.IOException)

Example 3 with Ssh

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);
}
Also used : Ssh(org.jenkinsci.test.acceptance.Ssh)

Example 4 with Ssh

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);
    }
}
Also used : Ssh(org.jenkinsci.test.acceptance.Ssh) IOException(java.io.IOException)

Example 5 with Ssh

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;
            }
        }
    }
}
Also used : Ssh(org.jenkinsci.test.acceptance.Ssh) IOException(java.io.IOException)

Aggregations

Ssh (org.jenkinsci.test.acceptance.Ssh)12 IOException (java.io.IOException)8 File (java.io.File)3 URL (java.net.URL)3 EC2Api (org.jclouds.ec2.EC2Api)2 InterruptedIOException (java.io.InterruptedIOException)1 MalformedURLException (java.net.MalformedURLException)1 RemoteJenkinsController (org.jenkinsci.test.acceptance.controller.RemoteJenkinsController)1 PluginDownloader (org.jenkinsci.test.acceptance.resolver.PluginDownloader)1