Search in sources :

Example 1 with SshSlaveLauncher

use of org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher in project acceptance-test-harness by jenkinsci.

the class TSRCreateSlaveTest method newSlave.

@Test
@Since("1.560")
public void newSlave() {
    // this test requires a newer version of credentials plugin that has inline "Add" button
    // I'm not sure exactly which version it is, but 1.532 LTS doesn't have it, and 1.555 has it,
    // so it's somewhere in between
    // TODO: this should be converted to "@WithPlugin("ssh-credentials") with specific version tag,
    // not the core version
    // Just to make sure the dumb slave is set up properly, we should seed it
    // with a FS root and executors
    final DumbSlave s = jenkins.slaves.create(DumbSlave.class);
    {
        SshSlaveLauncher l = s.setLauncher(SshSlaveLauncher.class);
        String username = "user1";
        String privateKey = "1212122112";
        String description = "Ssh key";
        l.host.set("127.0.0.1");
        // make sure this exists
        l.credentialsId.resolve();
        try {
            l.credentialsId.select(String.format("%s (%s)", username, description));
            fail();
        } catch (NoSuchElementException e) {
        // ignore
        }
        SshCredentialDialog f = l.addCredential();
        {
            SshPrivateKeyCredential sc = f.select(SshPrivateKeyCredential.class);
            sc.description.set(description);
            sc.username.set(username);
            sc.selectEnterDirectly().privateKey.set(privateKey);
        }
        f.add();
        l.credentialsId.select(String.format("%s (%s)", username, description));
    }
    s.save();
}
Also used : SshSlaveLauncher(org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher) SshPrivateKeyCredential(org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential) SshCredentialDialog(org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshCredentialDialog) Matchers.containsString(org.hamcrest.Matchers.containsString) DumbSlave(org.jenkinsci.test.acceptance.po.DumbSlave) NoSuchElementException(org.openqa.selenium.NoSuchElementException) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) Since(org.jenkinsci.test.acceptance.junit.Since)

Example 2 with SshSlaveLauncher

use of org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher in project acceptance-test-harness by jenkinsci.

the class WorkflowPluginTest method sshGitInsideDocker.

