From 6d50c3f83948e1e46bbd23962e2c8c5ca08a4404 Mon Sep 17 00:00:00 2001 From: Branan Purvine-Riley Date: Fri, 1 Jun 2012 14:04:44 -0700 Subject: [PATCH] Write spec test for openstack::compute * Include the puppetlabs_spec_helper gem for autogeneration of the fixtures dir --- .fixtures.yml | 10 +++ Rakefile | 2 +- spec/classes/openstack_compute_spec.rb | 100 +++++++++++++++++++++++++ spec/fixtures/manifests/site.pp | 0 spec/spec_helper.rb | 19 +---- 5 files changed, 112 insertions(+), 19 deletions(-) create mode 100644 .fixtures.yml create mode 100644 spec/fixtures/manifests/site.pp diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 0000000..c88edfe --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,10 @@ +fixtures: + repositories: + "apt": "git://github.com/puppetlabs/puppetlabs-apt.git" + "keystone": "git://github.com/puppetlabs/puppetlabs-keystone.git" + "mysql": "git://github.com/puppetlabs/puppetlabs-mysql.git" + "nova": "git://github.com/puppetlabs/puppetlabs-nova.git" + "stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git" + "sysctl": "git://github.com/duritong/puppet-sysctl.git" + symlinks: + "openstack": "#{source_dir}" diff --git a/Rakefile b/Rakefile index ff31fcd..3d5e8e3 100644 --- a/Rakefile +++ b/Rakefile @@ -5,7 +5,7 @@ # # -require 'puppet' +require 'puppetlabs_spec_helper/rake_tasks' repo_file = 'other_repos.yaml' default_modulepath = '/etc/puppet/modules' diff --git a/spec/classes/openstack_compute_spec.rb b/spec/classes/openstack_compute_spec.rb index 91e1a06..0a29651 100644 --- a/spec/classes/openstack_compute_spec.rb +++ b/spec/classes/openstack_compute_spec.rb @@ -2,4 +2,104 @@ require 'spec_helper' describe 'openstack::compute' do + let :default_params do + { + :private_interface => 'eth0', + :internal_address => '0.0.0.0', + } + end + + let :facts do + { + :operatingsystem => 'Ubuntu', + :osfamily => 'Debian', + } + end + describe "when using default class paramaters" do + let :params do + default_params + end + it { + should contain_nova_config('multi_host').with({ 'value' => 'False' }) + should_not contain_class('nova::api') + should_not contain_class('nova::volume') + should_not contain_class('nova::volume::iscsi') + should contain_class('nova::network').with({ + 'enabled' => false, + 'install_service' => false + }) + } + end + + describe "when enabling volume management" do + let :params do + default_params.merge({ + :manage_volumes => true + }) + end + + it { + should contain_nova_config('multi_host').with({ 'value' => 'False'}) + should_not contain_class('nova::api') + should contain_class('nova::volume') + should contain_class('nova::volume::iscsi') + should contain_class('nova::network').with({ + 'enabled' => false, + 'install_service' => false + }) + } + end + + describe "when configuring for multi host" do + let :params do + default_params.merge({ + :multi_host => true, + :public_interface => 'eth0' + }) + end + + it { + should contain_nova_config('multi_host').with({ 'value' => 'True'}) + should contain_class('nova::api') + should_not contain_class('nova::volume') + should_not contain_class('nova::volume::iscsi') + should contain_class('nova::network').with({ + 'enabled' => true, + 'install_service' => true + }) + } + end + + describe "when configuring for multi host without a public interface" do + let :params do + default_params.merge({ + :multi_host => true + }) + end + + it { + expect { should raise_error(Puppet::Error) } + } + end + + describe "when enabling volume management and using multi host" do + let :params do + default_params.merge({ + :multi_host => true, + :public_interface => 'eth0', + :manage_volumes => true, + }) + end + + it { + should contain_nova_config('multi_host').with({ 'value' => 'True'}) + should contain_class('nova::api') + should contain_class('nova::volume') + should contain_class('nova::volume::iscsi') + should contain_class('nova::network').with({ + 'enabled' => true, + 'install_service' => true + }) + } + end end diff --git a/spec/fixtures/manifests/site.pp b/spec/fixtures/manifests/site.pp new file mode 100644 index 0000000..e69de29 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1a1c3c4..2c6f566 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,18 +1 @@ -require 'puppet' -require 'rspec' -require 'rspec-puppet' - -def param_value(subject, type, title, param) - subject.resource(type, title).send(:parameters)[param.to_sym] -end - -def verify_contents(subject, title, expected_lines) - content = subject.resource('file', title).send(:parameters)[:content] - (content.split("\n") & expected_lines).should == expected_lines -end - -RSpec.configure do |c| - c.module_path = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures/modules/')) - # Using an empty site.pp file to avoid: https://github.com/rodjek/rspec-puppet/issues/15 - c.manifest_dir = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures/manifests')) -end +require 'puppetlabs_spec_helper/module_spec_helper'