Search in sources :

Example 1 with NodeParameter

use of org.jenkinsci.test.acceptance.plugins.nodelabelparameter.NodeParameter in project acceptance-test-harness by jenkinsci.

the class NodeLabelParameterPluginTest method run_on_a_particular_offline_slave_with_ignore.

/**
 * This test is intended to check that an offline slave is ignored
 * when selected for a job and the job is configured with "Node eligibility" setting
 * is set to "Ignore Offline Nodes"
 * <p/>
 * It is expected that the job is pending due no valid slave is available.
 */
@Test
public void run_on_a_particular_offline_slave_with_ignore() throws Exception {
    FreeStyleJob j = jenkins.jobs.create();
    j.configure();
    j.save();
    Slave s = slave.install(jenkins).get();
    j.configure();
    NodeParameter p = j.addParameter(NodeParameter.class);
    p.setName("slavename");
    p.disallowMultiple.check();
    p.eligibility.select("Ignore Offline Nodes");
    j.save();
    // as the slave has been started after creation, we have to take it down again
    s.markOffline();
    assertThat(s.isOffline(), is(true));
    // use scheduleBuild instead of startBuild to avoid a timeout waiting for Build being started
    Build b = j.scheduleBuild(singletonMap("slavename", s.getName()));
    // TODO: not the best way to wait for the scheduled job to go through the queue, but a bit of wait is needed
    elasticSleep(3000);
    shouldBeTriggeredWithoutValidOnlineNode(b, s.getName());
}
Also used : NodeParameter(org.jenkinsci.test.acceptance.plugins.nodelabelparameter.NodeParameter) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test)

Example 2 with NodeParameter

use of org.jenkinsci.test.acceptance.plugins.nodelabelparameter.NodeParameter in project acceptance-test-harness by jenkinsci.

the class NodeLabelParameterPluginTest method run_on_a_particular_offline_slave.

/**
 * This test is intended to check that an offline slave is not ignored
 * when selected for a job and the job is configured with "Node eligibility" setting
 * is set to "All Nodes"
 * <p/>
 * It is expected that the job is pending due to the offline status of the slave.
 * But it will be reactivated as soon as the slave status becomes online.
 */
@Test
public void run_on_a_particular_offline_slave() throws Exception {
    FreeStyleJob j = jenkins.jobs.create();
    Slave s = slave.install(jenkins).get();
    j.configure();
    NodeParameter p = j.addParameter(NodeParameter.class);
    p.setName("slavename");
    p.disallowMultiple.check();
    j.save();
    // as the slave has been started after creation, we have to take it down again
    s.markOffline();
    assertThat(s.isOffline(), is(true));
    // use scheduleBuild instead of startBuild to avoid a timeout waiting for Build being started
    Build b = j.scheduleBuild(singletonMap("slavename", s.getName()));
    // TODO: not the best way to wait for the scheduled job to go through the queue, but a bit of wait is needed
    elasticSleep(3000);
    shouldBeTriggeredWithoutOnlineNode(b, s.getName());
    // bring the slave up again, the Build should start immediately
    s.markOnline();
    assertThat(s.isOnline(), is(true));
    b.waitUntilFinished();
    assertThat(s.getBuildHistory().getBuildsOf(j), contains(b));
}
Also used : NodeParameter(org.jenkinsci.test.acceptance.plugins.nodelabelparameter.NodeParameter) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test)

Example 3 with NodeParameter

use of org.jenkinsci.test.acceptance.plugins.nodelabelparameter.NodeParameter in project acceptance-test-harness by jenkinsci.

the class NodeLabelParameterPluginTest method build_with_preselected_node.

@Test
public void build_with_preselected_node() throws Exception {
    FreeStyleJob j = jenkins.jobs.create();
    Node s = slave.install(jenkins).get();
    j.configure();
    NodeParameter p = j.addParameter(NodeParameter.class);
    p.setName("slavename");
    p.defaultNodes.select(s.getName());
    p.allowedNodes.select("ALL (no restriction)");
    p.disallowMultiple.check();
    j.save();
    visit(j.getBuildUrl());
    assertThat("Default node is selected", find(by.option(s.getName())).isSelected(), is(true));
    WebElement wbElement = find(by.xpath("//select[@name='value']"));
    List<WebElement> availableNodes = wbElement.findElements(by.tagName("option"));
    assertThat(availableNodes.get(0).getText(), is("built-in"));
    assertThat(availableNodes.get(1).getText(), is(s.getName()));
    Build b = j.startBuild(singletonMap("slavename", s.getName())).shouldSucceed();
    assertThat(s, is(b.getNode()));
}
Also used : NodeParameter(org.jenkinsci.test.acceptance.plugins.nodelabelparameter.NodeParameter) WebElement(org.openqa.selenium.WebElement) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test)

Example 4 with NodeParameter

use of org.jenkinsci.test.acceptance.plugins.nodelabelparameter.NodeParameter in project acceptance-test-harness by jenkinsci.

the class NodeLabelParameterPluginTest method trigger_if_succeeds_with_failed_post_build_step.

