Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,22 @@
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-${jenkins.baseline}.x</artifactId>
<version>4948.vcf1d17350668</version>
<version>5015.vb_52d36583443</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<!-- TODO until in BOM -->
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ssh-slaves</artifactId>
<version>3.1071.v0d059c7b_c555</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ssh-slaves</artifactId>
<classifier>tests</classifier>
<version>3.1071.v0d059c7b_c555</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -123,16 +135,27 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.test</groupId>
<artifactId>docker-fixtures</artifactId>
<version>200.v22a_e8766731c</version>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.21.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ssh-slaves</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ssh-slaves</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.jenkins.plugins.mina-sshd-api</groupId>
<artifactId>mina-sshd-api-common</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>apache-httpcomponents-client-4-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*d
* The MIT License
*
* Copyright 2018 CloudBees, Inc.
Expand Down Expand Up @@ -35,11 +35,6 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import com.cloudbees.plugins.credentials.domains.Domain;
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
import hudson.AbortException;
import hudson.EnvVars;
import hudson.ExtensionList;
Expand All @@ -50,15 +45,13 @@
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.TaskListener;
import hudson.plugins.sshslaves.SSHLauncher;
import hudson.remoting.Callable;
import hudson.slaves.DumbSlave;
import hudson.tasks.ArtifactArchiver;
import hudson.util.StreamTaskListener;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -68,20 +61,16 @@
import jenkins.model.ArtifactManager;
import jenkins.model.ArtifactManagerConfiguration;
import jenkins.model.ArtifactManagerFactory;
import jenkins.model.Jenkins;
import jenkins.model.StandardArtifactManager;
import jenkins.security.MasterToSlaveCallable;
import jenkins.util.VirtualFile;
import org.apache.commons.io.IOUtils;
import org.jenkinsci.plugins.workflow.flow.StashManager;
import org.jenkinsci.test.acceptance.docker.Docker;
import org.jenkinsci.test.acceptance.docker.DockerImage;
import org.jenkinsci.test.acceptance.docker.fixtures.JavaContainer;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.LoggerRule;
import test.ssh_agent.OutboundAgent;

/**
* {@link #artifactArchiveAndDelete} and variants allow an implementation of {@link ArtifactManager} plus {@link VirtualFile} to be run through a standard gantlet of tests.
Expand All @@ -90,26 +79,6 @@ public class ArtifactManagerTest {

@Rule public JenkinsRule r = new JenkinsRule();
@Rule public LoggerRule logging = new LoggerRule();

private static DockerImage image;

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

/**
* @deprecated Not actually used externally.
*/
@Deprecated
public static @CheckForNull DockerImage prepareImage() throws Exception {
Docker docker = new Docker();
if (!Functions.isWindows() && docker.isAvailable()) { // TODO: Windows agents on ci.jenkins.io have Docker, but cannot build the image.
return docker.build(JavaContainer.class);
} else {
System.err.println("No Docker support; falling back to running tests against an agent in a process on the same machine.");
return null;
}
}

/**
* Creates an agent, in a Docker container when possible, calls {@link #setUpWorkspace}, then runs some tests.
Expand All @@ -119,19 +88,10 @@ private static void wrapInContainer(@NonNull JenkinsRule r, @CheckForNull Artifa
if (factory != null) {
ArtifactManagerConfiguration.get().getArtifactManagerFactories().add(factory);
}
JavaContainer runningContainer = null;
try {
DumbSlave agent;
if (image != null) {
runningContainer = image.start(JavaContainer.class).start();
StandardUsernameCredentials creds = new UsernamePasswordCredentialsImpl(CredentialsScope.SYSTEM, "test", "desc", "test", "test");
CredentialsProvider.lookupStores(Jenkins.get()).iterator().next().addCredentials(Domain.global(), creds);
agent = new DumbSlave("test-agent", "/home/test/slave", new SSHLauncher(runningContainer.ipBound(22), runningContainer.port(22), "test"));
Jenkins.get().addNode(agent);
r.waitOnline(agent);
} else {
agent = r.createOnlineSlave();
}
try (var outboundAgent = new OutboundAgent()) {
OutboundAgent.createAgent(r, "remote", outboundAgent.start());
var agent = (DumbSlave) r.jenkins.getNode("remote");
r.waitOnline(agent);
FreeStyleProject p = r.createFreeStyleProject();
p.setAssignedNode(agent);
FilePath ws = agent.getWorkspaceFor(p);
Expand All @@ -141,10 +101,6 @@ private static void wrapInContainer(@NonNull JenkinsRule r, @CheckForNull Artifa
p.getPublishersList().add(aa);
FreeStyleBuild b = r.buildAndAssertSuccess(p);
f.apply(agent, p, b, ws);
} finally {
if (runningContainer != null) {
runningContainer.close();
}
}
}

Expand All @@ -161,10 +117,6 @@ public static void artifactArchive(@NonNull JenkinsRule r, @CheckForNull Artifac
assertTrue(b.getArtifactManager().root().child("file").isFile());
});
}
@Deprecated
public static void artifactArchive(@NonNull JenkinsRule r, @CheckForNull ArtifactManagerFactory factory, boolean weirdCharacters, @CheckForNull DockerImage image) throws Exception {
artifactArchive(r, factory, weirdCharacters);
}

/**
* Test artifact archiving in a plain manager.
Expand All @@ -180,10 +132,6 @@ public static void artifactArchiveAndDelete(@NonNull JenkinsRule r, @CheckForNul
assertFalse(b.getArtifactManager().delete());
});
}
@Deprecated
public static void artifactArchiveAndDelete(@NonNull JenkinsRule r, @CheckForNull ArtifactManagerFactory factory, boolean weirdCharacters, @CheckForNull DockerImage image) throws Exception {
artifactArchiveAndDelete(r, factory, weirdCharacters);
}

/**
* Test stashing and unstashing with a {@link StashManager.StashAwareArtifactManager} that does <em>not</em> honor deletion requests.
Expand All @@ -197,10 +145,6 @@ public static void artifactStash(@NonNull JenkinsRule r, @CheckForNull ArtifactM
assertTrue(ws.child("file").exists());
}));
}
@Deprecated
public static void artifactStash(@NonNull JenkinsRule r, @CheckForNull ArtifactManagerFactory factory, boolean weirdCharacters, @CheckForNull DockerImage image) throws Exception {
artifactStash(r, factory, weirdCharacters);
}

/**
* Test stashing and unstashing with a {@link StashManager.StashAwareArtifactManager} with standard behavior.
Expand All @@ -218,10 +162,6 @@ public static void artifactStashAndDelete(@NonNull JenkinsRule r, @CheckForNull
assertFalse(ws.child("file").exists());
}));
}
@Deprecated
public static void artifactStashAndDelete(@NonNull JenkinsRule r, @CheckForNull ArtifactManagerFactory factory, boolean weirdCharacters, @CheckForNull DockerImage image) throws Exception {
artifactStashAndDelete(r, factory, weirdCharacters);
}

/**
* Creates a variety of files in a directory structure designed to exercise interesting aspects of {@link VirtualFile}.
Expand Down Expand Up @@ -471,7 +411,7 @@ private static void assertNonexistent(VirtualFile f) throws IOException {
@Test public void standard() throws Exception {
logging.record(StandardArtifactManager.class, Level.FINE);
// Who knows about weird characters on NTFS; also case-sensitivity could confuse things
artifactArchiveAndDelete(r, null, !Functions.isWindows(), image);
artifactArchiveAndDelete(r, null, !Functions.isWindows());
}

}