Skip to content

Commit

Permalink
[JENKINS-51137] Tests need to pass the cloud labels
Browse files Browse the repository at this point in the history
  • Loading branch information
carlossg committed May 24, 2018
1 parent 62c9510 commit b1bfea3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static KubernetesCloud setupCloud(Object test) throws UnrecoverableKeyExc
CertificateEncodingException, NoSuchAlgorithmException, KeyStoreException, IOException {
KubernetesCloud cloud = new KubernetesCloud("kubernetes");
// unique labels per test
cloud.setLabels(getLabels(test));
cloud.setLabels(getLabels(cloud, test));
KubernetesClient client = cloud.connect();

// Run in our own testing namespace
Expand Down Expand Up @@ -118,7 +118,14 @@ public static void assumeKubernetes() throws Exception {
}

public static Map<String, String> getLabels(Object o) {
return getLabels(null, o);
}

public static Map<String, String> getLabels(KubernetesCloud cloud, Object o) {
HashMap<String, String> l = Maps.newHashMap(DEFAULT_LABELS);
if (cloud != null) {
l.putAll(cloud.getLabels());
}
l.put("class", o.getClass().getSimpleName());
return l;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class KubernetesPipelineTest extends AbstractKubernetesPipelineTest {

@Test
public void runInPod() throws Exception {
deletePods(cloud.connect(), getLabels(this), false);
deletePods(cloud.connect(), getLabels(cloud, this), false);

WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(loadPipelineScript("runInPod.groovy"), true));
Expand All @@ -83,7 +83,6 @@ public void runInPod() throws Exception {
}

assertEquals(Integer.MAX_VALUE, template.getInstanceCap());
assertThat(template.getLabelsMap(), hasEntry("jenkins", "slave"));
assertThat(template.getLabelsMap(), hasEntry("jenkins/mypod", "true"));

assertEquals(1, pods.getItems().size());
Expand All @@ -94,7 +93,7 @@ public void runInPod() throws Exception {
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogContains("script file contents: ", b);
assertFalse("There are pods leftover after test execution, see previous logs",
deletePods(cloud.connect(), getLabels(this), true));
deletePods(cloud.connect(), getLabels(cloud, this), true));
}

private PodTemplate podTemplateWithLabel(String label, List<PodTemplate> templates) {
Expand All @@ -104,7 +103,7 @@ private PodTemplate podTemplateWithLabel(String label, List<PodTemplate> templat

@Test
public void runInPodFromYaml() throws Exception {
deletePods(cloud.connect(), getLabels(this), false);
deletePods(cloud.connect(), getLabels(cloud, this), false);

WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(loadPipelineScript("runInPodFromYaml.groovy"), true));
Expand All @@ -122,7 +121,7 @@ public void runInPodFromYaml() throws Exception {
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogContains("script file contents: ", b);
assertFalse("There are pods leftover after test execution, see previous logs",
deletePods(cloud.connect(), getLabels(this), true));
deletePods(cloud.connect(), getLabels(cloud, this), true));
}

public void runInPodWithDifferentShell() throws Exception {
Expand Down

0 comments on commit b1bfea3

Please sign in to comment.