Create a separate class for [swift-constraints] options

... and improve support coverage of these options.

Change-Id: I4f4f45a37cb2371451bca713d7df340de1b1448c
This commit is contained in:
Takashi Kajinami 2022-08-22 16:52:51 +09:00
parent 428d620c7f
commit 7d220dd934
6 changed files with 232 additions and 11 deletions

121
manifests/constraints.pp Normal file
View File

@ -0,0 +1,121 @@
#
# Copyright (C) 2022 Red Hat
#
# 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: swift::constraints
#
# Configre the [swift-constraints] options
#
# == Parameters
#
# [*max_file_size*]
# (Optional) The largest "normal" object that can be saved in the cluster.
# Defaults to $::os_service_default
#
# [*max_meta_name_length*]
# (Optional) Max number of bytes in the utf8 encoding of the name portion of
# a metadata header.
# Defaults to $::os_service_default
#
# [*max_meta_value_length*]
# (Optional) Max number of bytes in the utf8 encoding of a metadata value.
# Defaults to $::os_service_default
#
# [*max_meta_count*]
# (Optional) Max number of metadata keys that can be store on a single
# account, container or object.
# Defaults to $::os_service_default
#
# [*max_meta_overall_size*]
# (Optional) The max number of bytes in the utf8 encoding of the metadata.
# Defaults to $::os_service_default
#
# [*max_header_size*]
# (Optional) Max HTTP header size for incoming requests for all swift
# services.
# Defaults to $::os_service_default
#
# [*extra_header_count*]
# (Optional) Allow additional headers in addition to max allowed metadata
# plus a default value of 36 for swift internally generated headers and
# regular http headers.
# Defaults to $::os_service_default
#
# [*max_object_name_length*]
# (Optional) Max number of bytes in the utf8 encoding of an object name.
# Defaults to $::os_service_default
#
# [*container_listing_limit*]
# (Optional) Default (and max) number of items returned for a container
# listing request.
# Defaults to $::os_service_default
#
# [*account_listing_limit*]
# (Optional) Default (and max) number of items returned for an account
# listing request.
# Defaults to $::os_service_default
#
# [*max_account_name_length*]
# (Optional) Max number of bytes in the utf8 encoding of an account name.
# Defaults to $::os_service_default
#
# [*max_container_name_length*]
# (Optional) Max number of bytes in the utf8 encoding of a container name.
# Defaults to $::os_service_default
#
# [*valid_api_versions*]
# (Optional) Allowed version strings for all REST API calls.
# Defaults to $::os_service_default
#
# [*auto_create_account_prefix*]
# (Optional) Prefix used for hiddne auto-created accounts.
# Defaults to $::os_service_default
#
class swift::constraints(
$max_file_size = $::os_service_default,
$max_meta_name_length = $::os_service_default,
$max_meta_value_length = $::os_service_default,
$max_meta_count = $::os_service_default,
$max_meta_overall_size = $::os_service_default,
$max_header_size = $::os_service_default,
$extra_header_count = $::os_service_default,
$max_object_name_length = $::os_service_default,
$container_listing_limit = $::os_service_default,
$account_listing_limit = $::os_service_default,
$max_account_name_length = $::os_service_default,
$max_container_name_length = $::os_service_default,
$valid_api_versions = $::os_service_default,
$auto_create_account_prefix = $::os_service_default,
) {
include swift::deps
include swift::params
swift_config {
'swift-constraints/max_file_size': value => $max_file_size;
'swift-constraints/max_meta_name_length': value => $max_meta_name_length;
'swift-constraints/max_meta_value_length': value => $max_meta_value_length;
'swift-constraints/max_meta_count': value => $max_meta_count;
'swift-constraints/max_meta_overall_size': value => $max_meta_overall_size;
'swift-constraints/max_header_size': value => pick($::swift::max_header_size, $max_header_size);
'swift-constraints/extra_header_count': value => $extra_header_count;
'swift-constraints/max_object_name_length': value => $max_object_name_length;
'swift-constraints/container_listing_limit': value => $container_listing_limit;
'swift-constraints/account_listing_limit': value => $account_listing_limit;
'swift-constraints/max_account_name_length': value => $max_account_name_length;
'swift-constraints/max_container_name_length': value => $max_container_name_length;
'swift-constraints/valid_api_versions': value => join(any2array($valid_api_versions), ',');
'swift-constraints/auto_create_account_prefix': value => $auto_create_account_prefix;
}
}

View File

