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

add darwin/osx support to slave class #351

Merged
merged 3 commits into from
Aug 15, 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
128 changes: 88 additions & 40 deletions manifests/slave.pp
Original file line number Diff line number Diff line change
Expand Up @@ -104,37 +104,6 @@
}
}

#add jenkins slave user if necessary.
if $manage_slave_user and $slave_uid {
user { 'jenkins-slave_user':
ensure => present,
name => $slave_user,
comment => 'Jenkins Slave user',
home => $slave_home,
managehome => true,
uid => $slave_uid,
}
}

if ($manage_slave_user) and (! $slave_uid) {
user { 'jenkins-slave_user':
ensure => present,
name => $slave_user,
comment => 'Jenkins Slave user',
home => $slave_home,
managehome => true,
}
}

exec { 'get_swarm_client':
command => "wget -O ${slave_home}/${client_jar} ${client_url}/${client_jar}",
path => '/usr/bin:/usr/sbin:/bin:/usr/local/bin',
user => $slave_user,
#refreshonly => true,
creates => "${slave_home}/${client_jar}",
## needs to be fixed if you create another version..
}

# customizations based on the OS family
case $::osfamily {
'Debian': {
Expand All @@ -145,31 +114,110 @@
before => Service['jenkins-slave'],
}
}
'Darwin': {
$defaults_location = $slave_home
}
default: {
$defaults_location = '/etc/sysconfig'
}
}

