From 72dcec4e9b22f7a4b3c995b49f6c527b88766d01 Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Thu, 7 Jul 2016 12:26:28 -0600 Subject: [PATCH] Switch horizon to use rspec-puppet-facts This change updates puppet-horizon to use rspec-puppet-facts for all rspec tests. Change-Id: I86e4e32037e7c96b47c12077cd0d2fc30c62c5f9 --- .../rspec-puppet-facts-7ec9c688aba3e69e.yaml | 4 + spec/classes/horizon_init_spec.rb | 91 ++++-------- spec/classes/horizon_wsgi_apache_spec.rb | 139 ++++++++---------- spec/spec_helper.rb | 5 - 4 files changed, 91 insertions(+), 148 deletions(-) create mode 100644 releasenotes/notes/rspec-puppet-facts-7ec9c688aba3e69e.yaml diff --git a/releasenotes/notes/rspec-puppet-facts-7ec9c688aba3e69e.yaml b/releasenotes/notes/rspec-puppet-facts-7ec9c688aba3e69e.yaml new file mode 100644 index 00000000..8053b7dd --- /dev/null +++ b/releasenotes/notes/rspec-puppet-facts-7ec9c688aba3e69e.yaml @@ -0,0 +1,4 @@ +--- +other: + - Tests updated to leverage rspec-puppet-facts for testing + multiple OS versions. diff --git a/spec/classes/horizon_init_spec.rb b/spec/classes/horizon_init_spec.rb index 84aa2621..d0780dbb 100644 --- a/spec/classes/horizon_init_spec.rb +++ b/spec/classes/horizon_init_spec.rb @@ -15,13 +15,7 @@ describe 'horizon' do File.expand_path(File.join(__FILE__, '..', '..', 'fixtures')) end - let :facts do - { :concat_basedir => '/var/lib/puppet/concat', - :fqdn => 'some.host.tld' - } - end - - shared_examples 'horizon' do + shared_examples_for 'horizon' do context 'with default parameters' do it { @@ -396,23 +390,7 @@ describe 'horizon' do end end - context 'on RedHat platforms' do - before do - facts.merge!({ - :osfamily => 'RedHat', - :operatingsystemrelease => '6.0', - :os_package_type => 'rpm' - }) - end - - let :platforms_params do - { :config_file => '/etc/openstack-dashboard/local_settings', - :package_name => 'openstack-dashboard', - :root_url => '/dashboard' } - end - - it_behaves_like 'horizon' - + shared_examples_for 'horizon on RedHat' do it 'sets WEBROOT in local_settings.py' do verify_concat_fragment_contents(catalogue, 'local_settings.py', [ "WEBROOT = '/dashboard/'", @@ -420,24 +398,7 @@ describe 'horizon' do end end - context 'on Debian platforms' do - before do - facts.merge!({ - :osfamily => 'Debian', - :operatingsystemrelease => '6.0', - :operatingsystem => 'Debian', - :os_package_type => 'debian' - }) - end - - let :platforms_params do - { :config_file => '/etc/openstack-dashboard/local_settings.py', - :package_name => 'openstack-dashboard-apache', - :root_url => '/horizon' } - end - - it_behaves_like 'horizon' - + shared_examples_for 'horizon on Debian' do it 'sets WEBROOT in local_settings.py' do verify_concat_fragment_contents(catalogue, 'local_settings.py', [ "WEBROOT = '/horizon/'", @@ -445,28 +406,34 @@ describe 'horizon' do end end - context 'on Ubuntu platforms' do - before do - facts.merge!({ - :osfamily => 'Debian', - :operatingsystem => 'Ubuntu', - :operatingsystemrelease => '14.04', - :os_package_type => 'ubuntu' - }) - 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 :platforms_params do - { :config_file => '/etc/openstack-dashboard/local_settings.py', - :package_name => 'openstack-dashboard', - :root_url => '/horizon' } - end + let(:platforms_params) do + case facts[:osfamily] + when 'Debian' + { :config_file => '/etc/openstack-dashboard/local_settings.py', + :package_name => 'openstack-dashboard', + :root_url => '/horizon' } + when 'RedHat' + { :config_file => '/etc/openstack-dashboard/local_settings', + :package_name => 'openstack-dashboard', + :root_url => '/dashboard' } + end + end - it_behaves_like 'horizon' - - it 'sets WEBROOT in local_settings.py' do - verify_concat_fragment_contents(catalogue, 'local_settings.py', [ - "WEBROOT = '/horizon/'", - ]) + it_behaves_like 'horizon' + it_behaves_like "horizon on #{facts[:osfamily]}" end end + end diff --git a/spec/classes/horizon_wsgi_apache_spec.rb b/spec/classes/horizon_wsgi_apache_spec.rb index 615703ee..b1248aea 100644 --- a/spec/classes/horizon_wsgi_apache_spec.rb +++ b/spec/classes/horizon_wsgi_apache_spec.rb @@ -19,13 +19,7 @@ describe 'horizon::wsgi::apache' do File.expand_path(File.join(__FILE__, '..', '..', 'fixtures')) end - let :facts do - { :concat_basedir => '/var/lib/puppet/concat', - :fqdn => 'some.host.tld' - } - end - - shared_examples 'apache for horizon' do + shared_examples_for 'apache for horizon' do context 'with default parameters' do it 'configures apache' do @@ -186,27 +180,7 @@ describe 'horizon::wsgi::apache' do end end - context 'on RedHat platforms' do - before do - facts.merge!({ - :osfamily => 'RedHat', - :operatingsystemrelease => '6.0' - }) - end - - let :platforms_params do - { :http_service => 'httpd', - :httpd_config_file => '/etc/httpd/conf.d/openstack-dashboard.conf', - :root_url => '/dashboard', - :apache_user => 'apache', - :apache_group => 'apache', - :wsgi_user => 'apache', - :wsgi_group => 'apache', - :unix_user => 'apache', - :unix_group => 'apache' } - end - - it_behaves_like 'apache for horizon' + shared_examples_for 'apache for horizon on RedHat platforms' do it { is_expected.to contain_class('apache::mod::wsgi').with(:wsgi_socket_prefix => '/var/run/wsgi') } @@ -223,29 +197,7 @@ describe 'horizon::wsgi::apache' do end end - context 'on Debian platforms' do - before do - facts.merge!({ - :osfamily => 'Debian', - :operatingsystem => 'Debian', - :operatingsystemrelease => '6.0', - :os_package_type => 'debian' - }) - end - - let :platforms_params do - { :http_service => 'apache2', - :httpd_config_file => '/etc/apache2/sites-available/openstack-dashboard-alias-only.conf', - :root_url => '/horizon', - :apache_user => 'www-data', - :apache_group => 'www-data', - :wsgi_user => 'horizon', - :wsgi_group => 'horizon', - :unix_user => 'horizon', - :unix_group => 'horizon' } - end - - it_behaves_like 'apache for horizon' + shared_examples_for 'apache for horizon on Debian platforms' do it 'configures webroot alias' do if (Gem::Version.new(Puppet.version) >= Gem::Version.new('4.0')) is_expected.to contain_apache__vhost('horizon_vhost').with( @@ -259,39 +211,64 @@ describe 'horizon::wsgi::apache' do end end - context 'on Ubuntu platforms' do - before do - facts.merge!({ - :osfamily => 'Debian', - :operatingsystem => 'Ubuntu', - :operatingsystemrelease => '14.04', - :os_package_type => 'ubuntu' - }) - end - let :platforms_params do - { :http_service => 'apache2', - :httpd_config_file => '/etc/apache2/conf-available/openstack-dashboard.conf', - :root_url => '/horizon', - :apache_user => 'www-data', - :apache_group => 'www-data', - :wsgi_user => 'horizon', - :wsgi_group => 'horizon', - :unix_user => 'horizon', - :unix_group => 'horizon' } - end + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + if facts[:operatingsystem] == 'Debian' + facts.merge!({:os_package_type => 'debian'}) + end - it_behaves_like 'apache for horizon' - it 'configures webroot alias' do - if (Gem::Version.new(Puppet.version) >= Gem::Version.new('4.0')) - is_expected.to contain_apache__vhost('horizon_vhost').with( - 'aliases' => [{'alias' => '/horizon/static', 'path' => '/usr/share/openstack-dashboard/static'}], - ) - else - is_expected.to contain_apache__vhost('horizon_vhost').with( - 'aliases' => [['alias', '/horizon/static'], ['path', '/usr/share/openstack-dashboard/static']], - ) + facts.merge!(OSDefaults.get_facts({ + :fqdn => 'some.host.tld', + :processorcount => 2, + :concat_basedir => '/var/lib/puppet/concat' + })) end + + let(:platforms_params) do + case facts[:osfamily] + when 'Debian' + case facts[:operatingsystem] + when 'Debian' + { :http_service => 'apache2', + :httpd_config_file => '/etc/apache2/sites-available/openstack-dashboard-alias-only.conf', + :root_url => '/horizon', + :apache_user => 'www-data', + :apache_group => 'www-data', + :wsgi_user => 'horizon', + :wsgi_group => 'horizon', + :unix_user => 'horizon', + :unix_group => 'horizon' } + when 'Ubuntu' + { :http_service => 'apache2', + :httpd_config_file => '/etc/apache2/conf-available/openstack-dashboard.conf', + :root_url => '/horizon', + :apache_user => 'www-data', + :apache_group => 'www-data', + :wsgi_user => 'horizon', + :wsgi_group => 'horizon', + :unix_user => 'horizon', + :unix_group => 'horizon' } + end + when 'RedHat' + { :http_service => 'httpd', + :httpd_config_file => '/etc/httpd/conf.d/openstack-dashboard.conf', + :root_url => '/dashboard', + :apache_user => 'apache', + :apache_group => 'apache', + :wsgi_user => 'apache', + :wsgi_group => 'apache', + :unix_user => 'apache', + :unix_group => 'apache' } + end + end + + it_behaves_like 'apache for horizon' + it_behaves_like "apache for horizon on #{facts[:osfamily]} platforms" end end + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8d236278..1913ca98 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 def verify_concat_fragment_contents(subject, title, expected_lines)