diff --git a/.fixtures.yml b/.fixtures.yml index 3ecc691..10652f2 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,3 +1,5 @@ fixtures: symlinks: "spacewalk": "#{source_dir}" + repositories: + stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git" diff --git a/manifests/client.pp b/manifests/client.pp index 0925cc0..3520822 100644 --- a/manifests/client.pp +++ b/manifests/client.pp @@ -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], } - - -} \ No newline at end of file + + 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] + } + } +} diff --git a/spec/classes/client_spec.rb b/spec/classes/client_spec.rb new file mode 100644 index 0000000..0d2d6d0 --- /dev/null +++ b/spec/classes/client_spec.rb @@ -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