Cleanup rspec tests of nova::compute::libvirt

Change-Id: Ie410ac8f2fc2d0ebd9e79a869f51e9b7bb315a6e
This commit is contained in:
Mathieu Gagné 2014-01-30 17:09:21 -05:00
parent c12ab34148
commit baeb98d5f8
3 changed files with 111 additions and 136 deletions

View File

@ -5,168 +5,136 @@ describe 'nova::compute::libvirt' do
"include nova\ninclude nova::compute"
end
describe 'on debian platforms' do
shared_examples 'nova-compute with libvirt' do
it { should contain_class('nova::params') }
context 'with default parameters' do
it 'installs libvirt package and service' do
should contain_package('libvirt').with(
:name => platform_params[:libvirt_package_name],
:ensure => 'present'
)
should contain_service('libvirt').with(
:name => platform_params[:libvirt_service_name],
:ensure => 'running',
:provider => platform_params[:special_service_provider],
:require => 'Package[libvirt]',
:before => 'Service[nova-compute]'
)
end
it 'configures nova.conf' do
should contain_nova_config('DEFAULT/compute_driver').with_value('libvirt.LibvirtDriver')
should contain_nova_config('DEFAULT/libvirt_type').with_value('kvm')
should contain_nova_config('DEFAULT/connection_type').with_value('libvirt')
should contain_nova_config('DEFAULT/vncserver_listen').with_value('127.0.0.1')
end
end
context 'with overridden parameters' do
let :params do
{ :libvirt_type => 'qemu' }
end
it { should contain_nova_config('DEFAULT/libvirt_type').with_value('qemu')}
end
describe 'with migration_support enabled' do
let :params do
{ :migration_support => true }
end
context 'with vncserver_listen set to 0.0.0.0' do
before do
params.merge!( :vncserver_listen => '0.0.0.0' )
end
it {
should contain_class('nova::migration::libvirt')
should contain_nova_config('DEFAULT/vncserver_listen').with_value('0.0.0.0')
}
end
context 'with vncserver_listen not set to 0.0.0.0' do
before do
params.merge!( :vncserver_listen => '127.0.0.1' )
end
it_raises 'a Puppet::Error', /For migration support to work, you MUST set vncserver_listen to '0.0.0.0'/
end
end
end
context 'on Debian platforms' do
let :facts do
{ :osfamily => 'Debian' }
end
describe 'with default parameters' do
it { should contain_class('nova::params')}
it { should contain_package('nova-compute-kvm').with(
:ensure => 'present',
:before => 'Package[nova-compute]'
) }
it { should contain_package('libvirt').with(
:name => 'libvirt-bin',
:ensure => 'present'
) }
it { should contain_service('libvirt').with(
:name => 'libvirt-bin',
:ensure => 'running',
:provider => 'upstart',
:require => 'Package[libvirt]',
:before => 'Service[nova-compute]'
)}
it { should contain_nova_config('DEFAULT/compute_driver').with_value('libvirt.LibvirtDriver')}
it { should contain_nova_config('DEFAULT/libvirt_type').with_value('kvm')}
it { should contain_nova_config('DEFAULT/connection_type').with_value('libvirt')}
it { should contain_nova_config('DEFAULT/vncserver_listen').with_value('127.0.0.1')}
let :platform_params do
{ :libvirt_package_name => 'libvirt-bin',
:libvirt_service_name => 'libvirt-bin' }
end
describe 'with params' do
let :params do
{ :libvirt_type => 'qemu',
:vncserver_listen => '0.0.0.0'
}
it { should contain_package('nova-compute-kvm').with(
:ensure => 'present',
:before => 'Package[nova-compute]'
) }
context 'on Debian operating systems' do
before do
facts.merge!(:operatingsystem => 'Debian')
platform_params.merge!(:special_service_provider => nil)
end
it { should contain_nova_config('DEFAULT/libvirt_type').with_value('qemu')}
it { should contain_nova_config('DEFAULT/vncserver_listen').with_value('0.0.0.0')}
it_behaves_like 'nova-compute with libvirt'
end
describe 'with migration_support enabled' do
context 'with vncserver_listen set to 0.0.0.0' do
let :params do
{ :vncserver_listen => '0.0.0.0',
:migration_support => true }
end
it { should contain_class('nova::migration::libvirt')}
it { should contain_nova_config('DEFAULT/vncserver_listen').with_value('0.0.0.0')}
context 'on Ubuntu operating systems' do
before do
facts.merge!(:operatingsystem => 'Ubuntu')
platform_params.merge!(:special_service_provider => 'upstart')
end
context 'with vncserver_listen not set to 0.0.0.0' do
let :params do
{ :vncserver_listen => '127.0.0.1',
:migration_support => true }
end
it { expect { should contain_class('nova::compute::libvirt') }.to \
raise_error(Puppet::Error, /For migration support to work, you MUST set vncserver_listen to '0.0.0.0'/) }
end
it_behaves_like 'nova-compute with libvirt'
end
end
describe 'on rhel platforms' do
context 'on RedHat platforms' do
let :facts do
{ :operatingsystem => 'RedHat', :osfamily => 'RedHat' }
{ :osfamily => 'RedHat' }
end
describe 'with default parameters' do
let :platform_params do
{ :libvirt_package_name => 'libvirt',
:libvirt_service_name => 'libvirtd',
:special_service_provider => 'init' }
end
it { should contain_class('nova::params')}
context 'on Fedora operating systems' do
before do
facts.merge!(:operatingsystem => 'Fedora')
platform_params.merge!(:special_service_provider => nil)
end
it { should contain_package('libvirt').with(
:name => 'libvirt',
:ensure => 'present'
) }
it_behaves_like 'nova-compute with libvirt'
end
context 'on other operating systems' do
before do
facts.merge!(:operatingsystem => 'RedHat')
platform_params.merge!(:special_service_provider => 'init')
end
it_behaves_like 'nova-compute with libvirt'
it { should contain_service('libvirt').with(
:name => 'libvirtd',
:ensure => 'running',
:provider => 'init',
:require => 'Package[libvirt]',
:before => 'Service[nova-compute]'
)}
it { should contain_service('messagebus').with(
:ensure => 'running',
:enable => true,
:before => 'Service[libvirt]',
:provider => 'init'
:provider => platform_params[:special_service_provider]
) }
it { should contain_nova_config('DEFAULT/compute_driver').with_value('libvirt.LibvirtDriver')}
it { should contain_nova_config('DEFAULT/libvirt_type').with_value('kvm')}
it { should contain_nova_config('DEFAULT/connection_type').with_value('libvirt')}
it { should contain_nova_config('DEFAULT/vncserver_listen').with_value('127.0.0.1')}
end
describe 'with params' do
let :params do
{ :libvirt_type => 'qemu',
:vncserver_listen => '0.0.0.0'
}
end
it { should contain_nova_config('DEFAULT/libvirt_type').with_value('qemu')}
it { should contain_nova_config('DEFAULT/vncserver_listen').with_value('0.0.0.0')}
end
describe 'with migration_support enabled' do
context 'with vncserver_listen set to 0.0.0.0' do
let :params do
{ :vncserver_listen => '0.0.0.0',
:migration_support => true }
end
it { should contain_class('nova::migration::libvirt')}
it { should contain_nova_config('DEFAULT/vncserver_listen').with_value('0.0.0.0')}
end
context 'with vncserver_listen not set to 0.0.0.0' do
let :params do
{ :vncserver_listen => '127.0.0.1',
:migration_support => true }
end
it { expect { should contain_class('nova::compute::libvirt') }.to \
raise_error(Puppet::Error, /For migration support to work, you MUST set vncserver_listen to '0.0.0.0'/) }
end
end
describe 'with default parameters on Fedora' do
let :facts do
{ :operatingsystem => 'Fedora', :osfamily => 'RedHat' }
end
it { should contain_class('nova::params')}
it { should contain_package('libvirt').with(
:name => 'libvirt',
:ensure => 'present'
) }
it { should contain_service('libvirt').with(
:name => 'libvirtd',
:ensure => 'running',
:provider => nil,
:require => 'Package[libvirt]',
:before => 'Service[nova-compute]'
)}
it { should contain_nova_config('DEFAULT/compute_driver').with_value('libvirt.LibvirtDriver')}
it { should contain_nova_config('DEFAULT/libvirt_type').with_value('kvm')}
it { should contain_nova_config('DEFAULT/connection_type').with_value('libvirt')}
it { should contain_nova_config('DEFAULT/vncserver_listen').with_value('127.0.0.1')}
end
end
end

5
spec/shared_examples.rb Normal file
View File

@ -0,0 +1,5 @@
shared_examples_for "a Puppet::Error" do |description|
it "with message matching #{description.inspect}" do
expect { should have_class_count(1) }.to raise_error(Puppet::Error, description)
end
end

View File

@ -1,5 +1,7 @@
require 'puppetlabs_spec_helper/module_spec_helper'
require 'shared_examples'
RSpec.configure do |c|
c.alias_it_should_behave_like_to :it_configures, 'configures'
c.alias_it_should_behave_like_to :it_raises, 'raises'
end