From de8fb53dc0363230ce86b0d9b2c6f724a999dcc2 Mon Sep 17 00:00:00 2001 From: Lance Albertson Date: Fri, 22 Oct 2021 17:12:12 -0700 Subject: [PATCH] CentOS 8 support - Update package names - Migrate to using apache2_mod_wsgi resource and require apache2 ~> 8.6 - Update ChefSpec Depends-On: https://review.opendev.org/c/openstack/cookbook-openstack-identity/+/815147 Change-Id: Ie94c860bc056349262325d2e90c513b64dbb3107 Signed-off-by: Lance Albertson --- README.rst | 2 +- attributes/default.rb | 5 +- metadata.rb | 2 +- recipes/apache2-server.rb | 2 +- spec/apache2-server-redhat_spec.rb | 104 ++++++++++---------- spec/apache2-server_spec.rb | 2 +- spec/horizon-redhat_spec.rb | 75 +++++++------- spec/horizon_spec.rb | 2 +- spec/neutron-lbaas-dashboard-redhat_spec.rb | 28 +++--- spec/spec_helper.rb | 13 ++- 10 files changed, 129 insertions(+), 106 deletions(-) diff --git a/README.rst b/README.rst index 64ef7c4..b7a16b8 100644 --- a/README.rst +++ b/README.rst @@ -36,7 +36,7 @@ Cookbooks The following cookbooks are dependencies: -- 'apache2', '~> 8.1' +- 'apache2', '~> 8.6' - 'openstack-common', '>= 20.0.0' - 'openstack-identity', '>= 20.0.0' diff --git a/attributes/default.rb b/attributes/default.rb index 888c579..ef515c1 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -111,8 +111,8 @@ when 'rhel' default['openstack']['dashboard']['logout_url'] = "#{node['openstack']['dashboard']['webroot']}auth/logout/" default['openstack']['dashboard']['login_redirect_url'] = node['openstack']['dashboard']['webroot'] default['openstack']['dashboard']['platform'] = { - 'horizon_packages' => %w(openstack-dashboard mod_wsgi), - 'memcache_python_packages' => %w(python-memcached), + 'horizon_packages' => %w(openstack-dashboard), + 'memcache_python_packages' => node['platform_version'].to_i >= 8 ? %w(python3-memcached) : %w(python-memcached), 'package_overrides' => '', } when 'debian' @@ -133,7 +133,6 @@ when 'debian' default['openstack']['dashboard']['platform']['horizon_packages'] = %w( node-less - libapache2-mod-wsgi-py3 python3-django-horizon openstack-dashboard ) diff --git a/metadata.rb b/metadata.rb index cf6f1bf..71f3624 100644 --- a/metadata.rb +++ b/metadata.rb @@ -9,7 +9,7 @@ version '20.0.0' supports os end -depends 'apache2', '~> 8.1' +depends 'apache2', '~> 8.6' depends 'openstack-common', '>= 20.0.0' depends 'openstack-identity', '>= 20.0.0' diff --git a/recipes/apache2-server.rb b/recipes/apache2-server.rb index 612784a..f301596 100644 --- a/recipes/apache2-server.rb +++ b/recipes/apache2-server.rb @@ -61,7 +61,7 @@ else end end -apache2_module 'wsgi' +apache2_mod_wsgi 'dashboard' apache2_module 'rewrite' apache2_module 'headers' apache2_module 'ssl' if node['openstack']['dashboard']['use_ssl'] diff --git a/spec/apache2-server-redhat_spec.rb b/spec/apache2-server-redhat_spec.rb index 15bf269..6bb03bc 100644 --- a/spec/apache2-server-redhat_spec.rb +++ b/spec/apache2-server-redhat_spec.rb @@ -1,67 +1,69 @@ require_relative 'spec_helper' describe 'openstack-dashboard::apache2-server' do - describe 'redhat' do - let(:runner) { ChefSpec::SoloRunner.new(REDHAT_OPTS) } - let(:node) { runner.node } - cached(:chef_run) do - runner.converge(described_recipe) - end - include_context 'dashboard_stubs' - include_context 'redhat_stubs' + ALL_RHEL.each do |p| + context "redhat #{p[:version]}" do + let(:runner) { ChefSpec::SoloRunner.new(p) } + let(:node) { runner.node } + cached(:chef_run) do + runner.converge(described_recipe) + end + include_context 'dashboard_stubs' + include_context 'redhat_stubs' - describe 'certs' do - describe 'get secret' do - let(:pem) { chef_run.file('/etc/pki/tls/certs/horizon.pem') } - let(:key) { chef_run.file('/etc/pki/tls/private/horizon.key') } + describe 'certs' do + describe 'get secret' do + let(:pem) { chef_run.file('/etc/pki/tls/certs/horizon.pem') } + let(:key) { chef_run.file('/etc/pki/tls/private/horizon.key') } - it 'create files and restarts apache' do - expect(chef_run).to create_file('/etc/pki/tls/certs/horizon.pem').with( - user: 'root', - group: 'root', - mode: '644' - ) - expect(chef_run).to create_file('/etc/pki/tls/private/horizon.key').with( - user: 'root', - group: 'root', - mode: '640' - ) - end - - context 'does not mess with certs if ssl not enabled' do - cached(:chef_run) do - node.override['openstack']['dashboard']['use_ssl'] = false - runner.converge(described_recipe) + it 'create files and restarts apache' do + expect(chef_run).to create_file('/etc/pki/tls/certs/horizon.pem').with( + user: 'root', + group: 'root', + mode: '644' + ) + expect(chef_run).to create_file('/etc/pki/tls/private/horizon.key').with( + user: 'root', + group: 'root', + mode: '640' + ) end - it do - expect(chef_run).not_to create_file('/etc/ssl/certs/horizon.pem') - expect(chef_run).not_to create_file('/etc/pki/tls/private/horizon.key') + + context 'does not mess with certs if ssl not enabled' do + cached(:chef_run) do + node.override['openstack']['dashboard']['use_ssl'] = false + runner.converge(described_recipe) + end + it do + expect(chef_run).not_to create_file('/etc/ssl/certs/horizon.pem') + expect(chef_run).not_to create_file('/etc/pki/tls/private/horizon.key') + end end end end - end - it 'deletes openstack-dashboard.conf' do - file = '/etc/httpd/conf.d/openstack-dashboard.conf' - expect(chef_run).to delete_file(file) - end + it 'deletes openstack-dashboard.conf' do + file = '/etc/httpd/conf.d/openstack-dashboard.conf' + expect(chef_run).to delete_file(file) + end - it do - expect(chef_run).to_not disable_apache2_site('000-default') - end + it do + expect(chef_run).to_not disable_apache2_site('000-default') + end - it do - expect(chef_run).to disable_apache2_site('default') - end + it do + expect(chef_run).to disable_apache2_site('default') + end - it 'sets the WSGI daemon user to attribute default' do - file = chef_run.template('/etc/httpd/sites-available/openstack-dashboard.conf') - expect(chef_run).to render_file(file.name).with_content('WSGIDaemonProcess dashboard user=apache') - end + it 'sets the WSGI daemon user to attribute default' do + file = chef_run.template('/etc/httpd/sites-available/openstack-dashboard.conf') + expect(chef_run).to render_file(file.name).with_content('WSGIDaemonProcess dashboard user=apache') + end - it 'has correct ownership on file with attribute defaults' do - file = chef_run.file('/usr/share/openstack-dashboard/openstack_dashboard/local/.secret_key_store') - expect(file.owner).to eq('apache') - expect(file.group).to eq('apache') + it 'has correct ownership on file with attribute defaults' do + file = chef_run.file('/usr/share/openstack-dashboard/openstack_dashboard/local/.secret_key_store') + expect(file.owner).to eq('apache') + expect(file.group).to eq('apache') + end end end end diff --git a/spec/apache2-server_spec.rb b/spec/apache2-server_spec.rb index 69df2b3..7c7c059 100644 --- a/spec/apache2-server_spec.rb +++ b/spec/apache2-server_spec.rb @@ -79,7 +79,7 @@ describe 'openstack-dashboard::apache2-server' do end it 'enables apache modules' do - expect(chef_run).to enable_apache2_module('wsgi') + expect(chef_run).to create_apache2_mod_wsgi 'dashboard' expect(chef_run).to enable_apache2_module('rewrite') expect(chef_run).to enable_apache2_module('headers') end diff --git a/spec/horizon-redhat_spec.rb b/spec/horizon-redhat_spec.rb index 278dc55..32574ae 100644 --- a/spec/horizon-redhat_spec.rb +++ b/spec/horizon-redhat_spec.rb @@ -1,44 +1,53 @@ require_relative 'spec_helper' describe 'openstack-dashboard::horizon' do - describe 'redhat' do - let(:runner) { ChefSpec::SoloRunner.new(REDHAT_OPTS) } - let(:node) { runner.node } - cached(:chef_run) do - runner.converge('openstack-identity::server-apache', described_recipe) - end - - include_context 'dashboard_stubs' - include_context 'redhat_stubs' - - it 'installs packages' do - expect(chef_run).to upgrade_package %w(openstack-dashboard mod_wsgi MySQL-python) - end - - describe 'local_settings' do - let(:file) { chef_run.template('/etc/openstack-dashboard/local_settings') } - - it 'creates local_settings' do - expect(chef_run).to create_template(file.name).with( - user: 'root', - group: 'apache', - mode: '640' - ) + ALL_RHEL.each do |p| + context "redhat #{p[:version]}" do + let(:runner) { ChefSpec::SoloRunner.new(p) } + let(:node) { runner.node } + cached(:chef_run) do + runner.converge('openstack-identity::server-apache', described_recipe) end - it 'has urls set' do - [ - %r{^LOGIN_URL = '/auth/login/'$}, - %r{^LOGOUT_URL = '/auth/logout/'$}, - %r{^LOGIN_REDIRECT_URL = '/'$}, - ].each do |line| - expect(chef_run).to render_file(file.name).with_content(line) + include_context 'dashboard_stubs' + include_context 'redhat_stubs' + + case p + when REDHAT_7 + it 'installs packages' do + expect(chef_run).to upgrade_package %w(openstack-dashboard MySQL-python) + end + when REDHAT_8 + it 'installs packages' do + expect(chef_run).to upgrade_package %w(openstack-dashboard python3-PyMySQL) end end - it 'has policy file path set' do - expect(chef_run).to render_file(file.name) - .with_content(%r{^POLICY_FILES_PATH = '/etc/openstack-dashboard'$}) + describe 'local_settings' do + let(:file) { chef_run.template('/etc/openstack-dashboard/local_settings') } + + it 'creates local_settings' do + expect(chef_run).to create_template(file.name).with( + user: 'root', + group: 'apache', + mode: '640' + ) + end + + it 'has urls set' do + [ + %r{^LOGIN_URL = '/auth/login/'$}, + %r{^LOGOUT_URL = '/auth/logout/'$}, + %r{^LOGIN_REDIRECT_URL = '/'$}, + ].each do |line| + expect(chef_run).to render_file(file.name).with_content(line) + end + end + + it 'has policy file path set' do + expect(chef_run).to render_file(file.name) + .with_content(%r{^POLICY_FILES_PATH = '/etc/openstack-dashboard'$}) + end end end end diff --git a/spec/horizon_spec.rb b/spec/horizon_spec.rb index 5e92b0b..2d03c0b 100644 --- a/spec/horizon_spec.rb +++ b/spec/horizon_spec.rb @@ -57,7 +57,7 @@ describe 'openstack-dashboard::horizon' do include_context 'dashboard_stubs' it 'installs packages' do - expect(chef_run).to upgrade_package %w(node-less libapache2-mod-wsgi-py3 python3-django-horizon openstack-dashboard python3-mysqldb) + expect(chef_run).to upgrade_package %w(node-less python3-django-horizon openstack-dashboard python3-mysqldb) end describe 'local_settings.py' do diff --git a/spec/neutron-lbaas-dashboard-redhat_spec.rb b/spec/neutron-lbaas-dashboard-redhat_spec.rb index 1638c77..d7e455a 100644 --- a/spec/neutron-lbaas-dashboard-redhat_spec.rb +++ b/spec/neutron-lbaas-dashboard-redhat_spec.rb @@ -1,22 +1,24 @@ require_relative 'spec_helper' describe 'openstack-dashboard::neutron-lbaas-dashboard' do - describe 'redhat' do - cached(:runner) { ChefSpec::SoloRunner.new(REDHAT_OPTS) } - cached(:node) { runner.node } - cached(:chef_run) do - runner.converge('openstack-identity::server-apache', described_recipe) - end + ALL_RHEL.each do |p| + context "redhat #{p[:version]}" do + cached(:runner) { ChefSpec::SoloRunner.new(p) } + cached(:node) { runner.node } + cached(:chef_run) do + runner.converge('openstack-identity::server-apache', described_recipe) + end - include_context 'redhat_stubs' - include_context 'dashboard_stubs' + include_context 'redhat_stubs' + include_context 'dashboard_stubs' - it do - expect(chef_run).to include_recipe('openstack-dashboard::horizon') - end + it do + expect(chef_run).to include_recipe('openstack-dashboard::horizon') + end - it do - expect(chef_run).to install_package('openstack-neutron-lbaas-ui') + it do + expect(chef_run).to install_package('openstack-neutron-lbaas-ui') + end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 256b8d3..93ffd53 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,10 +7,21 @@ RSpec.configure do |config| config.log_level = :warn end -REDHAT_OPTS = { +REDHAT_7 = { platform: 'redhat', version: '7', }.freeze + +REDHAT_8 = { + platform: 'redhat', + version: '8', +}.freeze + +ALL_RHEL = [ + REDHAT_7, + REDHAT_8, +].freeze + UBUNTU_OPTS = { platform: 'ubuntu', version: '18.04',