Skip to content
Permalink
Browse files
[JENKINS-51523] Delegate artifact lifecycle management to S3
  • Loading branch information
carlossg committed May 25, 2018
1 parent 706b58c commit a25b8ed49f40f29562c4a4af6cffd37024bb0f8b
@@ -19,7 +19,7 @@
<jclouds.version>2.0.3</jclouds.version>
<jenkins.version>2.121</jenkins.version>
<java.level>8</java.level>
<workflow-api-plugin.version>2.28-rc337.8abe7c5204d9</workflow-api-plugin.version> <!-- TODO https://github.com/jenkinsci/workflow-api-plugin/pull/67 -->
<workflow-api-plugin.version>2.28-rc338.1dfffb24a014</workflow-api-plugin.version> <!-- TODO https://github.com/jenkinsci/workflow-api-plugin/pull/67 -->
<useBeta>true</useBeta>
</properties>

@@ -83,9 +83,12 @@
@SuppressWarnings("FieldMayBeFinal")
private static String REGION = System.getProperty(S3BlobStore.class.getName() + ".region");
@SuppressWarnings("FieldMayBeFinal")
private static boolean DELETE_BLOBS = Boolean.getBoolean(S3BlobStore.class.getName() + ".deleteBlobs");
private static boolean DEFAULT_DELETE_BLOBS = Boolean.getBoolean(S3BlobStore.class.getName() + ".defaultDeleteBlobs");
@SuppressWarnings("FieldMayBeFinal")
private static boolean DELETE_STASHES = Boolean.getBoolean(S3BlobStore.class.getName() + ".deleteStashes");
private static boolean DEFAULT_DELETE_STASHES = Boolean.getBoolean(S3BlobStore.class.getName() + ".defaultDeleteStashes");

private boolean deleteBlobs = DEFAULT_DELETE_BLOBS;
private boolean deleteStashes = DEFAULT_DELETE_STASHES;

@DataBoundConstructor
public S3BlobStore() {}
@@ -102,12 +105,22 @@ public String getContainer() {

@Override
public boolean isDeleteBlobs() {
return DELETE_BLOBS;
return deleteBlobs;
}

@Restricted(NoExternalUse.class) // test only
public void setDeleteBlobs(boolean deleteBlobs) {
this.deleteBlobs = deleteBlobs;
}

@Override
public boolean isDeleteStashes() {
return DELETE_STASHES;
return deleteStashes;
}

@Restricted(NoExternalUse.class) // test only
public void setDeleteStashes(boolean deleteStashes) {
this.deleteStashes = deleteStashes;
}

@Override
@@ -29,6 +29,7 @@
import io.jenkins.plugins.artifact_manager_jclouds.JCloudsArtifactManagerFactory;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.junit.Assume.*;

import java.io.IOException;
import java.io.InputStream;
@@ -120,11 +121,11 @@ public String getContainer() {
}
@Override
public boolean isDeleteBlobs() {
return false;
return delegate.isDeleteBlobs();
}
@Override
public boolean isDeleteStashes() {
return false;
return delegate.isDeleteStashes();
}
@Override
public BlobStoreContext getContext() throws IOException {
@@ -145,24 +146,49 @@ public BlobStoreProviderDescriptor getDescriptor() {
}

@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);
}
public void agentPermissions() throws Exception {
assumeNotNull(image);
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);
}
}
}

@Test
public void artifactArchive() throws Exception {
// 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, image);
ArtifactManagerTest.artifactArchive(j, getArtifactManagerFactory(), /* TODO S3BlobStore.list does not seem to handle weird characters */false, image);
}

@Test
public void artifactArchiveAndDelete() throws Exception {
if (provider instanceof S3BlobStore) {
((S3BlobStore) provider).setDeleteBlobs(true);
}
ArtifactManagerTest.artifactArchiveAndDelete(j, getArtifactManagerFactory(), false, image);
}

@Test
public void artifactStash() throws Exception {
ArtifactManagerTest.artifactStash(j, getArtifactManagerFactory(), false, image);
}

@Test
public void artifactStashAndDelete() throws Exception {
if (provider instanceof S3BlobStore) {
((S3BlobStore) provider).setDeleteStashes(true);
}
ArtifactManagerTest.artifactStashAndDelete(j, getArtifactManagerFactory(), false, image);
}

private static final class LoadS3Credentials extends MasterToSlaveCallable<Void, RuntimeException> {
@Override
public Void call() {

0 comments on commit a25b8ed

Please sign in to comment.