@Category(DockerTest.class)
@WithDocker
@WithPlugins({ "workflow-cps@2.0", "workflow-job@2.0", "workflow-durable-task-step@2.0", "docker-workflow@1.5", "git", "ssh-agent@1.10", "ssh-slaves@1.11" })
@WithCredentials(credentialType = WithCredentials.SSH_USERNAME_PRIVATE_KEY, values = { "git", "/org/jenkinsci/test/acceptance/docker/fixtures/GitContainer/unsafe" }, id = "gitcreds")
@Issue("JENKINS-27152")
@Test
public void sshGitInsideDocker() throws Exception {
    GitContainer gitContainer = gitServer.get();
    try (GitRepo repo = new GitRepo()) {
        repo.changeAndCommitFoo("Initial commit");
        repo.transferToDockerContainer(gitContainer.host(), gitContainer.port());
        DumbSlave slave = jenkins.slaves.create(DumbSlave.class);
        slave.setExecutors(1);
        // TODO perhaps should be a constant in SshdContainer
        slave.remoteFS.set("/home/test");
        SshSlaveLauncher launcher = slave.setLauncher(SshSlaveLauncher.class);
        Process proc = new ProcessBuilder("stat", "-c", "%g", "/var/run/docker.sock").start();
        String group = IOUtils.toString(proc.getInputStream()).trim();
        Assume.assumeThat("docker.sock can be statted", proc.waitFor(), is(0));
        try {
            Integer.parseInt(group);
        } catch (NumberFormatException x) {
            Assume.assumeNoException("unexpected output from stat on docker.sock", x);
        }
        // Note that we need to link to the Git container both on the agent, for the benefit of JGit (TODO pending JENKINS-30600), and in the build container, for the benefit of git-pull:
        DockerAgentContainer agentContainer = agent.starter().withOptions(new CommandBuilder("--volume=/var/run/docker.sock:/var/run/docker.sock", "--env=DOCKER_GROUP=" + group, "--link=" + gitContainer.getCid() + ":git")).start();
        launcher.host.set(agentContainer.ipBound(22));
        launcher.port(agentContainer.port(22));
        launcher.pwdCredentials("test", "test");
        launcher.setSshHostKeyVerificationStrategy(SshSlaveLauncher.NonVerifyingKeyVerificationStrategy.class);
        slave.save();
        {
            // TODO JENKINS-30600 workaround
            JGitInstallation.addJGit(jenkins);
            find(by.button("Save")).click();
        }
        WorkflowJob job = jenkins.jobs.create(WorkflowJob.class);
        String networkOptions = StringUtils.isNotBlank(System.getenv("DOCKER_FIXTURES_NETWORK")) ? " --network=" + System.getenv("DOCKER_FIXTURES_NETWORK") : "";
        String options = "--link=" + gitContainer.getCid() + ":git" + networkOptions;
        String repoUrl = StringUtils.isNotBlank(System.getenv("DOCKER_FIXTURES_NETWORK")) ? gitContainer.getRepoUrlInsideDocker() : gitContainer.getRepoUrlInsideDocker("git");
        job.script.set("node('" + slave.getName() + "') {\n" + "  docker.image('cloudbees/java-build-tools').inside('" + options + "') {\n" + // TODO JENKINS-30600: "    git url: '" + gitContainer.getRepoUrlInsideDocker("git") + "', credentialsId: 'gitcreds'\n" +
        "    checkout([$class: 'GitSCM', userRemoteConfigs: [[url: '" + repoUrl + "', credentialsId: 'gitcreds']], gitTool: 'jgit'])\n" + "    sh 'mkdir ~/.ssh && echo StrictHostKeyChecking no > ~/.ssh/config'\n" + "    sshagent(['gitcreds']) {sh 'ls -l $SSH_AUTH_SOCK && git pull origin master'}\n" + "  }\n" + "}");
        job.sandbox.check();
        job.save();
        assertThat(job.startBuild().shouldSucceed().getConsole(), containsString("-> FETCH_HEAD"));
    }
}
Also used : SshSlaveLauncher(org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher) GitContainer(org.jenkinsci.test.acceptance.docker.fixtures.GitContainer) GitRepo(org.jenkinsci.test.acceptance.plugins.git.GitRepo) DockerAgentContainer(org.jenkinsci.test.acceptance.docker.fixtures.DockerAgentContainer) Matchers.containsString(org.hamcrest.Matchers.containsString) DumbSlave(org.jenkinsci.test.acceptance.po.DumbSlave) CommandBuilder(org.jenkinsci.utils.process.CommandBuilder) WorkflowJob(org.jenkinsci.test.acceptance.po.WorkflowJob) Category(org.junit.experimental.categories.Category) WithCredentials(org.jenkinsci.test.acceptance.junit.WithCredentials) Issue(org.jvnet.hudson.test.Issue) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) DockerTest(org.jenkinsci.test.acceptance.junit.DockerTest) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins) WithDocker(org.jenkinsci.test.acceptance.junit.WithDocker)

Example 3 with SshSlaveLauncher

use of org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher in project acceptance-test-harness by jenkinsci.

the class SshSlavesPluginTest method customJavaPath.

@Test
public void customJavaPath() {
    setUp();
    SshSlaveLauncher launcher = configureDefaultSSHSlaveLauncher().pwdCredentials("test", "test");
    launcher.javaPath.set("/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java");
    slave.save();
    verify();
    verifyLog("java-8-openjdk-amd64");
}
Also used : SshSlaveLauncher(org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) DockerTest(org.jenkinsci.test.acceptance.junit.DockerTest)

Example 4 with SshSlaveLauncher

use of org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher in project acceptance-test-harness by jenkinsci.

the class XvncSlaveContainer method connect.

/**
 * Attaches the slave to Jenkins.
 * @param j the server
 * @return return a configured slave; call {@link Slave#save} after any other customizations to complete; use {@link Slave#waitUntilOnline} if desired
 */
