Project

General

Profile

Jenkins » History » Version 28

Dominic Cleal, 06/03/2015 04:28 AM
smart proxy plugin testing

1 1 Dominic Cleal
h1. Jenkins
2 1 Dominic Cleal
3 1 Dominic Cleal
The Foreman project maintains its own Jenkins instance for continuous integration at http://ci.theforeman.org/
4 1 Dominic Cleal
5 11 Dominic Cleal
{{toc}}
6 11 Dominic Cleal
7 23 Dominic Cleal
h2. Managing jobs
8 23 Dominic Cleal
9 23 Dominic Cleal
Jenkins itself is deployed onto one master VM from foreman-infra.  Jobs are maintained in two ways:
10 23 Dominic Cleal
11 23 Dominic Cleal
# Updated by hand - some developers have accounts to log in and modify jobs
12 23 Dominic Cleal
# Jenkins Job Builder - a set of YAML configuration files in foreman-infra that generate jobs
13 23 Dominic Cleal
14 23 Dominic Cleal
New jobs should be written via Jenkins Job Builder if possible.
15 23 Dominic Cleal
16 23 Dominic Cleal
h3. Jenkins Job Builder
17 23 Dominic Cleal
18 23 Dominic Cleal
"Jenkins Job Builder":http://docs.openstack.org/infra/jenkins-job-builder/ (JJB) is an OpenStack tool for generating Jenkins job definitions (an XML file) from a set of YAML job descriptions, which we store in version control.
19 23 Dominic Cleal
20 23 Dominic Cleal
* "JJB YAML files in foreman-infra":https://github.com/theforeman/foreman-infra/tree/master/puppet/modules/jenkins_job_builder/files/config
21 23 Dominic Cleal
22 23 Dominic Cleal
Puppet deploys these onto our Jenkins server (a recursive file copy) and when they change, it runs the JJB tool to update the jobs in the live instance.  It also refreshes them daily to overwrite manual changes.
23 23 Dominic Cleal
24 23 Dominic Cleal
We use a fork of JJB with some extra support for plugins we use:
25 23 Dominic Cleal
26 23 Dominic Cleal
* "theforeman/jenkins-job-builder, local branch":https://github.com/theforeman/jenkins-job-builder/tree/local
27 23 Dominic Cleal
28 23 Dominic Cleal
To test it:
29 23 Dominic Cleal
30 23 Dominic Cleal
# check out the above JJB repo and local branch
31 23 Dominic Cleal
# recommended: "create a Python virtualenv and activate it":https://virtualenv.pypa.io/en/latest/userguide.html#usage
32 23 Dominic Cleal
## @virtualenv jjb@
33 23 Dominic Cleal
## @source jjb/bin/activate@
34 23 Dominic Cleal
# @easy_install .@
35 23 Dominic Cleal
# check out foreman-infra
36 23 Dominic Cleal
# @cd foreman-infra/puppet/modules/jenkins_job_builder/files@
37 23 Dominic Cleal
# @jenkins-jobs -l debug test -r . -o /tmp/jobs@
38 23 Dominic Cleal
39 23 Dominic Cleal
JJB will populate /tmp/jobs with the proposed XML files.
40 23 Dominic Cleal
41 23 Dominic Cleal
Useful resources:
42 23 Dominic Cleal
43 23 Dominic Cleal
# "Job definitions, templates etc.":http://docs.openstack.org/infra/jenkins-job-builder/definition.html
44 23 Dominic Cleal
# "Modules, e.g. SCM, publishers, builders":http://docs.openstack.org/infra/jenkins-job-builder/definition.html#modules
45 23 Dominic Cleal
46 1 Dominic Cleal
h2. Pull request testing
47 1 Dominic Cleal
48 1 Dominic Cleal
Core Foreman projects have GitHub pull requests tested on our Jenkins instance so it's identical to the way we test the primary development branches themselves.  Less significant projects (such as installer submodules) may use Travis CI.
49 1 Dominic Cleal
50 1 Dominic Cleal
h3. PR jobs
51 1 Dominic Cleal
52 1 Dominic Cleal
Every project that needs PR testing requires two Jenkins jobs.  Taking core Foreman as an example:
53 1 Dominic Cleal
54 1 Dominic Cleal
* Test job for the main development branch (develop or master): "test_develop":http://ci.theforeman.org/job/test_develop/
55 7 Dominic Cleal
* Test job taking parameters about the PR, which is merged and tested: "test_develop_pull_request":http://ci.theforeman.org/job/test_develop_pull_request/
56 1 Dominic Cleal
57 7 Dominic Cleal
The results from these PR jobs are only stored for a few weeks, sufficient for reviews.
58 7 Dominic Cleal
59 7 Dominic Cleal
The jobs are being transitioned at the moment from an old style, which used basic @git apply@ + patches to a proper merge of the branch under test to the primary project branch, which is far more reliable.
60 7 Dominic Cleal
61 7 Dominic Cleal
h4. Old style (.patch)
62 7 Dominic Cleal
63 1 Dominic Cleal
The PR test job takes the PR number parameter, downloads the patch from GitHub (by appending a .patch extension to the PR URL), applies it to the local checkout of the project and then builds as normal.  This process means PRs are effectively rebased onto the current development branch before tests are run, rather than testing the branch as-is.  GitHub tracks "mergeability" so we don't test PRs that can't be merged cleanly.
64 1 Dominic Cleal
65 7 Dominic Cleal
h4. New style (git URL/ref)
66 7 Dominic Cleal
67 7 Dominic Cleal
The PR test job takes the following parameters:
68 7 Dominic Cleal
69 9 Dominic Cleal
* pr_git_url: URL to the repository containing the PR to clone
70 9 Dominic Cleal
* pr_git_ref: branch name in the above repository for the PR
71 7 Dominic Cleal
* pr_number: optional, for informational purposes only (e.g. tracking from a job back to a PR)
72 7 Dominic Cleal
73 7 Dominic Cleal
Under source code management in the job configuration, set up:
74 7 Dominic Cleal
75 8 Dominic Cleal
# Project git repository:
76 8 Dominic Cleal
#* Repository URL: @https://github.com/theforeman/foreman@
77 7 Dominic Cleal
# Branches to build: @develop@
78 8 Dominic Cleal
# Additional Behaviours > Prune stale remote-tracking branches
79 8 Dominic Cleal
# Additional Behaviours > Wipe out repository & force clone
80 8 Dominic Cleal
81 8 Dominic Cleal
As the first build step, add:
82 8 Dominic Cleal
83 8 Dominic Cleal
<pre>
84 8 Dominic Cleal
#!/bin/bash -ex
85 10 Dominic Cleal
if [ -n "${pr_git_url}" ]; then
86 10 Dominic Cleal
  git remote add pr ${pr_git_url}
