]> review.fuel-infra Code Review - puppet-modules/puppet-ceilometer.git/commitdiff
Add rspec tests for ceilometer and ceilometer::api
authorMathieu Gagné <mgagne@iweb.com>
Thu, 4 Apr 2013 21:40:02 +0000 (17:40 -0400)
committerMathieu Gagné <mgagne@iweb.com>
Thu, 4 Apr 2013 21:40:02 +0000 (17:40 -0400)
.fixtures.yml [new file with mode: 0644]
.travis.yml [new file with mode: 0644]
Gemfile [new file with mode: 0644]
manifests/init.pp
spec/classes/ceilometer_api_spec.rb [new file with mode: 0644]
spec/classes/ceilometer_init_spec.rb [new file with mode: 0644]
spec/spec_helper.rb

diff --git a/.fixtures.yml b/.fixtures.yml
new file mode 100644 (file)
index 0000000..1605bb8
--- /dev/null
@@ -0,0 +1,7 @@
+fixtures:
+  repositories:
+    "stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
+    "inifile": "git://github.com/cprice-puppet/puppetlabs-inifile"
+    "mysql": "git://github.com/puppetlabs/puppetlabs-mysql.git"
+  symlinks:
+    "ceilometer": "#{source_dir}"
diff --git a/.travis.yml b/.travis.yml
new file mode 100644 (file)
index 0000000..6384445
--- /dev/null
@@ -0,0 +1,28 @@
+language: ruby
+bundler_args: --without development
+before_script:
+  - echo $PUPPET_GEM_VERSION | grep '2.6' && git clone git://github.com/puppetlabs/puppetlabs-create_resources.git spec/fixtures/modules/create_resources || true
+script: "bundle exec rake spec SPEC_OPTS='--format documentation'"
+rvm:
+  - 1.8.7
+  - 1.9.3
+  - ruby-head
+env:
+  - PUPPET_GEM_VERSION="~> 2.6"
+  - PUPPET_GEM_VERSION="~> 2.7"
+  - PUPPET_GEM_VERSION="~> 3.0"
+  - PUPPET_GEM_VERSION="~> 3.1"
+matrix:
+  allow_failures:
+    - rvm: ruby-head
+  exclude:
+    - rvm: 1.9.3
+      env: PUPPET_GEM_VERSION="~> 2.7"
+    - rvm: ruby-head
+      env: PUPPET_GEM_VERSION="~> 2.7"
+    - rvm: 1.9.3
+      env: PUPPET_GEM_VERSION="~> 2.6"
+    - rvm: ruby-head
+      env: PUPPET_GEM_VERSION="~> 2.6"
+notifications:
+  email: false
diff --git a/Gemfile b/Gemfile
new file mode 100644 (file)
index 0000000..8e5e04d
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,13 @@
+source :rubygems
+
+group :development, :test do
+  gem 'puppetlabs_spec_helper', :require => false
+end
+
+if puppetversion = ENV['PUPPET_GEM_VERSION']
+  gem 'puppet', puppetversion, :require => false
+else
+  gem 'puppet', :require => false
+end
+
+# vim:ft=ruby
index 064fcb0458ffbbebff680d6e88dc7b6c6b5d125e..ec9be19315ad3da7b10457703e5010be77ab371f 100644 (file)
@@ -1,8 +1,5 @@
 #
