Skip to content
Permalink
Browse files

[FIXED JENKINS-23517] InstallerTranslator should gracefully ignore of…

…fline slaves.
  • Loading branch information
jglick committed Jun 24, 2014
1 parent 25d8553 commit 3e44e1365e0d20ac77c914c3372767182735f616
@@ -55,6 +55,9 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=bug>
<code>IllegalArgumentException</code> from <code>AbstractProject.getEnvironment</code> when trying to get environment variables from an offline slave.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-23517">issue 23517</a>)
<li class=bug>
Overall.READ is sufficient to access /administrativeMonitor/hudsonHomeIsFull/
(SECURITY-134)
@@ -42,6 +42,10 @@
private static final Map<Node,Map<ToolInstallation,Semaphore>> mutexByNode = new WeakHashMap<Node,Map<ToolInstallation,Semaphore>>();

public String getToolHome(Node node, ToolInstallation tool, TaskListener log) throws IOException, InterruptedException {
if (node.getRootPath() == null) {
log.error(node.getDisplayName() + " is offline; cannot locate " + tool.getName());
return null;
}
InstallSourceProperty isp = tool.getProperties().get(InstallSourceProperty.class);
if (isp == null) {
return null;
@@ -0,0 +1,63 @@
/*
* The MIT License
*
* Copyright 2014 Jesse Glick.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package hudson.tools;

import hudson.model.FreeStyleProject;
import hudson.model.JDK;
import hudson.model.Node;
import hudson.slaves.DumbSlave;
import hudson.slaves.JNLPLauncher;
import hudson.slaves.NodeProperty;
import hudson.slaves.RetentionStrategy;
import hudson.util.StreamTaskListener;
import java.nio.charset.Charset;
import java.util.Collections;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Rule;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

public class InstallerTranslatorTest {

@Rule public JenkinsRule r = new JenkinsRule();

@Issue("JENKINS-23517")
@Test public void offlineNodeForJDK() throws Exception {
Node slave = new DumbSlave("disconnected-slave", null, "/wherever", "1", Node.Mode.NORMAL, null, new JNLPLauncher(), RetentionStrategy.NOOP, Collections.<NodeProperty<?>>emptyList());
String globalDefaultLocation = "/usr/lib/jdk";
JDK jdk = new JDK("my-jdk", globalDefaultLocation, Collections.singletonList(new InstallSourceProperty(Collections.singletonList(new CommandInstaller(null, "irrelevant", "/opt/jdk")))));
r.jenkins.getJDKs().add(jdk);
FreeStyleProject p = r.createFreeStyleProject();
p.setJDK(jdk);
StreamTaskListener listener = new StreamTaskListener(System.out, Charset.defaultCharset());
String javaHomeProp = "JAVA_HOME"; // cf. JDK.buildEnvVars
assertEquals(globalDefaultLocation, p.getEnvironment(slave, listener).get(javaHomeProp));
String slaveDefaultLocation = "/System/JDK";
slave.getNodeProperties().add(new ToolLocationNodeProperty(new ToolLocationNodeProperty.ToolLocation((ToolDescriptor) jdk.getDescriptor(), jdk.getName(), slaveDefaultLocation)));
assertEquals(slaveDefaultLocation, p.getEnvironment(slave, listener).get(javaHomeProp));
}

}

0 comments on commit 3e44e13

Please sign in to comment.
You can’t perform that action at this time.