Add rspec tests

This commit resolves failing tests from
glance::api and glance::registry related to recent
refactors.

It also adds tests for all of the new api fragment
classes/defines.
This commit is contained in:
Dan Bode 2012-03-31 16:09:29 -07:00
parent 98027b5470
commit 0a400dcc6a
8 changed files with 195 additions and 51 deletions

View File

@ -10,39 +10,27 @@ describe 'glance::api' do
let :default_params do
{
:log_verbose => 'false',
:log_debug => 'false',
:default_store => 'file',
:bind_host => '0.0.0.0',
:bind_port => '9292',
:log_verbose => 'False',
:log_debug => 'False',
:bind_host => '0.0.0.0',
:bind_port => '9292',
:registry_host => '0.0.0.0',
:registry_port => '9191',
:log_file => '/var/log/glance/api.log',
:filesystem_store_datadir => '/var/lib/glance/images/',
:swift_store_auth_address => '127.0.0.1:8080/v1.0/',
:swift_store_user => 'jdoe',
:swift_store_key => 'a86850deb2742ec3cb41518e26aa2d89',
:swift_store_container => 'glance',
:swift_store_create_container_on_put => 'False'
:log_file => '/var/log/glance/api.log',
:auth_type => 'keystone'
}
end
[{},
{
:log_verbose => 'true',
:log_debug => 'true',
:default_store => 'file',
:bind_host => '127.0.0.1',
:bind_port => '9222',
:log_verbose => 'true',
:log_debug => 'true',
:bind_host => '127.0.0.1',
:bind_port => '9222',
:registry_host => '127.0.0.1',
:registry_port => '9111',
:log_file => '/var/log/glance-api.log',
:filesystem_store_datadir => '/var/lib/glance-images/',
:swift_store_auth_address => '127.0.0.1:8080/v1.1/',
:swift_store_user => 'dan',
:swift_store_key => 'a',
:swift_store_container => 'other',
:swift_store_create_container_on_put => 'True'
:log_file => '/var/log/glance-api.log',
:auth_type => 'not_keystone'
}
].each do |param_set|
@ -58,32 +46,36 @@ describe 'glance::api' do
it { should contain_class 'glance' }
it do should contain_service('glance-api').with(
it { should contain_service('glance-api').with(
'ensure' => 'running',
'hasstatus' => 'true',
'hasrestart' => 'true',
'subscribe' => 'File[/etc/glance/glance-api.conf]'
) end
'subscribe' => 'Concat[/etc/glance/glance-api.conf]'
) }
it 'should compile the template based on the class parameters' do
content = param_value(subject, 'file', '/etc/glance/glance-api.conf', 'content')
expected_lines = [
"verbose = #{param_hash[:log_verbose]}",
"debug = #{param_hash[:log_debug]}",
"default_store = #{param_hash[:default_store]}",
"bind_host = #{param_hash[:bind_host]}",
"bind_port = #{param_hash[:bind_port]}",
"registry_host = #{param_hash[:registry_host]}",
"registry_port = #{param_hash[:registry_port]}",
"log_file = #{param_hash[:log_file]}",
"filesystem_store_datadir = #{param_hash[:filesystem_store_datadir]}",
"swift_store_auth_address = #{param_hash[:swift_store_auth_address]}",
"swift_store_user = #{param_hash[:swift_store_user]}",
"swift_store_key = #{param_hash[:swift_store_key]}",
"swift_store_container = #{param_hash[:swift_store_container]}",
"swift_store_create_container_on_put = #{param_hash[:swift_store_create_container_on_put]}"
]
(content.split("\n") & expected_lines).should == expected_lines
verify_contents(
subject,
'/var/lib/puppet/concat/_etc_glance_glance-api.conf/fragments/01_header',
[
"verbose = #{param_hash[:log_verbose]}",
"debug = #{param_hash[:log_debug]}",
"bind_host = #{param_hash[:bind_host]}",
"bind_port = #{param_hash[:bind_port]}",
"log_file = #{param_hash[:log_file]}",
"registry_host = #{param_hash[:registry_host]}",
"registry_port = #{param_hash[:registry_port]}",
]
)
end
it 'should add paste deploy footers' do
expected_lines = ['[paste_deploy]', 'flavor = keystone'] if params[:auth_type] = 'keystone'
verify_contents(
subject,
'/var/lib/puppet/concat/_etc_glance_glance-api.conf/fragments/99_footer',
expected_lines
)
end
end
end

View File

