Skip to content

Commit e03e7a6

Browse files
authored
Merge pull request #416 from jglick/OutboundAgent
Replacing `docker-fixtures` with `OutboundAgent`
2 parents f682ae8 + ae85c3f commit e03e7a6

File tree

2 files changed

+34
-71
lines changed

2 files changed

+34
-71
lines changed

pom.xml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,22 @@
7474
<dependency>
7575
<groupId>io.jenkins.tools.bom</groupId>
7676
<artifactId>bom-${jenkins.baseline}.x</artifactId>
77-
<version>4948.vcf1d17350668</version>
77+
<version>5015.vb_52d36583443</version>
7878
<scope>import</scope>
7979
<type>pom</type>
8080
</dependency>
81+
<!-- TODO until in BOM -->
82+
<dependency>
83+
<groupId>org.jenkins-ci.plugins</groupId>
84+
<artifactId>ssh-slaves</artifactId>
85+
<version>3.1071.v0d059c7b_c555</version>
86+
</dependency>
87+
<dependency>
88+
<groupId>org.jenkins-ci.plugins</groupId>
89+
<artifactId>ssh-slaves</artifactId>
90+
<classifier>tests</classifier>
91+
<version>3.1071.v0d059c7b_c555</version>
92+
</dependency>
8193
</dependencies>
8294
</dependencyManagement>
8395
<dependencies>
@@ -123,16 +135,27 @@
123135
<scope>test</scope>
124136
</dependency>
125137
<dependency>
126-
<groupId>org.jenkins-ci.test</groupId>
127-
<artifactId>docker-fixtures</artifactId>
128-
<version>200.v22a_e8766731c</version>
138+
<groupId>org.testcontainers</groupId>
139+
<artifactId>testcontainers</artifactId>
140+
<version>1.21.3</version>
129141
<scope>test</scope>
130142
</dependency>
131143
<dependency>
132144
<groupId>org.jenkins-ci.plugins</groupId>
133145
<artifactId>ssh-slaves</artifactId>
134146
<scope>test</scope>
135147
</dependency>
148+
<dependency>
149+
<groupId>org.jenkins-ci.plugins</groupId>
150+
<artifactId>ssh-slaves</artifactId>
151+
<classifier>tests</classifier>
152+
<scope>test</scope>
153+
</dependency>
154+
<dependency>
155+
<groupId>io.jenkins.plugins.mina-sshd-api</groupId>
156+
<artifactId>mina-sshd-api-common</artifactId>
157+
<scope>test</scope>
158+
</dependency>
136159
<dependency>
137160
<groupId>org.jenkins-ci.plugins</groupId>
138161
<artifactId>apache-httpcomponents-client-4-api</artifactId>

src/test/java/org/jenkinsci/plugins/workflow/ArtifactManagerTest.java

Lines changed: 7 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*d
22
* The MIT License
33
*
44
* Copyright 2018 CloudBees, Inc.
@@ -35,11 +35,6 @@
3535
import static org.junit.Assert.assertTrue;
3636
import static org.junit.Assert.fail;
3737

38-
import com.cloudbees.plugins.credentials.CredentialsProvider;
39-
import com.cloudbees.plugins.credentials.CredentialsScope;
40-
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
41-
import com.cloudbees.plugins.credentials.domains.Domain;
42-
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
4338
import hudson.AbortException;
4439
import hudson.EnvVars;
4540
import hudson.ExtensionList;
@@ -50,15 +45,13 @@
5045
import hudson.model.FreeStyleBuild;
5146
import hudson.model.FreeStyleProject;
5247
import hudson.model.TaskListener;
53-
import hudson.plugins.sshslaves.SSHLauncher;
5448
import hudson.remoting.Callable;
5549
import hudson.slaves.DumbSlave;
5650
import hudson.tasks.ArtifactArchiver;
5751
import hudson.util.StreamTaskListener;
5852
import java.io.IOException;
5953
import java.io.InputStream;
6054
import java.net.URL;
61-
import java.nio.charset.Charset;
6255
import java.nio.charset.StandardCharsets;
6356
import java.util.Arrays;
6457
import java.util.Collections;
@@ -68,20 +61,16 @@
6861
import jenkins.model.ArtifactManager;
6962
import jenkins.model.ArtifactManagerConfiguration;
7063
import jenkins.model.ArtifactManagerFactory;
71-
import jenkins.model.Jenkins;
7264
import jenkins.model.StandardArtifactManager;
7365
import jenkins.security.MasterToSlaveCallable;
7466
import jenkins.util.VirtualFile;
7567
import org.apache.commons.io.IOUtils;
7668
import org.jenkinsci.plugins.workflow.flow.StashManager;
77-
import org.jenkinsci.test.acceptance.docker.Docker;
78-
import org.jenkinsci.test.acceptance.docker.DockerImage;
79-
import org.jenkinsci.test.acceptance.docker.fixtures.JavaContainer;
80-
import org.junit.BeforeClass;
8169
import org.junit.Rule;
8270
import org.junit.Test;
8371
import org.jvnet.hudson.test.JenkinsRule;
8472
import org.jvnet.hudson.test.LoggerRule;
73+
import test.ssh_agent.OutboundAgent;
8574

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

