From 899bd6e03bbb2af581d5e4c9a53c526bcf555fcd Mon Sep 17 00:00:00 2001 From: Toni Schmidbauer Date: Mon, 3 Mar 2014 12:34:29 +0100 Subject: [PATCH 1/4] make spacewalk_client_repo optional, support reregistration introduced two new options to spacewalk::client - force_registration: if set to yes, the client is going to reregister itself to the spacewalk server on the next run. use with care as this can result in the same system registered more than once on the server. - use_spacewalk_client_repo: if spacewalk::client should configure the spacewalk client repository and exec setupSpacewalkClientRepo. when using a redhat satellite server, the client repo is not needed. --- manifests/client.pp | 92 +++++++++++++++++++++++++++++++++------------ 1 file changed, 69 insertions(+), 23 deletions(-) diff --git a/manifests/client.pp b/manifests/client.pp index 0925cc0..008395e 100644 --- a/manifests/client.pp +++ b/manifests/client.pp @@ -1,33 +1,79 @@ +# == 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 +# +# [*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 +# +# [*spacewalk_fqdn*] +# FQDN of the spacewalk server. +# +# Default: spacewalk.${::domain} +# +# [*activation_key*] +# Activation key need for the registration +# +# Default: unset +# +# === 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] + } + } +} From 1d0e3885eb330bb436f628c846b8301e5d183129 Mon Sep 17 00:00:00 2001 From: Toni Schmidbauer Date: Mon, 3 Mar 2014 12:39:05 +0100 Subject: [PATCH 2/4] import rspec tests for client.pp --- spec/classes/client_spec.rb | 107 ++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 spec/classes/client_spec.rb 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 From bf1c3834ffbbb07e7515c93b81b70827c9cc3496 Mon Sep 17 00:00:00 2001 From: Toni Schmidbauer Date: Mon, 3 Mar 2014 12:43:23 +0100 Subject: [PATCH 3/4] added stdlib to dependencies --- .fixtures.yml | 2 ++ 1 file changed, 2 insertions(+) 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" From a0d71e0ec2612c07ee8e53474c15c85a4fde7233 Mon Sep 17 00:00:00 2001 From: Toni Schmidbauer Date: Mon, 3 Mar 2014 13:01:37 +0100 Subject: [PATCH 4/4] documentation update for the force_registration option --- manifests/client.pp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/manifests/client.pp b/manifests/client.pp index 008395e..3520822 100644 --- a/manifests/client.pp +++ b/manifests/client.pp @@ -6,22 +6,28 @@ # # === Parameters # -# [*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 +# [*activation_key*] +# Activation key need for the registration +# Default: unset # # [*spacewalk_fqdn*] # FQDN of the spacewalk server. -# # Default: spacewalk.${::domain} # -# [*activation_key*] -# Activation key need for the registration +# [*force_registration*] # -# Default: unset +# 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 #