use of org.jenkinsci.test.acceptance.Ssh in project acceptance-test-harness by jenkinsci.
the class RemoteJenkinsProvider method createNewJenkinsController.
private JenkinsController createNewJenkinsController() {
Machine machine = machineProvider.get();
try {
// install jenkins WAR
jenkinsResolver.materialize(machine, jenkinsWar);
} catch (Exception e) {
logger.error("Error during setting up Jenkins: " + e.getMessage(), e);
throw new AssertionError(e);
}
String jenkinsHome = machine.dir() + newJenkinsHome() + "/";
String pluginDir = jenkinsHome + "plugins/";
String path = JenkinsResolver.JENKINS_TEMP_DIR + "form-element-path.hpi";
// install form-path-element plugin
new PluginDownloader("form-element-path").materialize(machine, path);
try (Ssh ssh = machine.connect()) {
ssh.executeRemoteCommand("mkdir -p " + pluginDir);
ssh.executeRemoteCommand(String.format("cp %s %s", path, pluginDir));
}
return new RemoteJenkinsController(injector, machine, jenkinsHome, jenkinsWar, privateKeyFile);
}
use of org.jenkinsci.test.acceptance.Ssh in project acceptance-test-harness by jenkinsci.
the class TSREc2Provider 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 TSREc2Provider method copyAutoterminateScript.
private void copyAutoterminateScript(String host) throws IOException, InterruptedException {
// run terminate script
URL script = this.getClass().getClassLoader().getResource("org/jenkinsci/test/acceptance/machine/autoterminate.sh");
File tempScriptFile = File.createTempFile("autoterminate", ".sh");
try {
FileUtils.copyURLToFile(script, tempScriptFile);
logger.info(String.format("Executing auto-terminate script on remote machine: %s, it will terminate after 180 minutes of " + "inactivity.", host));
try (Ssh ssh = new Ssh(host)) {
authenticator().authenticate(ssh.getConnection());
ssh.copyTo(tempScriptFile.getAbsolutePath(), "autoterminate.sh", ".");
ssh.executeRemoteCommand("chmod +x ./autoterminate.sh ; touch nohup.out");
// wait for 3 hours before termination
ssh.getConnection().exec(String.format("nohup ./autoterminate.sh %s %s `</dev/null` >nohup.out 2>&1 &", config.getUser(), AUTO_TERMINATE_TIMEOUT), System.out);
}
} finally {
if (!tempScriptFile.delete()) {
tempScriptFile.deleteOnExit();
}
}
}
use of org.jenkinsci.test.acceptance.Ssh in project acceptance-test-harness by jenkinsci.
the class RemoteJenkinsController method populateJenkinsHome.
@Override
public void populateJenkinsHome(byte[] _template, boolean clean) throws IOException {
boolean running = isRunning();
try (Ssh connection = machine.connect()) {
stop();
if (clean) {
connection.executeRemoteCommand("rm -rf " + Ssh.escape(jenkinsHome) + "; mkdir -p " + Ssh.escape(jenkinsHome));
}
File template = File.createTempFile("template", ".dat");
try {
org.apache.commons.io.FileUtils.writeByteArrayToFile(template, _template);
connection.copyTo(template.getAbsolutePath(), ".home-template.zip", jenkinsHome);
} finally {
template.delete();
}
String templateArchive = Ssh.escape(jenkinsHome + (jenkinsHome.endsWith("/") ? "" : "/") + ".home-template.zip");
connection.executeRemoteCommand("unzip -o " + templateArchive + " -d " + Ssh.escape(jenkinsHome) + " && rm -f " + templateArchive);
} catch (Exception e) {
throw new IOException(e.getMessage(), e);
} finally {
if (running && !isRunning()) {
start();
}
}
}
use of org.jenkinsci.test.acceptance.Ssh in project acceptance-test-harness by jenkinsci.
the class Ec2Provider method copyAutoterminateScript.
private void copyAutoterminateScript(String host) throws IOException, InterruptedException {
// run terminate script
URL script = this.getClass().getClassLoader().getResource("org/jenkinsci/test/acceptance/machine/autoterminate.sh");
File tempScriptFile = File.createTempFile("autoterminate", ".sh");
try {
FileUtils.copyURLToFile(script, tempScriptFile);
logger.info(String.format("Executing auto-terminate script on remote machine: %s, it will terminate after 180 minutes of " + "inactivity.", host));
try (Ssh ssh = new Ssh(host)) {
authenticator().authenticate(ssh.getConnection());
ssh.copyTo(tempScriptFile.getAbsolutePath(), "autoterminate.sh", ".");
ssh.executeRemoteCommand("chmod +x ./autoterminate.sh ; touch nohup.out");
// wait for 3 hours before termination
ssh.getConnection().exec(String.format("nohup ./autoterminate.sh %s %s `</dev/null` >nohup.out 2>&1 &", config.getUser(), AUTO_TERMINATE_TIMEOUT), System.out);
}
} finally {
if (!tempScriptFile.delete()) {
tempScriptFile.deleteOnExit();
}
}
}
Aggregations