From d1a8be5f8f5debfcfc6460f8e78fcfdd91704a0c Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Fri, 27 Jun 2014 19:09:38 +0200 Subject: [PATCH] spof: create resources on RH systems For now, the provider does not work, and it needs some investigation. During this time, let's simply use the exec provider. --- .fixtures.yml | 9 +++ Puppetfile | 2 +- manifests/spof.pp | 19 +++-- spec/classes/cloud_spof_spec.rb | 130 ++++++++++++++++++++++++++++++++ 4 files changed, 152 insertions(+), 8 deletions(-) create mode 100644 spec/classes/cloud_spof_spec.rb diff --git a/.fixtures.yml b/.fixtures.yml index 46be1a49..50f02d84 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -39,6 +39,15 @@ fixtures: 'concat': repo: 'git://github.com/enovance/puppet-concat.git' ref: '04356974f72b90a1d0f57346a00e95a717924e43' + 'corosync': + repo: 'git://github.com/enovance/puppetlabs-corosync.git' + ref: '79b61302b07fef30b65a42f3b55229616018aacf' + 'firewall': + repo: 'git://github.com/enovance/puppetlabs-firewall.git' + ref: '6540b31b0ca0727094ddf44436274436d2853d6d' + 'pacemaker': + repo: 'git://github.com/enovance/puppet-pacemaker.git' + ref: '7e304243b5bd2dced5f54d5146ecc58d0b5a51f1' 'elasticsearch': repo: 'git://github.com/enovance/puppet-elasticsearch.git' ref: '042720d52a3879786c2f9d9f67961c4f42004fae' diff --git a/Puppetfile b/Puppetfile index 23c5aa62..41a7895a 100644 --- a/Puppetfile +++ b/Puppetfile @@ -115,7 +115,7 @@ mod 'ntp', :ref => 'eb02ba2937ce86fb609ae41499767244b78ec58d' mod 'pacemaker', :git => 'git://github.com/enovance/puppet-pacemaker.git', - :ref => '1102d9861d8a63cc1577bc97a4415b9ff7488038' + :ref => '7e304243b5bd2dced5f54d5146ecc58d0b5a51f1' mod 'rabbitmq', :git => 'git://github.com/enovance/puppetlabs-rabbitmq.git', :ref => '25420cb3c26c9a8432ab519d43c094d614d4fec4' diff --git a/manifests/spof.pp b/manifests/spof.pp index e8b34717..9ff89e49 100644 --- a/manifests/spof.pp +++ b/manifests/spof.pp @@ -22,7 +22,6 @@ # [*cluster_ip*] # (optional) Interface used by Corosync to send multicast traffic # Defaults to '127.0.0.1' -# # [*cluster_members*] # (required on Red Hat) A space-separted list of cluster IP's or names # Defaults to false @@ -39,7 +38,7 @@ class cloud::spof( $cluster_password = 'secrete' ) { - if $::operatingsystem == 'RedHat' { + if $::osfamily == 'RedHat' { if ! $cluster_members { fail('cluster_members is a required parameter.') } @@ -62,17 +61,23 @@ class cloud::spof( owner => 'root', group => 'root', } -> - pcmk_resource { 'ceilometer-agent-central': - resource_type => 'ocf:heartbeat:ceilometer-agent-central' - } -> + exec {'pcmk_ceilometer_agent_central': + command => 'pcs resource create ceilometer-agent-central ocf:heartbeat:ceilometer-agent-central', + path => ['/usr/bin','/usr/sbin','/sbin/','/bin'], + user => 'root', + unless => '/usr/sbin/pcs resource | /bin/grep ceilometer-agent-central | /bin/grep Started' + } file { '/usr/lib/ocf/resource.d/heartbeat/heat-engine': source => 'puppet:///modules/cloud/heartbeat/heat-engine', mode => '0755', owner => 'root', group => 'root', } -> - pcmk_resource { 'heat-engine': - resource_type => 'ocf:heartbeat:heat-engine' + exec {'pcmk_heat_engine': + command => 'pcs resource create heat-engine ocf:heartbeat:heat-engine', + path => ['/usr/bin','/usr/sbin','/sbin/','/bin'], + user => 'root', + unless => '/usr/sbin/pcs resource | /bin/grep heat-engine | /bin/grep Started' } } else { diff --git a/spec/classes/cloud_spof_spec.rb b/spec/classes/cloud_spof_spec.rb new file mode 100644 index 00000000..d67d194b --- /dev/null +++ b/spec/classes/cloud_spof_spec.rb @@ -0,0 +1,130 @@ +# +# Copyright (C) 2014 eNovance SAS +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# Unit tests for cloud::spof class +# + +require 'spec_helper' + +describe 'cloud::spof' do + + shared_examples_for 'cloud spof' do + + let :params do + { :cluster_ip => '10.0.0.1', + :multicast_address => '239.1.1.2', + :cluster_members => false, + :cluster_password => 'verysecrete' } + end + + context 'with Pacemaker on Debian' do + before :each do + facts.merge!( :osfamily => 'Debian' ) + end + + it 'configure pacemaker/corosync' do + should contain_class('corosync').with( + :enable_secauth => false, + :authkey => '/var/lib/puppet/ssl/certs/ca.pem', + :bind_address => '10.0.0.1', + :multicast_address => '239.1.1.2', + ) + should contain_file('/usr/lib/ocf/resource.d/heartbeat/ceilometer-agent-central').with( + :source => 'puppet:///modules/cloud/heartbeat/ceilometer-agent-central', + :mode => '0755', + :owner => 'root', + :group => 'root' + ) + should contain_file('/usr/lib/ocf/resource.d/heartbeat/heat-engine').with( + :source => 'puppet:///modules/cloud/heartbeat/heat-engine', + :mode => '0755', + :owner => 'root', + :group => 'root' + ) + should contain_class('cloud::orchestration::engine').with(:enabled => false) + should contain_class('cloud::telemetry::centralagent').with(:enabled => false) + end + end + + context 'with Pacemaker on Red-Hat' do + before :each do + facts.merge!( :osfamily => 'RedHat' ) + params.merge!( :cluster_members => 'srv1 srv2 srv3') + end + + it 'configure pacemaker/corosync' do + should contain_class('pacemaker').with(:hacluster_pwd => 'verysecrete') + should contain_class('pacemaker::stonith').with(:disable => true) + should contain_class('pacemaker::corosync').with( + :cluster_name => 'openstack', + :cluster_members => 'srv1 srv2 srv3') + should contain_file('/usr/lib/ocf/resource.d/heartbeat/ceilometer-agent-central').with( + :source => 'puppet:///modules/cloud/heartbeat/ceilometer-agent-central', + :mode => '0755', + :owner => 'root', + :group => 'root' + ) + should contain_file('/usr/lib/ocf/resource.d/heartbeat/heat-engine').with( + :source => 'puppet:///modules/cloud/heartbeat/heat-engine', + :mode => '0755', + :owner => 'root', + :group => 'root' + ) + should contain_exec('pcmk_ceilometer_agent_central').with( + :command => 'pcs resource create ceilometer-agent-central ocf:heartbeat:ceilometer-agent-central', + :path => ['/usr/bin','/usr/sbin','/sbin/','/bin'], + :user => 'root', + :unless => '/usr/sbin/pcs resource | /bin/grep ceilometer-agent-central | /bin/grep Started' + ) + should contain_exec('pcmk_heat_engine').with( + :command => 'pcs resource create heat-engine ocf:heartbeat:heat-engine', + :path => ['/usr/bin','/usr/sbin','/sbin/','/bin'], + :user => 'root', + :unless => '/usr/sbin/pcs resource | /bin/grep heat-engine | /bin/grep Started' + ) + should contain_class('cloud::orchestration::engine').with(:enabled => false) + should contain_class('cloud::telemetry::centralagent').with(:enabled => false) + end + end + + context 'with Pacemaker on Red-Hat with missing parameters' do + before :each do + facts.merge!( :osfamily => 'RedHat' ) + params.merge!( :cluster_members => false) + end + it { should compile.and_raise_error(/cluster_members is a required parameter./) } + end + end + + context 'on Debian platforms' do + let :facts do + { :osfamily => 'Debian', + :concat_basedir => '/var/lib/puppet/concat', + :uniqueid => '123' } + end + + it_configures 'cloud spof' + end + + context 'on RedHat platforms' do + let :facts do + { :osfamily => 'RedHat', + :concat_basedir => '/var/lib/puppet/concat', + :uniqueid => '123' } + end + it_configures 'cloud spof' + end + +end