Merge "Add support for heat_api_{cfn_,}uwsgi_config in Debian"

This commit is contained in:
Zuul 2021-04-14 17:18:20 +00:00 committed by Gerrit Code Review
commit 5f210a4a0c
14 changed files with 497 additions and 0 deletions

View File

@ -0,0 +1,8 @@
Puppet::Type.type(:heat_api_cfn_uwsgi_config).provide(
:ini_setting,
:parent => Puppet::Type.type(:openstack_config).provider(:ini_setting)
) do
def self.file_path
'/etc/heat/heat-api-cfn-uwsgi.ini'
end
end

View File

@ -0,0 +1,10 @@
Puppet::Type.type(:heat_api_uwsgi_config).provide(
:ini_setting,
:parent => Puppet::Type.type(:openstack_config).provider(:ini_setting)
) do
def self.file_path
'/etc/heat/heat-api-uwsgi.ini'
end
end

View File

@ -0,0 +1,29 @@
Puppet::Type.newtype(:heat_api_cfn_uwsgi_config) do
ensurable
newparam(:name, :namevar => true) do
desc 'Section/setting name to manage from /etc/neutron/neutron-api-uwsgi.ini'
newvalues(/\S+\/\S+/)
end
newparam(:ensure_absent_val) do
desc 'A value that is specified as the value property will behave as if ensure => absent was specified'
defaultto('<SERVICE DEFAULT>')
end
newproperty(:value) do
desc 'The value of the setting to be defined.'
munge do |value|
value = value.to_s.strip
value.capitalize! if value =~ /^(true|false)$/i
value
end
newvalues(/^[\S ]*$/)
end
autorequire(:anchor) do
['heat::install::end']
end
end

View File

@ -0,0 +1,29 @@
Puppet::Type.newtype(:heat_api_uwsgi_config) do
ensurable
newparam(:name, :namevar => true) do
desc 'Section/setting name to manage from /etc/neutron/neutron-api-uwsgi.ini'
newvalues(/\S+\/\S+/)
end
newparam(:ensure_absent_val) do
desc 'A value that is specified as the value property will behave as if ensure => absent was specified'
defaultto('<SERVICE DEFAULT>')
end
newproperty(:value) do
desc 'The value of the setting to be defined.'
munge do |value|
value = value.to_s.strip
value.capitalize! if value =~ /^(true|false)$/i
value
end
newvalues(/^[\S ]*$/)
end
autorequire(:anchor) do
['heat::install::end']
end
end

View File

@ -28,6 +28,16 @@ class heat::deps {
# before service startup
Oslo::Cache<||> -> Anchor['heat::service::begin']
# On any uwsgi config change, we must restart Heat API.
Anchor['heat::config::begin']
-> Heat_api_uwsgi_config<||>
~> Anchor['heat::config::end']
# On any uwsgi config change, we must restart Heat API CFN.
Anchor['heat::config::begin']
-> Heat_api_uwsgi_config<||>
~> Anchor['heat::config::end']
# all db settings should be applied and all packages should be installed
# before dbsync starts
Oslo::Db<||> -> Anchor['heat::dbsync::begin']

View File

@ -0,0 +1,41 @@
#
# Copyright 2021 Thomas Goirand <zigo@debian.org>
#
# Author: Thomas Goirand <zigo@debian.org>
#
# == Class: heat::wsgi::uwsgi_api
#
# Configure the UWSGI service for Heat API.
#
# == Parameters
#
# [*processes*]
# (Optional) Number of processes.
# Defaults to $::os_workers.
#
# [*threads*]
# (Optional) Number of threads.
# Defaults to 32.
#
# [*listen_queue_size*]
# (Optional) Socket listen queue size.
# Defaults to 100
#
class heat::wsgi::uwsgi_api (
$processes = $::os_workers,
$threads = 32,
$listen_queue_size = 100,
){
include heat::deps
if $::os_package_type != 'debian'{
warning('This class is only valid for Debian, as other operating systems are not using uwsgi by default.')
}
heat_api_uwsgi_config {
'uwsgi/processes': value => $processes;
'uwsgi/threads': value => $threads;
'uwsgi/listen': value => $listen_queue_size;
}
}

View File

@ -0,0 +1,41 @@
#
# Copyright 2021 Thomas Goirand <zigo@debian.org>
#
# Author: Thomas Goirand <zigo@debian.org>
#
# == Class: heat::wsgi::uwsgi_api_cfn
#
# Configure the UWSGI service for Heat API CFN.
#
# == Parameters
#
# [*processes*]
# (Optional) Number of processes.
# Defaults to $::os_workers.
#
# [*threads*]
# (Optional) Number of threads.
# Defaults to 32.
#
# [*listen_queue_size*]
# (Optional) Socket listen queue size.
# Defaults to 100
#
class heat::wsgi::uwsgi_api_cfn (
$processes = $::os_workers,
$threads = 32,
$listen_queue_size = 100,
){
include heat::deps
if $::os_package_type != 'debian'{
warning('This class is only valid for Debian, as other operating systems are not using uwsgi by default.')
}
heat_api_cfn_uwsgi_config {
'uwsgi/processes': value => $processes;
'uwsgi/threads': value => $threads;
'uwsgi/listen': value => $listen_queue_size;
}
}

View File

@ -0,0 +1,9 @@
---
features:
- |
Two new classes heat::wsgi::uwsgi_api and heat::wsgi::uwsgi_api_cfn
exist to allow configuring uwsgi in operating systems that support
this (ie: currently Debian). This helps configuring the number of
processes, threads and listen socket. Also, two new
heat_api_uwsgi_config and heat_api_cfn_uwsgi_config providers now
exist.

View File

@ -0,0 +1,31 @@
require 'spec_helper'
describe 'heat::wsgi::uwsgi_api_cfn' do
shared_examples 'heat::wsgi::uwsgi_api_cfn' do
context 'with default parameters' do
it {
should contain_class('heat::deps')
}
it {
is_expected.to contain_heat_api_cfn_uwsgi_config('uwsgi/processes').with_value(facts[:os_workers])
is_expected.to contain_heat_api_cfn_uwsgi_config('uwsgi/threads').with_value('32')
is_expected.to contain_heat_api_cfn_uwsgi_config('uwsgi/listen').with_value('100')
}
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({
:os_workers => 8,
}))
end
it_behaves_like 'heat::wsgi::uwsgi_api_cfn'
end
end
end