/**
 * This test is intended to verify that the second build is not started when the
 * build already failed on the first slave in combination with the
 * "run next build only if build succeeds" setting of the node parameter.
 * <p/>
 * As a build can fail in different stages this test simulates a FAILED result
 * during the post build step. Therefore the text-finder plugin is used to
 * fail the build based on a simple pattern matching with a text file copied to
 * the slave's workspace.
 * <p/>
 * Note that in this case the main build action is still completed with status SUCCESS.
 */
@Test
@WithPlugins("text-finder")
@Issue("JENKINS-23129")
@Ignore("Until JENKINS-23129 is fixed")
public void trigger_if_succeeds_with_failed_post_build_step() throws Exception {
    FreeStyleJob j = jenkins.jobs.create();
    ArrayList<Node> slaves = new ArrayList<>();
    slaves.add(slave.install(jenkins).get());
    slaves.add(slave.install(jenkins).get());
    j.configure();
    // set up the node parameter
    NodeParameter p = j.addParameter(NodeParameter.class);
    p.setName("slavename");
    p.runIfSuccess.check();
    // copy the file to mark the status
    j.copyResource(resource("/textfinder_plugin/textfinder-result_failed.log"));
    // set up the post build action
    TextFinderPublisher tf = j.addPublisher(TextFinderPublisher.class);
    tf.filePath.sendKeys("textfinder-result_failed.log");
    tf.regEx.sendKeys("^RESULT=SUCCESS$");
    tf.succeedIfFound.click();
    j.save();
    // select both slaves for this build
    j.startBuild(singletonMap("slavename", slaves.get(0).getName() + "," + slaves.get(1).getName())).shouldFail();
    // verify failed result prevents the job to be built on further nodes.
    // As the nodes get random names and the selected nodes are utilized in alphabetical order
    // of their names, the first build will not necessarily be done on s1. Thus, it can only
    // be verified that the job has been built on one of the slaves.
    j.startBuild(singletonMap("slavename", slaves.get(0).getName() + "," + slaves.get(1).getName())).shouldFail();
    assertThat(j.getNextBuildNumber(), is(2));
}
Also used : TextFinderPublisher(org.jenkinsci.test.acceptance.plugins.textfinder.TextFinderPublisher) NodeParameter(org.jenkinsci.test.acceptance.plugins.nodelabelparameter.NodeParameter) ArrayList(java.util.ArrayList) Ignore(org.junit.Ignore) Issue(org.jvnet.hudson.test.Issue) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Example 5 with NodeParameter

use of org.jenkinsci.test.acceptance.plugins.nodelabelparameter.NodeParameter in project acceptance-test-harness by jenkinsci.

the class NodeLabelParameterPluginTest method run_on_several_online_and_offline_slaves.

/**
 * This test is intended to check that an offline slave is not ignored
 * when selected for a job and the job is configured with "Node eligibility" setting
 * is set to "All Nodes" in combination with "Allow multiple nodes" option.
 * <p/>
 * The job shall run on a mixed configuration of online and offline slaves.
 * It is expected that a number of builds is created equivalent to the number of
 * slaves selected. The build shall be pending for the offline slaves and executed
 * successfully for the online slaves.
 * Pending builds will be reactivated as soon as the particular slave becomes online.
 */
@Test
public void run_on_several_online_and_offline_slaves() throws Exception {
    FreeStyleJob j = jenkins.jobs.create();
    Slave s1 = slave.install(jenkins).get();
    Slave s2 = slave.install(jenkins).get();
    j.configure();
    NodeParameter p = j.addParameter(NodeParameter.class);
    p.setName("slavename");
    p.allowMultiple.check();
    j.concurrentBuild.check();
    j.save();
    // as both slaves have been started after creation, we have to take one of them down
    s2.markOffline();
    assertThat(s2.isOnline(), is(false));
    assertThat(s1.isOnline(), is(true));
    // select both slaves for this build
    Build b = j.startBuild(singletonMap("slavename", s1.getName() + "," + s2.getName())).shouldSucceed();
    // ensure that the build on the online slave has been done
    assertThat(j.getLastBuild().waitUntilFinished().getNumber(), is(equalTo(1)));
    assertThat(s1.getBuildHistory().getBuildsOf(j), contains(b));
    assertThat(j.open(), Matchers.hasContent(s2.getName() + " is offline"));
    // bring second slave online again
    s2.markOnline();
    assertThat(s2.isOnline(), is(true));
    assertThat(j.getLastBuild().waitUntilFinished().getNumber(), is(equalTo(2)));
    assertThat(s2.getBuildHistory().getBuildsOf(j), contains(j.getLastBuild()));
}
Also used : NodeParameter(org.jenkinsci.test.acceptance.plugins.nodelabelparameter.NodeParameter) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test)

Aggregations

AbstractJUnitTest (org.jenkinsci.test.acceptance.junit.AbstractJUnitTest)10 NodeParameter (org.jenkinsci.test.acceptance.plugins.nodelabelparameter.NodeParameter)10 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)2 Ignore (org.junit.Ignore)2 Issue (org.jvnet.hudson.test.Issue)2 WithPlugins (org.jenkinsci.test.acceptance.junit.WithPlugins)1 TextFinderPublisher (org.jenkinsci.test.acceptance.plugins.textfinder.TextFinderPublisher)1 WebElement (org.openqa.selenium.WebElement)1