file { '/etc/init.d/jenkins-slave':
ensure => 'file',
mode => '0755',
owner => 'root',
group => 'root',
source => "puppet:///modules/${module_name}/jenkins-slave.${::osfamily}",
notify => Service['jenkins-slave'],
case $::kernel {
'Linux': {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case statement smells a bit to me, would it be possible to refactor this into a jenkins::slave::linux and a jenkins::slave::darwin module which would then be included depending on the kernel?

$fetch_command = "wget -O ${slave_home}/${client_jar} ${client_url}/${client_jar}"
$service_name = 'jenkins-slave'
$defaults_user = 'root'
$defaults_group = 'root'
$manage_user_home = true

file { '/etc/init.d/jenkins-slave':
ensure => 'file',
mode => '0755',
owner => 'root',
group => 'root',
source => "puppet:///modules/${module_name}/jenkins-slave.${::osfamily}",
notify => Service['jenkins-slave'],
}
}
'Darwin': {
$fetch_command = "curl -O ${client_url}/${client_jar}"
$service_name = 'org.jenkins-ci.slave.jnlp'
$defaults_user = 'jenkins'
$defaults_group = 'wheel'
$manage_user_home = false

file { "${slave_home}/start-slave.sh":
ensure => 'file',
content => template("${module_name}/start-slave.sh.erb"),
mode => '0755',
owner => 'root',
group => 'wheel',
}

file { '/Library/LaunchDaemons/org.jenkins-ci.slave.jnlp.plist':
ensure => 'file',
content => template("${module_name}/org.jenkins-ci.slave.jnlp.plist.erb"),
mode => '0644',
owner => 'root',
group => 'wheel',
}

file { '/var/log/jenkins':
ensure => 'directory',
owner => $slave_user,
}

if $manage_slave_user {
# osx doesn't have managehome support, so create directory
file { $slave_home:
ensure => directory,
mode => '0755',
owner => $slave_user,
require => User['jenkins-slave_user'],
}
}

File['/var/log/jenkins'] ->
File['/Library/LaunchDaemons/org.jenkins-ci.slave.jnlp.plist'] ->
Service['jenkins-slave']
}
default: { }
}

#add jenkins slave user if necessary.
if $manage_slave_user {
user { 'jenkins-slave_user':
ensure => present,
name => $slave_user,
comment => 'Jenkins Slave user',
home => $slave_home,
managehome => $manage_user_home,
uid => $slave_uid,
}
}

file { "${defaults_location}/jenkins-slave":
ensure => 'file',
mode => '0600',
owner => 'root',
group => 'root',
owner => $defaults_user,
group => $defaults_group,
content => template("${module_name}/jenkins-slave-defaults.erb"),
notify => Service['jenkins-slave'],
}

exec { 'get_swarm_client':
command => $fetch_command,
path => '/usr/bin:/usr/sbin:/bin:/usr/local/bin',
user => $slave_user,
creates => "${slave_home}/${client_jar}",
cwd => $slave_home,
#refreshonly => true,
## needs to be fixed if you create another version..
}

service { 'jenkins-slave':
ensure => $ensure,
name => $service_name,
enable => $enable,
hasstatus => true,
hasrestart => true,
Expand Down
22 changes: 18 additions & 4 deletions spec/classes/jenkins_slave_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

shared_context 'a jenkins::slave catalog' do
it { should contain_exec('get_swarm_client') }
it { should contain_file('/etc/init.d/jenkins-slave') }
it { should contain_file(slave_service_file) }
it { should contain_service('jenkins-slave').with(:enable => true, :ensure => 'running') }
it { should contain_user('jenkins-slave_user').with_uid(nil) }
# Let the different platform blocks define `slave_runtime_file` separately below
Expand Down Expand Up @@ -44,9 +44,9 @@
end

describe 'RedHat' do
let(:facts) { { :osfamily => 'RedHat', :operatingsystem => 'CentOS' } }
let(:facts) { { :osfamily => 'RedHat', :operatingsystem => 'CentOS', :kernel => 'Linux' } }
let(:slave_runtime_file) { '/etc/sysconfig/jenkins-slave' }

let(:slave_service_file) { '/etc/init.d/jenkins-slave' }
it_behaves_like 'a jenkins::slave catalog'

describe 'with slave_name' do
Expand All @@ -56,8 +56,9 @@
end

describe 'Debian' do
let(:facts) { { :osfamily => 'Debian', :lsbdistid => 'debian', :lsbdistcodename => 'natty', :operatingsystem => 'Debian' } }
let(:facts) { { :osfamily => 'Debian', :lsbdistid => 'debian', :lsbdistcodename => 'natty', :operatingsystem => 'Debian', :kernel => 'Linux' } }
let(:slave_runtime_file) { '/etc/default/jenkins-slave' }
let(:slave_service_file) { '/etc/init.d/jenkins-slave' }

it_behaves_like 'a jenkins::slave catalog'

Expand All @@ -67,6 +68,19 @@
end
end

# describe 'Darwin' do
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason for these examples to be commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still learning rspec, and can't figure out how to get the tests to ignore java install on darwin.

Failures:

  1) jenkins::slave Darwin with slave_name behaves like using slave_name should contain File[/home/jenkins-slave/jenkins-slave] with content =~ /^CLIENT_NAME="jenkins-slave"$/
     Failure/Error: it { should contain_file(slave_runtime_file).with_content(/^CLIENT_NAME="jenkins-slave"$/) }
     Puppet::Error:
       Could not find resource 'Class[Java]' for relationship on 'Service[jenkins-slave]' on node myosx.local
     Shared Example Group: "using slave_name" called from ./spec/classes/jenkins_slave_spec.rb:80
     # ./spec/classes/jenkins_slave_spec.rb:43:in `block (3 levels) in <top (required)>'

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the puppetlabs/java module doesn't support Darwin so I think part of why this is failing.

# let(:facts) { { :osfamily => 'Darwin', :operatingsystem => 'Darwin', :kernel => 'Darwin' } }
# let(:slave_runtime_file) { '/home/jenkins-slave/jenkins-slave' }
# let(:slave_service_file) { '/Library/LaunchDaemons/org.jenkins-ci.slave.jnlp.plist' }
#
# it_behaves_like 'a jenkins::slave catalog'
#
# describe 'with slave_name' do
# let(:params) { { :slave_name => 'jenkins-slave' } }
# it_behaves_like 'using slave_name'
# end
# end

describe 'Unknown' do
let(:facts) { { :ostype => 'Unknown' } }
it { expect { should raise_error(Puppet::Error) } }
Expand Down
28 changes: 28 additions & 0 deletions templates/org.jenkins-ci.slave.jnlp.plist.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-/Apple/DTD PLIST 1.0/EN" "http:/www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.jenkins-ci.slave.jnlp</string>
<key>ProgramArguments</key>
<array>
<string><%= @slave_home %>/start-slave.sh</string>
</array>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
<key>UserName</key>
<string><%= @slave_user %></string>
<key>WorkingDirectory</key>
<string><%= @slave_home %></string>
<key>SessionCreate</key>
<true/>
<key>StandardInPath</key>
<string>/dev/null</string>
<key>StandardErrorPath</key>
<string>/var/log/jenkins/org.jenkins-ci.slave.jnlp.log</string>
<key>StandardOutPath</key>
<string>/var/log/jenkins/org.jenkins-ci.slave.jnlp.log</string>
</dict>
</plist>
4 changes: 4 additions & 0 deletions templates/start-slave.sh.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

source <%= @defaults_location %>/jenkins-slave
java -jar <%= @slave_home %>/<%= @client_jar %> $JENKINS_SLAVE_ARGS