public Slave connect(Jenkins j) {
    // Some code from SshSlaveController could be applicable here, but looks too tricky to reuse.
    DumbSlave s = j.slaves.create(DumbSlave.class);
    SshSlaveLauncher launcher = s.setLauncher(SshSlaveLauncher.class);
    launcher.host.set(ipBound(22));
    launcher.port(port(22));
    launcher.pwdCredentials("test", "test");
    launcher.setSshHostKeyVerificationStrategy(SshSlaveLauncher.NonVerifyingKeyVerificationStrategy.class);
    s.remoteFS.set("/home/test");
    s.setExecutors(1);
    return s;
}
Also used : SshSlaveLauncher(org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher) DumbSlave(org.jenkinsci.test.acceptance.po.DumbSlave)

Example 5 with SshSlaveLauncher

use of org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher in project acceptance-test-harness by jenkinsci.

the class TSRCreateSlaveTest method newSlaveWithExistingCredential.

@Test
@WithPlugins("credentials@2.0.7")
public void newSlaveWithExistingCredential() throws Exception {
    String username = "xyz";
    String description = "SSH Key setup";
    String privateKey = "1212121122121212";
    CredentialsPage c = new CredentialsPage(jenkins, "_");
    c.open();
    SshPrivateKeyCredential sc = c.add(SshPrivateKeyCredential.class);
    sc.username.set(username);
    sc.description.set(description);
    sc.selectEnterDirectly().privateKey.set(privateKey);
    c.create();
    // now verify
    c.open();
    ManagedCredentials mc = new ManagedCredentials(jenkins);
    String href = mc.credentialById("ssh_creds");
    c.setConfigUrl(href);
    verifyValueForCredential(c, sc.username, username);
    verifyValueForCredential(c, sc.selectEnterDirectly().privateKey, privateKey);
    // Just to make sure the dumb slave is set up properly, we should seed it
    // with a FS root and executors
    final DumbSlave s = jenkins.slaves.create(DumbSlave.class);
    SshSlaveLauncher l = s.setLauncher(SshSlaveLauncher.class);
    l.host.set("127.0.0.1");
    l.credentialsId.select(String.format("%s (%s)", username, description));
}
Also used : SshPrivateKeyCredential(org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential) SshSlaveLauncher(org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher) CredentialsPage(org.jenkinsci.test.acceptance.plugins.credentials.CredentialsPage) Matchers.containsString(org.hamcrest.Matchers.containsString) DumbSlave(org.jenkinsci.test.acceptance.po.DumbSlave) ManagedCredentials(org.jenkinsci.test.acceptance.plugins.credentials.ManagedCredentials) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Aggregations

SshSlaveLauncher (org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher)11 AbstractJUnitTest (org.jenkinsci.test.acceptance.junit.AbstractJUnitTest)8 Test (org.junit.Test)8 DumbSlave (org.jenkinsci.test.acceptance.po.DumbSlave)7 Matchers.containsString (org.hamcrest.Matchers.containsString)6 DockerTest (org.jenkinsci.test.acceptance.junit.DockerTest)6 SshPrivateKeyCredential (org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential)4 Since (org.jenkinsci.test.acceptance.junit.Since)2 WithPlugins (org.jenkinsci.test.acceptance.junit.WithPlugins)2 CredentialsPage (org.jenkinsci.test.acceptance.plugins.credentials.CredentialsPage)2 ManagedCredentials (org.jenkinsci.test.acceptance.plugins.credentials.ManagedCredentials)2 SshCredentialDialog (org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshCredentialDialog)2 NoSuchElementException (org.openqa.selenium.NoSuchElementException)2 VersionNumber (hudson.util.VersionNumber)1 DockerAgentContainer (org.jenkinsci.test.acceptance.docker.fixtures.DockerAgentContainer)1 GitContainer (org.jenkinsci.test.acceptance.docker.fixtures.GitContainer)1 JavaGitContainer (org.jenkinsci.test.acceptance.docker.fixtures.JavaGitContainer)1 WithCredentials (org.jenkinsci.test.acceptance.junit.WithCredentials)1 WithDocker (org.jenkinsci.test.acceptance.junit.WithDocker)1 GitRepo (org.jenkinsci.test.acceptance.plugins.git.GitRepo)1