From f61a058c5e39b1a2bc104201bc40b40edd39b8d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20Gagne=CC=81?= Date: Thu, 30 Jan 2014 16:30:43 -0500 Subject: [PATCH] Cleanup rspec tests of nova::api Change-Id: I0b93f4e22671ca71408e0a1aa2b7d959bb57437d --- spec/classes/nova_api_spec.rb | 199 ++++++++++++++++++---------------- 1 file changed, 108 insertions(+), 91 deletions(-) diff --git a/spec/classes/nova_api_spec.rb b/spec/classes/nova_api_spec.rb index e79c05ddf..1f5daf8e5 100644 --- a/spec/classes/nova_api_spec.rb +++ b/spec/classes/nova_api_spec.rb @@ -7,45 +7,32 @@ describe 'nova::api' do end let :params do - {:admin_password => 'passw0rd'} + { :admin_password => 'passw0rd' } end - describe 'on debian platforms' do - let :facts do - { :osfamily => 'Debian' } - end - it { should contain_service('nova-api').with( - 'name' => 'nova-api', - 'ensure' => 'stopped', - 'hasstatus' => true, - 'enable' => false - )} - it { should contain_package('nova-api').with( - 'name' => 'nova-api', - 'ensure' => 'present', - 'notify' => 'Service[nova-api]' - ) } - describe 'with enabled as true' do - let :params do - {:admin_password => 'passw0rd', :enabled => true} + let :facts do + { :processorcount => 5 } + end + + shared_examples 'nova-api' do + + context 'with default parameters' do + + it 'installs nova-api package and service' do + should contain_service('nova-api').with( + :name => platform_params[:nova_api_service], + :ensure => 'stopped', + :hasstatus => true, + :enable => false + ) + should contain_package('nova-api').with( + :name => platform_params[:nova_api_package], + :ensure => 'present', + :notify => 'Service[nova-api]' + ) end - it { should contain_service('nova-api').with( - 'name' => 'nova-api', - 'ensure' => 'running', - 'hasstatus' => true, - 'enable' => true - )} - end - describe 'with package version' do - let :params do - {:admin_password => 'passw0rd', :ensure_package => '2012.1-2'} - end - it { should contain_package('nova-api').with( - 'ensure' => '2012.1-2' - )} - end - describe 'with defaults' do - it 'should use default params for nova.conf' do + + it 'configures keystone_authtoken middleware' do should contain_nova_config( 'keystone_authtoken/auth_host').with_value('127.0.0.1') should contain_nova_config( @@ -63,41 +50,56 @@ describe 'nova::api' do should contain_nova_config( 'keystone_authtoken/admin_password').with_value('passw0rd').with_secret(true) end - it { should contain_nova_config('DEFAULT/ec2_listen').with('value' => '0.0.0.0') } - it { should contain_nova_config('DEFAULT/osapi_compute_listen').with('value' => '0.0.0.0') } - it { should contain_nova_config('DEFAULT/metadata_listen').with('value' => '0.0.0.0') } - it { should contain_nova_config('DEFAULT/osapi_volume_listen').with('value' => '0.0.0.0') } - it 'should unconfigure neutron_metadata proxy' do - should contain_nova_config('DEFAULT/service_neutron_metadata_proxy').with('value' => false) - should contain_nova_config('DEFAULT/neutron_metadata_proxy_shared_secret').with('ensure' => 'absent') + + it 'configures various stuff' do + should contain_nova_config('DEFAULT/ec2_listen').with('value' => '0.0.0.0') + should contain_nova_config('DEFAULT/osapi_compute_listen').with('value' => '0.0.0.0') + should contain_nova_config('DEFAULT/metadata_listen').with('value' => '0.0.0.0') + should contain_nova_config('DEFAULT/osapi_volume_listen').with('value' => '0.0.0.0') + end + + it 'unconfigures neutron_metadata proxy' do + should contain_nova_config('DEFAULT/service_neutron_metadata_proxy').with(:value => false) + should contain_nova_config('DEFAULT/neutron_metadata_proxy_shared_secret').with(:ensure => 'absent') end end - describe 'with params' do - let :facts do - { - :osfamily => 'RedHat', - :processorcount => 5 - } - end - let :params do - { - :auth_host => '10.0.0.1', - :auth_port => 1234, - :auth_protocol => 'https', - :auth_admin_prefix => '/keystone/admin', - :auth_uri => 'https://10.0.0.1:9999/', - :admin_tenant_name => 'service2', - :admin_user => 'nova2', - :admin_password => 'passw0rd2', - :api_bind_address => '192.168.56.210', - :metadata_listen => '127.0.0.1', - :volume_api_class => 'nova.volume.cinder.API', - :use_forwarded_for => false, + + context 'with overridden parameters' do + before do + params.merge!({ + :enabled => true, + :ensure_package => '2012.1-2', + :auth_host => '10.0.0.1', + :auth_port => 1234, + :auth_protocol => 'https', + :auth_admin_prefix => '/keystone/admin', + :auth_uri => 'https://10.0.0.1:9999/', + :admin_tenant_name => 'service2', + :admin_user => 'nova2', + :admin_password => 'passw0rd2', + :api_bind_address => '192.168.56.210', + :metadata_listen => '127.0.0.1', + :volume_api_class => 'nova.volume.cinder.API', + :use_forwarded_for => false, + :ratelimits => '(GET, "*", .*, 100, MINUTE);(POST, "*", .*, 200, MINUTE)', :neutron_metadata_proxy_shared_secret => 'secrete', - :ratelimits => '(GET, "*", .*, 100, MINUTE);(POST, "*", .*, 200, MINUTE)' - } + }) end - it 'should use defined params for nova.conf and api-paste.ini' do + + it 'installs nova-api package and service' do + should contain_package('nova-api').with( + :name => platform_params[:nova_api_package], + :ensure => '2012.1-2' + ) + should contain_service('nova-api').with( + :name => platform_params[:nova_api_service], + :ensure => 'running', + :hasstatus => true, + :enable => true + ) + end + + it 'configures keystone_authtoken middleware' do should contain_nova_config( 'keystone_authtoken/auth_host').with_value('10.0.0.1') should contain_nova_config( @@ -117,14 +119,17 @@ describe 'nova::api' do should contain_nova_paste_api_ini( 'filter:ratelimit/limits').with_value('(GET, "*", .*, 100, MINUTE);(POST, "*", .*, 200, MINUTE)') end - it { should contain_nova_config('DEFAULT/ec2_listen').with('value' => '192.168.56.210') } - it { should contain_nova_config('DEFAULT/osapi_compute_listen').with('value' => '192.168.56.210') } - it { should contain_nova_config('DEFAULT/metadata_listen').with('value' => '127.0.0.1') } - it { should contain_nova_config('DEFAULT/osapi_volume_listen').with('value' => '192.168.56.210') } - it { should contain_nova_config('DEFAULT/use_forwarded_for').with('value' => false) } - it { should contain_nova_config('DEFAULT/osapi_compute_workers').with('value' => '5') } - it { should contain_nova_config('DEFAULT/service_neutron_metadata_proxy').with('value' => true) } - it { should contain_nova_config('DEFAULT/neutron_metadata_proxy_shared_secret').with('value' => 'secrete') } + + it 'configures various stuff' do + should contain_nova_config('DEFAULT/ec2_listen').with('value' => '192.168.56.210') + should contain_nova_config('DEFAULT/osapi_compute_listen').with('value' => '192.168.56.210') + should contain_nova_config('DEFAULT/metadata_listen').with('value' => '127.0.0.1') + should contain_nova_config('DEFAULT/osapi_volume_listen').with('value' => '192.168.56.210') + should contain_nova_config('DEFAULT/use_forwarded_for').with('value' => false) + should contain_nova_config('DEFAULT/osapi_compute_workers').with('value' => '5') + should contain_nova_config('DEFAULT/service_neutron_metadata_proxy').with('value' => true) + should contain_nova_config('DEFAULT/neutron_metadata_proxy_shared_secret').with('value' => 'secrete') + end end [ @@ -135,28 +140,40 @@ describe 'nova::api' do 'keystone/admin/', 'keystone/admin' ].each do |auth_admin_prefix| - describe "with auth_admin_prefix_containing incorrect value #{auth_admin_prefix}" do - let :params do - { - :auth_admin_prefix => auth_admin_prefix, - :admin_password => 'dummy' - } + context "with auth_admin_prefix_containing incorrect value #{auth_admin_prefix}" do + before do + params.merge!({ :auth_admin_prefix => auth_admin_prefix }) end - it { expect { should contain_nova_config('keystone_authtoken/auth_admin_prefix') }.to \ raise_error(Puppet::Error, /validate_re\(\): "#{auth_admin_prefix}" does not match/) } end end end - describe 'on rhel' do - let :facts do - { :osfamily => 'RedHat' } + + context 'on Debian platforms' do + before do + facts.merge!( :osfamily => 'Debian' ) end - it { should contain_service('nova-api').with( - 'name' => 'openstack-nova-api', - 'ensure' => 'stopped', - 'enable' => false - )} - it { should contain_package('nova-api').with_name('openstack-nova-api') } + + let :platform_params do + { :nova_api_package => 'nova-api', + :nova_api_service => 'nova-api' } + end + + it_behaves_like 'nova-api' end + + context 'on RedHat platforms' do + before do + facts.merge!( :osfamily => 'RedHat' ) + end + + let :platform_params do + { :nova_api_package => 'openstack-nova-api', + :nova_api_service => 'openstack-nova-api' } + end + + it_behaves_like 'nova-api' + end + end