Skip to content
Permalink
Browse files
[JENKINS-29998] Reproduce
  • Loading branch information
olivergondza committed Aug 20, 2015
1 parent 935342b commit 991b467a35a2169b39674d49192776c59fa88886
Showing 1 changed file with 74 additions and 18 deletions.
@@ -23,8 +23,14 @@
*/
package plugins;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.jenkinsci.test.acceptance.Matchers.*;

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

import javax.inject.Named;

import org.jenkinsci.test.acceptance.junit.AbstractJUnitTest;
@@ -35,17 +41,26 @@
import org.jenkinsci.test.acceptance.plugins.openstack.OpenstackCloud;
import org.jenkinsci.test.acceptance.plugins.openstack.OpenstackSlaveTemplate;
import org.jenkinsci.test.acceptance.plugins.openstack.UserDataConfig;
import org.jenkinsci.test.acceptance.po.Build;
import org.jenkinsci.test.acceptance.po.FreeStyleJob;
import org.jenkinsci.test.acceptance.po.Jenkins;
import org.jenkinsci.test.acceptance.po.JenkinsConfig;
import org.jenkinsci.test.acceptance.po.MatrixBuild;
import org.jenkinsci.test.acceptance.po.MatrixProject;
import org.jenkinsci.test.acceptance.po.MatrixRun;
import org.jenkinsci.test.acceptance.po.Node;
import org.junit.After;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;

import com.google.inject.Inject;

@WithPlugins("openstack-cloud")
@TestActivation({"ENDPOINT", "IDENTITY", "CREDENTIAL"})
public class OpenstackCloudPluginTest extends AbstractJUnitTest {

private static final String CLOUD_INIT_NAME = "cloudInit";

@Inject(optional = true) @Named("OpenstackCloudPluginTest.ENDPOINT")
public String ENDPOINT;

@@ -64,6 +79,15 @@ public class OpenstackCloudPluginTest extends AbstractJUnitTest {
@Inject(optional = true) @Named("OpenstackCloudPluginTest.KEY_PAIR_NAME")
public String KEY_PAIR_NAME;

private final List<Node> nodes = new ArrayList<Node>();

@After // Terminate all nodes
public void tearDown() {
for (Node n: nodes) {
jenkins.runScript("Jenkins.instance.getNode('%s').tarminate()", n.getName());
}
}

@Test
public void testConnection() {
jenkins.configure();
@@ -77,39 +101,71 @@ public void testConnection() {
@WithCredentials(credentialType = WithCredentials.SSH_USERNAME_PRIVATE_KEY, values = {"root", "/openstack_plugin/unsafe"})
@TestActivation({"HARDWARE_ID", "IMAGE_ID", "KEY_PAIR_NAME"})
public void provisionSshSlave() {
configureCloudInit();
configureProvisioning("label");

FreeStyleJob job = jenkins.jobs.create();
job.configure();
job.setLabelExpression("label");
job.save();
Build build = job.scheduleBuild().waitUntilFinished(240).shouldSucceed();

nodes.add(build.getNode());
}

@Test @Issue("JENKINS-29998")
@WithPlugins({"config-file-provider", "ssh-slaves"})
@WithCredentials(credentialType = WithCredentials.SSH_USERNAME_PRIVATE_KEY, values = {"root", "/openstack_plugin/unsafe"})
@TestActivation({"HARDWARE_ID", "IMAGE_ID", "KEY_PAIR_NAME"})
public void scheduleMatrixWithoutLabel() {
configureCloudInit();
configureProvisioning("label");
jenkins.configure();
jenkins.getConfigPage().numExecutors.set(0);
jenkins.save();

MatrixProject job = jenkins.jobs.create(MatrixProject.class);
job.configure();
job.save();

MatrixBuild pb = job.scheduleBuild().waitUntilFinished(240).shouldSucceed().as(MatrixBuild.class);
assertThat(pb.getNode(), equalTo((Node) jenkins));
MatrixRun cb = pb.getConfiguration("default");
assertThat(cb.getNode(), not(equalTo((Node) jenkins)));

nodes.add(cb.getNode());
}

private OpenstackCloud addCloud(JenkinsConfig config) {
return config.addCloud(OpenstackCloud.class)
.profile(Jenkins.createRandomName())
.endpoint(ENDPOINT)
.identity(IDENTITY)
.credential(CREDENTIAL)
;
}

private void configureCloudInit() {
ConfigFileProvider fileProvider = new ConfigFileProvider(jenkins);
UserDataConfig cloudInit = fileProvider.addFile(UserDataConfig.class);
cloudInit.open();
cloudInit.name("cloudInit");
cloudInit.name(CLOUD_INIT_NAME);
cloudInit.content(resource("/openstack_plugin/cloud-init").asText());
cloudInit.save();
}

private void configureProvisioning(String labels) {
jenkins.configure();
OpenstackCloud cloud = addCloud(jenkins.getConfigPage()).associateFloatingIp();
OpenstackSlaveTemplate template = cloud.addSlaveTemplate();

template.name("ath-integration-test");
template.labels("template-a");
template.labels(labels);
template.hardwareId(HARDWARE_ID);
template.imageId(IMAGE_ID);
template.credentials("root");
template.userData("cloudInit");
template.userData(CLOUD_INIT_NAME);
template.keyPair(KEY_PAIR_NAME);
jenkins.save();

FreeStyleJob job = jenkins.jobs.create();
job.configure();
job.setLabelExpression("template-a");
job.save();
job.scheduleBuild().waitUntilFinished(240).shouldSucceed();
}

private OpenstackCloud addCloud(JenkinsConfig config) {
return config.addCloud(OpenstackCloud.class)
.profile(Jenkins.createRandomName())
.endpoint(ENDPOINT)
.identity(IDENTITY)
.credential(CREDENTIAL)
;
}
}

0 comments on commit 991b467

Please sign in to comment.