Skip to content

Commit

Permalink
Added XvncSlaveContainer for a more controlled test environment.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Jun 10, 2015
1 parent c8a9600 commit 399e9d3
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* The MIT License
*
* Copyright 2015 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 org.jenkinsci.test.acceptance.docker.fixtures;

import org.jenkinsci.test.acceptance.docker.DockerContainer;
import org.jenkinsci.test.acceptance.docker.DockerFixture;
import org.jenkinsci.test.acceptance.plugins.credentials.UserPwdCredential;
import org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshCredentialDialog;
import org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher;
import org.jenkinsci.test.acceptance.po.DumbSlave;
import org.jenkinsci.test.acceptance.po.Jenkins;
import org.jenkinsci.test.acceptance.po.Slave;

/**
* A fixture consisting of a Jenkins slave which can run XVNC.
*/
@DockerFixture(id="xvnc-slave", ports=22)
public class XvncSlaveContainer extends DockerContainer {

/**
* Attaches the slave to Jenkins.
* @param j the server
* @return return a configured slave; call {@link Slave#save} after any other customizations to complete; use {@link Slave#waitUntilOnline} if desired
*/
public Slave connect(Jenkins j) {
// Some code from SshSlaveController could be applicable here, but looks too tricky to reuse.
DumbSlave s = j.slaves.create(DumbSlave.class);
SshSlaveLauncher launcher = s.setLauncher(SshSlaveLauncher.class);
launcher.host.set(ipBound(22));
launcher.port(port(22));
SshCredentialDialog dialog = launcher.addCredential();
UserPwdCredential sc = dialog.select(UserPwdCredential.class);
sc.username.set("jenkins");
sc.password.set("jenkins");
dialog.add();
s.remoteFS.set("/home/jenkins");
s.setExecutors(1);
return s;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM evarga/jenkins-slave
RUN apt-get install -y vnc4server imagemagick

# So it is owned by root and has the permissions vncserver seems to require:
RUN mkdir /tmp/.X11-unix && chmod 1777 /tmp/.X11-unix/

# TODO seems this can be picked up from the host, which is unwanted:
ENV XAUTHORITY /home/jenkins/.Xauthority

USER jenkins
RUN mkdir /home/jenkins/.vnc && (echo jenkins; echo jenkins) | vncpasswd /home/jenkins/.vnc/passwd
# Default content includes x-window-manager, which is not installed, plus other stuff we do not need (vncconfig, x-terminal-emulator, etc.):
RUN touch /home/jenkins/.vnc/xstartup && chmod a+x /home/jenkins/.vnc/xstartup
USER root
17 changes: 12 additions & 5 deletions src/test/java/plugins/XvncPluginTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package plugins;

import com.google.inject.Inject;
import org.jenkinsci.test.acceptance.junit.AbstractJUnitTest;
import org.jenkinsci.test.acceptance.junit.Native;
import org.jenkinsci.test.acceptance.junit.WithPlugins;
import org.jenkinsci.test.acceptance.plugins.xvnc.XvncGlobalJobConfig;
import org.jenkinsci.test.acceptance.plugins.xvnc.XvncJobConfig;
Expand All @@ -11,19 +11,29 @@
import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import org.jenkinsci.test.acceptance.docker.DockerContainerHolder;
import org.jenkinsci.test.acceptance.docker.fixtures.XvncSlaveContainer;
import static org.jenkinsci.test.acceptance.plugins.xvnc.XvncJobConfig.*;
import org.jenkinsci.test.acceptance.po.Slave;

@WithPlugins("xvnc")
public class XvncPluginTest extends AbstractJUnitTest {
FreeStyleJob job;

@Inject DockerContainerHolder<XvncSlaveContainer> containerHolder;

@Before
public void setUp() {
Slave slave = containerHolder.get().connect(jenkins);
slave.setLabels("xvnc");
slave.save();
job = jenkins.jobs.create(FreeStyleJob.class);
job.configure();
job.setLabelExpression("xvnc");
job.save();
}

@Test
@Native("vncserver")
public void run_xvnc_during_the_build() {
job.configure();
new XvncJobConfig(job).useXvnc();
Expand All @@ -34,7 +44,6 @@ public void run_xvnc_during_the_build() {
}

@Test
@Native({"vncserver", "import"})
public void take_screenshot_at_the_end_of_the_build() {
job.configure();
new XvncJobConfig(job).useXvnc().takeScreenshot();
Expand All @@ -49,10 +58,8 @@ public void take_screenshot_at_the_end_of_the_build() {
@Test
public void use_specific_display_number() {
jenkins.configure();
// Do not actually run vnc as DISPLAY_NUMBER can collide with accupied one.
new XvncGlobalJobConfig(jenkins.getConfigPage())
.useDisplayNumber(42)
.command("echo 'Fake vncserver on :$DISPLAY_NUMBER' display")
;
jenkins.save();

Expand Down

0 comments on commit 399e9d3

Please sign in to comment.