Improve spec test coverage
This commit is contained in:
parent
f63c1c5864
commit
81647d6b35
51
spec/classes/keystone_mysql_spec.rb
Normal file
51
spec/classes/keystone_mysql_spec.rb
Normal file
@ -0,0 +1,51 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'keystone::mysql' do
|
||||
|
||||
let :facts do
|
||||
{ :osfamily => 'Debian' }
|
||||
end
|
||||
|
||||
let :param_defaults do
|
||||
{
|
||||
'password' => 'keystone_default_password',
|
||||
'dbname' => 'keystone',
|
||||
'user' => 'keystone_admin',
|
||||
'host' => '127.0.0.1'
|
||||
}
|
||||
end
|
||||
|
||||
[
|
||||
{},
|
||||
{
|
||||
'password' => 'password',
|
||||
'dbname' => 'not_keystone',
|
||||
'user' => 'dan',
|
||||
'host' => '127.0.0.2'
|
||||
}
|
||||
].each do |p|
|
||||
|
||||
let :params do
|
||||
p
|
||||
end
|
||||
|
||||
let :param_values do
|
||||
param_defaults.merge(p)
|
||||
end
|
||||
|
||||
it { should contain_file('/var/lib/keystone/keystone.db').with(
|
||||
'ensure' => 'absent',
|
||||
'subscribe' => 'Package[keystone]',
|
||||
'before' => "Mysql::Db[#{param_values['dbname']}]"
|
||||
)}
|
||||
|
||||
it { should contain_mysql__db(param_values['dbname']).with(
|
||||
'user' => param_values['user'],
|
||||
'password' => param_values['password'],
|
||||
'host' => param_values['host'],
|
||||
'charset' => 'latin1',
|
||||
'require' => 'Class[Mysql::Server]'
|
||||
)}
|
||||
end
|
||||
|
||||
end
|
@ -2,43 +2,63 @@ require 'spec_helper'
|
||||
|
||||
describe 'keystone' do
|
||||
|
||||
let :concat_file do
|
||||
{
|
||||
:type => 'File',
|
||||
:title => '/var/lib/puppet/concat/_etc_keystone_keystone.conf/fragments.concat.out'
|
||||
}
|
||||
end
|
||||
|
||||
let :default_params do
|
||||
{
|
||||
'package_ensure' => 'present',
|
||||
'bind_host' => '0.0.0.0',
|
||||
'public_port' => '5000',
|
||||
'admin_port' => '35357',
|
||||
'admin_token' => 'service_token',
|
||||
'compute_port' => '3000',
|
||||
'log_verbose' => 'False',
|
||||
'log_debug' => 'False',
|
||||
'default_store' => 'sqlite',
|
||||
'bind_host' => '0.0.0.0',
|
||||
'bind_port' => '5000',
|
||||
'admin_bind_host' => '0.0.0.0',
|
||||
'admin_bind_port' => '5001'
|
||||
'use_syslog' => 'False',
|
||||
'catalog_type' => 'template'
|
||||
}
|
||||
end
|
||||
|
||||
[{},
|
||||
{
|
||||
'package_ensure' => 'latest',
|
||||
'bind_host' => '127.0.0.1',
|
||||
'public_port' => '5001',
|
||||
'admin_port' => '35358',
|
||||
'admin_token' => 'service_token_override',
|
||||
'compute_port' => '3001',
|
||||
'log_verbose' => 'True',
|
||||
'log_debug' => 'True',
|
||||
'default_store' => 'ldap',
|
||||
'bind_host' => '127.0.0.1',
|
||||
'bind_port' => '50000',
|
||||
'admin_bind_host' => '127.0.0.1',
|
||||
'admin_bind_port' => '50001'
|
||||
'catalog_type' => 'sql'
|
||||
}
|
||||
].each do |param_set|
|
||||
|
||||
describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
|
||||
let :param_hash do
|
||||
param_set == {} ? default_params : param_set
|
||||
default_params.merge(param_set)
|
||||
end
|
||||
|
||||
let :params do
|
||||
param_set
|
||||
end
|
||||
|
||||
it { should contain_class('keystone::params') }
|
||||
|
||||
it { should contain_class('concat::setup') }
|
||||
|
||||
it { should contain_package('keystone').with_ensure(param_hash['package_ensure']) }
|
||||
|
||||
it { should contain_group('keystone').with_ensure('present') }
|
||||
it { should contain_user('keystone').with(
|
||||
'ensure' => 'present',
|
||||
'gid' => 'keystone'
|
||||
) }
|
||||
|
||||
it { should contain_file('/etc/keystone').with(
|
||||
'ensure' => 'directory',
|
||||
'owner' => 'keystone',
|
||||
@ -47,8 +67,12 @@ describe 'keystone' do
|
||||
'require' => 'Package[keystone]'
|
||||
) }
|
||||
|
||||
# maybe keystone should always be with the API server?
|
||||
it 'should refresh nova-api if they are on the same machine'
|
||||
it { should contain_concat('/etc/keystone/keystone.conf').with(
|
||||
'owner' => 'keystone',
|
||||
'group' => 'keystone',
|
||||
'require' => 'Package[keystone]',
|
||||
'notify' => 'Service[keystone]'
|
||||
)}
|
||||
|
||||
it { should contain_service('keystone').with(
|
||||
'ensure' => 'running',
|
||||
@ -57,19 +81,38 @@ describe 'keystone' do
|
||||
'hasrestart' => 'true'
|
||||
) }
|
||||
|
||||
it 'should compile the template based on the class parameters' do
|
||||
content = param_value(subject, 'file', 'keystone.conf', 'content')
|
||||
expected_lines = [
|
||||
it 'should correctly configure catalog based on catalog_type'
|
||||
|
||||
it 'should create the expected DEFAULT configuration' do
|
||||
#require 'ruby-debug';debugger
|
||||
verify_contents(
|
||||
subject,
|
||||
'/var/lib/puppet/concat/_etc_keystone_keystone.conf/fragments/00_kestone-DEFAULT',
|
||||
[
|
||||
"bind_host = #{param_hash['bind_host']}",
|
||||
"public_port = #{param_hash['public_port']}",
|
||||
"admin_port = #{param_hash['admin_port']}",
|
||||
"admin_token = #{param_hash['admin_token']}",
|
||||
"compute_port = #{param_hash['compute_port']}",
|
||||
"verbose = #{param_hash['log_verbose']}",
|
||||
"debug = #{param_hash['log_debug']}",
|
||||
"default_store = #{param_hash['default_store']}",
|
||||
"service_host = #{param_hash['bind_host']}",
|
||||
"service_port = #{param_hash['bind_port']}",
|
||||
"admin_host = #{param_hash['admin_bind_host']}",
|
||||
"admin_port = #{param_hash['admin_bind_port']}"
|
||||
"log_file = /var/log/keystone/keystone.log",
|
||||
"use_syslog = #{param_hash['use_syslog']}"
|
||||
]
|
||||
(content.split("\n") & expected_lines).should == expected_lines
|
||||
)
|
||||
end
|
||||
it 'should create the expected identity section' do
|
||||
verify_contents(
|
||||
subject,
|
||||
'/var/lib/puppet/concat/_etc_keystone_keystone.conf/fragments/03_kestone-identity',
|
||||
[
|
||||
"[identity]",
|
||||
"driver = keystone.identity.backends.sql.Identity"
|
||||
]
|
||||
)
|
||||
end
|
||||
it { should create_file(
|
||||
'/var/lib/puppet/concat/_etc_keystone_keystone.conf/fragments/99_kestone-footer') }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -6,6 +6,11 @@ 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__), '../../')
|
||||
|
Loading…
Reference in New Issue
Block a user