Switch sahara to use rspec-puppet-facts

This change updates puppet-sahara to use rspec-puppet-facts for all
rspec tests.

Change-Id: I363aadf941467a01ac0f15f254ee23ec7055b323
This commit is contained in:
Alex Schultz 2016-07-07 10:34:48 -06:00
parent a230e85974
commit 1600fdedac
14 changed files with 288 additions and 269 deletions

View File

@ -0,0 +1,4 @@
---
other:
- Tests updated to leverage rspec-puppet-facts for testing
multiple OS versions.

View File

@ -2,28 +2,29 @@ require 'spec_helper'
describe 'sahara::service::all' do
context 'on Debian platforms' do
let :facts do
@default_facts.merge({
:osfamily => 'Debian',
:operatingsystem => 'Debian'
})
end
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge(OSDefaults.get_facts)
end
it_behaves_like 'generic sahara service', {
:name => 'sahara-all',
:package_name => 'sahara',
:service_name => 'sahara' }
case facts[:osfamily]
when 'Debian'
platform_params = {
:name => 'sahara-all',
:package_name => 'sahara',
:service_name => 'sahara' }
when 'RedHat'
platform_params = {
:name => 'sahara-all',
:package_name => 'openstack-sahara',
:service_name => 'openstack-sahara-all' }
end
it_behaves_like 'generic sahara service', platform_params
end
end
context 'on RedHat platforms' do
let :facts do
@default_facts.merge({ :osfamily => 'RedHat' })
end
it_behaves_like 'generic sahara service', {
:name => 'sahara-all',
:package_name => 'openstack-sahara',
:service_name => 'openstack-sahara-all' }
end
end

View File

@ -20,33 +20,30 @@ describe 'sahara::service::api' do
end
context 'on Debian platforms' do
let :facts do
@default_facts.merge({
:osfamily => 'Debian',
:operatingsystem => 'Debian'
})
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge(OSDefaults.get_facts)
end
case facts[:osfamily]
when 'Debian'
platform_params = {
:name => 'sahara-api',
:package_name => 'sahara-api',
:service_name => 'sahara-api' }
when 'RedHat'
platform_params = {
:name => 'sahara-api',
:package_name => 'openstack-sahara-api',
:service_name => 'openstack-sahara-api' }
end
it_configures 'sahara-api'
it_behaves_like 'generic sahara service', platform_params
end
it_configures 'sahara-api'
it_behaves_like 'generic sahara service', {
:name => 'sahara-api',
:package_name => 'sahara-api',
:service_name => 'sahara-api' }
end
context 'on RedHat platforms' do
let :facts do
@default_facts.merge({ :osfamily => 'RedHat' })
end
it_configures 'sahara-api'
it_behaves_like 'generic sahara service', {
:name => 'sahara-api',
:package_name => 'openstack-sahara-api',
:service_name => 'openstack-sahara-api' }
end
end

View File

@ -28,22 +28,16 @@ describe 'sahara::client' do
end
context 'on Debian platforms' do
let :facts do
{
:osfamily => 'Debian',
:operatingsystem => 'Debian'
}
end
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge(OSDefaults.get_facts)
end
it_configures 'sahara client'
it_configures 'sahara client'
end
end
context 'on RedHat platforms' do
let :facts do
{ :osfamily => 'RedHat' }
end
it_configures 'sahara client'
end
end

View File

