1- /*
1+ /*d
22 * The MIT License
33 *
44 * Copyright 2018 CloudBees, Inc.
3535import static org .junit .Assert .assertTrue ;
3636import 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 ;
4338import hudson .AbortException ;
4439import hudson .EnvVars ;
4540import hudson .ExtensionList ;
5045import hudson .model .FreeStyleBuild ;
5146import hudson .model .FreeStyleProject ;
5247import hudson .model .TaskListener ;
53- import hudson .plugins .sshslaves .SSHLauncher ;
5448import hudson .remoting .Callable ;
5549import hudson .slaves .DumbSlave ;
5650import hudson .tasks .ArtifactArchiver ;
5751import hudson .util .StreamTaskListener ;
5852import java .io .IOException ;
5953import java .io .InputStream ;
6054import java .net .URL ;
61- import java .nio .charset .Charset ;
6255import java .nio .charset .StandardCharsets ;
6356import java .util .Arrays ;
6457import java .util .Collections ;
6861import jenkins .model .ArtifactManager ;
6962import jenkins .model .ArtifactManagerConfiguration ;
7063import jenkins .model .ArtifactManagerFactory ;
71- import jenkins .model .Jenkins ;
7264import jenkins .model .StandardArtifactManager ;
7365import jenkins .security .MasterToSlaveCallable ;
7466import jenkins .util .VirtualFile ;
7567import org .apache .commons .io .IOUtils ;
7668import 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 ;
8169import org .junit .Rule ;
8270import org .junit .Test ;
8371import org .jvnet .hudson .test .JenkinsRule ;
8472import 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