From 8334bd36663737f234d4e34b72f32feb40bc5718 Mon Sep 17 00:00:00 2001 From: Thomas Goirand Date: Wed, 7 Apr 2021 15:06:37 +0200 Subject: [PATCH] Add support for nova_api_{metadata_,}uwsgi_config in Debian This patch is adding the configuration of the number of workers, threads, and the size of the listen queue in Debian, which uses uwsgi to run Nova API and api-metadata. Therefore, this patch adds two new nova_api_uwsgi_config and nova_api_metadata_uwsgi_config providers as well as two new nova::wsgi::uwsgi_api and nova::wsgi::uwsgi_api_metadata classes. Change-Id: Idd141edc5cddcfd79cf23e2041dbd1ce6a8252a8 --- .../openstackconfig.rb | 10 +++ .../nova_api_uwsgi_config/openstackconfig.rb | 10 +++ .../type/nova_api_metadata_uwsgi_config.rb | 29 ++++++++ lib/puppet/type/nova_api_uwsgi_config.rb | 29 ++++++++ manifests/deps.pp | 10 +++ manifests/wsgi/uwsgi_api.pp | 41 +++++++++++ manifests/wsgi/uwsgi_api_metadata.pp | 41 +++++++++++ .../notes/uwsgi-a9f90e3a5148a7f7.yaml | 8 +++ .../nova_wsgi_uwsgi_api_metadata_spec.rb | 31 +++++++++ spec/classes/nova_wsgi_uwsgi_api_spec.rb | 31 +++++++++ .../openstackconfig_spec.rb | 68 +++++++++++++++++++ .../openstackconfig_spec.rb | 68 +++++++++++++++++++ .../nova_api_metadata_uwsgi_config_spec.rb | 64 +++++++++++++++++ spec/unit/type/nova_api_uwsgi_config_spec.rb | 64 +++++++++++++++++ 14 files changed, 504 insertions(+) create mode 100644 lib/puppet/provider/nova_api_metadata_uwsgi_config/openstackconfig.rb create mode 100644 lib/puppet/provider/nova_api_uwsgi_config/openstackconfig.rb create mode 100644 lib/puppet/type/nova_api_metadata_uwsgi_config.rb create mode 100644 lib/puppet/type/nova_api_uwsgi_config.rb create mode 100644 manifests/wsgi/uwsgi_api.pp create mode 100644 manifests/wsgi/uwsgi_api_metadata.pp create mode 100644 releasenotes/notes/uwsgi-a9f90e3a5148a7f7.yaml create mode 100644 spec/classes/nova_wsgi_uwsgi_api_metadata_spec.rb create mode 100644 spec/classes/nova_wsgi_uwsgi_api_spec.rb create mode 100644 spec/unit/provider/nova_api_metadata_uwsgi_config/openstackconfig_spec.rb create mode 100644 spec/unit/provider/nova_api_uwsgi_config/openstackconfig_spec.rb create mode 100644 spec/unit/type/nova_api_metadata_uwsgi_config_spec.rb create mode 100644 spec/unit/type/nova_api_uwsgi_config_spec.rb diff --git a/lib/puppet/provider/nova_api_metadata_uwsgi_config/openstackconfig.rb b/lib/puppet/provider/nova_api_metadata_uwsgi_config/openstackconfig.rb new file mode 100644 index 000000000..c031a426a --- /dev/null +++ b/lib/puppet/provider/nova_api_metadata_uwsgi_config/openstackconfig.rb @@ -0,0 +1,10 @@ +Puppet::Type.type(:nova_api_metadata_uwsgi_config).provide( + :openstackconfig, + :parent => Puppet::Type.type(:openstack_config).provider(:ruby) +) do + + def self.file_path + '/etc/nova/nova-api-metadata-uwsgi.ini' + end + +end diff --git a/lib/puppet/provider/nova_api_uwsgi_config/openstackconfig.rb b/lib/puppet/provider/nova_api_uwsgi_config/openstackconfig.rb new file mode 100644 index 000000000..82408df75 --- /dev/null +++ b/lib/puppet/provider/nova_api_uwsgi_config/openstackconfig.rb @@ -0,0 +1,10 @@ +Puppet::Type.type(:nova_api_uwsgi_config).provide( + :openstackconfig, + :parent => Puppet::Type.type(:openstack_config).provider(:ruby) +) do + + def self.file_path + '/etc/nova/nova-api-uwsgi.ini' + end + +end diff --git a/lib/puppet/type/nova_api_metadata_uwsgi_config.rb b/lib/puppet/type/nova_api_metadata_uwsgi_config.rb new file mode 100644 index 000000000..ebf3b6d1c --- /dev/null +++ b/lib/puppet/type/nova_api_metadata_uwsgi_config.rb @@ -0,0 +1,29 @@ +Puppet::Type.newtype(:nova_api_metadata_uwsgi_config) do + + ensurable + + newparam(:name, :namevar => true) do + desc 'Section/setting name to manage from /etc/nova/nova-api-metadata-uwsgi.ini' + newvalues(/\S+\/\S+/) + 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 + + newparam(:ensure_absent_val) do + desc 'A value that is specified as the value property will behave as if ensure => absent was specified' + defaultto('') + end + + autorequire(:anchor) do + ['nova::install::end'] + end + +end diff --git a/lib/puppet/type/nova_api_uwsgi_config.rb b/lib/puppet/type/nova_api_uwsgi_config.rb new file mode 100644 index 000000000..016417362 --- /dev/null +++ b/lib/puppet/type/nova_api_uwsgi_config.rb @@ -0,0 +1,29 @@ +Puppet::Type.newtype(:nova_api_uwsgi_config) do + + ensurable + + newparam(:name, :namevar => true) do + desc 'Section/setting name to manage from /etc/nova/nova-api-uwsgi.ini' + newvalues(/\S+\/\S+/) + 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 + + newparam(:ensure_absent_val) do + desc 'A value that is specified as the value property will behave as if ensure => absent was specified' + defaultto('') + end + + autorequire(:anchor) do + ['nova::install::end'] + end + +end diff --git a/manifests/deps.pp b/manifests/deps.pp index 920a1b488..8a970c019 100644 --- a/manifests/deps.pp +++ b/manifests/deps.pp @@ -27,6 +27,16 @@ class nova::deps { -> Nova_paste_api_ini<||> ~> Anchor['nova::config::end'] + # On any uwsgi config change, we must restart Nova APIs. + Anchor['nova::config::begin'] + -> Nova_api_uwsgi_config<||> + ~> Anchor['nova::config::end'] + + Anchor['nova::config::begin'] + -> Nova_api_metadata_uwsgi_config<||> + ~> Anchor['nova::config::end'] + + # Support packages need to be installed in the install phase, but we don't # put them in the chain above because we don't want any false dependencies # between packages with the nova-package tag and the nova-support-package diff --git a/manifests/wsgi/uwsgi_api.pp b/manifests/wsgi/uwsgi_api.pp new file mode 100644 index 000000000..8ce4ea6fd --- /dev/null +++ b/manifests/wsgi/uwsgi_api.pp @@ -0,0 +1,41 @@ +# +# Copyright 2021 Thomas Goirand +# +# Author: Thomas Goirand +# +# == Class: nova::wsgi::uwsgi_api +# +# Configure the UWSGI service for Nova 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 nova::wsgi::uwsgi_api ( + $processes = $::os_workers, + $threads = 32, + $listen_queue_size = 100, +){ + + include nova::deps + + if $::os_package_type != 'debian'{ + warning('This class is only valid for Debian, as other operating systems are not using uwsgi by default.') + } + + nova_api_uwsgi_config { + 'uwsgi/processes': value => $processes; + 'uwsgi/threads': value => $threads; + 'uwsgi/listen': value => $listen_queue_size; + } +} diff --git a/manifests/wsgi/uwsgi_api_metadata.pp b/manifests/wsgi/uwsgi_api_metadata.pp new file mode 100644 index 000000000..0d4e3b0b3 --- /dev/null +++ b/manifests/wsgi/uwsgi_api_metadata.pp @@ -0,0 +1,41 @@ +# +# Copyright 2021 Thomas Goirand +# +# Author: Thomas Goirand +# +# == Class: nova::wsgi::uwsgi_api_metadata +# +# Configure the UWSGI service for Nova API Metadata. +# +# == 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 nova::wsgi::uwsgi_api_metadata ( + $processes = $::os_workers, + $threads = 32, + $listen_queue_size = 100, +){ + + include nova::deps + + if $::os_package_type != 'debian'{ + warning('This class is only valid for Debian, as other operating systems are not using uwsgi by default.') + } + + nova_api_metadata_uwsgi_config { + 'uwsgi/processes': value => $processes; + 'uwsgi/threads': value => $threads; + 'uwsgi/listen': value => $listen_queue_size; + } +} diff --git a/releasenotes/notes/uwsgi-a9f90e3a5148a7f7.yaml b/releasenotes/notes/uwsgi-a9f90e3a5148a7f7.yaml new file mode 100644 index 000000000..591524c2c --- /dev/null +++ b/releasenotes/notes/uwsgi-a9f90e3a5148a7f7.yaml @@ -0,0 +1,8 @@ +--- +features: + - | + Two new calsses nova::wsgi::wsgi_api and nova::wsgi::wsgi_api_metadata + 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 nova_api_uwsgi_config and + nova_api_metadata_uwsgi_config provider now exist. diff --git a/spec/classes/nova_wsgi_uwsgi_api_metadata_spec.rb b/spec/classes/nova_wsgi_uwsgi_api_metadata_spec.rb new file mode 100644 index 000000000..197ba2eb9 --- /dev/null +++ b/spec/classes/nova_wsgi_uwsgi_api_metadata_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe 'nova::wsgi::uwsgi_api_metadata' do + + shared_examples 'nova::wsgi::uwsgi_api_metadata' do + context 'with default parameters' do + it { + should contain_class('nova::deps') + } + + it { + is_expected.to contain_nova_api_metadata_uwsgi_config('uwsgi/processes').with_value(facts[:os_workers]) + is_expected.to contain_nova_api_metadata_uwsgi_config('uwsgi/threads').with_value('32') + is_expected.to contain_nova_api_metadata_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 'nova::wsgi::uwsgi_api_metadata' + end + end +end diff --git a/spec/classes/nova_wsgi_uwsgi_api_spec.rb b/spec/classes/nova_wsgi_uwsgi_api_spec.rb new file mode 100644 index 000000000..72a68dadb --- /dev/null +++ b/spec/classes/nova_wsgi_uwsgi_api_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe 'nova::wsgi::uwsgi_api' do + + shared_examples 'nova::wsgi::uwsgi_api' do + context 'with default parameters' do + it { + should contain_class('nova::deps') + } + + it { + is_expected.to contain_nova_api_uwsgi_config('uwsgi/processes').with_value(facts[:os_workers]) + is_expected.to contain_nova_api_uwsgi_config('uwsgi/threads').with_value('32') + is_expected.to contain_nova_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 'nova::wsgi::uwsgi_api' + end + end +end diff --git a/spec/unit/provider/nova_api_metadata_uwsgi_config/openstackconfig_spec.rb b/spec/unit/provider/nova_api_metadata_uwsgi_config/openstackconfig_spec.rb new file mode 100644 index 000000000..ed9aa7cec --- /dev/null +++ b/spec/unit/provider/nova_api_metadata_uwsgi_config/openstackconfig_spec.rb @@ -0,0 +1,68 @@ +# +# these tests are a little concerning b/c they are hacking around the +# modulepath, so these tests will not catch issues that may eventually arise +# related to loading these plugins. +# I could not, for the life of me, figure out how to programatcally set the modulepath +$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(:nova_api_metadata_uwsgi_config).provider(:openstackconfig) +describe provider_class do + + it 'should default to the default setting when no other one is specified' do + resource = Puppet::Type::Nova_api_metadata_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::Nova_api_metadata_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 is specified as a value' do + resource = Puppet::Type::Nova_api_metadata_uwsgi_config.new( + {:name => 'dude/foo', :value => ''} + ) + 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::Nova_api_metadata_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 diff --git a/spec/unit/provider/nova_api_uwsgi_config/openstackconfig_spec.rb b/spec/unit/provider/nova_api_uwsgi_config/openstackconfig_spec.rb new file mode 100644 index 000000000..35ecfa80c --- /dev/null +++ b/spec/unit/provider/nova_api_uwsgi_config/openstackconfig_spec.rb @@ -0,0 +1,68 @@ +# +# these tests are a little concerning b/c they are hacking around the +# modulepath, so these tests will not catch issues that may eventually arise +# related to loading these plugins. +# I could not, for the life of me, figure out how to programatcally set the modulepath +$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(:nova_api_uwsgi_config).provider(:openstackconfig) +describe provider_class do + + it 'should default to the default setting when no other one is specified' do + resource = Puppet::Type::Nova_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::Nova_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 is specified as a value' do + resource = Puppet::Type::Nova_api_uwsgi_config.new( + {:name => 'dude/foo', :value => ''} + ) + 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::Nova_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 diff --git a/spec/unit/type/nova_api_metadata_uwsgi_config_spec.rb b/spec/unit/type/nova_api_metadata_uwsgi_config_spec.rb new file mode 100644 index 000000000..427240fd6 --- /dev/null +++ b/spec/unit/type/nova_api_metadata_uwsgi_config_spec.rb @@ -0,0 +1,64 @@ +require 'puppet' +require 'puppet/type/nova_api_metadata_uwsgi_config' + +describe 'Puppet::Type.type(:nova_api_metadata_uwsgi_config)' do + before :each do + @nova_api_metadata_uwsgi_config = Puppet::Type.type(:nova_api_metadata_uwsgi_config).new(:name => 'DEFAULT/foo', :value => 'bar') + end + + it 'should require a name' do + expect { + Puppet::Type.type(:nova_api_metadata_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(:nova_api_metadata_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(:nova_api_metadata_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(:nova_api_metadata_uwsgi_config).new(:name => 'DEFAULT/foo', :ensure => :absent) + end + + it 'should accept a valid value' do + @nova_api_metadata_uwsgi_config[:value] = 'bar' + expect(@nova_api_metadata_uwsgi_config[:value]).to eq('bar') + end + + it 'should not accept a value with whitespace' do + @nova_api_metadata_uwsgi_config[:value] = 'b ar' + expect(@nova_api_metadata_uwsgi_config[:value]).to eq('b ar') + end + + it 'should accept valid ensure values' do + @nova_api_metadata_uwsgi_config[:ensure] = :present + expect(@nova_api_metadata_uwsgi_config[:ensure]).to eq(:present) + @nova_api_metadata_uwsgi_config[:ensure] = :absent + expect(@nova_api_metadata_uwsgi_config[:ensure]).to eq(:absent) + end + + it 'should not accept invalid ensure values' do + expect { + @nova_api_metadata_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 => 'nova::install::end') + catalog.add_resource anchor, @nova_api_metadata_uwsgi_config + dependency = @nova_api_metadata_uwsgi_config.autorequire + expect(dependency.size).to eq(1) + expect(dependency[0].target).to eq(@nova_api_metadata_uwsgi_config) + expect(dependency[0].source).to eq(anchor) + end + +end diff --git a/spec/unit/type/nova_api_uwsgi_config_spec.rb b/spec/unit/type/nova_api_uwsgi_config_spec.rb new file mode 100644 index 000000000..65e95c4a6 --- /dev/null +++ b/spec/unit/type/nova_api_uwsgi_config_spec.rb @@ -0,0 +1,64 @@ +require 'puppet' +require 'puppet/type/nova_api_uwsgi_config' + +describe 'Puppet::Type.type(:nova_api_uwsgi_config)' do + before :each do + @nova_api_uwsgi_config = Puppet::Type.type(:nova_api_uwsgi_config).new(:name => 'DEFAULT/foo', :value => 'bar') + end + + it 'should require a name' do + expect { + Puppet::Type.type(:nova_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(:nova_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(:nova_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(:nova_api_uwsgi_config).new(:name => 'DEFAULT/foo', :ensure => :absent) + end + + it 'should accept a valid value' do + @nova_api_uwsgi_config[:value] = 'bar' + expect(@nova_api_uwsgi_config[:value]).to eq('bar') + end + + it 'should not accept a value with whitespace' do + @nova_api_uwsgi_config[:value] = 'b ar' + expect(@nova_api_uwsgi_config[:value]).to eq('b ar') + end + + it 'should accept valid ensure values' do + @nova_api_uwsgi_config[:ensure] = :present + expect(@nova_api_uwsgi_config[:ensure]).to eq(:present) + @nova_api_uwsgi_config[:ensure] = :absent + expect(@nova_api_uwsgi_config[:ensure]).to eq(:absent) + end + + it 'should not accept invalid ensure values' do + expect { + @nova_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 => 'nova::install::end') + catalog.add_resource anchor, @nova_api_uwsgi_config + dependency = @nova_api_uwsgi_config.autorequire + expect(dependency.size).to eq(1) + expect(dependency[0].target).to eq(@nova_api_uwsgi_config) + expect(dependency[0].source).to eq(anchor) + end + +end