Skip to content
Open
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
2 changes: 2 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
fixtures:
symlinks:
"spacewalk": "#{source_dir}"
repositories:
stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git"
98 changes: 75 additions & 23 deletions manifests/client.pp
Original file line number Diff line number Diff line change
@@ -1,33 +1,85 @@
# == Class: spacewalk::client
#
# This class will setup a node to talk to a spacewalk server. You
# need to provide the activation key that you create within the
# spacewalk UI
#
# === Parameters
#
# [*activation_key*]
# Activation key need for the registration
# Default: unset
#
# [*spacewalk_fqdn*]
# FQDN of the spacewalk server.
# Default: spacewalk.${::domain}
#
# [*force_registration*]
#
# If the client should forcefully register itself on the spacewalk
# server.
# WARNING: if set to yes the client currently re-registers
# itself to the server on every puppet run. This could result in the
# same spacewalk client registered multiple times on the server.
# Default: false
#
# [*use_spacewalk_client_repo*]
# If we should also enable the spacewalk
# client repositories. This is not required for a client that
# registers on a satellite server.
# Default: true
#
# === Examples
#
# class {'spacewalk::client':
# spacewalk_fqdn => 'spacewalk.local.net',
# activation_key => '1-d9e796114e1e8ef073b605341ee6580d',
# }

class spacewalk::client (
$spacewalk_fqdn = "spacewalk.$::domain",
$activation_key # this must be set
) {
# This class will setup a node to talk to a spacewalk server.
# You need to provide the activation key that you create within the spacewalk UI
#
# class {'spacewalk::client':
# spacewalk_fqdn => 'spacewalk.local.net',
# activation_key => '1-d9e796114e1e8ef073b605341ee6580d',
# }

include spacewalk::repo_client

$activation_key,
$spacewalk_fqdn = "spacewalk.${::domain}",
$force_registration = false,
$use_spacewalk_client_repo = true,
) {

validate_bool($use_spacewalk_client_repo)
validate_bool($force_registration)

# spacewalk client packages needed
$packageList = ['rhn-client-tools','rhn-check', 'rhn-setup', 'm2crypto', 'yum-rhn-plugin']

package {$packageList:
ensure => installed,
require => Exec['setupSpacewalkClientRepo'],
ensure => installed,
}


if $use_spacewalk_client_repo == true {
include spacewalk::repo_client

Package[$packageList] -> Exec['setupSpacewalkClientRepo']
}

# Exec to register with the spacewalk server
exec {'registerSpacewalk':
cwd => '/root',
path => '/usr/bin:/usr/sbin:/bin',
cwd => '/root',
path => '/usr/bin:/usr/sbin:/bin',
creates => '/etc/sysconfig/rhn/systemid',
command => "rhnreg_ks --serverUrl=http://$spacewalk_fqdn/XMLRPC --activationkey=$activation_key",
require => Package[$packageList],
}


}

if $force_registration == true {
file { 'spacewalk_systemid':
path => '/etc/sysconfig/rhn/systemid',
ensure => absent,
}

Exec['registerSpacewalk'] {
require => [ File['/etc/sysconfig/rhn/systemid'], Package[$packageList] ]
}
}
else {
Exec['registerSpacewalk'] {
require => Package[$packageList]
}
}
}
107 changes: 107 additions & 0 deletions spec/classes/client_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
require 'spec_helper'

describe 'spacewalk::client', :type => :class do

let :facts do
{
:domain => 'test.com',
:osfamily => 'RedHat',
:operatingsystemrelease => '6',
}
end

context 'when use_spacewalk_client_repo is set to true' do

let :params do
{
:force_registration => false,
:use_spacewalk_client_repo => true,
:activation_key => '12345',
}
end

it do
should contain_exec('registerSpacewalk').with({
'cwd' => '/root',
'path' => '/usr/bin:/usr/sbin:/bin',
'creates' => '/etc/sysconfig/rhn/systemid',
'command' => "rhnreg_ks --serverUrl=http://spacewalk.test.com/XMLRPC --activationkey=12345",
})
end

it { should contain_class('spacewalk::repo_client')}

packages = ['rhn-client-tools','rhn-check', 'rhn-setup', 'm2crypto', 'yum-rhn-plugin']
packages.each do |name|
it { should contain_package("#{name}").with('ensure' => 'installed') }
it { should contain_exec('setupSpacewalkClientRepo').that_requires("Package[#{name}]") }
end
end

context 'when use_spacewalk_client_repo is set to false' do
let :params do
{
:force_registration => false,
:use_spacewalk_client_repo => false,
:activation_key => '12345',
}
end

it do
should contain_exec('registerSpacewalk').with({
'cwd' => '/root',
'path' => '/usr/bin:/usr/sbin:/bin',
'creates' => '/etc/sysconfig/rhn/systemid',
'command' => "rhnreg_ks --serverUrl=http://spacewalk.test.com/XMLRPC --activationkey=12345",
})
end

it { should_not contain_class('spacewalk::repo_client')}

packages = ['rhn-client-tools','rhn-check', 'rhn-setup', 'm2crypto', 'yum-rhn-plugin']
packages.each do |name|
it { should_not contain_exec('setupSpacewalkClientRepo').that_requires("Package[#{name}]") }
it { should contain_package("#{name}").with( 'ensure' => 'installed') }
end

end

context 'when force_reqistration is true' do
let :params do
{
:force_registration => true,
:use_spacewalk_client_repo => false,
:activation_key => '12345',
}
end

it do
should contain_file('spacewalk_systemid').with({
'ensure' => 'absent',
'path' => '/etc/sysconfig/rhn/systemid',
})
end

# it do
# should contain_exec('registerSpacewalk').with_require('[File[/etc/sysconfig/rhn/systemid]{:path=>"/etc/sysconfig/rhn/systemid"}, Package[rhn-client-tools]{:name=>"rhn-client-tools"}, Package[rhn-check]{:name=>"rhn-check"}, Package[rhn-setup]{:name=>"rhn-setup"}, Package[m2crypto]{:name=>"m2crypto"}, Package[yum-rhn-plugin]{:name=>"yum-rhn-plugin"}]')
# end

end

context 'when force_reqistration is false' do
let :params do
{
:force_registration => false,
:use_spacewalk_client_repo => false,
:activation_key => '12345',
}
end

it { should_not contain_file('spacewalk_systemid') }

# it do
# should contain_exec('registerSpacewalk').with_require('[Package[rhn-client-tools]{:name=>"rhn-client-tools"}, Package[rhn-check]{:name=>"rhn-check"}, Package[rhn-setup]{:name=>"rhn-setup"}, Package[m2crypto]{:name=>"m2crypto"}, Package[yum-rhn-plugin]{:name=>"yum-rhn-plugin"}]')
# end

end
end