Skip to content

Commit

Permalink
add slaveagentport param to jenkins class
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Mestrum committed May 18, 2015
1 parent 118dc34 commit 16ea9c1
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
12 changes: 12 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
$port = $jenkins::params::port,
$libdir = $jenkins::params::libdir,
$executors = undef,
$slaveagentport = undef,
) inherits jenkins::params {

validate_bool($lts, $install_java, $repo)
Expand Down Expand Up @@ -240,6 +241,17 @@
Class['jenkins::jobs']
}

if $slaveagentport {
jenkins::cli::exec { 'set_slaveagent_port':
command => ['set_slaveagent_port', $slaveagentport],
unless => "[ \$(\$HELPER_CMD get_slaveagent_port) -eq ${slaveagentport} ]"
}

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

Anchor['jenkins::begin'] ->
Class[$jenkins_package_class] ->
Class['jenkins::config'] ->
Expand Down
29 changes: 29 additions & 0 deletions spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,33 @@ class {'jenkins':
it { should contain ' <numExecutors>42</numExecutors>' }
end
end # executors

context 'slaveagentport' do
it 'should work with no errors' do
pp = <<-EOS
class {'jenkins':
slaveagentport => 7777,
}
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 ' <slaveAgentPort>7777</slaveAgentPort>' }
end
end # slaveagentport
end
29 changes: 29 additions & 0 deletions spec/classes/jenkins_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,34 @@
end
end
end # executors =>

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

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

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

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

it 'should fail' do
should raise_error(Puppet::Error, /to be an Integer/)
end
end
end # slaveagentport =>
end
end

0 comments on commit 16ea9c1

Please sign in to comment.