Add support for independent designate-dashboard configurations

This change introduces the new horizon::dashboards::designate class,
which allows users to manage the independent configuration file for
designate dashboard (_1799_dns_settings.py).

Depends-on: https://review.opendev.org/823238
Change-Id: Ie36d70b7b9fdde5f1ceb4be59cfb4f5c16981e7d
This commit is contained in:
Takashi Kajinami 2022-02-21 19:05:42 +09:00
parent 49a20369cb
commit 7577a23c65
6 changed files with 243 additions and 29 deletions

View File

@ -37,7 +37,7 @@ define horizon::dashboard (
$dashboard = downcase($name) $dashboard = downcase($name)
if $dashboard in ['heat', 'octavia', 'manila'] { if $dashboard in ['designate', 'heat', 'octavia', 'manila'] {
warning("Use the horizon::dashboard::${dashboard} class instead. \ warning("Use the horizon::dashboard::${dashboard} class instead. \
The class allows more flexible customization of the ${dashboard} dashboard.") The class allows more flexible customization of the ${dashboard} dashboard.")
} }

View File

@ -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,
}
}
}

View File

@ -22,6 +22,7 @@ class horizon::params {
$wsgi_user = 'apache' $wsgi_user = 'apache'
$wsgi_group = 'apache' $wsgi_group = 'apache'
$memcache_package = 'python3-memcached' $memcache_package = 'python3-memcached'
$designate_dashboard_package_name = 'openstack-designate-ui'
$heat_dashboard_package_name = 'openstack-heat-ui' $heat_dashboard_package_name = 'openstack-heat-ui'
$manila_dashboard_package_name = 'openstack-manila-ui' $manila_dashboard_package_name = 'openstack-manila-ui'
$octavia_dashboard_package_name = 'openstack-octavia-ui' $octavia_dashboard_package_name = 'openstack-octavia-ui'
@ -37,6 +38,7 @@ class horizon::params {
$wsgi_user = 'horizon' $wsgi_user = 'horizon'
$wsgi_group = 'horizon' $wsgi_group = 'horizon'
$memcache_package = 'python3-memcache' $memcache_package = 'python3-memcache'
$designate_dashboard_package_name = 'python3-designate-dashboard'
$heat_dashboard_package_name = 'python3-heat-dashboard' $heat_dashboard_package_name = 'python3-heat-dashboard'
$manila_dashboard_package_name = 'python3-manila-dashboard' $manila_dashboard_package_name = 'python3-manila-dashboard'
$octavia_dashboard_package_name = 'python3-octavia-dashboard' $octavia_dashboard_package_name = 'python3-octavia-dashboard'

View File

@ -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.

View File

@ -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

View File

@ -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',
})