diff --git a/manifests/dashboard.pp b/manifests/dashboard.pp index 41380459..2390d8ce 100644 --- a/manifests/dashboard.pp +++ b/manifests/dashboard.pp @@ -37,7 +37,7 @@ define horizon::dashboard ( $dashboard = downcase($name) - if $dashboard in ['heat', 'octavia', 'manila'] { + if $dashboard in ['designate', 'heat', 'octavia', 'manila'] { warning("Use the horizon::dashboard::${dashboard} class instead. \ The class allows more flexible customization of the ${dashboard} dashboard.") } diff --git a/manifests/dashboards/designate.pp b/manifests/dashboards/designate.pp new file mode 100644 index 00000000..b761e28d --- /dev/null +++ b/manifests/dashboards/designate.pp @@ -0,0 +1,88 @@ +# +# 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::designate +# +# Manage parameters of designate-dashboard +# +# === Parameters: +# +# [*policy_file*] +# (optional) Local copy of service policy files. +# Defaults to 'designate_policy.yaml' +# +# [*policies*] +# (optional) Set of policies to configure. +# Defaults to undef +# +class horizon::dashboards::designate( + $policy_file = 'designate_policy.yaml', + $policies = undef, +) { + + 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::designate class') + } + + $log_handlers = $::horizon::log_handlers + $log_level = $::horizon::log_level + $policy_files = $::horizon::policy_files + + if $policy_files and $policy_files['load-balancer'] { + $policy_file_real = $policy_files['load-balancer'] + } else { + $policy_file_real = $policy_file + } + + $config_file = "${::horizon::params::conf_d_dir}/_1799_dns_settings.py" + + package { 'designate-dashboard': + ensure => $::horizon::package_ensure, + name => $::horizon::params::designate_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 { '_1799_dns_settings.py': + target => $config_file, + content => template('horizon/_1799_dns_settings.py.erb'), + order => '50', + } + + if $policies != undef { + # The horizon::policy class should be included so that some common + # parameters about policy management can be picked here + if !defined(Class[horizon::policy]){ + fail('The horizon::policy class should be include in advance to customize policies') + } + + horizon::policy::base { $policy_file_real: + policies => $policies, + file_mode => $::horizon::policy::file_mode, + file_format => $::horizon::policy::file_format, + purge_config => $::horizon::policy::purge_config, + } + } +} diff --git a/manifests/params.pp b/manifests/params.pp index 5b9c0a96..8dbeb176 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -10,36 +10,38 @@ class horizon::params { case $::osfamily { 'RedHat': { - $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' - $policy_dir = '/etc/openstack-dashboard' - $httpd_config_file = '/etc/httpd/conf.d/openstack-dashboard.conf' - $httpd_listen_config_file = '/etc/httpd/conf/httpd.conf' - $root_url = '/dashboard' - $static_path = '/usr/share' - $wsgi_user = 'apache' - $wsgi_group = 'apache' - $memcache_package = 'python3-memcached' - $heat_dashboard_package_name = 'openstack-heat-ui' - $manila_dashboard_package_name = 'openstack-manila-ui' - $octavia_dashboard_package_name = 'openstack-octavia-ui' + $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' + $policy_dir = '/etc/openstack-dashboard' + $httpd_config_file = '/etc/httpd/conf.d/openstack-dashboard.conf' + $httpd_listen_config_file = '/etc/httpd/conf/httpd.conf' + $root_url = '/dashboard' + $static_path = '/usr/share' + $wsgi_user = 'apache' + $wsgi_group = 'apache' + $memcache_package = 'python3-memcached' + $designate_dashboard_package_name = 'openstack-designate-ui' + $heat_dashboard_package_name = 'openstack-heat-ui' + $manila_dashboard_package_name = 'openstack-manila-ui' + $octavia_dashboard_package_name = 'openstack-octavia-ui' } 'Debian': { - $config_dir = '/etc/openstack-dashboard' - $conf_d_dir = '/etc/openstack-dashboard/local_settings.d' - $config_file = '/etc/openstack-dashboard/local_settings.py' - $policy_dir = undef - $httpd_listen_config_file = '/etc/apache2/ports.conf' - $root_url = '/horizon' - $static_path = '/var/lib' - $wsgi_user = 'horizon' - $wsgi_group = 'horizon' - $memcache_package = 'python3-memcache' - $heat_dashboard_package_name = 'python3-heat-dashboard' - $manila_dashboard_package_name = 'python3-manila-dashboard' - $octavia_dashboard_package_name = 'python3-octavia-dashboard' + $config_dir = '/etc/openstack-dashboard' + $conf_d_dir = '/etc/openstack-dashboard/local_settings.d' + $config_file = '/etc/openstack-dashboard/local_settings.py' + $policy_dir = undef + $httpd_listen_config_file = '/etc/apache2/ports.conf' + $root_url = '/horizon' + $static_path = '/var/lib' + $wsgi_user = 'horizon' + $wsgi_group = 'horizon' + $memcache_package = 'python3-memcache' + $designate_dashboard_package_name = 'python3-designate-dashboard' + $heat_dashboard_package_name = 'python3-heat-dashboard' + $manila_dashboard_package_name = 'python3-manila-dashboard' + $octavia_dashboard_package_name = 'python3-octavia-dashboard' case $::operatingsystem { 'Debian': { $package_name = 'openstack-dashboard-apache' diff --git a/releasenotes/notes/designate-dashboard-db1a2ec4621c61e3.yaml b/releasenotes/notes/designate-dashboard-db1a2ec4621c61e3.yaml new file mode 100644 index 00000000..226ee83e --- /dev/null +++ b/releasenotes/notes/designate-dashboard-db1a2ec4621c61e3.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + The new ``horizon::dashboards::designate`` class has been added. This class + can be used to manage parameters for designate-dashboard. diff --git a/spec/classes/horizon_dashboards_designate_spec.rb b/spec/classes/horizon_dashboards_designate_spec.rb new file mode 100644 index 00000000..07c1524c --- /dev/null +++ b/spec/classes/horizon_dashboards_designate_spec.rb @@ -0,0 +1,109 @@ +require 'spec_helper' + +describe 'horizon::dashboards::designate' do + + let :params do + {} + end + + shared_examples_for 'horizon::dashboards::designate' do + + context 'with default parameters' do + let(:pre_condition) do + <<-eos + class { 'horizon': + secret_key => 'elj1IWiLoWHgcyYxFVLj7cM5rGOOxWl0', + } +eos + end + + it 'installs designate-dashboard package' do + is_expected.to contain_package('designate-dashboard').with( + :ensure => 'present', + :name => platform_params[:designate_dashboard_package_name], + :tag => ['openstack', 'horizon-package'] + ) + end + + it 'generates _1799_dns_settings.py' do + verify_concat_fragment_contents(catalogue, '_1799_dns_settings.py', [ + "settings.POLICY_FILES.update({", + " 'dns': 'designate_policy.yaml',", + "})" + ]) + end + end + + context 'without the horizon class defined' do + it { should raise_error(Puppet::Error) } + end + + context 'with policy customization' do + let(:pre_condition) do + <<-eos + class { 'horizon': + secret_key => 'elj1IWiLoWHgcyYxFVLj7cM5rGOOxWl0', + policy_files_path => '/etc/openstack-dashboard', + } + class { 'horizon::policy': } +eos + end + + before do + params.merge!({ + :policies => {} + }) + end + + it 'configures policy' do + is_expected.to contain_horizon__policy__base('designate_policy.yaml').with( + :policies => {}, + :file_mode => '0640', + :file_format => 'yaml', + :purge_config => false, + ) + end + end + + context 'with policy customization but without the horizon::policy class' do + let(:pre_condition) do + <<-eos + class { 'horizon': + secret_key => 'elj1IWiLoWHgcyYxFVLj7cM5rGOOxWl0', + policy_files_path => '/etc/openstack-dashboard', + } +eos + end + + before do + params.merge!({ + :policies => {} + }) + end + + 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' + { :designate_dashboard_package_name => 'python3-designate-dashboard' } + when 'RedHat' + { :designate_dashboard_package_name => 'openstack-designate-ui' } + end + end + + it_behaves_like 'horizon::dashboards::designate' + end + end + +end diff --git a/templates/_1799_dns_settings.py.erb b/templates/_1799_dns_settings.py.erb new file mode 100644 index 00000000..4b00bce6 --- /dev/null +++ b/templates/_1799_dns_settings.py.erb @@ -0,0 +1,10 @@ +from django.conf import settings + + +settings.POLICY_FILES.update({ + 'dns': '<%= @policy_file_real %>', +}) + +settings.DEFAULT_POLICY_FILES.update({ + 'dns': 'default_policies/designate.yaml', +})