@ -27,10 +27,12 @@
# (Optional) The ensure state for the swift package. # (Optional) The ensure state for the swift package.
# Defaults to present. # Defaults to present.
# #
# DEPRECATED PARAMETERS
#
# [*max_header_size*] # [*max_header_size*]
# (Optional) Max HTTP header size for incoming requests for all swift # (Optional) Max HTTP header size for incoming requests for all swift
# services. # services.
# Defaults to $::os_service_default # Defaults to undef
# #
# == Dependencies # == Dependencies
# #
@ -48,7 +50,8 @@ class swift(
$swift_hash_path_suffix = $::os_service_default, $swift_hash_path_suffix = $::os_service_default,
$swift_hash_path_prefix = $::os_service_default, $swift_hash_path_prefix = $::os_service_default,
$package_ensure = 'present', $package_ensure = 'present',
$max_header_size = $::os_service_default, # DEPRECATED PARAMETERS
$max_header_size = undef
) { ) {
include swift::deps include swift::deps
@ -68,6 +71,10 @@ class swift(
swift_config { swift_config {
'swift-hash/swift_hash_path_suffix': value => $swift_hash_path_suffix; 'swift-hash/swift_hash_path_suffix': value => $swift_hash_path_suffix;
'swift-hash/swift_hash_path_prefix': value => $swift_hash_path_prefix; 'swift-hash/swift_hash_path_prefix': value => $swift_hash_path_prefix;
'swift-constraints/max_header_size': value => $max_header_size; }
if $max_header_size != undef {
warning('The swift::max_header_size parameter is deprecated. Use the swift::constraints class.')
include swift::constraints
} }
} }

View File