@ -2,30 +2,45 @@ require 'spec_helper'
describe 'sahara::config' do
let :params do
{ :sahara_config => {
'DEFAULT/foo' => { 'value' => 'fooValue' },
'DEFAULT/bar' => { 'value' => 'barValue' },
'DEFAULT/baz' => { 'ensure' => 'absent' }
},
:sahara_api_paste_ini => {
'DEFAULT/foo2' => { 'value' => 'fooValue' },
'DEFAULT/bar2' => { 'value' => 'barValue' },
'DEFAULT/baz2' => { 'ensure' => 'absent' }
shared_examples_for 'sahara-config' do
let :params do
{ :sahara_config => {
'DEFAULT/foo' => { 'value' => 'fooValue' },
'DEFAULT/bar' => { 'value' => 'barValue' },
'DEFAULT/baz' => { 'ensure' => 'absent' }
},
:sahara_api_paste_ini => {
'DEFAULT/foo2' => { 'value' => 'fooValue' },
'DEFAULT/bar2' => { 'value' => 'barValue' },
'DEFAULT/baz2' => { 'ensure' => 'absent' }
}
}
}
end
it 'configures arbitrary sahara configurations' do
is_expected.to contain_sahara_config('DEFAULT/foo').with_value('fooValue')
is_expected.to contain_sahara_config('DEFAULT/bar').with_value('barValue')
is_expected.to contain_sahara_config('DEFAULT/baz').with_ensure('absent')
end
it 'configures arbitrary sahara-api-paste configurations' do
is_expected.to contain_sahara_api_paste_ini('DEFAULT/foo2').with_value('fooValue')
is_expected.to contain_sahara_api_paste_ini('DEFAULT/bar2').with_value('barValue')
is_expected.to contain_sahara_api_paste_ini('DEFAULT/baz2').with_ensure('absent')
end
end
it 'configures arbitrary sahara configurations' do
is_expected.to contain_sahara_config('DEFAULT/foo').with_value('fooValue')
is_expected.to contain_sahara_config('DEFAULT/bar').with_value('barValue')
is_expected.to contain_sahara_config('DEFAULT/baz').with_ensure('absent')
end
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge(OSDefaults.get_facts)
end
it 'configures arbitrary sahara-api-paste configurations' do
is_expected.to contain_sahara_api_paste_ini('DEFAULT/foo2').with_value('fooValue')
is_expected.to contain_sahara_api_paste_ini('DEFAULT/bar2').with_value('barValue')
is_expected.to contain_sahara_api_paste_ini('DEFAULT/baz2').with_ensure('absent')
it_configures 'sahara-config'
end
end
end

View File

@ -74,19 +74,15 @@ describe 'sahara::db::mysql' do
end
context 'on Debian platforms' do
let :facts do
{ :osfamily => 'Debian' }
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge(OSDefaults.get_facts)
end
it_configures 'sahara mysql database'
end
it_configures 'sahara mysql database'
end
context 'on RedHat platforms' do
let :facts do
{ :osfamily => 'RedHat' }
end
it_configures 'sahara mysql database'
end
end

View File

@ -73,42 +73,48 @@ describe 'sahara::db' do
end
end
context 'on Debian platforms' do
let :facts do
@default_facts.merge({ :osfamily => 'Debian',
:operatingsystem => 'Debian',
:operatingsystemrelease => 'jessie',
})
end
it_configures 'sahara::db'
shared_examples_for 'sahara::db on Debian' do
context 'using pymysql driver' do
let :params do
{ :database_connection => 'mysql+pymysql://sahara:sahara@localhost/sahara' }
{ :database_connection => 'mysql+pymysql://sahara:sahara@localhost/sahara', }
end
it { is_expected.to contain_package('db_backend_package').with({ :ensure => 'present', :name => 'python-pymysql' }) }
it 'install the proper backend package' do
is_expected.to contain_package('db_backend_package').with(
:ensure => 'present',
:name => 'python-pymysql',
:tag => 'openstack'
)
end
end
end
context 'on Redhat platforms' do
let :facts do
@default_facts.merge({ :osfamily => 'RedHat',
:operatingsystemrelease => '7.1',
})
end
it_configures 'sahara::db'
shared_examples_for 'sahara::db on RedHat' do
context 'using pymysql driver' do
let :params do
{ :database_connection => 'mysql+pymysql://sahara:sahara@localhost/sahara' }
{ :database_connection => 'mysql+pymysql://sahara:sahara@localhost/sahara', }
end
it { is_expected.not_to contain_package('db_backend_package') }
end
end
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge!(OSDefaults.get_facts())
end
case facts[:osfamily]
when 'Debian'
it_configures 'sahara::db on Debian'
when 'RedHat'
it_configures 'sahara::db on RedHat'
end
it_configures 'sahara::db'
end
end
end

View File

@ -4,18 +4,20 @@ describe 'sahara::db::sync' do
shared_examples_for 'sahara-dbsync' do
it 'runs sahara-dbmanage' do
is_expected.to contain_exec('sahara-dbmanage').with(
:command => 'sahara-db-manage --config-file /etc/sahara/sahara.conf upgrade head',
:path => '/usr/bin',
:user => 'sahara',
:refreshonly => 'true',
:logoutput => 'on_failure',
:tag => 'openstack-db',
)
context 'default patameters' do
it 'runs sahara-dbmanage' do
is_expected.to contain_exec('sahara-dbmanage').with(
:command => 'sahara-db-manage --config-file /etc/sahara/sahara.conf upgrade head',
:path => '/usr/bin',
:user => 'sahara',
:refreshonly => 'true',
:logoutput => 'on_failure',
:tag => 'openstack-db',
)
end
end
describe 'overriding extra_params' do
context 'overriding extra_params' do
let :params do
{
:extra_params => '--config-file /etc/sahara/sahara01.conf',

View File

@ -2,26 +2,29 @@ require 'spec_helper'
describe 'sahara::service::engine' do
context 'on Debian platforms' do
let :facts do
@default_facts.merge({ :osfamily => 'Debian' })
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge(OSDefaults.get_facts)
end
case facts[:osfamily]
when 'Debian'
platform_params = {
:name => 'sahara-engine',
:package_name => 'sahara-engine',
:service_name => 'sahara-engine' }
when 'RedHat'
platform_params = {
:name => 'sahara-engine',
:package_name => 'openstack-sahara-engine',
:service_name => 'openstack-sahara-engine' }
end
it_behaves_like 'generic sahara service', platform_params
end
it_behaves_like 'generic sahara service', {
:name => 'sahara-engine',
:package_name => 'sahara-engine',
:service_name => 'sahara-engine' }
end
context 'on RedHat platforms' do
let :facts do
@default_facts.merge({ :osfamily => 'RedHat' })
end
it_behaves_like 'generic sahara service', {
:name => 'sahara-engine',
:package_name => 'openstack-sahara-engine',
:service_name => 'openstack-sahara-engine' }
end
end

View File

@ -317,30 +317,19 @@ describe 'sahara' do
end
end
context 'on Debian platforms' do
let :facts do
@default_facts.merge({
:osfamily => 'Debian',
:operatingsystem => 'Debian'
})
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge(OSDefaults.get_facts)
end
it_configures 'sahara'
it_configures 'sahara config'
it_configures 'sahara ssl'
it_configures 'sahara rpc_backend'
end
it_configures 'sahara'
it_configures 'sahara config'
it_configures 'sahara ssl'
it_configures 'sahara rpc_backend'
end
context 'on RedHat platforms' do
let :facts do
@default_facts.merge({ :osfamily => 'RedHat' })
end
it_configures 'sahara'
it_configures 'sahara config'
it_configures 'sahara ssl'
it_configures 'sahara rpc_backend'
end
end

View File

@ -5,75 +5,85 @@ require 'spec_helper'
describe 'sahara::keystone::auth' do
let :facts do
{ :osfamily => 'Debian' }
end
shared_examples_for 'sahara-keystone-auth' do
context 'with default class parameters' do
let :params do
{ :password => 'sahara_password',
:tenant => 'foobar' }
end
describe 'with default class parameters' do
let :params do
{ :password => 'sahara_password',
:tenant => 'foobar' }
it { is_expected.to contain_keystone_user('sahara').with(
:ensure => 'present',
:password => 'sahara_password',
) }
it { is_expected.to contain_keystone_user_role('sahara@foobar').with(
:ensure => 'present',
:roles => ['admin']
)}
it { is_expected.to contain_keystone_service('sahara::data-processing').with(
:ensure => 'present',
:description => 'Sahara Data Processing'
) }
it { is_expected.to contain_keystone_endpoint('RegionOne/sahara::data-processing').with(
:ensure => 'present',
:public_url => "http://127.0.0.1:8386/v1.1/%(tenant_id)s",
:admin_url => "http://127.0.0.1:8386/v1.1/%(tenant_id)s",
:internal_url => "http://127.0.0.1:8386/v1.1/%(tenant_id)s"
) }
end
it { is_expected.to contain_keystone_user('sahara').with(
:ensure => 'present',
:password => 'sahara_password',
) }
context 'when configuring sahara-server' do
let :pre_condition do
"class { 'sahara::server': auth_password => 'test' }"
end
it { is_expected.to contain_keystone_user_role('sahara@foobar').with(
:ensure => 'present',
:roles => ['admin']
)}
it { is_expected.to contain_keystone_service('sahara::data-processing').with(
:ensure => 'present',
:description => 'Sahara Data Processing'
) }
it { is_expected.to contain_keystone_endpoint('RegionOne/sahara::data-processing').with(
:ensure => 'present',
:public_url => "http://127.0.0.1:8386/v1.1/%(tenant_id)s",
:admin_url => "http://127.0.0.1:8386/v1.1/%(tenant_id)s",
:internal_url => "http://127.0.0.1:8386/v1.1/%(tenant_id)s"
) }
end
describe 'when configuring sahara-server' do
let :pre_condition do
"class { 'sahara::server': auth_password => 'test' }"
let :params do
{ :password => 'sahara_password',
:tenant => 'foobar' }
end
end
let :params do
{ :password => 'sahara_password',
:tenant => 'foobar' }
end
end
context 'with endpoint parameters' do
let :params do
{ :password => 'sahara_password',
:public_url => 'https://10.10.10.10:80/v1.1/%(tenant_id)s',
:internal_url => 'http://10.10.10.11:81/v1.1/%(tenant_id)s',
:admin_url => 'http://10.10.10.12:81/v1.1/%(tenant_id)s' }
end
describe 'with endpoint parameters' do
let :params do
{ :password => 'sahara_password',
it { is_expected.to contain_keystone_endpoint('RegionOne/sahara::data-processing').with(
:ensure => 'present',
:public_url => 'https://10.10.10.10:80/v1.1/%(tenant_id)s',
:internal_url => 'http://10.10.10.11:81/v1.1/%(tenant_id)s',
:admin_url => 'http://10.10.10.12:81/v1.1/%(tenant_id)s' }
:admin_url => 'http://10.10.10.12:81/v1.1/%(tenant_id)s'
) }
end
it { is_expected.to contain_keystone_endpoint('RegionOne/sahara::data-processing').with(
:ensure => 'present',
:public_url => 'https://10.10.10.10:80/v1.1/%(tenant_id)s',
:internal_url => 'http://10.10.10.11:81/v1.1/%(tenant_id)s',
:admin_url => 'http://10.10.10.12:81/v1.1/%(tenant_id)s'
) }
end
context 'when overriding auth name' do
let :params do
{ :password => 'foo',
:auth_name => 'saharay' }
end
describe 'when overriding auth name' do
let :params do
{ :password => 'foo',
:auth_name => 'saharay' }
it { is_expected.to contain_keystone_user('saharay') }
it { is_expected.to contain_keystone_user_role('saharay@services') }
it { is_expected.to contain_keystone_service('sahara::data-processing') }
it { is_expected.to contain_keystone_endpoint('RegionOne/sahara::data-processing') }
end
it { is_expected.to contain_keystone_user('saharay') }
it { is_expected.to contain_keystone_user_role('saharay@services') }
it { is_expected.to contain_keystone_service('sahara::data-processing') }
it { is_expected.to contain_keystone_endpoint('RegionOne/sahara::data-processing') }
end
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge(OSDefaults.get_facts)
end
it_configures 'sahara-keystone-auth'
end
end
end

View File

@ -120,19 +120,15 @@ describe 'sahara::logging' do
}
end
context 'on Debian platforms' do
let :facts do
@default_facts.merge({ :osfamily => 'Debian' })
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge(OSDefaults.get_facts)
end
it_configures 'sahara-logging'
end
it_configures 'sahara-logging'
end
context 'on RedHat platforms' do
let :facts do
@default_facts.merge({ :osfamily => 'RedHat' })
end
it_configures 'sahara-logging'
end
end

View File

@ -1,34 +1,45 @@
require 'spec_helper'
describe 'sahara::notify' do
let :facts do
@default_facts.merge({
:osfamily => 'Debian'
})
end
describe 'when defaults with notify enabled' do
it { is_expected.to contain_sahara_config('oslo_messaging_notifications/transport_url').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_sahara_config('oslo_messaging_notifications/enable').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_sahara_config('oslo_messaging_notifications/driver').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_sahara_config('oslo_messaging_notifications/topics').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_sahara_config('oslo_messaging_notifications/level').with_value('<SERVICE DEFAULT>') }
end
shared_examples_for 'sahara-notify' do
context 'when defaults with notify enabled' do
it { is_expected.to contain_sahara_config('oslo_messaging_notifications/transport_url').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_sahara_config('oslo_messaging_notifications/enable').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_sahara_config('oslo_messaging_notifications/driver').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_sahara_config('oslo_messaging_notifications/topics').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_sahara_config('oslo_messaging_notifications/level').with_value('<SERVICE DEFAULT>') }
end
describe 'when passing params' do
let :params do
{
:enable_notifications => 'true',
:notification_transport_url => 'rabbit://guest2:pass@localhost2:5673',
:notification_driver => 'messaging',
:notification_topics => 'notifications',
:notification_level => 'INFO',
}
it { is_expected.to contain_sahara_config('oslo_messaging_notifications/transport_url').with_value('rabbit://guest2:pass@localhost2:5673') }
it { is_expected.to contain_sahara_config('oslo_messaging_notifications/driver').with_value('messaging') }
it { is_expected.to contain_sahara_config('oslo_messaging_notifications/enable').with_value('true') }
it { is_expected.to contain_sahara_config('oslo_messaging_notifications/topics').with_value('notifications') }
it { is_expected.to contain_sahara_config('oslo_messaging_notifications/level').with_value('INFO') }
context 'when passing params' do
let :params do
{
:enable_notifications => 'true',
:notification_transport_url => 'rabbit://guest2:pass@localhost2:5673',
:notification_driver => 'messaging',
:notification_topics => 'notifications',
:notification_level => 'INFO',
}
it { is_expected.to contain_sahara_config('oslo_messaging_notifications/transport_url').with_value('rabbit://guest2:pass@localhost2:5673') }
it { is_expected.to contain_sahara_config('oslo_messaging_notifications/driver').with_value('messaging') }
it { is_expected.to contain_sahara_config('oslo_messaging_notifications/enable').with_value('true') }
it { is_expected.to contain_sahara_config('oslo_messaging_notifications/topics').with_value('notifications') }
it { is_expected.to contain_sahara_config('oslo_messaging_notifications/level').with_value('INFO') }
end
end
end
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge!(OSDefaults.get_facts())
end
it_configures 'sahara-notify'
end
end
end

View File

@ -8,11 +8,6 @@ include RspecPuppetFacts
RSpec.configure do |c|
c.alias_it_should_behave_like_to :it_configures, 'configures'
c.alias_it_should_behave_like_to :it_raises, 'raises'
# TODO(aschultz): remove this after all tests converted to use OSDefaults
# instead of referencing @default_facts
c.before :each do
@default_facts = OSDefaults.get_facts
end
end
at_exit { RSpec::Puppet::Coverage.report! }