Add support for independent manila-dashboard configurations

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

Change-Id: Ie1442d34b6837ced5f44018d038d4d716d568655
This commit is contained in:
Takashi Kajinami 2021-05-09 11:14:01 +09:00
parent c29622ee45
commit a7d71fb37d
5 changed files with 226 additions and 0 deletions

View File

@ -0,0 +1,93 @@
#
# 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::manila
#
# Manage parameters of manila-dashboard
#
# === Parameters:
#
# [*policy_file*]
# (optional) Local copy of service policy files.
# Defaults to 'manila_policy.yaml'
#
# [*manila_options*]
# (optional) A hash of parameters to enable features specific to Manila.
# These include;
# 'enable_share_groups': Boolean
# 'enable_replication': Boolean
# 'enable_migration': Boolean
# 'enable_public_share_type_creation': Boolean
# 'enable_public_share_group_type_creation': Boolean
# 'enable_public_shares': Boolean
# 'enabled_share_protocols': Array
#
class horizon::dashboards::manila(
$policy_file = 'manila_policy.yaml',
$manila_options = {}
) {
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::manila class')
}
$log_handlers = $::horizon::log_handlers
$log_level = $::horizon::log_level
$policy_files = $::horizon::policy_files
if $policy_files and $policy_files['share'] {
$policy_file_real = $policy_files['share']
} else {
$policy_file_real = $policy_file
}
# Default options for the OPENSTACK_MANILA_FEATURES section. These will
# be merged with user-provided options when the _90_manila_shares.py.erb
# template is interpolated.
$manila_defaults = {
'enable_share_groups' => true,
'enable_replication' => true,
'enable_migration' => true,
'enable_public_share_type_creation' => true,
'enable_public_share_group_type_creation' => true,
'enable_public_shares' => true,
'enabled_share_protocols' => ['NFS', 'CIFS', 'GlusterFS', 'HDFS', 'CephFS', 'MapRFS'],
}
$manila_options_real = merge($manila_defaults, $manila_options)
$config_file = "${::horizon::params::conf_d_dir}/_90_manila_shares.py"
package { 'manila-dashboard':
ensure => $::horizon::package_ensure,
name => $::horizon::params::manila_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 { '_90_manila_shares.py':
target => $config_file,
content => template('horizon/_90_manila_shares.py.erb'),
order => '50',
}
}

View File

@ -26,6 +26,7 @@ class horizon::params {
$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'
}
'Debian': {
@ -42,6 +43,7 @@ class horizon::params {
$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'
case $::os_package_type {
'debian': {

View File

@ -0,0 +1,5 @@
---
features:
- |
The new ``horizon::dashboards::manila`` class has been added. This class
can be used to manage parameters for manila-dashboard.

View File

@ -0,0 +1,72 @@
require 'spec_helper'
describe 'horizon::dashboards::manila' do
let :params do
{}
end
shared_examples_for 'horizon::dashboards::manila' do
context 'with default parameters' do
let(:pre_condition) do
<<-eos
class { 'horizon':
secret_key => 'elj1IWiLoWHgcyYxFVLj7cM5rGOOxWl0',
}
eos
end
it 'installs manila-dashboard package' do
is_expected.to contain_package('manila-dashboard').with(
:ensure => 'present',
:name => platform_params[:manila_dashboard_package_name],
:tag => ['openstack', 'horizon-package']
)
end
it 'generates _90_manila_shares.py' do
verify_concat_fragment_contents(catalogue, '_90_manila_shares.py', [
"settings.POLICY_FILES.update({",
" 'share': 'manila_policy.yaml',",
"})"
])
verify_concat_fragment_contents(catalogue, '_90_manila_shares.py', [
" 'enable_share_groups': True,",
" 'enable_replication': True,",
" 'enable_migration': True,",
" 'enable_public_share_type_creation': True,",
" 'enable_public_share_group_type_creation': True,",
" 'enable_public_shares': True,",
" 'enabled_share_protocols': ['NFS', 'CIFS', 'GlusterFS', 'HDFS', 'CephFS', 'MapRFS'],",
])
end
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'
{ :manila_dashboard_package_name => 'python3-manila-dashboard' }
when 'RedHat'
{ :manila_dashboard_package_name => 'openstack-manila-ui' }
end
end
it_behaves_like 'horizon::dashboards::manila'
end
end
end

View File

@ -0,0 +1,54 @@
from django.conf import settings
settings.POLICY_FILES.update({
'share': '<%= @policy_file_real %>',
})
settings.DEFAULT_POLICY_FILES.update({
'share': 'default_policies/manila.yaml',
})
# Sample
# settings.LOGGING['loggers'].update({
# 'manilaclient': {
# 'handlers': ['console'],
# 'level': 'DEBUG',
# 'propagate': False,
# }
# })
settings.LOGGING['loggers'].update({
'manilaclient': {
# 'handlers': ['console'],
'handlers': ['<%= @log_handlers.join("', '") %>']
# level': 'DEBUG',
'level': '<%= @log_level %>',
'propagate': False,
}
})
# The OPENSTACK_MANILA_FEATURES settings can be used to enable or disable
# the UI for the various services provided by Manila.
#OPENSTACK_MANILA_FEATURES = {
# 'enable_share_groups': True,
# 'enable_replication': True,
# 'enable_migration': True,
# 'enable_public_share_type_creation': True,
# 'enable_public_share_group_type_creation': True,
# 'enable_public_shares': True,
# 'enabled_share_protocols': ['NFS', 'CIFS', 'GlusterFS', 'HDFS', 'CephFS',
# 'MapRFS'],
#}
<%- if ! (@manila_options_real.empty?) -%>
OPENSTACK_MANILA_FEATURES = {
<%- @manila_options_real.sort.each do |opt_name,opt_val| -%>
<%- if opt_val == true or opt_val == false -%>
'<%= opt_name -%>': <%= opt_val.to_s.capitalize -%>,
<%- elsif opt_val.kind_of?(Array) -%>
'<%= opt_name -%>': ['<%= opt_val.join("', '") %>'],
<%- else -%>
'<%= opt_name -%>': '<%= opt_val -%>',
<%-end-%>
<%-end-%>
}
<%-end-%>