View File

@ -0,0 +1,31 @@
require 'spec_helper'
describe 'heat::wsgi::uwsgi_api' do
shared_examples 'heat::wsgi::uwsgi_api' do
context 'with default parameters' do
it {
should contain_class('heat::deps')
}
it {
is_expected.to contain_heat_api_uwsgi_config('uwsgi/processes').with_value(facts[:os_workers])
is_expected.to contain_heat_api_uwsgi_config('uwsgi/threads').with_value('32')
is_expected.to contain_heat_api_uwsgi_config('uwsgi/listen').with_value('100')
}
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({
:os_workers => 8,
}))
end
it_behaves_like 'heat::wsgi::uwsgi_api'
end
end
end

View File

@ -0,0 +1,65 @@
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'..',
'fixtures',
'modules',
'inifile',
'lib')
)
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'..',
'fixtures',
'modules',
'openstacklib',
'lib')
)
require 'spec_helper'
provider_class = Puppet::Type.type(:heat_api_cfn_uwsgi_config).provider(:ini_setting)
describe provider_class do
it 'should default to the default setting when no other one is specified' do
resource = Puppet::Type::Heat_api_cfn_uwsgi_config.new(
{:name => 'DEFAULT/foo', :value => 'bar'}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('DEFAULT')
expect(provider.setting).to eq('foo')
end
it 'should allow setting to be set explicitly' do
resource = Puppet::Type::Heat_api_cfn_uwsgi_config.new(
{:name => 'dude/foo', :value => 'bar'}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('dude')
expect(provider.setting).to eq('foo')
end
it 'should ensure absent when <SERVICE DEFAULT> is specified as a value' do
resource = Puppet::Type::Heat_api_cfn_uwsgi_config.new(
{:name => 'dude/foo', :value => '<SERVICE DEFAULT>'}
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
it 'should ensure absent when value matches ensure_absent_val' do
resource = Puppet::Type::Heat_api_cfn_uwsgi_config.new(
{:name => 'dude/foo', :value => 'foo', :ensure_absent_val => 'foo' }
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
end

View File

@ -0,0 +1,65 @@
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'..',
'fixtures',
'modules',
'inifile',
'lib')
)
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'..',
'fixtures',
'modules',
'openstacklib',
'lib')
)
require 'spec_helper'
provider_class = Puppet::Type.type(:heat_api_uwsgi_config).provider(:ini_setting)
describe provider_class do
it 'should default to the default setting when no other one is specified' do
resource = Puppet::Type::Heat_api_uwsgi_config.new(
{:name => 'DEFAULT/foo', :value => 'bar'}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('DEFAULT')
expect(provider.setting).to eq('foo')
end
it 'should allow setting to be set explicitly' do
resource = Puppet::Type::Heat_api_uwsgi_config.new(
{:name => 'dude/foo', :value => 'bar'}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('dude')
expect(provider.setting).to eq('foo')
end
it 'should ensure absent when <SERVICE DEFAULT> is specified as a value' do
resource = Puppet::Type::Heat_api_uwsgi_config.new(
{:name => 'dude/foo', :value => '<SERVICE DEFAULT>'}
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
it 'should ensure absent when value matches ensure_absent_val' do
resource = Puppet::Type::Heat_api_uwsgi_config.new(
{:name => 'dude/foo', :value => 'foo', :ensure_absent_val => 'foo' }
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
end

View File

@ -0,0 +1,64 @@
require 'puppet'
require 'puppet/type/heat_api_cfn_uwsgi_config'
describe 'Puppet::Type.type(:heat_api_cfn_uwsgi_config)' do
before :each do
@heat_api_cfn_uwsgi_config = Puppet::Type.type(:heat_api_cfn_uwsgi_config).new(:name => 'DEFAULT/foo', :value => 'bar')
end
it 'should require a name' do
expect {
Puppet::Type.type(:heat_api_cfn_uwsgi_config).new({})
}.to raise_error(Puppet::Error, 'Title or name must be provided')
end
it 'should not expect a name with whitespace' do
expect {
Puppet::Type.type(:heat_api_cfn_uwsgi_config).new(:name => 'f oo')
}.to raise_error(Puppet::Error, /Parameter name failed/)
end
it 'should fail when there is no section' do
expect {
Puppet::Type.type(:heat_api_cfn_uwsgi_config).new(:name => 'foo')
}.to raise_error(Puppet::Error, /Parameter name failed/)
end
it 'should not require a value when ensure is absent' do
Puppet::Type.type(:heat_api_cfn_uwsgi_config).new(:name => 'DEFAULT/foo', :ensure => :absent)
end
it 'should accept a valid value' do
@heat_api_cfn_uwsgi_config[:value] = 'bar'
expect(@heat_api_cfn_uwsgi_config[:value]).to eq('bar')
end
it 'should not accept a value with whitespace' do
@heat_api_cfn_uwsgi_config[:value] = 'b ar'
expect(@heat_api_cfn_uwsgi_config[:value]).to eq('b ar')
end
it 'should accept valid ensure values' do
@heat_api_cfn_uwsgi_config[:ensure] = :present
expect(@heat_api_cfn_uwsgi_config[:ensure]).to eq(:present)
@heat_api_cfn_uwsgi_config[:ensure] = :absent
expect(@heat_api_cfn_uwsgi_config[:ensure]).to eq(:absent)
end
it 'should not accept invalid ensure values' do
expect {
@heat_api_cfn_uwsgi_config[:ensure] = :latest
}.to raise_error(Puppet::Error, /Invalid value/)
end
it 'should autorequire the package that install the file' do
catalog = Puppet::Resource::Catalog.new
anchor = Puppet::Type.type(:anchor).new(:name => 'heat::install::end')
catalog.add_resource anchor, @heat_api_cfn_uwsgi_config
dependency = @heat_api_cfn_uwsgi_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@heat_api_cfn_uwsgi_config)
expect(dependency[0].source).to eq(anchor)
end
end

View File

@ -0,0 +1,64 @@
require 'puppet'
require 'puppet/type/heat_api_uwsgi_config'
describe 'Puppet::Type.type(:heat_api_uwsgi_config)' do
before :each do
@heat_api_uwsgi_config = Puppet::Type.type(:heat_api_uwsgi_config).new(:name => 'DEFAULT/foo', :value => 'bar')
end
it 'should require a name' do
expect {
Puppet::Type.type(:heat_api_uwsgi_config).new({})
}.to raise_error(Puppet::Error, 'Title or name must be provided')
end
it 'should not expect a name with whitespace' do
expect {
Puppet::Type.type(:heat_api_uwsgi_config).new(:name => 'f oo')
}.to raise_error(Puppet::Error, /Parameter name failed/)
end
it 'should fail when there is no section' do
expect {
Puppet::Type.type(:heat_api_uwsgi_config).new(:name => 'foo')
}.to raise_error(Puppet::Error, /Parameter name failed/)
end
it 'should not require a value when ensure is absent' do
Puppet::Type.type(:heat_api_uwsgi_config).new(:name => 'DEFAULT/foo', :ensure => :absent)
end
it 'should accept a valid value' do
@heat_api_uwsgi_config[:value] = 'bar'
expect(@heat_api_uwsgi_config[:value]).to eq('bar')
end
it 'should not accept a value with whitespace' do
@heat_api_uwsgi_config[:value] = 'b ar'
expect(@heat_api_uwsgi_config[:value]).to eq('b ar')
end
it 'should accept valid ensure values' do
@heat_api_uwsgi_config[:ensure] = :present
expect(@heat_api_uwsgi_config[:ensure]).to eq(:present)
@heat_api_uwsgi_config[:ensure] = :absent
expect(@heat_api_uwsgi_config[:ensure]).to eq(:absent)
end
it 'should not accept invalid ensure values' do
expect {
@heat_api_uwsgi_config[:ensure] = :latest
}.to raise_error(Puppet::Error, /Invalid value/)
end
it 'should autorequire the package that install the file' do
catalog = Puppet::Resource::Catalog.new
anchor = Puppet::Type.type(:anchor).new(:name => 'heat::install::end')
catalog.add_resource anchor, @heat_api_uwsgi_config
dependency = @heat_api_uwsgi_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@heat_api_uwsgi_config)
expect(dependency[0].source).to eq(anchor)
end
end