9180
@Rule public JenkinsRule r = new JenkinsRule();
9281
@Rule public LoggerRule logging = new LoggerRule();
93-
94-
private static DockerImage image;
95-
96-
@BeforeClass public static void doPrepareImage() throws Exception {
97-
image = prepareImage();
98-
}
99-
100-
/**
101-
* @deprecated Not actually used externally.
102-
*/
103-
@Deprecated
104-
public static @CheckForNull DockerImage prepareImage() throws Exception {
105-
Docker docker = new Docker();
106-
if (!Functions.isWindows() && docker.isAvailable()) { // TODO: Windows agents on ci.jenkins.io have Docker, but cannot build the image.
107-
return docker.build(JavaContainer.class);
108-
} else {
109-
System.err.println("No Docker support; falling back to running tests against an agent in a process on the same machine.");
110-
return null;
111-
}
112-
}
11382

11483
/**
11584
* Creates an agent, in a Docker container when possible, calls {@link #setUpWorkspace}, then runs some tests.
@@ -119,19 +88,10 @@ private static void wrapInContainer(@NonNull JenkinsRule r, @CheckForNull Artifa
11988
if (factory != null) {
12089
ArtifactManagerConfiguration.get().getArtifactManagerFactories().add(factory);
12190
}
122-
JavaContainer runningContainer = null;
123-
try {
124-
DumbSlave agent;
125-
if (image != null) {
126-
runningContainer = image.start(JavaContainer.class).start();
127-
StandardUsernameCredentials creds = new UsernamePasswordCredentialsImpl(CredentialsScope.SYSTEM, "test", "desc", "test", "test");
128-
CredentialsProvider.lookupStores(Jenkins.get()).iterator().next().addCredentials(Domain.global(), creds);
129-
agent = new DumbSlave("test-agent", "/home/test/slave", new SSHLauncher(runningContainer.ipBound(22), runningContainer.port(22), "test"));
130-
Jenkins.get().addNode(agent);
131-
r.waitOnline(agent);
132-
} else {
133-
agent = r.createOnlineSlave();
134-
}
91+
try (var outboundAgent = new OutboundAgent()) {
92+
OutboundAgent.createAgent(r, "remote", outboundAgent.start());
93+
var agent = (DumbSlave) r.jenkins.getNode("remote");
94+
r.waitOnline(agent);
13595
FreeStyleProject p = r.createFreeStyleProject();
13696
p.setAssignedNode(agent);
13797
FilePath ws = agent.getWorkspaceFor(p);
@@ -141,10 +101,6 @@ private static void wrapInContainer(@NonNull JenkinsRule r, @CheckForNull Artifa
141101
p.getPublishersList().add(aa);
142102
FreeStyleBuild b = r.buildAndAssertSuccess(p);
143103
f.apply(agent, p, b, ws);
144-
} finally {
145-
if (runningContainer != null) {
146-
runningContainer.close();
147-
}
148104
}
149105
}
150106

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

169121
/**
170122
* Test artifact archiving in a plain manager.
@@ -180,10 +132,6 @@ public static void artifactArchiveAndDelete(@NonNull JenkinsRule r, @CheckForNul
180132
assertFalse(b.getArtifactManager().delete());
181133
});
182134
}
183-
@Deprecated
184-
public static void artifactArchiveAndDelete(@NonNull JenkinsRule r, @CheckForNull ArtifactManagerFactory factory, boolean weirdCharacters, @CheckForNull DockerImage image) throws Exception {
185-
artifactArchiveAndDelete(r, factory, weirdCharacters);
186-
}
187135

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

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

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

477417
}

0 commit comments

Comments
 (0)