Skip to content

Commit

Permalink
Merge pull request #303 from rmestrum/puppet_helper_slaveagentport
Browse files Browse the repository at this point in the history
Puppet helper slaveagentport
  • Loading branch information
R. Tyler Croy committed Aug 8, 2015
2 parents 9c39706 + 6318cfb commit 3d343dc
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
24 changes: 24 additions & 0 deletions files/puppet_helper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,30 @@ class Actions {
j.setNumExecutors(n.toInteger())
j.save()
}

////////////////////////
// get_slaveagent_port
////////////////////////
/*
* Print the portnumber of the slave agent
*/
void get_slaveagent_port() {
def j = Jenkins.getInstance()
def n = j.getSlaveAgentPort()
out.println(n)
}

////////////////////////
// set_slaveagent_port
////////////////////////
/*
* Set the portnumber of the slave agent
*/
void set_slaveagent_port(String n) {
def j = Jenkins.getInstance()
j.setSlaveAgentPort(n.toInteger())
j.save()
}
} // class Actions

///////////////////////////////////////////////////////////////////////////////
Expand Down
15 changes: 15 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
# executors = undef (Default)
# Integer number of executors on the Jenkin's master.
#
# slaveagentport = undef (Default)
# Integer number of portnumber for the slave agent.
#
# Example use
#
# class{ 'jenkins':
Expand Down Expand Up @@ -171,6 +174,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 @@ -249,6 +253,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 3d343dc

Please sign in to comment.