87 10 Dominic Cleal
  git fetch pr
88 10 Dominic Cleal
  git merge pr/${pr_git_ref}
89 10 Dominic Cleal
fi
90 8 Dominic Cleal
</pre>
91 1 Dominic Cleal
92 1 Dominic Cleal
h3. PR scanner
93 1 Dominic Cleal
94 2 Dominic Cleal
To initiate the PR tests, the "test-pull-requests":https://github.com/theforeman/test-pull-requests script is used to scan for open PRs, check they're mergeable and then trigger the Jenkins job.  The script is a fork from the OpenShift upstream, enhanced in a few areas including changing from comment-based updates to the GitHub status API.
95 2 Dominic Cleal
96 2 Dominic Cleal
The script runs under the "pull_request_scanner":http://ci.theforeman.org/job/pull_request_scanner/ job under Jenkins and is set to run a few times every hour.  It scans all configured projects for PRs and then exits, leaving the PR test jobs themselves to execute asynchronously.
97 2 Dominic Cleal
98 2 Dominic Cleal
The configuration files are deployed via our Puppet infrastructure for each project, and mostly just detail the GitHub repos, branches and Jenkins job names.  These are managed in the "slave foreman-infra module":https://github.com/theforeman/foreman-infra/tree/master/puppet/modules/slave in slave itself and templates/.
99 3 Dominic Cleal
100 3 Dominic Cleal
After a PR test job completes, the Jenkins jobs are configured to build the PR scanner job again, which means immediately after the PR test results come in, the PR scanner script is able to update the status on the GitHub PR.  A kind of feedback loop, if you will.
101 3 Dominic Cleal
102 3 Dominic Cleal
h3. PR scanner repo hooks
103 3 Dominic Cleal
104 3 Dominic Cleal
In addition to regular scheduled runs of the PR scanner, hooks are added to the GitHub repositories to kick the PR scanner "build" when a PR is opened or synchronised.
105 3 Dominic Cleal
106 3 Dominic Cleal
They currently point to a very simple sinatra app running on OpenShift, which reads in the source repo from the hook payload and then runs the PR scanner build remotely via a POST request to Jenkins.  This means PRs begin building within a minute or two of the PR being opened, giving better feedback to developers.
107 3 Dominic Cleal
108 16 Dominic Cleal
The app is prprocessor, hosted on the project's OpenShift account and the source is available here: https://github.com/theforeman/prprocessor (please keep this in sync with OpenShift's repo)
109 15 Dominic Cleal
110 25 Dominic Cleal
h3. Adding a new generic project
111 4 Dominic Cleal
112 24 Dominic Cleal
For a project "foo":
113 4 Dominic Cleal
114 4 Dominic Cleal
# create a test_foo job that tests the primary development branch, enable IRC notifications in post build
115 4 Dominic Cleal
# clone to test_foo_pull_request
116 4 Dominic Cleal
#* without IRC notifications
117 4 Dominic Cleal
#* add pr_number parameter
118 1 Dominic Cleal
#* add initial build step to download the patch and apply
119 24 Dominic Cleal
# add template to foreman-infra/puppet/modules/slave/templates, update branch, job names etc.
120 24 Dominic Cleal
# add project to slave::pr_test_config list in foreman-infra/puppet/modules/slave/manifests/init.pp
121 24 Dominic Cleal
# add pull_request hook to GitHub repo
122 24 Dominic Cleal
123 25 Dominic Cleal
h3. Foreman plugin testing
124 1 Dominic Cleal
125 25 Dominic Cleal
Foreman plugins are tested by adding the plugin to a Foreman checkout and running core tests, so it checks that existing behaviours still work and new plugin tests are run too.  The "test_plugin_matrix job":http://ci.theforeman.org/job/test_plugin_matrix/ copies the core jobs, but adds a plugin from a given git repo/branch and is usually used to test plugins in a generic way.
126 25 Dominic Cleal
127 25 Dominic Cleal
Each plugin should have a job defined in JJB that calls test_plugin_matrix here: http://ci.theforeman.org/view/Plugins/
128 25 Dominic Cleal
129 25 Dominic Cleal
h4. Foreman plugin PR testing
130 25 Dominic Cleal
131 25 Dominic Cleal
To test pull requests, a separate job is used that also takes the PR details: http://ci.theforeman.org/view/Plugins/job/test_plugin_pull_request/
132 25 Dominic Cleal
133 25 Dominic Cleal
To set this up for a plugin, make the template + manifest addition as noted in the PR section below to configure the PR scanner.  Also enable the prprocessor webhook on the GitHub repo for immediate builds.
134 25 Dominic Cleal
135 25 Dominic Cleal
h4. Adding a new Foreman plugin
136 25 Dominic Cleal
137 27 Dominic Cleal
For a plugin "foreman_example", first create a job that tests the main (master or develop) branch.
138 17 Dominic Cleal
139 26 Dominic Cleal
# ensure plugin tests run when @rake jenkins:unit@ is called, see "the example plugin":https://github.com/theforeman/foreman_plugin_template/ and "testing a plugin":http://projects.theforeman.org/projects/foreman/wiki/How_to_Create_a_Plugin#Testing for help
140 17 Dominic Cleal
# create a foreman_example.yaml file in foreman-infra/JJB
141 17 Dominic Cleal
#* https://github.com/theforeman/foreman-infra/tree/master/puppet/modules/jenkins_job_builder/files/config/yaml/jobs/plugins
142 1 Dominic Cleal
#* This will create a "test_plugin_foreman_example_master" job in Jenkins to test the master branch.
143 27 Dominic Cleal
# ensure the job is green by fixing bugs, installing dependencies etc.
144 27 Dominic Cleal
145 27 Dominic Cleal
Next, set up PR testing for the plugin:
146 27 Dominic Cleal
147 17 Dominic Cleal
# add template to foreman-infra/puppet/modules/slave/templates, update branch, job names etc.
148 17 Dominic Cleal
# add project to slave::pr_test_config list in foreman-infra/puppet/modules/slave/manifests/init.pp
149 17 Dominic Cleal
# add pull_request hook to GitHub repo
150 17 Dominic Cleal
151 28 Dominic Cleal
h3. Smart proxy plugin testing
152 28 Dominic Cleal
153 28 Dominic Cleal
Proxy plugins are tested like ordinary gems with tests run entirely from the plugin directory, installing the smart proxy as a dependency (via bundler's git support).  The "test_proxy_plugin_matrix job":http://ci.theforeman.org/job/test_proxy_plugin_matrix/ is usually used to test plugins in a generic way.
154 28 Dominic Cleal
155 28 Dominic Cleal
Each plugin should have a job defined in JJB that calls test_proxy_plugin_matrix here: http://ci.theforeman.org/view/Plugins/
156 28 Dominic Cleal
157 28 Dominic Cleal
h4. Smart proxy plugin PR testing
158 28 Dominic Cleal
159 28 Dominic Cleal
To test pull requests, a separate job is used that also takes the PR details: http://ci.theforeman.org/view/Plugins/job/test_proxy_plugin_pull_request/
160 28 Dominic Cleal
161 28 Dominic Cleal
To set this up for a plugin, make the template + manifest addition as noted in the PR section below to configure the PR scanner.  Also enable the prprocessor webhook on the GitHub repo for immediate builds.
162 28 Dominic Cleal
163 28 Dominic Cleal
h4. Adding a new smart proxy plugin
164 28 Dominic Cleal
165 28 Dominic Cleal
For a plugin "smart_proxy_example", first create a job that tests the main (master or develop) branch.
166 28 Dominic Cleal
167 28 Dominic Cleal
# ensure plugin tests run when doing @bundle install@ and @rake test@, see "testing a plugin":http://projects.theforeman.org/projects/foreman/wiki/How_to_Create_a_Smart-Proxy_Plugin#Testing for help
168 28 Dominic Cleal
#* if different branches rely on different versions of smart proxy, specify @:branch@ in Gemfile on those branches
169 28 Dominic Cleal
# create a smart_proxy_example.yaml file in foreman-infra/JJB
170 28 Dominic Cleal
#* https://github.com/theforeman/foreman-infra/tree/master/puppet/modules/jenkins_job_builder/files/config/yaml/jobs/plugins
171 28 Dominic Cleal
#* This will create a "test_proxy_plugin_smart_proxy_example_master" job in Jenkins to test the master branch.
172 28 Dominic Cleal
# ensure the job is green by fixing bugs, installing dependencies etc.
173 28 Dominic Cleal
174 28 Dominic Cleal
Next, set up PR testing for the plugin:
175 28 Dominic Cleal
176 28 Dominic Cleal
# add template to foreman-infra/puppet/modules/slave/templates, update branch, job names etc.
177 28 Dominic Cleal
# add project to slave::pr_test_config list in foreman-infra/puppet/modules/slave/manifests/init.pp
178 28 Dominic Cleal
# add pull_request hook to GitHub repo
179 28 Dominic Cleal
180 5 Dominic Cleal
h2. System testing with foreman-bats
181 5 Dominic Cleal
182 6 Dominic Cleal
Some system tests are performed on the complete all-in-one Foreman setup, which includes packages, the installer, the CLI and related components.
183 5 Dominic Cleal
184 6 Dominic Cleal
These tests are currently in the "foreman-bats":http://github.com/theforeman/foreman-bats project and use the BATS test framework (based on bash).
185 1 Dominic Cleal
186 6 Dominic Cleal
They are intended to be smoke tests only, not in depth testing of any component of the stack.  Most components have their own unit tests, which are cheaper to execute and are run closer to where the code is developed, reducing the turnaround time for fixes.
187 5 Dominic Cleal
188 5 Dominic Cleal
h3. systest jobs
189 5 Dominic Cleal
190 6 Dominic Cleal
The systest_* jobs in Jenkins run the system tests, with "systest_foreman":http://ci.theforeman.org/job/systest_foreman/ being the main parameterised job for executing them.
191 5 Dominic Cleal
192 6 Dominic Cleal
For RPM-based distributions, the systest_foreman job is run from the packaging_publish_rpm job as an intermediate test phase between the repo being generated and published to the public web site.
193 5 Dominic Cleal
194 6 Dominic Cleal
For Debian distributions, the systest_foreman_debian job runs nightly against the published repos to report problems.  This is a matrix job that runs once for each Debian-based distribution.
195 5 Dominic Cleal
196 5 Dominic Cleal
h3. Vagrant setup
197 5 Dominic Cleal
198 6 Dominic Cleal
foreman-bats is very simple - it's a bash script that executes as root on a host, installs Foreman and tests the result.  Since we don't want to install Foreman directly on slaves, this is run on the "Rackspace public cloud":http://www.rackspace.com/cloud/servers/, under a project account.
199 5 Dominic Cleal
200 6 Dominic Cleal
The Jenkins jobs use "Vagrant":http://vagrantup.com/ to create hosts on Rackspace and to run the foreman-bats project on it.  Vagrant is installed via the "foreman-infra Puppet modules":https://github.com/theforeman/foreman-infra/blob/master/puppet/modules/slave/manifests/vagrant.pp along with the "vagrant-rackspace":https://github.com/mitchellh/vagrant-rackspace/ plugin.  This launches a standard Rackspace image for the OS under test, Vagrant rsyncs the current directory (workspace) to it containing foreman-bats, and the job script then executes the foreman-bats test over @vagrant ssh@.
201 5 Dominic Cleal
202 6 Dominic Cleal
The same Vagrant setup can be used to run foreman-bats locally via vagrant-libvirt or other plugins.
203 11 Dominic Cleal
204 11 Dominic Cleal
h2. Slaves
205 11 Dominic Cleal
206 11 Dominic Cleal
h3. Configuration management
207 11 Dominic Cleal
208 11 Dominic Cleal
All slaves are maintained through our own Foreman instance using Puppet.  The Foreman instance has a host group called "Base/Builders" and "Base/Builders/Red Hat" and "Base/Builders/Debian" which have the "slave" and other classes assigned to them.
209 11 Dominic Cleal
210 11 Dominic Cleal
https://github.com/theforeman/foreman-infra/tree/master/puppet/modules contains the source for all Puppet modules.
211 11 Dominic Cleal
212 18 Dominic Cleal
h3. Slave requirements
213 18 Dominic Cleal
214 18 Dominic Cleal
* CentOS 6 currently (or 7 once we've tested and updated our Puppet modules)
215 20 Dominic Cleal
** Clean, minimal base installation or the option to reinstall it
216 18 Dominic Cleal
* 1GB of RAM per vCPU (4 vCPU + 4GB RAM is typical)
217 19 Dominic Cleal
* 40GB disk (minimum), SSD preferred
218 22 Dominic Cleal
* ~20GB/month bandwidth
219 21 Dominic Cleal
* Public facing IP address
220 20 Dominic Cleal
* Root access
221 18 Dominic Cleal
222 18 Dominic Cleal
h3. Configuring a new slave
223 11 Dominic Cleal
224 11 Dominic Cleal
If using Rackspace, start the new server via the web UI or the "rumm":https://github.com/rackspace/rumm CLI utility.  Ensure you select:
225 11 Dominic Cleal
226 11 Dominic Cleal
* Image: CentOS 6.5
227 11 Dominic Cleal
* Flavor: Performance 1 (4GB)
228 11 Dominic Cleal
229 11 Dominic Cleal
Set up the data partition for the Jenkins workspace:
230 11 Dominic Cleal
231 12 Dominic Cleal
# @mkfs.ext4 -L data /dev/xvde1@
232 12 Dominic Cleal
# @echo "LABEL=data /var/lib/workspace ext4 defaults,noatime 1 2" >> /etc/fstab@
233 12 Dominic Cleal
# @mkdir /var/lib/workspace && mount /var/lib/workspace@
234 11 Dominic Cleal
235 11 Dominic Cleal
Then:
236 11 Dominic Cleal
237 12 Dominic Cleal
# Ensure EPEL is configured: "epel-release":http://dl.fedoraproject.org/pub/epel/6/x86_64/repoview/epel-release.html
238 12 Dominic Cleal
# Ensure yum.pl.com is configured: "puppetlabs-release":http://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm
239 13 Dominic Cleal
# @yum -y install puppet@
240 12 Dominic Cleal
# @echo "server = puppetmaster.theforeman.org" >> /etc/puppet/puppet.conf@
241 12 Dominic Cleal
# @puppet agent -t@
242 12 Dominic Cleal
# Sign the certificate on the puppetmaster or via Foreman
243 14 Dominic Cleal
# @puppet agent -t@
244 14 Dominic Cleal
# Set the host group to "Base/Builders/Red Hat" in Foreman
245 12 Dominic Cleal
# Run @puppet agent -t@ twice (second run is important, due to the rvm module behaviour)
246 12 Dominic Cleal
# Add the node by IP address to Jenkins, copying an existing slave (except slave01)