Skip to content

Commit

Permalink
Merge pull request #10 from vjuranek/JENKINS-9773
Browse files Browse the repository at this point in the history
Jenkins 9773
  • Loading branch information
vjuranek committed Jun 27, 2011
2 parents 3e5ed16 + 1792273 commit df31371
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/ec2/EC2Cloud.java
Expand Up @@ -124,7 +124,7 @@ public SlaveTemplate getTemplate(String ami) {
*/
public SlaveTemplate getTemplate(Label label) {
for (SlaveTemplate t : templates)
if(t.containsLabel(label))
if(label.matches(t.getLabelSet()))
return t;
return null;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/hudson/plugins/ec2/SlaveTemplate.java
Expand Up @@ -102,6 +102,10 @@ public String getRootCommandPrefix() {
return rootCommandPrefix;
}

public Set getLabelSet(){
return labelSet;
}

/**
* Does this contain the given label?
*
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/hudson/plugins/ec2/TemplateLabelsTest.java
@@ -0,0 +1,43 @@
package hudson.plugins.ec2;

import hudson.model.Label;
import hudson.model.labels.LabelAtom;

import java.util.ArrayList;
import java.util.List;

import org.jvnet.hudson.test.HudsonTestCase;

import com.xerox.amazonws.ec2.InstanceType;

public class TemplateLabelsTest extends HudsonTestCase{

private AmazonEC2Cloud ac;
private final String LABEL1 = "label1";
private final String LABEL2 = "label2";

@Override
public void setUp() throws Exception{
super.setUp();
SlaveTemplate template = new SlaveTemplate("ami", "foo", "22", InstanceType.LARGE, LABEL1 + " " + LABEL2, "foo ami", "bar", "aaa", "10", "rrr", "fff", "-Xmx1g");
List<SlaveTemplate> templates = new ArrayList<SlaveTemplate>();
templates.add(template);
ac = new AmazonEC2Cloud(AwsRegion.US_EAST_1, "abc", "def", "ghi", "3", templates);
}

public void testLabelAtom(){
assertEquals(true, ac.canProvision(new LabelAtom(LABEL1)));
assertEquals(true, ac.canProvision(new LabelAtom(LABEL2)));
assertEquals(false, ac.canProvision(new LabelAtom("aaa")));
}

public void testLabelExpression() throws Exception{
assertEquals(true, ac.canProvision(Label.parseExpression(LABEL1 + " || " + LABEL2)));
assertEquals(true, ac.canProvision(Label.parseExpression(LABEL1 + " && " + LABEL2)));
assertEquals(true, ac.canProvision(Label.parseExpression(LABEL1 + " || aaa")));
assertEquals(false, ac.canProvision(Label.parseExpression(LABEL1 + " && aaa")));
assertEquals(false, ac.canProvision(Label.parseExpression("aaa || bbb")));
assertEquals(false, ac.canProvision(Label.parseExpression("aaa || bbb")));
}

}

0 comments on commit df31371

Please sign in to comment.