scheduler/filter: use os_service_default for arrays
Some arrays were set to False by default. This patch makes the values with the following rules: - default is $::os_service_default so Puppet won't try to configure it. - if set to something, we'll validate it's an array that is not empty and configure the parameter. - Otherwise, fallback to default. That way, our users can let the default value or set an empty array, it won't try to configure it; or set the parameters to an array and Puppet will configure it properly. Change-Id: Ib6c441f89f9cee81991fccdf1d3b4f6eb77e4d55
This commit is contained in:
parent
f040ced872
commit
61bf070188
@ -29,12 +29,12 @@
|
||||
# Defaults to '8'
|
||||
#
|
||||
# [*isolated_images*]
|
||||
# (optional) Images to run on isolated host
|
||||
# Defaults to false
|
||||
# (optional) An array of images to run on isolated host
|
||||
# Defaults to $::os_service_default
|
||||
#
|
||||
# [*isolated_hosts*]
|
||||
# (optional) Host reserved for specific images
|
||||
# Defaults to false
|
||||
# (optional) An array of hosts reserved for specific images
|
||||
# Defaults to $::os_service_default
|
||||
#
|
||||
# [*max_instances_per_host*]
|
||||
# (optional) Ignore hosts that have too many instances
|
||||
@ -50,7 +50,7 @@
|
||||
#
|
||||
# [*scheduler_default_filters*]
|
||||
# (optional) An array of filters to be used by default
|
||||
# Defaults to false
|
||||
# Defaults to $::os_service_default
|
||||
#
|
||||
# [*scheduler_weight_classes*]
|
||||
# (optional) Which weight class names to use for weighing hosts
|
||||
@ -58,7 +58,7 @@
|
||||
#
|
||||
# [*baremetal_scheduler_default_filters*]
|
||||
# (optional) An array of filters to be used by default for baremetal hosts
|
||||
# Defaults to undef
|
||||
# Defaults to $::os_service_default
|
||||
#
|
||||
# [*scheduler_use_baremetal_filters*]
|
||||
# (optional) Use baremetal_scheduler_default_filters or not.
|
||||
@ -73,60 +73,62 @@ class nova::scheduler::filter (
|
||||
$max_io_ops_per_host = '8',
|
||||
$max_instances_per_host = '50',
|
||||
$ram_allocation_ratio = '1.5',
|
||||
$isolated_images = false,
|
||||
$isolated_hosts = false,
|
||||
$isolated_images = $::os_service_default,
|
||||
$isolated_hosts = $::os_service_default,
|
||||
$scheduler_available_filters = 'nova.scheduler.filters.all_filters',
|
||||
$scheduler_default_filters = false,
|
||||
$scheduler_default_filters = $::os_service_default,
|
||||
$scheduler_weight_classes = 'nova.scheduler.weights.all_weighers',
|
||||
$baremetal_scheduler_default_filters = undef,
|
||||
$baremetal_scheduler_default_filters = $::os_service_default,
|
||||
$scheduler_use_baremetal_filters = false,
|
||||
) {
|
||||
|
||||
include ::nova::deps
|
||||
|
||||
# The following values are following this rule:
|
||||
# - default is $::os_service_default so Puppet won't try to configure it.
|
||||
# - if set, we'll validate it's an array that is not empty and configure the parameter.
|
||||
# - Otherwise, fallback to default.
|
||||
if !is_service_default($scheduler_default_filters) and !empty($scheduler_default_filters){
|
||||
validate_array($scheduler_default_filters)
|
||||
$scheduler_default_filters_real = join($scheduler_default_filters, ',')
|
||||
} else {
|
||||
$scheduler_default_filters_real = $::os_service_default
|
||||
}
|
||||
if !is_service_default($baremetal_scheduler_default_filters) and !empty($baremetal_scheduler_default_filters){
|
||||
validate_array($baremetal_scheduler_default_filters)
|
||||
$baremetal_scheduler_default_filters_real = join($baremetal_scheduler_default_filters, ',')
|
||||
} else {
|
||||
$baremetal_scheduler_default_filters_real = $::os_service_default
|
||||
}
|
||||
if !is_service_default($isolated_images) and !empty($isolated_images){
|
||||
validate_array($isolated_images)
|
||||
$isolated_images_real = join($isolated_images, ',')
|
||||
} else {
|
||||
$isolated_images_real = $::os_service_default
|
||||
}
|
||||
if !is_service_default($isolated_hosts) and !empty($isolated_hosts){
|
||||
validate_array($isolated_hosts)
|
||||
$isolated_hosts_real = join($isolated_hosts, ',')
|
||||
} else {
|
||||
$isolated_hosts_real = $::os_service_default
|
||||
}
|
||||
|
||||
nova_config {
|
||||
'DEFAULT/scheduler_host_manager': value => $scheduler_host_manager;
|
||||
'DEFAULT/scheduler_max_attempts': value => $scheduler_max_attempts;
|
||||
'DEFAULT/scheduler_host_subset_size': value => $scheduler_host_subset_size;
|
||||
'DEFAULT/cpu_allocation_ratio': value => $cpu_allocation_ratio;
|
||||
'DEFAULT/disk_allocation_ratio': value => $disk_allocation_ratio;
|
||||
'DEFAULT/max_io_ops_per_host': value => $max_io_ops_per_host;
|
||||
'DEFAULT/max_instances_per_host': value => $max_instances_per_host;
|
||||
'DEFAULT/ram_allocation_ratio': value => $ram_allocation_ratio;
|
||||
'DEFAULT/scheduler_available_filters': value => $scheduler_available_filters;
|
||||
'DEFAULT/scheduler_weight_classes': value => $scheduler_weight_classes;
|
||||
'DEFAULT/scheduler_use_baremetal_filters': value => $scheduler_use_baremetal_filters;
|
||||
}
|
||||
if ($scheduler_default_filters) {
|
||||
nova_config { 'DEFAULT/scheduler_default_filters': value => join($scheduler_default_filters,',')
|
||||
}
|
||||
} else {
|
||||
nova_config { 'DEFAULT/scheduler_default_filters': ensure => absent
|
||||
}
|
||||
}
|
||||
if ($baremetal_scheduler_default_filters) {
|
||||
nova_config { 'DEFAULT/baremetal_scheduler_default_filters': value => join($baremetal_scheduler_default_filters,',')
|
||||
}
|
||||
} else {
|
||||
nova_config { 'DEFAULT/baremetal_scheduler_default_filters': ensure => absent
|
||||
}
|
||||
}
|
||||
if ($isolated_images) {
|
||||
nova_config {
|
||||
'DEFAULT/isolated_images': value => join($isolated_images,',')
|
||||
}
|
||||
} else {
|
||||
nova_config {
|
||||
'DEFAULT/isolated_images': ensure => absent
|
||||
}
|
||||
}
|
||||
if ($isolated_hosts) {
|
||||
nova_config {
|
||||
'DEFAULT/isolated_hosts': value => join($isolated_hosts,',')
|
||||
}
|
||||
} else {
|
||||
nova_config {
|
||||
'DEFAULT/isolated_hosts': ensure => absent
|
||||
}
|
||||
'DEFAULT/scheduler_host_manager': value => $scheduler_host_manager;
|
||||
'DEFAULT/scheduler_max_attempts': value => $scheduler_max_attempts;
|
||||
'DEFAULT/scheduler_host_subset_size': value => $scheduler_host_subset_size;
|
||||
'DEFAULT/cpu_allocation_ratio': value => $cpu_allocation_ratio;
|
||||
'DEFAULT/disk_allocation_ratio': value => $disk_allocation_ratio;
|
||||
'DEFAULT/max_io_ops_per_host': value => $max_io_ops_per_host;
|
||||
'DEFAULT/max_instances_per_host': value => $max_instances_per_host;
|
||||
'DEFAULT/ram_allocation_ratio': value => $ram_allocation_ratio;
|
||||
'DEFAULT/scheduler_available_filters': value => $scheduler_available_filters;
|
||||
'DEFAULT/scheduler_weight_classes': value => $scheduler_weight_classes;
|
||||
'DEFAULT/scheduler_use_baremetal_filters': value => $scheduler_use_baremetal_filters;
|
||||
'DEFAULT/scheduler_default_filters': value => $scheduler_default_filters_real;
|
||||
'DEFAULT/baremetal_scheduler_default_filters': value => $baremetal_scheduler_default_filters_real;
|
||||
'DEFAULT/isolated_images': value => $isolated_images_real;
|
||||
'DEFAULT/isolated_hosts': value => $isolated_hosts_real;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,37 +2,73 @@ require 'spec_helper'
|
||||
|
||||
describe 'nova::scheduler::filter' do
|
||||
|
||||
it { is_expected.to contain_nova_config('DEFAULT/scheduler_host_manager').with_value('host_manager') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/scheduler_max_attempts').with_value('3') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/scheduler_host_subset_size').with_value('1') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/cpu_allocation_ratio').with_value('16.0') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/disk_allocation_ratio').with_value('1.0') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/max_io_ops_per_host').with_value('8') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/max_instances_per_host').with_value('50') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/ram_allocation_ratio').with_value('1.5') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/scheduler_available_filters').with_value('nova.scheduler.filters.all_filters') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/scheduler_weight_classes').with_value('nova.scheduler.weights.all_weighers') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/scheduler_use_baremetal_filters').with_value(false) }
|
||||
let :params do
|
||||
{}
|
||||
end
|
||||
|
||||
describe 'when overriding params' do
|
||||
shared_examples 'nova::scheduler::filter' do
|
||||
|
||||
let :params do
|
||||
{:scheduler_max_attempts => '4',
|
||||
:isolated_images => ['ubuntu1','centos2'],
|
||||
:isolated_hosts => ['192.168.1.2','192.168.1.3'],
|
||||
:scheduler_default_filters => ['RetryFilter','AvailabilityZoneFilter','RamFilter'],
|
||||
:scheduler_use_baremetal_filters => true,
|
||||
:baremetal_scheduler_default_filters => ['ExactRamFilter','ExactDiskFilter','ExactCoreFilter']
|
||||
}
|
||||
context 'with default parameters' do
|
||||
it { is_expected.to contain_nova_config('DEFAULT/scheduler_host_manager').with_value('host_manager') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/scheduler_max_attempts').with_value('3') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/scheduler_host_subset_size').with_value('1') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/cpu_allocation_ratio').with_value('16.0') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/disk_allocation_ratio').with_value('1.0') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/max_io_ops_per_host').with_value('8') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/max_instances_per_host').with_value('50') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/ram_allocation_ratio').with_value('1.5') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/scheduler_available_filters').with_value('nova.scheduler.filters.all_filters') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/scheduler_weight_classes').with_value('nova.scheduler.weights.all_weighers') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/scheduler_use_baremetal_filters').with_value(false) }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/isolated_images').with_value('<SERVICE DEFAULT>') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/isolated_hosts').with_value('<SERVICE DEFAULT>') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/scheduler_default_filters').with_value('<SERVICE DEFAULT>') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/baremetal_scheduler_default_filters').with_value('<SERVICE DEFAULT>') }
|
||||
end
|
||||
|
||||
it { is_expected.to contain_nova_config('DEFAULT/scheduler_max_attempts').with_value('4') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/isolated_images').with_value('ubuntu1,centos2') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/isolated_hosts').with_value('192.168.1.2,192.168.1.3') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/scheduler_default_filters').with_value('RetryFilter,AvailabilityZoneFilter,RamFilter') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/scheduler_use_baremetal_filters').with_value(true) }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/baremetal_scheduler_default_filters').with_value('ExactRamFilter,ExactDiskFilter,ExactCoreFilter') }
|
||||
context 'when overriding params with non-empty arrays' do
|
||||
let :params do
|
||||
{ :scheduler_max_attempts => '4',
|
||||
:isolated_images => ['ubuntu1','centos2'],
|
||||
:isolated_hosts => ['192.168.1.2','192.168.1.3'],
|
||||
:scheduler_default_filters => ['RetryFilter','AvailabilityZoneFilter','RamFilter'],
|
||||
:scheduler_use_baremetal_filters => true,
|
||||
:baremetal_scheduler_default_filters => ['ExactRamFilter','ExactDiskFilter','ExactCoreFilter'], }
|
||||
end
|
||||
|
||||
it { is_expected.to contain_nova_config('DEFAULT/scheduler_max_attempts').with_value('4') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/isolated_images').with_value('ubuntu1,centos2') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/isolated_hosts').with_value('192.168.1.2,192.168.1.3') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/scheduler_default_filters').with_value('RetryFilter,AvailabilityZoneFilter,RamFilter') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/scheduler_use_baremetal_filters').with_value(true) }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/baremetal_scheduler_default_filters').with_value('ExactRamFilter,ExactDiskFilter,ExactCoreFilter') }
|
||||
end
|
||||
|
||||
context 'when overriding params with empty arrays' do
|
||||
let :params do
|
||||
{ :isolated_images => [],
|
||||
:isolated_hosts => [],
|
||||
:scheduler_default_filters => [],
|
||||
:baremetal_scheduler_default_filters => [], }
|
||||
end
|
||||
|
||||
it { is_expected.to contain_nova_config('DEFAULT/isolated_images').with_value('<SERVICE DEFAULT>') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/isolated_hosts').with_value('<SERVICE DEFAULT>') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/scheduler_default_filters').with_value('<SERVICE DEFAULT>') }
|
||||
it { is_expected.to contain_nova_config('DEFAULT/baremetal_scheduler_default_filters').with_value('<SERVICE DEFAULT>') }
|
||||
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 'nova::scheduler::filter'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user