From 4ea286a15b3e14b5a3b6ada1de81ea133238767f Mon Sep 17 00:00:00 2001 From: David Gurtner Date: Fri, 30 May 2014 00:07:00 +0200 Subject: [PATCH] Initial classes/tests for a roles/profiles pattern This is a first step to providing roles/profiles manifests according to the roles/profiles pattern. The roles/profiles pattern is a way to combine ceph manifests into functional units: Profiles combine multiple manifest to provide a single service. For example a ceph monitor server needs the repository, packages, configuration and finally the monitor service. Roles define sets of profiles to configure a specific server. For example an allinone role would install the monitor as well as an osd profile. The learn more have a look at: http://www.slideshare.net/PuppetLabs/roles-talk To start with the basic configuration this provides: * params: extracts the configuration from hiera * base: installs ceph and configures ceph.conf All configuration happens via hiera. Example hiera files are provided. NB: this uses hiera autoloading and will only work with Puppet >=3.0 Change-Id: Iba9aca7f124bd3a719dc18292b18fc0f4f386d5c --- examples/common.yaml | 29 ++++++ examples/hiera.yaml | 8 ++ manifests/profile/base.pp | 39 ++++++++ manifests/profile/params.pp | 41 ++++++++ spec/classes/ceph_profile_base_spec.rb | 66 ++++++++++++ spec/fixtures/hieradata/hiera.yaml | 8 ++ spec/spec_helper_system.rb | 3 + spec/system/ceph_profile_base_spec.rb | 133 +++++++++++++++++++++++++ 8 files changed, 327 insertions(+) create mode 100644 examples/common.yaml create mode 100644 examples/hiera.yaml create mode 100644 manifests/profile/base.pp create mode 100644 manifests/profile/params.pp create mode 100644 spec/classes/ceph_profile_base_spec.rb create mode 100644 spec/fixtures/hieradata/hiera.yaml create mode 100644 spec/system/ceph_profile_base_spec.rb diff --git a/examples/common.yaml b/examples/common.yaml new file mode 100644 index 00000000..343006c3 --- /dev/null +++ b/examples/common.yaml @@ -0,0 +1,29 @@ +--- +######## Ceph +ceph::profile::params::release: 'firefly' + +######## Ceph.conf +ceph::profile::params::fsid: '4b5c8c0a-ff60-454b-a1b4-9747aa737d19' +ceph::profile::params::authentication_type: 'cephx' +ceph::profile::params::mon_initial_members: 'first, second' +ceph::profile::params::mon_host: '10.11.12.2:6789, 10.11.12.3:6789' +ceph::profile::params::osd_pool_default_pg_num: '200' +ceph::profile::params::osd_pool_default_pgp_num: '200' +ceph::profile::params::osd_pool_default_size: '2' +ceph::profile::params::osd_pool_default_min_size: '1' +ceph::profile::params::cluster_network: '10.12.13.0/24' +ceph::profile::params::public_network: '10.11.12.0/24' + +######## Keys +ceph::profiles::params::mon_key: 'AQATGHJTUCBqIBAA7M2yafV1xctn1pgr3GcKPg==' +ceph::profiles::params::mon_keyring: '/tmp/keyring' +ceph::profiles::params::admin_key: 'AQBMGHJTkC8HKhAAJ7NH255wYypgm1oVuV41MA==' +ceph::profiles::params::admin_key_mode: '0600' +ceph::profiles::params::bootstrap_osd_key: 'AQARG3JTsDDEHhAAVinHPiqvJkUi5Mww/URupw==' +ceph::profiles::params::bootstrap_mds_key: 'AQCztJdSyNb0NBAASA2yPZPuwXeIQnDJ9O8gVw==' +ceph::profiles::params::osds: + '/dev/sdc': + journal: '/dev/sdb1' + '/dev/sdd': + journal: '/dev/sdb2' + diff --git a/examples/hiera.yaml b/examples/hiera.yaml new file mode 100644 index 00000000..81c0fc9e --- /dev/null +++ b/examples/hiera.yaml @@ -0,0 +1,8 @@ +--- +:backends: + - yaml +:yaml: + :datadir: /var/lib/hiera +:hierarchy: + - "nodes/%{::hostname}" + - common diff --git a/manifests/profile/base.pp b/manifests/profile/base.pp new file mode 100644 index 00000000..fcdfb75a --- /dev/null +++ b/manifests/profile/base.pp @@ -0,0 +1,39 @@ +# +# Copyright (C) 2014 Nine Internet Solutions AG +# +# 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. +# +# Author: David Gurtner +# +# Base profile to install ceph and configure /etc/ceph/ceph.conf +# +class ceph::profile::base { + class { 'ceph::profile::params': } -> + + class { 'ceph::repo': + release => $ceph::profile::params::release, + } -> + + class { 'ceph': + fsid => $ceph::profile::params::fsid, + authentication_type => $ceph::profile::params::authentication_type, + osd_pool_default_pg_num => $ceph::profile::params::osd_pool_default_pg_num, + osd_pool_default_pgp_num => $ceph::profile::params::osd_pool_default_pgp_num, + osd_pool_default_size => $ceph::profile::params::osd_pool_default_size, + osd_pool_default_min_size => $ceph::profile::params::osd_pool_default_min_size, + mon_initial_members => $ceph::profile::params::mon_initial_members, + mon_host => $ceph::profile::params::mon_host, + cluster_network => $ceph::profile::params::cluster_network, + public_network => $ceph::profile::params::public_network, + } +} diff --git a/manifests/profile/params.pp b/manifests/profile/params.pp new file mode 100644 index 00000000..86fda610 --- /dev/null +++ b/manifests/profile/params.pp @@ -0,0 +1,41 @@ +# +# Copyright (C) 2014 Nine Internet Solutions AG +# +# 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. +# +# Author: David Gurtner +# +# Extract the data from hiera where available +# +class ceph::profile::params ( + # puppet 2.7 compatibiliy hack. TODO: change to undef once 2.7 is deprecated + $fsid = '4b5c8c0a-ff60-454b-a1b4-9747aa737d19', + $release = undef, + $authentication_type = undef, + $mon_initial_members = undef, + $mon_host = undef, + $osd_pool_default_pg_num = undef, + $osd_pool_default_pgp_num = undef, + $osd_pool_default_size = undef, + $osd_pool_default_min_size = undef, + $cluster_network = undef, + $public_network = undef, + $admin_key = undef, + $admin_key_mode = undef, + $mon_key = undef, + $mon_keyring = undef, + $bootstrap_osd_key = undef, + $bootstrap_mds_key = undef, + $osds = undef, +) { +} diff --git a/spec/classes/ceph_profile_base_spec.rb b/spec/classes/ceph_profile_base_spec.rb new file mode 100644 index 00000000..f4eef1cf --- /dev/null +++ b/spec/classes/ceph_profile_base_spec.rb @@ -0,0 +1,66 @@ +# +# Copyright (C) 2014 Nine Internet Solutions AG +# +# 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. +# +# Author: David Gurtner +# +require 'spec_helper' + +describe 'ceph::profile::base' do + + shared_examples_for 'ceph profile base' do + it { should contain_class('ceph::profile::params') } + it { should contain_class('ceph::repo') } + it { should contain_class('ceph') } + end + + context 'on Debian' do + + let :facts do + { + :osfamily => 'Debian', + :lsbdistcodename => 'wheezy' + } + end + + it_configures 'ceph profile base' + end + + context 'on Ubuntu' do + + let :facts do + { + :osfamily => 'Debian', + :lsbdistcodename => 'Precise' + } + end + + it_configures 'ceph profile base' + end + + context 'on RHEL6' do + + let :facts do + { :osfamily => 'RedHat', } + end + + it_configures 'ceph profile base' + end +end +# Local Variables: +# compile-command: "cd ../.. ; +# BUNDLE_PATH=/tmp/vendor bundle install ; +# BUNDLE_PATH=/tmp/vendor bundle exec rake spec +# " +# End: diff --git a/spec/fixtures/hieradata/hiera.yaml b/spec/fixtures/hieradata/hiera.yaml new file mode 100644 index 00000000..81c0fc9e --- /dev/null +++ b/spec/fixtures/hieradata/hiera.yaml @@ -0,0 +1,8 @@ +--- +:backends: + - yaml +:yaml: + :datadir: /var/lib/hiera +:hierarchy: + - "nodes/%{::hostname}" + - common diff --git a/spec/spec_helper_system.rb b/spec/spec_helper_system.rb index 4b3fa445..f46e871c 100644 --- a/spec/spec_helper_system.rb +++ b/spec/spec_helper_system.rb @@ -44,6 +44,9 @@ RSpec.configure do |c| :node => vm) shell(:command => 'puppet module install --version 1.4.0 puppetlabs/apt', :node => vm) + rcp(:sp => File.join(proj_root, 'spec/fixtures/hieradata/hiera.yaml'), + :dp => '/etc/puppet/hiera.yaml', + :d => node(:name => vm)) # Flush the firewall flushfw = <<-EOS iptables -F diff --git a/spec/system/ceph_profile_base_spec.rb b/spec/system/ceph_profile_base_spec.rb new file mode 100644 index 00000000..51470425 --- /dev/null +++ b/spec/system/ceph_profile_base_spec.rb @@ -0,0 +1,133 @@ +# +# Copyright (C) 2014 Nine Internet Solutions AG +# +# Author: David Gurtner +# +# 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. +# +require 'spec_helper_system' + +describe 'ceph::profile::base' do + + release2version = { + 'dumpling' => '0.67', + 'emperor' => '0.72', + 'firefly' => '0.80', + } + + releases = ENV['RELEASES'] ? ENV['RELEASES'].split : release2version.keys + machines = ENV['MACHINES'] ? ENV['MACHINES'].split : [ 'first', 'second' ] + # passing it directly as unqoted array is not supported everywhere + packages = "[ 'python-ceph', 'ceph-common', 'librados2', 'librbd1', 'libcephfs1' ]" + fsid = 'a4807c9a-e76f-4666-a297-6d6cbc922e3a' + hieradata_common = '/var/lib/hiera/common.yaml' + hiera_shared = <<-EOS +--- +ceph::profile::params::fsid: '#{fsid}' + EOS + + releases.each do |release| + describe release do + + version = release2version[release] + + after(:all) do + pp = <<-EOS + package { #{packages}: + ensure => purged + } + class { 'ceph::repo': + release => '#{release}', + ensure => absent, + } + EOS + + machines.each do |vm| + puppet_apply(:node => vm, :code => pp) do |r| + r.exit_code.should_not == 1 + end + end + end + + describe 'on one host' do + it 'should install ceph' do + osfamily = facter.facts['osfamily'] + + osfamily2querycommand = { + 'Debian' => 'apt-cache policy ceph', + 'RedHat' => 'yum info ceph', + } + osfamily2queryresult = { + 'Debian' => "Candidate: #{version}" , + 'RedHat' => "Version : #{version}", + } + + querycommand = osfamily2querycommand[osfamily] + queryresult = osfamily2queryresult[osfamily] + + hiera = <<-EOS +ceph::profile::params::release: '#{release}' + EOS + + file = Tempfile.new('hieradata') + begin + file.write(hiera_shared + hiera) + file.close + rcp(:sp => file.path, :dp => hieradata_common, :d => node) + ensure + file.unlink + end + + pp = <<-EOS + include ::ceph::profile::base + EOS + + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + r.refresh + r.exit_code.should_not == 1 + end + + shell 'cat /etc/ceph/ceph.conf' do |r| + r.stdout.should =~ /#{fsid}/ + r.stderr.should be_empty + r.exit_code.should be_zero + end + + shell querycommand do |r| + r.stdout.should =~ /#{queryresult}/ + r.stderr.should be_empty + r.exit_code.should be_zero + end + end + end + end + end +end +# Local Variables: +# compile-command: "cd ../.. +# ( +# cd .rspec_system/vagrant_projects/one-ubuntu-server-12042-x64 +# vagrant destroy --force +# ) +# cp -a Gemfile-rspec-system Gemfile +# BUNDLE_PATH=/tmp/vendor bundle install --no-deployment +# MACHINES=first \ +# RELEASES=dumpling \ +# RS_DESTROY=no \ +# RS_SET=one-ubuntu-server-12042-x64 \ +# BUNDLE_PATH=/tmp/vendor \ +# bundle exec rake spec:system SPEC=spec/system/ceph_profile_base_spec.rb && +# git checkout Gemfile +# " +# End: