Skip to content

Commit

Permalink
add executors param to jenkins class
Browse files Browse the repository at this point in the history
Similar semantics as `class { 'jenkins::slave': executors => ... }` but for
the Jenkins master.
  • Loading branch information
Joshua Hoblitt committed Mar 26, 2015
1 parent ef2546c commit 6f3ef22
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
17 changes: 17 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
# config_hash = undef (Default)
# Hash with config options to set in sysconfig/jenkins defaults/jenkins
#
# executors = undef (Default)
# Integer number of executors on the Jenkin's master.
#
# Example use
#
# class{ 'jenkins':
Expand Down Expand Up @@ -124,6 +127,7 @@
$cli_try_sleep = $jenkins::params::cli_try_sleep,
$port = $jenkins::params::port,
$libdir = $jenkins::params::libdir,
$executors = undef,
) inherits jenkins::params {

validate_bool($lts, $install_java, $repo)
Expand All @@ -137,6 +141,8 @@
validate_array($no_proxy_list)
}

validate_string($executors)

anchor {'jenkins::begin':}
anchor {'jenkins::end':}

Expand Down Expand Up @@ -177,6 +183,17 @@
include jenkins::cli::reload
}

if $executors {
jenkins::cli::exec { 'set_num_executors':
command => ['set_num_executors', $executors],
unless => "[ \$(\$HELPER_CMD get_num_executors) -eq ${executors} ]"
}

Class['jenkins::cli'] ->
Jenkins::Cli::Exec['set_num_executors'] ->
Class['jenkins::jobs']
}

Anchor['jenkins::begin'] ->
Class['jenkins::package'] ->
Class['jenkins::config'] ->
Expand Down
31 changes: 30 additions & 1 deletion spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,33 @@ class {'jenkins':
end

end
end

context 'executors' do
it 'should work with no errors' do
pp = <<-EOS
class {'jenkins':
executors => 42,
}
EOS

# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end

describe port(8080) do
# jenkins should already have been running so we shouldn't have to
# sleep
it { should be_listening }
end

describe service('jenkins') do
it { should be_running }
it { should be_enabled }
end

describe file('/var/lib/jenkins/config.xml') do
it { should contain ' <numExecutors>42</numExecutors>' }
end
end # executors
end
29 changes: 29 additions & 0 deletions spec/classes/jenkins_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,34 @@
let(:pre_condition) { 'define firewall ($action, $state, $dport, $proto) {}' }
it { expect { should raise_error(Puppet::Error) } }
end

describe 'executors =>' do
context 'undef' do
it { should_not contain_class('jenkins::cli_helper') }
it { should_not contain_jenkins__cli__exec('set_num_executors') }
end

context '42' do
let(:params) {{ :executors => 42 }}

it { should contain_class('jenkins::cli_helper') }
it do
should contain_jenkins__cli__exec('set_num_executors').with(
:command => ['set_num_executors', 42],
:unless => '[ $($HELPER_CMD get_num_executors) -eq 42 ]',
)
end
it { should contain_jenkins__cli__exec('set_num_executors').that_requires('Class[jenkins::cli]') }
it { should contain_jenkins__cli__exec('set_num_executors').that_comes_before('Class[jenkins::jobs]') }
end

context '{}' do
let(:params) {{ :executors => {} }}

it 'should fail' do
should raise_error(Puppet::Error, /is not a string./)
end
end
end # executors =>
end
end

0 comments on commit 6f3ef22

Please sign in to comment.