Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Puppet helper slaveagentport #303

Merged
merged 2 commits into from
Aug 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -162,6 +165,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 +244,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