From 7557d5e8ee4f66f56ddf10c8697768693ef52ca0 Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Thu, 24 Oct 2013 11:14:54 +0200 Subject: [PATCH] integration tests environment Use https://github.com/puppetlabs/rspec-system-puppet to implement vagrant based integration tests. The README.md is updated with instructions to run the integration tests locally. These tests could be run by a deamon listening to the gerrit stream, when a changeset is submitted for review, to prove that they do not introduce a regression. The dependencies from .fixtures.yml have been manually replicated to spec/spec_helper_system.rb . rspec system puppet is still young and people do this. It will be a burden only for long term maintenance. And when it does, in a few months from now, it is safe to assume that rspec system puppet will have support for reading from an existing file. The alternative is that rspec system puppet is obsoleted / dead, in which case this is even a bigger problem. In any case, if work had to be done to fix this, it should be a patch against rspec system puppet and not part of puppet-ceph. https://github.com/puppetlabs/rspec-system-puppet/issues/5 A test for the ceph::repo class is included to demonstrate the environment actually works. It is not meant to fully test the ceph::repo integration this would require a separate patch. rspec-system-puppet requires at least one file in spec/system otherwise it will fail with an unrelated error: Could not autoload puppet/provider/ceph_config/ini_setting: undefined method `provider' for nil:NilClass (Puppet::Error) This test can be removed as soon as another is added. Change-Id: Ib65120a58ce203126be5897f602e280c474642dc Signed-off-by: Loic Dachary --- .gitignore | 3 +++ .nodeset.yml | 6 +++++ Gemfile | 4 ++-- README.md | 23 +++++++++++++++++++ Rakefile | 6 +++++ spec/spec_helper_system.rb | 38 ++++++++++++++++++++++++++++++++ spec/system/basic_spec.rb | 45 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 .nodeset.yml create mode 100644 spec/spec_helper_system.rb create mode 100644 spec/system/basic_spec.rb diff --git a/.gitignore b/.gitignore index 3bd683ca..11d8e5f1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ metadata.json spec/fixtures/modules/* pkg Gemfile.lock +.bundle +vendor +.rspec_system diff --git a/.nodeset.yml b/.nodeset.yml new file mode 100644 index 00000000..7550ca66 --- /dev/null +++ b/.nodeset.yml @@ -0,0 +1,6 @@ +default_set: 'ubuntu-server-12042-x64' +sets: + 'ubuntu-server-12042-x64': + nodes: + 'main.vm': + prefab: 'ubuntu-server-12042-x64' diff --git a/Gemfile b/Gemfile index 89f2e1b2..cf3fc94f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,10 @@ +# vim:ft=ruby source 'https://rubygems.org' group :development, :test do gem 'puppetlabs_spec_helper', :require => false gem 'puppet-lint', '~> 0.3.2' + gem 'rspec-system-puppet' end if puppetversion = ENV['PUPPET_GEM_VERSION'] @@ -10,5 +12,3 @@ if puppetversion = ENV['PUPPET_GEM_VERSION'] else gem 'puppet', :require => false end - -# vim:ft=ruby diff --git a/README.md b/README.md index 42cea295..807c5f17 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ ceph 5. [Limitations - OS compatibility, etc.](#limitations) 6. [Development - Guide for contributing to the module](#development) 7. [Contributors - Those with commits](#contributors) +7. [Integration - Apply the module and test restults](#integration-tests) 8. [Release Notes - Notes on the most recent updates to the module](#release-notes) Overview @@ -50,6 +51,28 @@ IRC channels: * irc.freenode.net#puppet-openstack * irc.oftc.net#ceph-devel +Integration +----------- + +Relies on +[rspec-system-puppet](https://github.com/puppetlabs/rspec-system-puppet) +and tests are in spec/system. It runs virtual machines and requires +4GB of free memory and 10GB of free disk space. + +* [Install Vagrant and Virtualbox](http://docs-v1.vagrantup.com/v1/docs/getting-started/) + +* bundle install --path vendor/bundle + +* bundle exec rake spec:system + +On success it should complete with + + ... + =end============================================================= + Finished in 4 minutes 1.7 seconds + 1 example, 0 failures + + Contributors ------------ diff --git a/Rakefile b/Rakefile index 4c2b2ed0..58bdf266 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,11 @@ require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-lint/tasks/puppet-lint' +begin + require 'rspec-system/rake_task' +rescue LoadError => e + warn e.message + warn "Run `gem install rspec-system-puppet` to enable integration tests." +end PuppetLint.configuration.fail_on_warnings = true PuppetLint.configuration.send('disable_80chars') diff --git a/spec/spec_helper_system.rb b/spec/spec_helper_system.rb new file mode 100644 index 00000000..45272b1d --- /dev/null +++ b/spec/spec_helper_system.rb @@ -0,0 +1,38 @@ +# +# Copyright 2013 Cloudwatt +# +# Author: Loic Dachary +# +# 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 'rspec-system/spec_helper' +require 'rspec-system-puppet/helpers' + +include RSpecSystemPuppet::Helpers + +RSpec.configure do |c| + # Project root + proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + + # Enable colour + c.tty = true + + c.include RSpecSystemPuppet::Helpers + + c.before :suite do + puppet_install + puppet_master_install + puppet_module_install(:source => proj_root, :module_name => 'ceph') + shell 'puppet module install --version 1.4.0 puppetlabs/apt' + end +end diff --git a/spec/system/basic_spec.rb b/spec/system/basic_spec.rb new file mode 100644 index 00000000..09ee6fc7 --- /dev/null +++ b/spec/system/basic_spec.rb @@ -0,0 +1,45 @@ +# +# Copyright 2013 Cloudwatt +# +# Author: Loic Dachary +# +# 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 'basic tests:' do + + # Using puppet_apply as a helper + it 'ceph::repo should work with no errors' do + pp = <<-EOS + class { 'ceph::repo': + release => 'dumpling' + } + EOS + + # Run it twice and test for idempotency + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + r.refresh + r.exit_code.should be_zero + end + + end + + context shell 'apt-cache policy ceph' do + its(:stdout) { should =~ /Candidate: 0.67/ } + its(:stderr) { should be_empty } + its(:exit_code) { should be_zero } + end + +end