@ -0,0 +1,38 @@
require 'spec_helper'
describe 'glance::backend::file' do
let :facts do
{
:osfamily => 'Debian'
}
end
it 'should set the default store to file' do
verify_contents(
subject,
'/var/lib/puppet/concat/_etc_glance_glance-api.conf/fragments/02_backend',
['default_store = file']
)
end
it 'should configure file backend settings' do
verify_contents(
subject,
'/var/lib/puppet/concat/_etc_glance_glance-api.conf/fragments/05_file',
['filesystem_store_datadir = /var/lib/glance/images/']
)
end
describe 'when datadir is overridden' do
let :params do
{
:filesystem_store_datadir => '/var/lib/glance/images2'
}
end
it 'should configure file backend settings with specified parameter' do
verify_contents(
subject,
'/var/lib/puppet/concat/_etc_glance_glance-api.conf/fragments/05_file',
['filesystem_store_datadir = /var/lib/glance/images2']
)
end
end
end

View File

@ -0,0 +1,60 @@
require 'spec_helper'
describe 'glance::backend::swift' do
let :facts do
{
:osfamily => 'Debian'
}
end
let :params do
{
'swift_store_user' => 'glance',
'swift_store_key' => 'glance_key'
}
end
it 'should set the default store to file' do
verify_contents(
subject,
'/var/lib/puppet/concat/_etc_glance_glance-api.conf/fragments/02_backend',
['default_store = swift']
)
end
it 'should configure swift settings with defaults' do
verify_contents(
subject,
'/var/lib/puppet/concat/_etc_glance_glance-api.conf/fragments/05_swift',
[
'swift_store_auth_address = 127.0.0.1:8080/v1.0/',
'swift_store_user = glance',
'swift_store_key = glance_key',
'swift_store_container = glance',
'swift_store_create_container_on_put = False'
]
)
end
describe 'when datadir is overridden' do
let :params do
{
'swift_store_user' => 'glance',
'swift_store_key' => 'glance_key',
'swift_store_container' => 'glance2',
'swift_store_auth_address' => '127.0.0.1:8080/v2.0/',
'swift_store_create_container_on_put' => 'True'
}
end
it 'should configure file backend settings with specified parameter' do
verify_contents(
subject,
'/var/lib/puppet/concat/_etc_glance_glance-api.conf/fragments/05_swift',
[
'swift_store_auth_address = 127.0.0.1:8080/v2.0/',
'swift_store_user = glance',
'swift_store_key = glance_key',
'swift_store_container = glance2',
'swift_store_create_container_on_put = True'
]
)
end
end
end

View File

@ -0,0 +1,24 @@
require 'spec_helper'
describe 'glance::notify::qpid' do
let :facts do
{
:osfamily => 'Debian'
}
end
describe 'with default parameters' do
it 'should set nofier strategy to qpid' do
verify_contents(
subject,
'/var/lib/puppet/concat/_etc_glance_glance-api.conf/fragments/06_notify',
['notifier_strategy = qpid']
)
end
it 'should use the current qpid template' do
verify_contents(
subject,
'/var/lib/puppet/concat/_etc_glance_glance-api.conf/fragments/07_qpid',
['#qpid_port = 5672']
)
end
end
end

View File

@ -0,0 +1,24 @@
require 'spec_helper'
describe 'glance::notify::rabbitmq' do
let :facts do
{
:osfamily => 'Debian'
}
end
describe 'with default parameters' do
it 'should set nofier strategy to rabbit' do
verify_contents(
subject,
'/var/lib/puppet/concat/_etc_glance_glance-api.conf/fragments/06_notify',
['notifier_strategy = rabbit']
)
end
it 'should use the current rabbitmq template' do
verify_contents(
subject,
'/var/lib/puppet/concat/_etc_glance_glance-api.conf/fragments/07_rabbitmq',
['#rabbit_port = 5672']
)
end
end
end

View File

@ -10,12 +10,12 @@ describe 'glance::registry' do
let :default_params do
{
:log_verbose => 'false',
:log_debug => 'false',
:bind_host => '0.0.0.0',
:bind_port => '9191',
:log_file => '/var/log/glance/registry.log',
:sql_connection => 'sqlite:///var/lib/glance/glance.sqlite',
:log_verbose => 'False',
:log_debug => 'False',
:bind_host => '0.0.0.0',
:bind_port => '9191',
:log_file => '/var/log/glance/registry.log',
:sql_connection => 'sqlite:///var/lib/glance/glance.sqlite',
:sql_idle_timeout => '3600'
}
end

0
spec/fixtures/manifests/site.pp vendored Normal file
View File

View File

@ -6,6 +6,12 @@ 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.manifest_dir = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures/manifests'))
c.module_path = File.join(File.dirname(__FILE__), '../../')
end