-# == parameters
-#   * package_ensure - ensure state for package.
-#
-class ceilometer(
+class ceilometer (
   $metering_secret,
   $package_ensure     = 'present',
   $verbose            = 'False',
@@ -18,7 +15,7 @@ class ceilometer(
 
   group { 'ceilometer':
     name    => $::ceilometer::params::groupname,
-    require => $::ceilometer::common_package_name,
+    require => Package['ceilometer-common'],
   }
 
   user { 'ceilometer':
diff --git a/spec/classes/ceilometer_api_spec.rb b/spec/classes/ceilometer_api_spec.rb
new file mode 100644 (file)
index 0000000..0be0e6c
--- /dev/null
@@ -0,0 +1,50 @@
+require 'spec_helper'
+
+describe 'ceilometer::api' do
+
+  let :pre_condition do
+    "class { 'ceilometer': metering_secret => 's3cr3t' }"
+  end
+
+  let :params do
+    { :enabled           => true,
+      :keystone_host     => '127.0.0.1',
+      :keystone_port     => '35357',
+      :keystone_protocol => 'http',
+      :keystone_user     => 'ceilometer',
+      :keystone_password => 'ceilometer-passw0rd'
+    }
+  end
+
+  context 'with all parameters' do
+
+    it { should include_class('ceilometer::params') }
+
+    it 'installs ceilometer-api package' do
+      should contain_package('ceilometer-api').with(
+        :ensure => 'installed'
+      )
+    end
+
+    it 'configures ceilometer-api service' do
+      should contain_service('ceilometer-api').with(
+        :ensure     => 'running',
+        :name       => 'ceilometer-api',
+        :enable     => true,
+        :hasstatus  => true,
+        :hasrestart => true,
+        :require    => ['Package[ceilometer-api]', 'Class[Ceilometer::Db]'],
+        :subscribe  => 'Exec[ceilometer-dbsync]'
+      )
+    end
+
+    it 'configures ceilometer with keystone' do
+      should contain_ceilometer_config('keystone_authtoken/auth_host').with_value( params[:keystone_host] )
+      should contain_ceilometer_config('keystone_authtoken/auth_port').with_value( params[:keystone_port] )
+      should contain_ceilometer_config('keystone_authtoken/auth_protocol').with_value( params[:keystone_protocol] )
+      should contain_ceilometer_config('keystone_authtoken/admin_tenant_name').with_value('services')
+      should contain_ceilometer_config('keystone_authtoken/admin_user').with_value( params[:keystone_user] )
+      should contain_ceilometer_config('keystone_authtoken/admin_password').with_value( params[:keystone_password] )
+    end
+  end
+end
diff --git a/spec/classes/ceilometer_init_spec.rb b/spec/classes/ceilometer_init_spec.rb
new file mode 100644 (file)
index 0000000..11a3e46
--- /dev/null
@@ -0,0 +1,91 @@
+require 'spec_helper'
+
+describe 'ceilometer' do
+
+  let :params do
+    { :metering_secret    => 'metering-s3cr3t',
+      :package_ensure     => 'present',
+      :verbose            => 'False',
+      :debug              => 'False',
+      :rabbit_host        => '127.0.0.1',
+      :rabbit_port        => 5672,
+      :rabbit_userid      => 'guest',
+      :rabbit_password    => '',
+      :rabbit_virtualhost => '/',
+    }
+  end
+
+  context 'with all parameters' do
+
+    it { should include_class('ceilometer::params') }
+
+    it 'configures ceilometer group' do
+      should contain_group('ceilometer').with(
+        :name    => 'ceilometer',
+        :require => 'Package[ceilometer-common]'
+      )
+    end
+
+    it 'configures ceilometer user' do
+      should contain_user('ceilometer').with(
+        :name    => 'ceilometer',
+        :gid     => 'ceilometer',
+        :groups  => ['nova'],
+        :system  => true,
+        :require => ['Group[ceilometer]', 'Package[ceilometer-common]']
+      )
+    end
+
+    it 'configures ceilometer configuration folder' do
+      should contain_file('/etc/ceilometer/').with(
+        :ensure  => 'directory',
+        :owner   => 'ceilometer',
+        :group   => 'ceilometer',
+        :mode    => '0750',
+        :require => ['Package[ceilometer-common]', 'User[ceilometer]']
+      )
+    end
+
+    it 'configures ceilometer configuration file' do
+      should contain_file('/etc/ceilometer/ceilometer.conf').with(
+        :ensure  => 'file',
+        :owner   => 'ceilometer',
+        :group   => 'ceilometer',
+        :mode    => '0640',
+        :require => ['File[/etc/ceilometer]', 'User[ceilometer]']
+      )
+    end
+
+    it 'installs ceilometer common package' do
+      should contain_package('ceilometer-common').with(
+        :ensure => 'present',
+        :name   => 'ceilometer-common'
+      )
+    end
+
+    it 'configures required metering_secret' do
+      should contain_ceilometer_config('DEFAULT/metering_secret').with_value('metering-s3cr3t')
+    end
+
+    it 'configures rabbit' do
+      should contain_ceilometer_config('DEFAULT/rabbit_host').with_value( params[:rabbit_host] )
+      should contain_ceilometer_config('DEFAULT/rabbit_port').with_value( params[:rabbit_port] )
+      should contain_ceilometer_config('DEFAULT/rabbit_userid').with_value( params[:rabbit_userid] )
+      should contain_ceilometer_config('DEFAULT/rabbit_password').with_value( params[:rabbit_password] )
+      should contain_ceilometer_config('DEFAULT/rabbit_virtualhost').with_value( params[:rabbit_virtualhost] )
+    end
+
+    it 'configures debug and verbose' do
+      should contain_ceilometer_config('DEFAULT/debug').with_value( params[:debug] )
+      should contain_ceilometer_config('DEFAULT/verbose').with_value( params[:verbose] )
+    end
+
+    it 'fixes a bad value in ceilometer (glance_control_exchange)' do
+      should contain_ceilometer_config('DEFAULT/glance_control_exchange').with_value('glance')
+    end
+
+    it 'adds glance-notifications topic' do
+      should contain_ceilometer_config('DEFAULT/notification_topics').with_value('notifications,glance_notifications')
+    end
+  end
+end
index 5fda58875b10d1e401b1c389092a6b8553c591cb..2c6f56649aeb15c37a49bf07898570e8ab51cf97 100644 (file)
@@ -1,17 +1 @@
-dir = File.expand_path(File.dirname(__FILE__))
-$LOAD_PATH.unshift File.join(dir, 'lib')
-
-require 'mocha'
-require 'puppet'
-require 'rspec'
-require 'spec/autorun'
-
-Spec::Runner.configure do |config|
-    config.mock_with :mocha
-end
-
-# We need this because the RAL uses 'should' as a method.  This
-# allows us the same behaviour but with a different method name.
-class Object
-    alias :must :should
-end
+require 'puppetlabs_spec_helper/module_spec_helper'