Skip to content

Commit

Permalink
Merge pull request #7 from jenkinsci/docker-JENKINS-50518
Browse files Browse the repository at this point in the history
[JENKINS-50518] Run tests inside Dockerized agents
  • Loading branch information
carlossg committed Apr 6, 2018
2 parents 23cd439 + ad9fabe commit fb9698c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
26 changes: 25 additions & 1 deletion pom.xml
Expand Up @@ -18,7 +18,7 @@
<jenkins-core.version>2.115-20180402.200252-1</jenkins-core.version> <!-- TODO https://github.com/jenkinsci/jenkins/pull/3302 -->
<jenkins-war.version>2.115-20180402.200314-1</jenkins-war.version>
<java.level>8</java.level>
<workflow-api-plugin.version>2.27-20180402.200639-11</workflow-api-plugin.version> <!-- TODO https://github.com/jenkinsci/workflow-api-plugin/pull/67 -->
<workflow-api-plugin.version>2.27-20180404.204940-13</workflow-api-plugin.version> <!-- TODO https://github.com/jenkinsci/workflow-api-plugin/pull/67 -->
<useBeta>true</useBeta>
</properties>

Expand Down Expand Up @@ -111,6 +111,30 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.test</groupId>
<artifactId>docker-fixtures</artifactId>
<version>1.7</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ssh-slaves</artifactId>
<version>1.26</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>jdk-tool</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
Expand Down
Expand Up @@ -59,6 +59,7 @@ public static void live() {
assumeTrue(S3_BUCKET + " bucket does not exist", builder.build().doesBucketExistV2(S3_BUCKET));
assumeThat("can get credentials from environment", builder.getCredentials().getCredentials(), notNullValue());
} catch (SdkClientException x) {
x.printStackTrace();
assumeNoException("failed to connect to S3 with current credentials", x);
}
}
Expand Down
Expand Up @@ -24,6 +24,8 @@

package io.jenkins.plugins.artifact_manager_s3;

import com.amazonaws.SdkClientException;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

Expand All @@ -37,7 +39,6 @@
import org.apache.commons.io.output.NullOutputStream;
import org.jclouds.rest.internal.InvokeHttpMethod;
import org.jenkinsci.plugins.workflow.ArtifactManagerTest;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
Expand All @@ -53,12 +54,17 @@
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Run;
import hudson.plugins.sshslaves.SSHLauncher;
import hudson.remoting.Which;
import hudson.slaves.DumbSlave;
import hudson.tasks.ArtifactArchiver;
import jenkins.model.ArtifactManager;
import jenkins.model.ArtifactManagerConfiguration;
import jenkins.model.ArtifactManagerFactory;
import jenkins.model.Jenkins;
import jenkins.security.MasterToSlaveCallable;
import org.jenkinsci.test.acceptance.docker.DockerImage;
import org.jenkinsci.test.acceptance.docker.fixtures.JavaContainer;

public class JCloudsArtifactManagerTest {

Expand All @@ -69,6 +75,13 @@ public static void live() {
JCloudsAbstractTest.live();
}

private static DockerImage image;

@BeforeClass
public static void doPrepareImage() throws Exception {
image = ArtifactManagerTest.prepareImage();
}

@Rule
public JenkinsRule j = new JenkinsRule();

Expand Down Expand Up @@ -106,8 +119,29 @@ protected ArtifactManagerFactory getArtifactManagerFactory() {

@Test
public void smokes() throws Exception {
if (image != null) {
System.err.println("verifying that while the master can connect to S3, a Dockerized agent cannot");
try (JavaContainer container = image.start(JavaContainer.class).start()) {
DumbSlave agent = new DumbSlave("assumptions", "/home/test/slave", new SSHLauncher(container.ipBound(22), container.port(22), "test", "test", "", ""));
Jenkins.get().addNode(agent);
j.waitOnline(agent);
try {
agent.getChannel().call(new LoadS3Credentials());
fail("did not expect to be able to connect to S3 from a Dockerized agent"); // or AssumptionViolatedException?
} catch (SdkClientException x) {
System.err.println("a Dockerized agent was unable to connect to S3, as expected: " + x);
}
}
}
// To demo class loading performance: loggerRule.record(SlaveComputer.class, Level.FINEST);
ArtifactManagerTest.run(j, getArtifactManagerFactory(), /* TODO S3BlobStore.list does not seem to handle weird characters */false);
ArtifactManagerTest.run(j, getArtifactManagerFactory(), /* TODO S3BlobStore.list does not seem to handle weird characters */false, image);
}
private static final class LoadS3Credentials extends MasterToSlaveCallable<Void, RuntimeException> {
@Override
public Void call() {
AmazonS3ClientBuilder.standard().build();
return null;
}
}

@Test
Expand Down

0 comments on commit fb9698c

Please sign in to comment.