From 51f4ad1cb3dbd534716a589562413e3c5e31ab58 Mon Sep 17 00:00:00 2001 From: Thomas Goirand Date: Thu, 8 Apr 2021 00:28:23 +0200 Subject: [PATCH] Add support for swift_{proxy,account,container}_uwsgi_config in Debian This patch is adding the configuration of the number of workers, and the size of the listen queue in Debian, which uses uwsgi to run Swift. Therefore, this patch adds new swift_proxy_uwsgi_config, swift_account_uwsgi_config, and swift_container_uwsgi_config, providers as well as e new swift::wsgi::uwsgi_proxy, swift::wsgi::uwsgi_container, and swift::wsgi::uwsgi_account classes. Change-Id: Ib18f3479bc6a4513a7b3d823cda480c4ace2f2c0 --- .../swift_account_uwsgi_config/ini_setting.rb | 8 +++ .../ini_setting.rb | 8 +++ .../swift_proxy_uwsgi_config/ini_setting.rb | 8 +++ lib/puppet/type/swift_account_uwsgi_config.rb | 27 ++++++++ .../type/swift_container_uwsgi_config.rb | 27 ++++++++ lib/puppet/type/swift_proxy_uwsgi_config.rb | 27 ++++++++ manifests/deps.pp | 13 ++++ manifests/wsgi/uwsgi_account.pp | 35 ++++++++++ manifests/wsgi/uwsgi_container.pp | 35 ++++++++++ manifests/wsgi/uwsgi_proxy.pp | 35 ++++++++++ .../notes/uwsgi-d10bf5ebcf3ff07d.yaml | 9 +++ spec/classes/swift_wsgi_uwsgi_account_spec.rb | 30 +++++++++ .../swift_wsgi_uwsgi_container_spec.rb | 30 +++++++++ spec/classes/swift_wsgi_uwsgi_proxy_spec.rb | 30 +++++++++ .../ini_setting_spec.rb | 57 +++++++++++++++++ .../ini_setting_spec.rb | 57 +++++++++++++++++ .../ini_setting_spec.rb | 57 +++++++++++++++++ .../type/swift_account_uwsgi_config_spec.rb | 64 +++++++++++++++++++ .../type/swift_container_uwsgi_config_spec.rb | 64 +++++++++++++++++++ .../type/swift_proxy_uwsgi_config_spec.rb | 64 +++++++++++++++++++ 20 files changed, 685 insertions(+) create mode 100644 lib/puppet/provider/swift_account_uwsgi_config/ini_setting.rb create mode 100644 lib/puppet/provider/swift_container_uwsgi_config/ini_setting.rb create mode 100644 lib/puppet/provider/swift_proxy_uwsgi_config/ini_setting.rb create mode 100644 lib/puppet/type/swift_account_uwsgi_config.rb create mode 100644 lib/puppet/type/swift_container_uwsgi_config.rb create mode 100644 lib/puppet/type/swift_proxy_uwsgi_config.rb create mode 100644 manifests/wsgi/uwsgi_account.pp create mode 100644 manifests/wsgi/uwsgi_container.pp create mode 100644 manifests/wsgi/uwsgi_proxy.pp create mode 100644 releasenotes/notes/uwsgi-d10bf5ebcf3ff07d.yaml create mode 100644 spec/classes/swift_wsgi_uwsgi_account_spec.rb create mode 100644 spec/classes/swift_wsgi_uwsgi_container_spec.rb create mode 100644 spec/classes/swift_wsgi_uwsgi_proxy_spec.rb create mode 100644 spec/unit/provider/swift_account_uwsgi_config/ini_setting_spec.rb create mode 100644 spec/unit/provider/swift_container_uwsgi_config/ini_setting_spec.rb create mode 100644 spec/unit/provider/swift_proxy_uwsgi_config/ini_setting_spec.rb create mode 100644 spec/unit/type/swift_account_uwsgi_config_spec.rb create mode 100644 spec/unit/type/swift_container_uwsgi_config_spec.rb create mode 100644 spec/unit/type/swift_proxy_uwsgi_config_spec.rb diff --git a/lib/puppet/provider/swift_account_uwsgi_config/ini_setting.rb b/lib/puppet/provider/swift_account_uwsgi_config/ini_setting.rb new file mode 100644 index 00000000..912fa0f6 --- /dev/null +++ b/lib/puppet/provider/swift_account_uwsgi_config/ini_setting.rb @@ -0,0 +1,8 @@ +Puppet::Type.type(:swift_account_uwsgi_config).provide( + :ini_setting, + :parent => Puppet::Type.type(:openstack_config).provider(:ini_setting) +) do + def self.file_path + '/etc/swift/swift-account-server-uwsgi.ini' + end +end diff --git a/lib/puppet/provider/swift_container_uwsgi_config/ini_setting.rb b/lib/puppet/provider/swift_container_uwsgi_config/ini_setting.rb new file mode 100644 index 00000000..bc6a0d62 --- /dev/null +++ b/lib/puppet/provider/swift_container_uwsgi_config/ini_setting.rb @@ -0,0 +1,8 @@ +Puppet::Type.type(:swift_container_uwsgi_config).provide( + :ini_setting, + :parent => Puppet::Type.type(:openstack_config).provider(:ini_setting) +) do + def self.file_path + '/etc/swift/swift-container-server-uwsgi.ini' + end +end diff --git a/lib/puppet/provider/swift_proxy_uwsgi_config/ini_setting.rb b/lib/puppet/provider/swift_proxy_uwsgi_config/ini_setting.rb new file mode 100644 index 00000000..ec9c31ef --- /dev/null +++ b/lib/puppet/provider/swift_proxy_uwsgi_config/ini_setting.rb @@ -0,0 +1,8 @@ +Puppet::Type.type(:swift_proxy_uwsgi_config).provide( + :ini_setting, + :parent => Puppet::Type.type(:openstack_config).provider(:ini_setting) +) do + def self.file_path + '/etc/swift/swift-proxy-server-uwsgi.ini' + end +end diff --git a/lib/puppet/type/swift_account_uwsgi_config.rb b/lib/puppet/type/swift_account_uwsgi_config.rb new file mode 100644 index 00000000..bccafd77 --- /dev/null +++ b/lib/puppet/type/swift_account_uwsgi_config.rb @@ -0,0 +1,27 @@ +Puppet::Type.newtype(:swift_account_uwsgi_config) do + + ensurable + + newparam(:name, :namevar => true) do + desc 'Section/setting name to manage from /etc/swift/swift-account-server-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('') + end + + autorequire(:anchor) do + ['swift::install::end'] + 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 + end +end diff --git a/lib/puppet/type/swift_container_uwsgi_config.rb b/lib/puppet/type/swift_container_uwsgi_config.rb new file mode 100644 index 00000000..9d9b9d60 --- /dev/null +++ b/lib/puppet/type/swift_container_uwsgi_config.rb @@ -0,0 +1,27 @@ +Puppet::Type.newtype(:swift_container_uwsgi_config) do + + ensurable + + newparam(:name, :namevar => true) do + desc 'Section/setting name to manage from /etc/swift/swift-container-server-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('') + end + + autorequire(:anchor) do + ['swift::install::end'] + 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 + end +end diff --git a/lib/puppet/type/swift_proxy_uwsgi_config.rb b/lib/puppet/type/swift_proxy_uwsgi_config.rb new file mode 100644 index 00000000..99462794 --- /dev/null +++ b/lib/puppet/type/swift_proxy_uwsgi_config.rb @@ -0,0 +1,27 @@ +Puppet::Type.newtype(:swift_proxy_uwsgi_config) do + + ensurable + + newparam(:name, :namevar => true) do + desc 'Section/setting name to manage from /etc/swift/swift-proxy-server-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('') + end + + autorequire(:anchor) do + ['swift::install::end'] + 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 + end +end diff --git a/manifests/deps.pp b/manifests/deps.pp index 2a4dca83..9e546e51 100644 --- a/manifests/deps.pp +++ b/manifests/deps.pp @@ -46,6 +46,19 @@ class swift::deps { -> Concat<| tag == 'swift-concat' |> ~> Anchor['swift::config::end'] + # On any uwsgi config change, we must restart Swift. + Anchor['swift::config::begin'] + -> Swift_proxy_uwsgi_config<||> + ~> Anchor['swift::config::end'] + + Anchor['swift::config::begin'] + -> Swift_account_uwsgi_config<||> + ~> Anchor['swift::config::end'] + + Anchor['swift::config::begin'] + -> Swift_container_uwsgi_config<||> + ~> Anchor['swift::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 swift-package tag and the swift-support-package diff --git a/manifests/wsgi/uwsgi_account.pp b/manifests/wsgi/uwsgi_account.pp new file mode 100644 index 00000000..9a385954 --- /dev/null +++ b/manifests/wsgi/uwsgi_account.pp @@ -0,0 +1,35 @@ +# +# Copyright 2021 Thomas Goirand +# +# Author: Thomas Goirand +# +# == Class: swift::wsgi::uwsgi_account +# +# Configure the UWSGI service for Swift Account. +# +# == Parameters +# +# [*processes*] +# (Optional) Number of processes. +# Defaults to $::os_workers. +# +# [*listen_queue_size*] +# (Optional) Socket listen queue size. +# Defaults to 100 +# +class swift::wsgi::uwsgi_account ( + $processes = $::os_workers, + $listen_queue_size = 100, +){ + + include swift::deps + + if $::os_package_type != 'debian'{ + warning('This class is only valid for Debian, as other operating systems are not using uwsgi by default.') + } + + swift_account_uwsgi_config { + 'uwsgi/processes': value => $processes; + 'uwsgi/listen': value => $listen_queue_size; + } +} diff --git a/manifests/wsgi/uwsgi_container.pp b/manifests/wsgi/uwsgi_container.pp new file mode 100644 index 00000000..31ad17de --- /dev/null +++ b/manifests/wsgi/uwsgi_container.pp @@ -0,0 +1,35 @@ +# +# Copyright 2021 Thomas Goirand +# +# Author: Thomas Goirand +# +# == Class: swift::wsgi::uwsgi_container +# +# Configure the UWSGI service for Swift Container. +# +# == Parameters +# +# [*processes*] +# (Optional) Number of processes. +# Defaults to $::os_workers. +# +# [*listen_queue_size*] +# (Optional) Socket listen queue size. +# Defaults to 100 +# +class swift::wsgi::uwsgi_container ( + $processes = $::os_workers, + $listen_queue_size = 100, +){ + + include swift::deps + + if $::os_package_type != 'debian'{ + warning('This class is only valid for Debian, as other operating systems are not using uwsgi by default.') + } + + swift_container_uwsgi_config { + 'uwsgi/processes': value => $processes; + 'uwsgi/listen': value => $listen_queue_size; + } +} diff --git a/manifests/wsgi/uwsgi_proxy.pp b/manifests/wsgi/uwsgi_proxy.pp new file mode 100644 index 00000000..e1b91ced --- /dev/null +++ b/manifests/wsgi/uwsgi_proxy.pp @@ -0,0 +1,35 @@ +# +# Copyright 2021 Thomas Goirand +# +# Author: Thomas Goirand +# +# == Class: swift::wsgi::uwsgi_proxy +# +# Configure the UWSGI service for Swift Proxy. +# +# == Parameters +# +# [*processes*] +# (Optional) Number of processes. +# Defaults to $::os_workers. +# +# [*listen_queue_size*] +# (Optional) Socket listen queue size. +# Defaults to 100 +# +class swift::wsgi::uwsgi_proxy ( + $processes = $::os_workers, + $listen_queue_size = 100, +){ + + include swift::deps + + if $::os_package_type != 'debian'{ + warning('This class is only valid for Debian, as other operating systems are not using uwsgi by default.') + } + + swift_proxy_uwsgi_config { + 'uwsgi/processes': value => $processes; + 'uwsgi/listen': value => $listen_queue_size; + } +} diff --git a/releasenotes/notes/uwsgi-d10bf5ebcf3ff07d.yaml b/releasenotes/notes/uwsgi-d10bf5ebcf3ff07d.yaml new file mode 100644 index 00000000..809385ad --- /dev/null +++ b/releasenotes/notes/uwsgi-d10bf5ebcf3ff07d.yaml @@ -0,0 +1,9 @@ +--- +features: + - | + 3 new classes swift::wsgi::uwsgi_proxy, swift::wsgi::uwsgi_account and + swift::wsgi::uwsgi_container exist to allow configuring uwsgi in + operating systems that support this (ie: currently Debian). This helps + configuring the number of processes and listen socket. + Also, 3 new swift_proxy_uwsgi_config, swift_account_uwsgi_config, and + swift_container_uwsgi_config providers now exist. diff --git a/spec/classes/swift_wsgi_uwsgi_account_spec.rb b/spec/classes/swift_wsgi_uwsgi_account_spec.rb new file mode 100644 index 00000000..1dfd6079 --- /dev/null +++ b/spec/classes/swift_wsgi_uwsgi_account_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe 'swift::wsgi::uwsgi_account' do + + shared_examples 'swift::wsgi::uwsgi_account' do + context 'with default parameters' do + it { + should contain_class('swift::deps') + } + + it { + is_expected.to contain_swift_account_uwsgi_config('uwsgi/processes').with_value(facts[:os_workers]) + is_expected.to contain_swift_account_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 'swift::wsgi::uwsgi_account' + end + end +end diff --git a/spec/classes/swift_wsgi_uwsgi_container_spec.rb b/spec/classes/swift_wsgi_uwsgi_container_spec.rb new file mode 100644 index 00000000..a2b79ab1 --- /dev/null +++ b/spec/classes/swift_wsgi_uwsgi_container_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe 'swift::wsgi::uwsgi_container' do + + shared_examples 'swift::wsgi::uwsgi_container' do + context 'with default parameters' do + it { + should contain_class('swift::deps') + } + + it { + is_expected.to contain_swift_container_uwsgi_config('uwsgi/processes').with_value(facts[:os_workers]) + is_expected.to contain_swift_container_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 'swift::wsgi::uwsgi_container' + end + end +end diff --git a/spec/classes/swift_wsgi_uwsgi_proxy_spec.rb b/spec/classes/swift_wsgi_uwsgi_proxy_spec.rb new file mode 100644 index 00000000..7581c961 --- /dev/null +++ b/spec/classes/swift_wsgi_uwsgi_proxy_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe 'swift::wsgi::uwsgi_proxy' do + + shared_examples 'swift::wsgi::uwsgi_proxy' do + context 'with default parameters' do + it { + should contain_class('swift::deps') + } + + it { + is_expected.to contain_swift_proxy_uwsgi_config('uwsgi/processes').with_value(facts[:os_workers]) + is_expected.to contain_swift_proxy_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 'swift::wsgi::uwsgi_proxy' + end + end +end diff --git a/spec/unit/provider/swift_account_uwsgi_config/ini_setting_spec.rb b/spec/unit/provider/swift_account_uwsgi_config/ini_setting_spec.rb new file mode 100644 index 00000000..93c99902 --- /dev/null +++ b/spec/unit/provider/swift_account_uwsgi_config/ini_setting_spec.rb @@ -0,0 +1,57 @@ +# +# 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') +) +require 'spec_helper' +provider_class = Puppet::Type.type(:swift_account_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::Swift_account_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::Swift_account_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::Swift_account_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::Swift_account_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/swift_container_uwsgi_config/ini_setting_spec.rb b/spec/unit/provider/swift_container_uwsgi_config/ini_setting_spec.rb new file mode 100644 index 00000000..7216c19b --- /dev/null +++ b/spec/unit/provider/swift_container_uwsgi_config/ini_setting_spec.rb @@ -0,0 +1,57 @@ +# +# 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') +) +require 'spec_helper' +provider_class = Puppet::Type.type(:swift_container_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::Swift_container_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::Swift_container_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::Swift_container_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::Swift_container_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/swift_proxy_uwsgi_config/ini_setting_spec.rb b/spec/unit/provider/swift_proxy_uwsgi_config/ini_setting_spec.rb new file mode 100644 index 00000000..3cd39bad --- /dev/null +++ b/spec/unit/provider/swift_proxy_uwsgi_config/ini_setting_spec.rb @@ -0,0 +1,57 @@ +# +# 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') +) +require 'spec_helper' +provider_class = Puppet::Type.type(:swift_proxy_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::Swift_proxy_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::Swift_proxy_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::Swift_proxy_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::Swift_proxy_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/swift_account_uwsgi_config_spec.rb b/spec/unit/type/swift_account_uwsgi_config_spec.rb new file mode 100644 index 00000000..5417daab --- /dev/null +++ b/spec/unit/type/swift_account_uwsgi_config_spec.rb @@ -0,0 +1,64 @@ +require 'puppet' +require 'puppet/type/swift_account_uwsgi_config' + +describe 'Puppet::Type.type(:swift_account_uwsgi_config)' do + before :each do + @swift_account_uwsgi_config = Puppet::Type.type(:swift_account_uwsgi_config).new(:name => 'DEFAULT/foo', :value => 'bar') + end + + it 'should require a name' do + expect { + Puppet::Type.type(:swift_account_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(:swift_account_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(:swift_account_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(:swift_account_uwsgi_config).new(:name => 'DEFAULT/foo', :ensure => :absent) + end + + it 'should accept a valid value' do + @swift_account_uwsgi_config[:value] = 'bar' + expect(@swift_account_uwsgi_config[:value]).to eq('bar') + end + + it 'should not accept a value with whitespace' do + @swift_account_uwsgi_config[:value] = 'b ar' + expect(@swift_account_uwsgi_config[:value]).to eq('b ar') + end + + it 'should accept valid ensure values' do + @swift_account_uwsgi_config[:ensure] = :present + expect(@swift_account_uwsgi_config[:ensure]).to eq(:present) + @swift_account_uwsgi_config[:ensure] = :absent + expect(@swift_account_uwsgi_config[:ensure]).to eq(:absent) + end + + it 'should not accept invalid ensure values' do + expect { + @swift_account_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 => 'swift::install::end') + catalog.add_resource anchor, @swift_account_uwsgi_config + dependency = @swift_account_uwsgi_config.autorequire + expect(dependency.size).to eq(1) + expect(dependency[0].target).to eq(@swift_account_uwsgi_config) + expect(dependency[0].source).to eq(anchor) + end + +end diff --git a/spec/unit/type/swift_container_uwsgi_config_spec.rb b/spec/unit/type/swift_container_uwsgi_config_spec.rb new file mode 100644 index 00000000..84255205 --- /dev/null +++ b/spec/unit/type/swift_container_uwsgi_config_spec.rb @@ -0,0 +1,64 @@ +require 'puppet' +require 'puppet/type/swift_container_uwsgi_config' + +describe 'Puppet::Type.type(:swift_container_uwsgi_config)' do + before :each do + @swift_container_uwsgi_config = Puppet::Type.type(:swift_container_uwsgi_config).new(:name => 'DEFAULT/foo', :value => 'bar') + end + + it 'should require a name' do + expect { + Puppet::Type.type(:swift_container_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(:swift_container_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(:swift_container_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(:swift_container_uwsgi_config).new(:name => 'DEFAULT/foo', :ensure => :absent) + end + + it 'should accept a valid value' do + @swift_container_uwsgi_config[:value] = 'bar' + expect(@swift_container_uwsgi_config[:value]).to eq('bar') + end + + it 'should not accept a value with whitespace' do + @swift_container_uwsgi_config[:value] = 'b ar' + expect(@swift_container_uwsgi_config[:value]).to eq('b ar') + end + + it 'should accept valid ensure values' do + @swift_container_uwsgi_config[:ensure] = :present + expect(@swift_container_uwsgi_config[:ensure]).to eq(:present) + @swift_container_uwsgi_config[:ensure] = :absent + expect(@swift_container_uwsgi_config[:ensure]).to eq(:absent) + end + + it 'should not accept invalid ensure values' do + expect { + @swift_container_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 => 'swift::install::end') + catalog.add_resource anchor, @swift_container_uwsgi_config + dependency = @swift_container_uwsgi_config.autorequire + expect(dependency.size).to eq(1) + expect(dependency[0].target).to eq(@swift_container_uwsgi_config) + expect(dependency[0].source).to eq(anchor) + end + +end diff --git a/spec/unit/type/swift_proxy_uwsgi_config_spec.rb b/spec/unit/type/swift_proxy_uwsgi_config_spec.rb new file mode 100644 index 00000000..7580a339 --- /dev/null +++ b/spec/unit/type/swift_proxy_uwsgi_config_spec.rb @@ -0,0 +1,64 @@ +require 'puppet' +require 'puppet/type/swift_proxy_uwsgi_config' + +describe 'Puppet::Type.type(:swift_proxy_uwsgi_config)' do + before :each do + @swift_proxy_uwsgi_config = Puppet::Type.type(:swift_proxy_uwsgi_config).new(:name => 'DEFAULT/foo', :value => 'bar') + end + + it 'should require a name' do + expect { + Puppet::Type.type(:swift_proxy_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(:swift_proxy_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(:swift_proxy_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(:swift_proxy_uwsgi_config).new(:name => 'DEFAULT/foo', :ensure => :absent) + end + + it 'should accept a valid value' do + @swift_proxy_uwsgi_config[:value] = 'bar' + expect(@swift_proxy_uwsgi_config[:value]).to eq('bar') + end + + it 'should not accept a value with whitespace' do + @swift_proxy_uwsgi_config[:value] = 'b ar' + expect(@swift_proxy_uwsgi_config[:value]).to eq('b ar') + end + + it 'should accept valid ensure values' do + @swift_proxy_uwsgi_config[:ensure] = :present + expect(@swift_proxy_uwsgi_config[:ensure]).to eq(:present) + @swift_proxy_uwsgi_config[:ensure] = :absent + expect(@swift_proxy_uwsgi_config[:ensure]).to eq(:absent) + end + + it 'should not accept invalid ensure values' do + expect { + @swift_proxy_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 => 'swift::install::end') + catalog.add_resource anchor, @swift_proxy_uwsgi_config + dependency = @swift_proxy_uwsgi_config.autorequire + expect(dependency.size).to eq(1) + expect(dependency[0].target).to eq(@swift_proxy_uwsgi_config) + expect(dependency[0].source).to eq(anchor) + end + +end