From a6e6657811f52ce35c6af69b1cba3f0a376285c4 Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Mon, 11 Jan 2016 21:26:03 -0700 Subject: [PATCH] Update tests to leverage rspec-puppet-facts This change updates the test that currently do Debian/RedHat sets of tests to use on_supported_os from rspec-puppet-facts. This improves the over all coverage with the specific CentOS, Debian, RedHat and Ubuntu flavors of facts. Change-Id: Ibd7e2914419a492363de70d1e93c86abeeabc357 --- spec/classes/aodh_api_spec.rb | 111 +++++++----------------- spec/classes/aodh_auth_spec.rb | 22 ++--- spec/classes/aodh_client_spec.rb | 21 ++--- spec/classes/aodh_db_postgresql_spec.rb | 38 +++----- spec/classes/aodh_db_spec.rb | 40 ++++----- spec/classes/aodh_evaluator_spec.rb | 42 ++++----- spec/classes/aodh_init_spec.rb | 38 ++++---- spec/classes/aodh_listener_spec.rb | 38 ++++---- spec/classes/aodh_logging_spec.rb | 22 ++--- spec/classes/aodh_notifier_spec.rb | 39 ++++----- spec/classes/aodh_policy_spec.rb | 21 ++--- spec/classes/aodh_wsgi_apache_spec.rb | 75 +++++++--------- 12 files changed, 205 insertions(+), 302 deletions(-) diff --git a/spec/classes/aodh_api_spec.rb b/spec/classes/aodh_api_spec.rb index dd320b4d..3567e000 100644 --- a/spec/classes/aodh_api_spec.rb +++ b/spec/classes/aodh_api_spec.rb @@ -119,89 +119,44 @@ describe 'aodh::api' do it_raises 'a Puppet::Error', /Invalid service_name/ end - end - context 'on Debian platforms' do - let :facts do - @default_facts.merge({ - :osfamily => 'Debian', - :operatingsystem => 'Debian', - :operatingsystemrelease => '8.0', - :concat_basedir => '/var/lib/puppet/concat', - :fqdn => 'some.host.tld', - :processorcount => 2, - }) - end - - let :platform_params do - { :api_package_name => 'aodh-api', - :api_service_name => 'aodh-api' } - end - - it_configures 'aodh-api' - end - - context 'on RedHat platforms' do - let :facts do - @default_facts.merge({ - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '7.1', - :fqdn => 'some.host.tld', - :concat_basedir => '/var/lib/puppet/concat', - :processorcount => 2, - }) - end - - let :platform_params do - { :api_package_name => 'openstack-aodh-api', - :api_service_name => 'openstack-aodh-api' } - end - - it_configures 'aodh-api' - end - - describe 'with custom auth_uri' do - let :facts do - @default_facts.merge({ :osfamily => 'RedHat' }) - end - before do - params.merge!({ - :keystone_auth_uri => 'https://foo.bar:1234/', - }) - end - it 'should configure custom auth_uri correctly' do - is_expected.to contain_aodh_config('keystone_authtoken/auth_uri').with_value( 'https://foo.bar:1234/' ) + context "with custom keystone identity_uri and auth_uri" do + before do + params.merge!({ + :keystone_identity_uri => 'https://foo.bar:35357/', + :keystone_auth_uri => 'https://foo.bar:5000/v2.0/', + }) + end + it 'configures identity_uri and auth_uri but deprecates old auth settings' do + is_expected.to contain_aodh_config('keystone_authtoken/identity_uri').with_value("https://foo.bar:35357/"); + is_expected.to contain_aodh_config('keystone_authtoken/auth_uri').with_value("https://foo.bar:5000/v2.0/"); + end end end - describe "with custom keystone identity_uri" do - let :facts do - @default_facts.merge({ :osfamily => 'RedHat' }) - end - before do - params.merge!({ - :keystone_identity_uri => 'https://foo.bar:1234/', - }) - end - it 'configures identity_uri' do - is_expected.to contain_aodh_config('keystone_authtoken/identity_uri').with_value("https://foo.bar:1234/"); - 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({ + :fqdn => 'some.host.tld', + :processorcount => 2, + :concat_basedir => '/var/lib/puppet/concat' + })) + end - describe "with custom keystone identity_uri and auth_uri" do - let :facts do - @default_facts.merge({ :osfamily => 'RedHat' }) - end - before do - params.merge!({ - :keystone_identity_uri => 'https://foo.bar:35357/', - :keystone_auth_uri => 'https://foo.bar:5000/v2.0/', - }) - end - it 'configures identity_uri and auth_uri but deprecates old auth settings' do - is_expected.to contain_aodh_config('keystone_authtoken/identity_uri').with_value("https://foo.bar:35357/"); - is_expected.to contain_aodh_config('keystone_authtoken/auth_uri').with_value("https://foo.bar:5000/v2.0/"); + let(:platform_params) do + case facts[:osfamily] + when 'Debian' + { :api_package_name => 'aodh-api', + :api_service_name => 'aodh-api' } + when 'RedHat' + { :api_package_name => 'openstack-aodh-api', + :api_service_name => 'openstack-aodh-api' } + end + end + it_configures 'aodh-api' end end diff --git a/spec/classes/aodh_auth_spec.rb b/spec/classes/aodh_auth_spec.rb index 9813451c..2ff64a7c 100644 --- a/spec/classes/aodh_auth_spec.rb +++ b/spec/classes/aodh_auth_spec.rb @@ -36,20 +36,16 @@ describe 'aodh::auth' 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 'aodh-auth' end - - it_configures 'aodh-auth' - end - - context 'on RedHat platforms' do - let :facts do - { :osfamily => 'RedHat' } - end - - it_configures 'aodh-auth' end end diff --git a/spec/classes/aodh_client_spec.rb b/spec/classes/aodh_client_spec.rb index 8c43670f..748699d7 100644 --- a/spec/classes/aodh_client_spec.rb +++ b/spec/classes/aodh_client_spec.rb @@ -15,19 +15,16 @@ describe 'aodh::client' do end end - context 'on Debian platforms' do - let :facts do - { :osfamily => '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 'aodh client' + it_configures 'aodh client' + end end - context 'on RedHat platforms' do - let :facts do - { :osfamily => 'RedHat' } - end - - it_configures 'aodh client' - end end diff --git a/spec/classes/aodh_db_postgresql_spec.rb b/spec/classes/aodh_db_postgresql_spec.rb index 437fdfc1..4f868625 100644 --- a/spec/classes/aodh_db_postgresql_spec.rb +++ b/spec/classes/aodh_db_postgresql_spec.rb @@ -10,15 +10,7 @@ describe 'aodh::db::postgresql' do 'include postgresql::server' end - context 'on a RedHat osfamily' do - let :facts do - { - :osfamily => 'RedHat', - :operatingsystemrelease => '7.0', - :concat_basedir => '/var/lib/puppet/concat' - } - end - + shared_examples 'aodh::db::postgresql' do context 'with only required parameters' do let :params do req_params @@ -32,27 +24,19 @@ describe 'aodh::db::postgresql' do end - context 'on a Debian osfamily' do - let :facts do - { - :operatingsystemrelease => '7.8', - :operatingsystem => 'Debian', - :osfamily => 'Debian', - :concat_basedir => '/var/lib/puppet/concat' - } - end - - context 'with only required parameters' do - let :params do - req_params + 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({ + :concat_basedir => '/var/lib/puppet/concat' + })) end - it { is_expected.to contain_postgresql__server__db('aodh').with( - :user => 'aodh', - :password => 'md534e5dd092d680f3d8c11c62951fb5c19' - )} + it_configures 'aodh::db::postgresql' end - end + end diff --git a/spec/classes/aodh_db_spec.rb b/spec/classes/aodh_db_spec.rb index 07c906de..e78caa3c 100644 --- a/spec/classes/aodh_db_spec.rb +++ b/spec/classes/aodh_db_spec.rb @@ -87,16 +87,7 @@ describe 'aodh::db' do end end - context 'on Debian platforms' do - let :facts do - { :osfamily => 'Debian', - :operatingsystem => 'Debian', - :operatingsystemrelease => 'jessie', - } - end - - it_configures 'aodh::db' - + shared_examples_for 'aodh::db on Debian' do context 'with sqlite backend' do let :params do { :database_connection => 'sqlite:///var/lib/aodh/aodh.sqlite', } @@ -109,7 +100,6 @@ describe 'aodh::db' do :tag => 'openstack' ) end - end context 'using pymysql driver' do @@ -127,15 +117,7 @@ describe 'aodh::db' do end end - context 'on Redhat platforms' do - let :facts do - { :osfamily => 'RedHat', - :operatingsystemrelease => '7.1', - } - end - - it_configures 'aodh::db' - + shared_examples_for 'aodh::db on RedHat' do context 'using pymysql driver' do let :params do { :database_connection => 'mysql+pymysql://aodh:aodh@localhost/aodh', } @@ -144,5 +126,23 @@ describe 'aodh::db' do it { is_expected.not_to contain_package('aodh-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 'aodh::db on Debian' + when 'RedHat' + it_configures 'aodh::db on RedHat' + end + it_configures 'aodh::db' + end + end end diff --git a/spec/classes/aodh_evaluator_spec.rb b/spec/classes/aodh_evaluator_spec.rb index 07450b76..471db05d 100644 --- a/spec/classes/aodh_evaluator_spec.rb +++ b/spec/classes/aodh_evaluator_spec.rb @@ -85,29 +85,31 @@ describe 'aodh::evaluator' do end end - context 'on Debian platforms' do - let :facts do - @default_facts.merge({ :osfamily => '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({ + :fqdn => 'some.host.tld', + :processorcount => 2, + :concat_basedir => '/var/lib/puppet/concat' + })) + end - let :platform_params do - { :evaluator_package_name => 'aodh-evaluator', - :evaluator_service_name => 'aodh-evaluator' } + let(:platform_params) do + case facts[:osfamily] + when 'Debian' + { :evaluator_package_name => 'aodh-evaluator', + :evaluator_service_name => 'aodh-evaluator' } + when 'RedHat' + { :evaluator_package_name => 'openstack-aodh-evaluator', + :evaluator_service_name => 'openstack-aodh-evaluator' } + end + end + it_configures 'aodh-evaluator' end - - it_configures 'aodh-evaluator' end - context 'on RedHat platforms' do - let :facts do - @default_facts.merge({ :osfamily => 'RedHat' }) - end - let :platform_params do - { :evaluator_package_name => 'openstack-aodh-evaluator', - :evaluator_service_name => 'openstack-aodh-evaluator' } - end - - it_configures 'aodh-evaluator' - end end diff --git a/spec/classes/aodh_init_spec.rb b/spec/classes/aodh_init_spec.rb index 4ca9f3da..e0bbbbc8 100644 --- a/spec/classes/aodh_init_spec.rb +++ b/spec/classes/aodh_init_spec.rb @@ -212,31 +212,25 @@ describe 'aodh' do end end - 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 - let :platform_params do - { :aodh_common_package => 'aodh-common' } + let(:platform_params) do + case facts[:osfamily] + when 'Debian' + { :aodh_common_package => 'aodh-common' } + when 'RedHat' + { :aodh_common_package => 'openstack-aodh-common' } + end + end + it_behaves_like 'aodh' end - - it_behaves_like 'aodh' end - context 'on RedHat platforms' do - let :facts do - @default_facts.merge({ :osfamily => 'RedHat' }) - end - - let :platform_params do - { :aodh_common_package => 'openstack-aodh-common' } - end - - it_behaves_like 'aodh' - end end diff --git a/spec/classes/aodh_listener_spec.rb b/spec/classes/aodh_listener_spec.rb index 32f1076e..f54d1e43 100644 --- a/spec/classes/aodh_listener_spec.rb +++ b/spec/classes/aodh_listener_spec.rb @@ -71,29 +71,27 @@ describe 'aodh::listener' do end end - context 'on Debian platforms' do - let :facts do - @default_facts.merge({ :osfamily => '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 - let :platform_params do - { :listener_package_name => 'aodh-listener', - :listener_service_name => 'aodh-listener' } + let(:platform_params) do + case facts[:osfamily] + when 'Debian' + { :listener_package_name => 'aodh-listener', + :listener_service_name => 'aodh-listener' } + when 'RedHat' + { :listener_package_name => 'openstack-aodh-listener', + :listener_service_name => 'openstack-aodh-listener' } + end + end + it_configures 'aodh-listener' end - - it_configures 'aodh-listener' end - context 'on RedHat platforms' do - let :facts do - @default_facts.merge({ :osfamily => 'RedHat' }) - end - let :platform_params do - { :listener_package_name => 'openstack-aodh-listener', - :listener_service_name => 'openstack-aodh-listener' } - end - - it_configures 'aodh-listener' - end end diff --git a/spec/classes/aodh_logging_spec.rb b/spec/classes/aodh_logging_spec.rb index 4cb4f1a1..1281e20d 100644 --- a/spec/classes/aodh_logging_spec.rb +++ b/spec/classes/aodh_logging_spec.rb @@ -125,20 +125,16 @@ describe 'aodh::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 'aodh-logging' end - - it_configures 'aodh-logging' - end - - context 'on RedHat platforms' do - let :facts do - @default_facts.merge({ :osfamily => 'RedHat' }) - end - - it_configures 'aodh-logging' end end diff --git a/spec/classes/aodh_notifier_spec.rb b/spec/classes/aodh_notifier_spec.rb index 6c786c2a..3bb88074 100644 --- a/spec/classes/aodh_notifier_spec.rb +++ b/spec/classes/aodh_notifier_spec.rb @@ -71,29 +71,26 @@ describe 'aodh::notifier' do end end - context 'on Debian platforms' do - let :facts do - @default_facts.merge({ :osfamily => '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 - let :platform_params do - { :notifier_package_name => 'aodh-notifier', - :notifier_service_name => 'aodh-notifier' } + let(:platform_params) do + case facts[:osfamily] + when 'Debian' + { :notifier_package_name => 'aodh-notifier', + :notifier_service_name => 'aodh-notifier' } + when 'RedHat' + { :notifier_package_name => 'openstack-aodh-notifier', + :notifier_service_name => 'openstack-aodh-notifier' } + end + end + it_configures 'aodh-notifier' end - - it_configures 'aodh-notifier' end - context 'on RedHat platforms' do - let :facts do - @default_facts.merge({ :osfamily => 'RedHat' }) - end - - let :platform_params do - { :notifier_package_name => 'openstack-aodh-notifier', - :notifier_service_name => 'openstack-aodh-notifier' } - end - - it_configures 'aodh-notifier' - end end diff --git a/spec/classes/aodh_policy_spec.rb b/spec/classes/aodh_policy_spec.rb index 9bce550a..6a45d2b3 100644 --- a/spec/classes/aodh_policy_spec.rb +++ b/spec/classes/aodh_policy_spec.rb @@ -23,19 +23,16 @@ describe 'aodh::policy' do end end - context 'on Debian platforms' do - let :facts do - { :osfamily => '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 'aodh policies' + it_configures 'aodh policies' + end end - context 'on RedHat platforms' do - let :facts do - { :osfamily => 'RedHat' } - end - - it_configures 'aodh policies' - end end diff --git a/spec/classes/aodh_wsgi_apache_spec.rb b/spec/classes/aodh_wsgi_apache_spec.rb index 2cd2b44d..f6cfb6c6 100644 --- a/spec/classes/aodh_wsgi_apache_spec.rb +++ b/spec/classes/aodh_wsgi_apache_spec.rb @@ -2,14 +2,6 @@ require 'spec_helper' describe 'aodh::wsgi::apache' do - let :global_facts do - { - :processorcount => 42, - :concat_basedir => '/var/lib/puppet/concat', - :fqdn => 'some.host.tld' - } - end - shared_examples_for 'apache serving aodh with mod_wsgi' do it { is_expected.to contain_service('httpd').with_name(platform_parameters[:httpd_service_name]) } it { is_expected.to contain_class('aodh::params') } @@ -81,44 +73,39 @@ describe 'aodh::wsgi::apache' do end end - context 'on RedHat platforms' do - let :facts do - global_facts.merge({ - :osfamily => 'RedHat', - :operatingsystemrelease => '7.0' - }) - 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({ + :processorcount => 42, + :concat_basedir => '/var/lib/puppet/concat', + :fqdn => 'some.host.tld' + })) + end - let :platform_parameters do - { - :httpd_service_name => 'httpd', - :httpd_ports_file => '/etc/httpd/conf/ports.conf', - :wsgi_script_path => '/var/www/cgi-bin/aodh', - :wsgi_script_source => '/usr/lib/python2.7/site-packages/aodh/api/app.wsgi' - } - end + let(:platform_parameters) do + case facts[:osfamily] + when 'Debian' + { + :httpd_service_name => 'apache2', + :httpd_ports_file => '/etc/apache2/ports.conf', + :wsgi_script_path => '/usr/lib/cgi-bin/aodh', + :wsgi_script_source => '/usr/share/aodh-common/app.wsgi' + } + when 'RedHat' + { + :httpd_service_name => 'httpd', + :httpd_ports_file => '/etc/httpd/conf/ports.conf', + :wsgi_script_path => '/var/www/cgi-bin/aodh', + :wsgi_script_source => '/usr/lib/python2.7/site-packages/aodh/api/app.wsgi' + } - it_configures 'apache serving aodh with mod_wsgi' + end + end + it_configures 'apache serving aodh with mod_wsgi' + end end - context 'on Debian platforms' do - let :facts do - global_facts.merge({ - :osfamily => 'Debian', - :operatingsystem => 'Debian', - :operatingsystemrelease => '7.0' - }) - end - - let :platform_parameters do - { - :httpd_service_name => 'apache2', - :httpd_ports_file => '/etc/apache2/ports.conf', - :wsgi_script_path => '/usr/lib/cgi-bin/aodh', - :wsgi_script_source => '/usr/share/aodh-common/app.wsgi' - } - end - - it_configures 'apache serving aodh with mod_wsgi' - end end