@ -17,10 +17,6 @@
# (optional) The list of elements of the object expirer pipeline. # (optional) The list of elements of the object expirer pipeline.
# Defaults to ['catch_errors', 'proxy-logging', 'cache', 'proxy-server'] # Defaults to ['catch_errors', 'proxy-logging', 'cache', 'proxy-server']
# #
# [*auto_create_account_prefix*]
# (optional) Prefix to use when automatically creating accounts.
# Defaults to $::os_service_default.
#
# [*concurrency*] # [*concurrency*]
# (optional) Number of replication workers to spawn. # (optional) Number of replication workers to spawn.
# Defaults to $::os_service_default. # Defaults to $::os_service_default.
@ -105,12 +101,17 @@
# (optional) Log level # (optional) Log level
# Defaults to 'LOG_LOCAL2'. # Defaults to 'LOG_LOCAL2'.
# #
# DEPRECATED PARAMETERS
#
# [*auto_create_account_prefix*]
# (optional) Prefix to use when automatically creating accounts.
# Defaults to undef
#
class swift::objectexpirer( class swift::objectexpirer(
$manage_service = true, $manage_service = true,
$enabled = true, $enabled = true,
$package_ensure = 'present', $package_ensure = 'present',
$pipeline = ['catch_errors', 'proxy-logging', 'cache', 'proxy-server'], $pipeline = ['catch_errors', 'proxy-logging', 'cache', 'proxy-server'],
$auto_create_account_prefix = $::os_service_default,
$concurrency = $::os_service_default, $concurrency = $::os_service_default,
$expiring_objects_account_name = $::os_service_default, $expiring_objects_account_name = $::os_service_default,
$interval = $::os_service_default, $interval = $::os_service_default,
@ -127,12 +128,18 @@ class swift::objectexpirer(
$cache_tls_keyfile = undef, $cache_tls_keyfile = undef,
$log_level = 'INFO', $log_level = 'INFO',
$log_facility = 'LOG_LOCAL2', $log_facility = 'LOG_LOCAL2',
# DEPRECATED PARAMETERS
$auto_create_account_prefix = undef,
) inherits swift::params { ) inherits swift::params {
include swift::deps include swift::deps
Swift_config<| |> ~> Service['swift-object-expirer'] Swift_config<| |> ~> Service['swift-object-expirer']
Swift_object_expirer_config<||> ~> Service['swift-object-expirer'] Swift_object_expirer_config<||> ~> Service['swift-object-expirer']
if $auto_create_account_prefix != undef {
warning('The auto_create_account_prefix parameter is deprecated. Use the swift::constraints class.')
}
# On Red Hat platforms, it may be defined already, # On Red Hat platforms, it may be defined already,
# because it is part of openstack-swift-proxy # because it is part of openstack-swift-proxy
if $::swift::params::object_expirer_package_name != $::swift::params::proxy_package_name { if $::swift::params::object_expirer_package_name != $::swift::params::proxy_package_name {
@ -174,7 +181,7 @@ class swift::objectexpirer(
swift_object_expirer_config { swift_object_expirer_config {
'pipeline:main/pipeline': value => join($pipeline, ' '); 'pipeline:main/pipeline': value => join($pipeline, ' ');
'object-expirer/auto_create_account_prefix': value => $auto_create_account_prefix; 'object-expirer/auto_create_account_prefix': value => pick($auto_create_account_prefix, $::os_service_default);
'object-expirer/concurrency': value => $concurrency; 'object-expirer/concurrency': value => $concurrency;
'object-expirer/expiring_objects_account_name': value => $expiring_objects_account_name; 'object-expirer/expiring_objects_account_name': value => $expiring_objects_account_name;
'object-expirer/interval': value => $interval; 'object-expirer/interval': value => $interval;

View File

@ -0,0 +1,15 @@
---
features:
- |
The new ``swift::constraints`` class, which manages the
``[swift-constraints]`` options, has been added.
deprecations:
- |
The ``swift::max_header_size`` parameter has been deprecated in favor of
the new ``swift::constraints`` class.
- |
The ``swift::objectexpirer::auto_create_account_prefix`` parameter has been
deprecated. Use the ``swift::constraints::auto_create_account_prefix``
parameter instead.

View File

@ -0,0 +1,73 @@
require 'spec_helper'
describe 'swift::constraints' do
shared_examples 'swift::constraints' do
context 'with defaults' do
it 'should configure swift.conf' do
is_expected.to contain_swift_config('swift-constraints/max_file_size').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_config('swift-constraints/max_meta_name_length').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_config('swift-constraints/max_meta_value_length').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_config('swift-constraints/max_meta_count').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_config('swift-constraints/max_meta_overall_size').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_config('swift-constraints/max_header_size').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_config('swift-constraints/extra_header_count').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_config('swift-constraints/max_object_name_length').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_config('swift-constraints/container_listing_limit').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_config('swift-constraints/account_listing_limit').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_config('swift-constraints/max_account_name_length').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_config('swift-constraints/max_container_name_length').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_config('swift-constraints/valid_api_versions').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_config('swift-constraints/auto_create_account_prefix').with_value('<SERVICE DEFAULT>')
end
end
context 'with parameters' do
let :params do
{
:max_file_size => 5368709122,
:max_meta_name_length => 128,
:max_meta_value_length => 256,
:max_meta_count => 20,
:max_meta_overall_size => 4096,
:max_header_size => 8192,
:extra_header_count => 0,
:max_object_name_length => 1024,
:container_listing_limit => 10000,
:account_listing_limit => 10000,
:max_account_name_length => 256,
:max_container_name_length => 256,
:valid_api_versions => ['v1', 'v1.0'],
:auto_create_account_prefix => '.',
}
end
it 'should configure swift.conf' do
is_expected.to contain_swift_config('swift-constraints/max_file_size').with_value(5368709122)
is_expected.to contain_swift_config('swift-constraints/max_meta_name_length').with_value(128)
is_expected.to contain_swift_config('swift-constraints/max_meta_value_length').with_value(256)
is_expected.to contain_swift_config('swift-constraints/max_meta_count').with_value(20)
is_expected.to contain_swift_config('swift-constraints/max_meta_overall_size').with_value(4096)
is_expected.to contain_swift_config('swift-constraints/max_header_size').with_value(8192)
is_expected.to contain_swift_config('swift-constraints/extra_header_count').with_value(0)
is_expected.to contain_swift_config('swift-constraints/max_object_name_length').with_value(1024)
is_expected.to contain_swift_config('swift-constraints/container_listing_limit').with_value(10000)
is_expected.to contain_swift_config('swift-constraints/account_listing_limit').with_value(10000)
is_expected.to contain_swift_config('swift-constraints/max_account_name_length').with_value(256)
is_expected.to contain_swift_config('swift-constraints/max_container_name_length').with_value(256)
is_expected.to contain_swift_config('swift-constraints/valid_api_versions').with_value('v1,v1.0')
is_expected.to contain_swift_config('swift-constraints/auto_create_account_prefix').with_value('.')
end
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
it_configures 'swift::constraints'
end
end
end

View File

@ -24,8 +24,6 @@ describe 'swift' do
'swift-hash/swift_hash_path_suffix').with_value('string') 'swift-hash/swift_hash_path_suffix').with_value('string')
is_expected.to contain_swift_config( is_expected.to contain_swift_config(
'swift-hash/swift_hash_path_prefix').with_value('<SERVICE DEFAULT>') 'swift-hash/swift_hash_path_prefix').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_config(
'swift-constraints/max_header_size').with_value('<SERVICE DEFAULT>')
end end
it { it {