From e998f5dd28215f00b258a05c7ed89a2fac13edf3 Mon Sep 17 00:00:00 2001 From: David Gurtner Date: Mon, 2 Feb 2015 01:46:39 +0100 Subject: [PATCH] Adding base infrastructure for beaker CI tests Change-Id: Iad5984bd9eab24d2ff589fd6d70b3ed46bab56ec --- .gitignore | 1 + Gemfile | 6 +- README.md | 35 ++++- spec/acceptance/ceph_usecases_spec.rb | 130 ++++++++++++++++++ spec/acceptance/nodesets/centos-65-x64.yml | 14 ++ spec/acceptance/nodesets/default.yml | 1 + spec/acceptance/nodesets/nodepool.yml | 12 ++ .../acceptance/nodesets/two-centos-65-x64.yml | 21 +++ .../nodesets/two-ubuntu-server-1204-x64.yml | 21 +++ .../nodesets/ubuntu-server-1204-x64.yml | 14 ++ spec/spec_helper_acceptance.rb | 54 ++++++++ 11 files changed, 306 insertions(+), 3 deletions(-) create mode 100644 spec/acceptance/ceph_usecases_spec.rb create mode 100644 spec/acceptance/nodesets/centos-65-x64.yml create mode 120000 spec/acceptance/nodesets/default.yml create mode 100644 spec/acceptance/nodesets/nodepool.yml create mode 100644 spec/acceptance/nodesets/two-centos-65-x64.yml create mode 100644 spec/acceptance/nodesets/two-ubuntu-server-1204-x64.yml create mode 100644 spec/acceptance/nodesets/ubuntu-server-1204-x64.yml create mode 100644 spec/spec_helper_acceptance.rb diff --git a/.gitignore b/.gitignore index 4b544580..c939edf6 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ Gemfile.lock vendor .rspec_system Gemfile-rspec-system.lock +.vagrant/* diff --git a/Gemfile b/Gemfile index f3182fde..1d276cac 100644 --- a/Gemfile +++ b/Gemfile @@ -3,11 +3,15 @@ source 'https://rubygems.org' group :development, :test do gem 'puppetlabs_spec_helper', :require => false gem 'puppet-lint', '~> 0.3.2' - gem 'rspec-puppet', '~> 1.0.1' + gem 'rspec-puppet', '~> 1.0.1', :require => false + gem 'beaker-rspec', '~> 2.2.4', :require => false gem 'rake', '10.1.1' gem 'rspec', '< 2.99' gem 'json' gem 'webmock' + gem 'minitest', :require => false + gem 'test', :require => false + gem 'test-unit', :require => false end if puppetversion = ENV['PUPPET_GEM_VERSION'] diff --git a/README.md b/README.md index 666422f9..6318e618 100644 --- a/README.md +++ b/README.md @@ -65,8 +65,39 @@ IRC channels: * irc.freenode.net#puppet-openstack * irc.oftc.net#ceph-devel -Integration Tests ------------------ +Beaker Integration Tests +------------------------ + +Relies on +[rspec-beaker](https://github.com/puppetlabs/beaker-rspec) +and tests are in spec/acceptance. +It also requires [Vagrant and Virtualbox](http://docs-v1.vagrantup.com/v1/docs/getting-started/) +. + +``` +BUNDLE_PATH=/tmp/vendor bundle install +BUNDLE_PATH=/tmp/vendor bundle exec rspec spec/acceptance +``` + +The BEAKER_set environment variable contains the resource set of linux +distribution configurations for which integration tests are going +to be run. Available values are + +* two-ubuntu-server-1204-x64 +* ubuntu-server-1204-x64 +* two-centos-64-x64 +* centos-64-x64 + +The default is + +``` +BUNDLE_PATH=/tmp/vendor \ +BEAKER_set=two-ubuntu-server-1204-x64 \ +bundle exec rspec spec/acceptance +``` + +Deprecated Integration Tests +---------------------------- Relies on [rspec-system-puppet](https://github.com/puppetlabs/rspec-system-puppet) diff --git a/spec/acceptance/ceph_usecases_spec.rb b/spec/acceptance/ceph_usecases_spec.rb new file mode 100644 index 00000000..dd3a31ab --- /dev/null +++ b/spec/acceptance/ceph_usecases_spec.rb @@ -0,0 +1,130 @@ +# +# Copyright (C) 2015 David Gurtner +# +# 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_acceptance' + +describe 'ceph usecases' do + + # passing it directly as unqoted array is not supported everywhere + packages = "[ 'python-ceph', 'ceph-common', 'librados2', 'librbd1', 'libcephfs1' ]" + + describe 'I want to try this module, heard of ceph, want to see it in action' do + + it 'should install one monitor and one OSD on /srv/data' do + pp = <<-EOS + class { 'ceph::repo': } + class { 'ceph': + fsid => generate('/usr/bin/uuidgen'), + mon_host => $::ipaddress_eth0, + authentication_type => 'none', + osd_pool_default_size => '1', + osd_pool_default_min_size => '1', + } + ceph_config { + 'global/osd_journal_size': value => '100'; + } + ceph::mon { 'a': + public_addr => $::ipaddress_eth0, + authentication_type => 'none', + } + ceph::osd { '/srv/data': } + EOS + + # due to the generate() the above is not idempotent + # so we don't run twice as usual + apply_manifest(pp, :catch_failures => true) + + shell 'sleep 10' # we need to wait a bit until the OSD is up + + shell 'ceph -s', { :acceptable_exit_codes => [0] } do |r| + r.stdout.should =~ /1 mons at/ + r.stderr.should be_empty + end + + shell 'ceph osd tree', { :acceptable_exit_codes => [0] } do |r| + r.stdout.should =~ /osd.0/ + r.stderr.should be_empty + end + end + + it 'should uninstall one osd' do + shell 'ceph osd tree | grep DNE', { :acceptable_exit_codes => [1] } + + pp = <<-EOS + ceph::osd { '/srv/data': + ensure => absent, + } + EOS + + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + + shell 'sleep 10' # we need to wait a bit until the OSD is down + + shell 'ceph osd tree | grep DNE', { :acceptable_exit_codes => [0] } + end + + it 'should uninstall one monitor' do + pp = <<-EOS + ceph::mon { 'a': + ensure => absent, + } + EOS + + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + + osfamily = fact 'osfamily' + operatingsystem = fact 'operatingsystem' + + if osfamily == 'Debian' && operatingsystem == 'Ubuntu' + shell 'status ceph-mon id=a', { :acceptable_exit_codes => [1] } do |r| + r.stdout.should be_empty + r.stderr.should =~ /Unknown instance: ceph.a/ + end + end + if osfamily == 'RedHat' + shell 'service ceph status mon.a', { :acceptable_exit_codes => [1] } do |r| + r.stdout.should =~ /mon.a not found/ + r.stderr.should be_empty + end + end + end + + it 'should purge all packages' do + pp = <<-EOS + package { #{packages}: + ensure => purged + } + class { 'ceph::repo': + ensure => absent, + } + EOS + + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + end +end +# Local Variables: +# compile-command: "cd ../.. +# BUNDLE_PATH=/tmp/vendor bundle install +# BEAKER_set=ubuntu-server-1204-x64 \ +# BUNDLE_PATH=/tmp/vendor \ +# bundle exec rspec spec/acceptance/ceph_usecases_spec.rb +# " +# End: diff --git a/spec/acceptance/nodesets/centos-65-x64.yml b/spec/acceptance/nodesets/centos-65-x64.yml new file mode 100644 index 00000000..372483bb --- /dev/null +++ b/spec/acceptance/nodesets/centos-65-x64.yml @@ -0,0 +1,14 @@ +HOSTS: + first: + roles: + - master + - mon + - osd + - client + platform: el-6-x86_64 + box: puppetlabs/centos-6.5-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/boxes/centos-6.5-64-nocm + hypervisor: vagrant + ip: 10.11.12.2 +CONFIG: + type: foss diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml new file mode 120000 index 00000000..d3f9b1a7 --- /dev/null +++ b/spec/acceptance/nodesets/default.yml @@ -0,0 +1 @@ +two-ubuntu-server-1204-x64.yml \ No newline at end of file diff --git a/spec/acceptance/nodesets/nodepool.yml b/spec/acceptance/nodesets/nodepool.yml new file mode 100644 index 00000000..45367696 --- /dev/null +++ b/spec/acceptance/nodesets/nodepool.yml @@ -0,0 +1,12 @@ +HOSTS: + first: + roles: + - master + - mon + - osd + - client + platform: ubuntu-1204-amd64 + hypervisor: none + ip: 127.0.0.1 +CONFIG: + type: foss diff --git a/spec/acceptance/nodesets/two-centos-65-x64.yml b/spec/acceptance/nodesets/two-centos-65-x64.yml new file mode 100644 index 00000000..f92a7743 --- /dev/null +++ b/spec/acceptance/nodesets/two-centos-65-x64.yml @@ -0,0 +1,21 @@ +HOSTS: + first: + roles: + - master + - mon + platform: el-6-x86_64 + box: puppetlabs/centos-6.5-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/boxes/centos-6.5-64-nocm + hypervisor: vagrant + ip: 10.11.12.2 + second: + roles: + - osd + - client + platform: el-6-x86_64 + box: puppetlabs/centos-6.5-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/boxes/centos-6.5-64-nocm + hypervisor: vagrant + ip: 10.11.12.3 +CONFIG: + type: foss diff --git a/spec/acceptance/nodesets/two-ubuntu-server-1204-x64.yml b/spec/acceptance/nodesets/two-ubuntu-server-1204-x64.yml new file mode 100644 index 00000000..cdef42cf --- /dev/null +++ b/spec/acceptance/nodesets/two-ubuntu-server-1204-x64.yml @@ -0,0 +1,21 @@ +HOSTS: + first: + roles: + - master + - mon + platform: ubuntu-1204-amd64 + box: puppetlabs/ubuntu-12.04-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/boxes/ubuntu-12.04-64-nocm + hypervisor: vagrant + ip: 10.11.12.2 + second: + roles: + - osd + - client + platform: ubuntu-1204-amd64 + box: puppetlabs/ubuntu-12.04-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/boxes/ubuntu-12.04-64-nocm + hypervisor: vagrant + ip: 10.11.12.3 +CONFIG: + type: foss diff --git a/spec/acceptance/nodesets/ubuntu-server-1204-x64.yml b/spec/acceptance/nodesets/ubuntu-server-1204-x64.yml new file mode 100644 index 00000000..2b2f960a --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu-server-1204-x64.yml @@ -0,0 +1,14 @@ +HOSTS: + first: + roles: + - master + - mon + - osd + - client + platform: ubuntu-1204-amd64 + box: puppetlabs/ubuntu-12.04-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/boxes/ubuntu-12.04-64-nocm + hypervisor: vagrant + ip: 10.11.12.2 +CONFIG: + type: foss diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb new file mode 100644 index 00000000..f301c819 --- /dev/null +++ b/spec/spec_helper_acceptance.rb @@ -0,0 +1,54 @@ +# +# Copyright (C) 2015 David Gurtner +# +# 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 'minitest' +require 'beaker-rspec' + +RSpec.configure do |c| + # Project root + proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + + hosts.each do |host| + install_puppet + on host, "mkdir -p #{host['distmoduledir']}" + end + + c.before :suite do + puppet_module_install(:source => proj_root, :module_name => 'ceph') + scp_to hosts, File.join(proj_root, 'spec/fixtures/hieradata/hiera.yaml'), '/etc/puppet/hiera.yaml' + hosts.each do |host| + # https://tickets.puppetlabs.com/browse/PUP-2566 + on host, 'sed -i "/templatedir/d" /etc/puppet/puppet.conf' + install_package host, 'git' + on host, "git clone https://github.com/bodepd/scenario_node_terminus.git #{host['distmoduledir']}/scenario_node_terminus" + on host, puppet('module install puppetlabs/stdlib --version ">=4.0.0 <5.0.0"'), { :acceptable_exit_codes => [0,1] } + on host, puppet('module install puppetlabs/inifile --version ">=1.0.0 <2.0.0"'), { :acceptable_exit_codes => [0,1] } + on host, puppet('module install puppetlabs/apt --version ">=1.4.0 <2.0.0"'), { :acceptable_exit_codes => [0,1] } + on host, puppet('module install puppetlabs/concat --version ">=1.1.0 <2.0.0"'), { :acceptable_exit_codes => [0,1] } + on host, puppet('module install puppetlabs/apache --version ">=1.0.1 <2.0.0"'), { :acceptable_exit_codes => [0,1] } + # Flush the firewall + flushfw = <<-EOS + iptables -F + iptables -X + iptables -P INPUT ACCEPT + iptables -P OUTPUT ACCEPT + iptables -P FORWARD ACCEPT + EOS + on host, flushfw + end + end +end