From 382877dd4c8ee321eff1846c7c7afe4104dbd58f Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Fri, 12 Feb 2021 16:28:49 +0900 Subject: [PATCH] Add support for independent heat-dashboard configurations Currently horizon supports per-dashboard configurations in /etc/openstack-dashboard/local_settings.d. Each dashboard plugin provides a specific file to define its parameters, and any parameters used in dashboard plugins have been removed from the base local_settings(.py) in horizon repo. To follow how each plugin is supposed to have its configurations managed, this change introduces an independent file for heat-dashboard. Support for the other dashboards like manila-ui, octavia-ui, and etc will be added later. Change-Id: I5999c2eaf8d7788d3c0d76e69a56a0b10058dfe9 --- manifests/dashboards/heat.pp | 74 +++++++++++++++ manifests/init.pp | 28 ++++-- manifests/params.pp | 6 ++ .../heat-dashboard-c34cea1d256164cd.yaml | 10 +++ spec/classes/horizon_dashboards_heat_spec.rb | 90 +++++++++++++++++++ spec/classes/horizon_init_spec.rb | 20 +---- templates/_1699_orchestration_settings.py.erb | 38 ++++++++ templates/local_settings.py.erb | 20 ----- 8 files changed, 243 insertions(+), 43 deletions(-) create mode 100644 manifests/dashboards/heat.pp create mode 100644 releasenotes/notes/heat-dashboard-c34cea1d256164cd.yaml create mode 100644 spec/classes/horizon_dashboards_heat_spec.rb create mode 100644 templates/_1699_orchestration_settings.py.erb diff --git a/manifests/dashboards/heat.pp b/manifests/dashboards/heat.pp new file mode 100644 index 00000000..5de7b8b4 --- /dev/null +++ b/manifests/dashboards/heat.pp @@ -0,0 +1,74 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# == Class: horizon::dashboards::heat +# +# Manage parameters of heat-dashboard +# +# === Parameters: +# +# [*enable_user_pass*] +# (optional) Enable the password field while launching a Heat stack. +# Defaults to true +# +# [*policy_file*] +# (optional) Local copy of service policy files. +# Defaults to 'heat_policy.yaml' +# +class horizon::dashboards::heat( + $enable_user_pass = true, + $policy_file = 'heat_policy.yaml', +) { + + include horizon::deps + include horizon::params + + # The horizon class should be included so that some common parameters + # can be picked here. + if ! defined(Class[horizon]) { + fail('The horizon class should be included before the horizon::dashboards::heat class') + } + $log_handlers = $::horizon::log_handlers + $log_level = $::horizon::log_level + $policy_files = $::horizon::policy_files + + if $policy_files and $policy_files['orchestration'] { + $policy_file_real = $policy_files['orchestration'] + } else { + $policy_file_real = $policy_file + } + + $enable_user_pass_real = pick($::horizon::enable_user_pass, $enable_user_pass) + + $config_file = "${::horizon::params::conf_d_dir}/_1699_orchestration_settings.py" + + package { 'heat-dashboard': + ensure => $::horizon::package_ensure, + name => $::horizon::params::heat_dashboard_package_name, + tag => ['openstack', 'horizon-package'], + } + + concat { $config_file: + mode => '0640', + owner => $::horizon::params::wsgi_user, + group => $::horizon::params::wsgi_group, + require => File[$::horizon::params::conf_d_dir], + tag => ['django-config'], + } + + concat::fragment { '_1699_orchestration_settings.py': + target => $config_file, + content => template('horizon/_1699_orchestration_settings.py.erb'), + order => '50', + } +} diff --git a/manifests/init.pp b/manifests/init.pp index 0869c80e..b6941187 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -484,10 +484,6 @@ # [*password_validator_help*] # (optional) Help text to display when password validation fails in horizon. # -# [*enable_user_pass*] -# (optional) Enable the password field while launching a Heat stack. -# Defaults to true -# # [*customization_module*] # (optional) Horizon has a global override mechanism available to perform # customizations. This adds a key - customization_module - to HORIZON_CONFIG @@ -515,6 +511,10 @@ # [*horizon_ca*] # (required with listen_ssl) CA certificate to use for SSL support. # +# [*enable_user_pass*] +# (optional) Enable the password field while launching a Heat stack. +# Defaults to undef +# # === Examples # # class { 'horizon': @@ -616,17 +616,22 @@ class horizon( $websso_default_redirect_logout = undef, $password_validator = undef, $password_validator_help = undef, - $enable_user_pass = true, $customization_module = undef, $horizon_upload_mode = undef, # DEPRECATED PARAMETERS $horizon_cert = undef, $horizon_key = undef, $horizon_ca = undef, + $enable_user_pass = undef, ) inherits horizon::params { include horizon::deps + if $enable_user_pass != undef { + warning('The enable_user_pass parameter is deprecated. Use the horizon::dashboards::heat class') + include horizon::dashboards::heat + } + if $cache_server_url and $cache_server_ip { fail('Only one of cache_server_url or cache_server_ip can be set.') } @@ -714,6 +719,7 @@ class horizon( owner => $::horizon::params::wsgi_user, group => $::horizon::params::wsgi_group, require => Anchor['horizon::config::begin'], + tag => ['django-config'], } concat::fragment { 'local_settings.py': @@ -722,6 +728,14 @@ class horizon( order => '50', } + file { $::horizon::params::conf_d_dir: + ensure => 'directory', + mode => '0755', + owner => $::horizon::params::wsgi_user, + group => $::horizon::params::wsgi_group, + require => Anchor['horizon::config::begin'], + } + exec { 'refresh_horizon_django_cache': command => "${::horizon::params::manage_py} collectstatic --noinput --clear", refreshonly => true, @@ -735,9 +749,9 @@ class horizon( } if $compress_offline { - Concat[$::horizon::params::config_file] ~> Exec['refresh_horizon_django_compress'] + Concat<| tag == 'django-config' |> ~> Exec['refresh_horizon_django_compress'] if $::os_package_type == 'rpm' { - Concat[$::horizon::params::config_file] ~> Exec['refresh_horizon_django_cache'] -> Exec['refresh_horizon_django_compress'] + Concat<| tag == 'django-config' |> ~> Exec['refresh_horizon_django_cache'] -> Exec['refresh_horizon_django_compress'] } } diff --git a/manifests/params.pp b/manifests/params.pp index abd2286f..9dfceed3 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -13,6 +13,8 @@ class horizon::params { $http_service = 'httpd' $http_modwsgi = 'mod_wsgi' $package_name = 'openstack-dashboard' + $config_dir = '/etc/openstack-dashboard' + $conf_d_dir = '/etc/openstack-dashboard/local_settings.d' $config_file = '/etc/openstack-dashboard/local_settings' $httpd_config_file = '/etc/httpd/conf.d/openstack-dashboard.conf' $httpd_listen_config_file = '/etc/httpd/conf/httpd.conf' @@ -23,9 +25,12 @@ class horizon::params { $wsgi_user = 'apache' $wsgi_group = 'apache' $memcache_package = 'python3-memcached' + $heat_dashboard_package_name = 'openstack-heat-ui' } 'Debian': { $http_service = 'apache2' + $config_dir = '/etc/openstack-dashboard' + $conf_d_dir = '/etc/openstack-dashboard/local_settings.d' $config_file = '/etc/openstack-dashboard/local_settings.py' $httpd_listen_config_file = '/etc/apache2/ports.conf' $root_url = '/horizon' @@ -35,6 +40,7 @@ class horizon::params { $wsgi_user = 'horizon' $wsgi_group = 'horizon' $memcache_package = 'python3-memcache' + $heat_dashboard_package_name = 'python3-heat-dashboard' case $::os_package_type { 'debian': { $package_name = 'openstack-dashboard-apache' diff --git a/releasenotes/notes/heat-dashboard-c34cea1d256164cd.yaml b/releasenotes/notes/heat-dashboard-c34cea1d256164cd.yaml new file mode 100644 index 00000000..640e22b2 --- /dev/null +++ b/releasenotes/notes/heat-dashboard-c34cea1d256164cd.yaml @@ -0,0 +1,10 @@ +--- +features: + - | + The new ``horizon::dashboards::heat`` class has been added. This class can + be used to manage parameters for heat-dashboard. + +deprecations: + - | + The ``horizon::enable_user_pass`` parameter has been deprecated. Use + the ``horizon::dashboards::heat`` class instead. diff --git a/spec/classes/horizon_dashboards_heat_spec.rb b/spec/classes/horizon_dashboards_heat_spec.rb new file mode 100644 index 00000000..f13b1114 --- /dev/null +++ b/spec/classes/horizon_dashboards_heat_spec.rb @@ -0,0 +1,90 @@ +require 'spec_helper' + +describe 'horizon::dashboards::heat' do + + let :params do + {} + end + + shared_examples_for 'horizon::dashboards::heat' do + + context 'with default parameters' do + let(:pre_condition) do + <<-eos + class { 'horizon': + secret_key => 'elj1IWiLoWHgcyYxFVLj7cM5rGOOxWl0', + } +eos + end + + it 'installs heat-dashboard package' do + is_expected.to contain_package('heat-dashboard').with( + :ensure => 'present', + :name => platform_params[:heat_dashboard_package_name], + :tag => ['openstack', 'horizon-package'] + ) + end + + it 'generates _1699_orchestration_settings.py' do + verify_concat_fragment_contents(catalogue, '_1699_orchestration_settings.py', [ + "settings.POLICY_FILES.update({", + " 'orchestration': 'heat_policy.yaml',", + "})" + ]) + verify_concat_fragment_contents(catalogue, '_1699_orchestration_settings.py', [ + "OPENSTACK_HEAT_STACK = {", + " 'enable_user_pass': True,", + "}", + ]) + end + end + + context 'with enable_user_pass disabled' do + let(:pre_condition) do + <<-eos + class { 'horizon': + secret_key => 'elj1IWiLoWHgcyYxFVLj7cM5rGOOxWl0', + } +eos + end + + before do + params.merge!({ :enable_user_pass => false }) + end + + it { + verify_concat_fragment_contents(catalogue, '_1699_orchestration_settings.py', [ + "OPENSTACK_HEAT_STACK = {", + " 'enable_user_pass': False,", + "}", + ]) + } + end + + context 'without the horizon class defined' do + it { should raise_error(Puppet::Error) } + 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 + + let(:platform_params) do + case facts[:osfamily] + when 'Debian' + { :heat_dashboard_package_name => 'python3-heat-dashboard' } + when 'RedHat' + { :heat_dashboard_package_name => 'openstack-heat-ui' } + end + end + + it_behaves_like 'horizon::dashboards::heat' + end + end + +end diff --git a/spec/classes/horizon_init_spec.rb b/spec/classes/horizon_init_spec.rb index 24286a78..c10f25b0 100644 --- a/spec/classes/horizon_init_spec.rb +++ b/spec/classes/horizon_init_spec.rb @@ -78,9 +78,6 @@ describe 'horizon' do " 'handlers': ['file'],", 'COMPRESS_OFFLINE = True', "FILE_UPLOAD_TEMP_DIR = '/tmp'", - "OPENSTACK_HEAT_STACK = {", - " 'enable_user_pass': True", - "}", ]) # From internals of verify_contents, get the contents to check for absence of a line @@ -212,25 +209,13 @@ describe 'horizon' do ]) end + it { is_expected.to contain_file(platforms_params[:conf_d_dir]).with_ensure('directory') } it { is_expected.not_to contain_file(platforms_params[:config_file]).that_notifies('Exec[refresh_horizon_django_cache]') } it { is_expected.not_to contain_file(platforms_params[:config_file]).that_notifies('Exec[refresh_horizon_django_compress]') } it { is_expected.to contain_file(params[:file_upload_temp_dir]) } end - context 'with enable_user_pass disabled' do - before do - params.merge!({ :enable_user_pass => false }) - end - it { - verify_concat_fragment_contents(catalogue, 'local_settings.py', [ - "OPENSTACK_HEAT_STACK = {", - " 'enable_user_pass': False", - "}", - ]) - } - end - context 'with overridden parameters and cache_server_ip array' do before do params.merge!({ @@ -767,6 +752,7 @@ describe 'horizon' do when 'Debian' if facts[:os_package_type] == 'debian' { :config_file => '/etc/openstack-dashboard/local_settings.py', + :conf_d_dir => '/etc/openstack-dashboard/local_settings.d', :package_name => 'openstack-dashboard-apache', :root_url => '/horizon', :root_path => '/var/lib/openstack-dashboard', @@ -774,6 +760,7 @@ describe 'horizon' do } else { :config_file => '/etc/openstack-dashboard/local_settings.py', + :conf_d_dir => '/etc/openstack-dashboard/local_settings.d', :package_name => 'openstack-dashboard', :root_url => '/horizon', :root_path => '/var/lib/openstack-dashboard', @@ -782,6 +769,7 @@ describe 'horizon' do end when 'RedHat' { :config_file => '/etc/openstack-dashboard/local_settings', + :conf_d_dir => '/etc/openstack-dashboard/local_settings.d', :package_name => 'openstack-dashboard', :root_url => '/dashboard', :root_path => '/usr/share/openstack-dashboard', diff --git a/templates/_1699_orchestration_settings.py.erb b/templates/_1699_orchestration_settings.py.erb new file mode 100644 index 00000000..f449a375 --- /dev/null +++ b/templates/_1699_orchestration_settings.py.erb @@ -0,0 +1,38 @@ +from django.conf import settings + + +OPENSTACK_HEAT_STACK = { + 'enable_user_pass': <%= @enable_user_pass_real.to_s.capitalize %>, +} + +settings.POLICY_FILES.update({ + 'orchestration': '<%= @policy_file_real %>', +}) + +settings.DEFAULT_POLICY_FILES.update({ + 'orchestration': 'default_policies/heat.yaml', +}) + +# Sample +# settings.LOGGING['loggers'].update({ +# 'heatclient': { +# 'handlers': ['console'], +# 'level': 'DEBUG', +# 'propagate': False, +# } +# }) +settings.LOGGING['loggers'].update({ + 'heatclient': { + # 'handlers': ['console'], + 'handlers': ['<%= @log_handlers.join("', '") %>'] + # level': 'DEBUG', + 'level': '<%= @log_level %>', + 'propagate': False, + } +}) + +# Template Generator retrieve options API TIMEOUT +HEAT_TEMPLATE_GENERATOR_API_TIMEOUT = 60 + +# Template Generator retrieve options API PARALLEL LEVEL +HEAT_TEMPLATE_GENERATOR_API_PARALLEL = 2 diff --git a/templates/local_settings.py.erb b/templates/local_settings.py.erb index 78ffb18e..0ad13347 100644 --- a/templates/local_settings.py.erb +++ b/templates/local_settings.py.erb @@ -529,19 +529,6 @@ OPENSTACK_NEUTRON_NETWORK = { } <%-end-%> -# The OPENSTACK_HEAT_STACK settings can be used to disable password -# field required while launching the stack. -#OPENSTACK_HEAT_STACK = { -# 'enable_user_pass': True, -#} -OPENSTACK_HEAT_STACK = { -<%- if @enable_user_pass -%> - 'enable_user_pass': True -<%- else -%> - 'enable_user_pass': False -<%- end -%> -} - # The OPENSTACK_IMAGE_BACKEND settings can be used to customize features # in the OpenStack Dashboard related to the Image service, such as the list # of supported image formats. @@ -835,13 +822,6 @@ LOGGING = { 'level': '<%= @log_level %>', 'propagate': False, }, - 'heatclient': { - # 'handlers': ['console'], - 'handlers': ['<%= @log_handlers.join("', '") %>'], - # 'level': 'DEBUG', - 'level': '<%= @log_level %>', - 'propagate': False, - }, 'swiftclient': { # 'handlers': ['console'], 'handlers': ['<%= @log_handlers.join("', '") %>'],