Update main glare class

- adding glare class
- modifying parameters class

Change-Id: I3e2ead1e63e31d78e3de2558b0388573733aaff0
This commit is contained in:
Peter Zhurba 2016-09-20 20:15:52 +03:00 committed by Maciej Relewicz
parent 54d8acc9dc
commit 7cbd4398d0
8 changed files with 533 additions and 5 deletions

View File

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

View File

@ -0,0 +1,53 @@
Puppet::Type.newtype(:glare_paste_ini) do
ensurable
newparam(:name, :namevar => true) do
desc 'Section/setting name to manage from glare_paste.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 ]*$/)
def is_to_s( currentvalue )
if resource.secret?
return '[old secret redacted]'
else
return currentvalue
end
end
def should_to_s( newvalue )
if resource.secret?
return '[new secret redacted]'
else
return newvalue
end
end
end
newparam(:secret, :boolean => true) do
desc 'Whether to hide the value from Puppet logs. Defaults to `false`.'
newvalues(:true, :false)
defaultto false
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
autorequire(:package) do
'glare'
end
end

View File

@ -1,14 +1,176 @@
# == Class: glare
#
# Full description of class glare here.
# Base glare config.
#
# === Parameters
# [*package_ensure*]
# (optional) Ensure state for package. On RedHat platforms this
# setting is ignored and the setting from the glance class is used
# because there is only one glance package. Defaults to 'present'.
#
# [*sample_parameter*]
# Explanation of what this parameter affects and what it defaults to.
# [*bind_host*]
# (optional) The address of the host to bind to.
# Default: 0.0.0.0
#
class glare {
# [*bind_port*]
# (optional) The port the server should bind to.
# Default: 9494
#
# [*backlog*]
# (optional) Backlog requests when creating socket
# Default: 4096
#
# [*workers*]
# (optional) Number of Glare worker processes to start
# Default: $::os_workers
#
# [*auth_strategy*]
# (optional) Type is authorization being used.
# Defaults to 'keystone'
#
# [*pipeline*]
# (optional) Partial name of a pipeline in your paste configuration file with the
# service name removed.
# Defaults to 'keystone'.
#
# [*manage_service*]
# (optional) If Puppet should manage service startup / shutdown.
# Defaults to true.
#
# [*enabled*]
# (optional) Whether to enable services.
# Defaults to true.
#
# [*cert_file*]
# (optinal) Certificate file to use when starting API server securely
# Defaults to $::os_service_default
#
# [*key_file*]
# (optional) Private key file to use when starting API server securely
# Defaults to $::os_service_default
#
# [*ca_file*]
# (optional) CA certificate file to use to verify connecting clients
# Defaults to $::os_service_default
#
# [*stores*]
# (optional) List of which store classes and store class locations are
# currently known to glare at startup.
# Defaults to $::os_service_default,
# Example: file,http
# Possible values:
# * A comma separated list that could include:
# * file
# * http
# * swift
# * rbd
# * sheepdog
# * cinder
# * vmware
# Related Options:
# * default_store
#
#
# [*default_store*]
# (optional) Allowed values: file, filesystem, http, https, swift,
# swift+http, swift+https, swift+config, rbd, sheepdog, cinder, vsphere
# default_store = $::os_service_default,
#
# [*filesystem_store_datadir*]
#
# filesystem_store_datadir = /var/lib/glance/images
#
# [*os_region_name*]
# (optional) Sets the keystone region to use.
# Defaults to 'RegionOne'.
#
# [*allow_anonymous_access*]
# (optional)Allow unauthenticated users to access the API with read-only
# privileges. This only applies when using ContextMiddleware. (boolean
# value)
# Defaults to false
#
class glare (
$package_ensure = 'present',
$bind_host = $::os_service_default,
$bind_port = $::os_service_default,
$backlog = $::os_service_default,
$workers = $::os_workers,
$auth_strategy = 'keystone',
$pipeline = 'keystone',
$manage_service = true,
$enabled = true,
$cert_file = $::os_service_default,
$key_file = $::os_service_default,
$ca_file = $::os_service_default,
$stores = $::os_service_default,
$default_store = $::os_service_default,
$filesystem_store_datadir = '/var/lib/glare/images',
$os_region_name = 'RegionOne',
$allow_anonymous_access = $::os_service_default,
) {
include ::glare::params
include ::glare::db
include ::glare::logging
ensure_packages ( 'glare' , {
ensure => $package_ensure,
name => $::glare::params::glare_package_name,
})
glare_config {
'DEFAULT/bind_host' : value => $bind_host;
'DEFAULT/bind_port' : value => $bind_port;
'DEFAULT/backlog' : value => $backlog;
'DEFAULT/workers' : value => $workers;
'DEFAULT/allow_anonymous_access': value => $allow_anonymous_access;
}
glare_config {
'glance_store/os_region_name' : value => $os_region_name;
'glance_store/stores' : value => $stores;
'glance_store/default_store' : value => $default_store;
'glance_store/filesystem_store_datadir': value => $filesystem_store_datadir;
}
if $pipeline != '' {
glare_config {
'paste_deploy/flavor':
ensure => present,
value => $pipeline,
}
if $pipeline == 'session' {
glare_paste_ini { 'pipeline:glare-api-session/pipeline':
value => 'cors faultwrapper healthcheck versionnegotiation context glarev1api'
}
}
} else {
glare_config { 'paste_deploy/flavor': ensure => absent }
}
# keystone config
if $auth_strategy == 'keystone' {
include ::glare::keystone::authtoken
}
# SSL Options
glare_config {
'DEFAULT/cert_file': value => $cert_file;
'DEFAULT/key_file' : value => $key_file;
'DEFAULT/ca_file' : value => $ca_file;
}
if $manage_service {
if $enabled {
$service_ensure = 'running'
} else {
$service_ensure = 'stopped'
}
}
service { 'glare':
ensure => $service_ensure,
name => $::glare::params::glare_service_name,
enable => $enabled
}
}

View File

@ -5,8 +5,12 @@ class glare::params {
case $::osfamily {
'RedHat': {
$glare_package_name = 'openstack-glare'
$glare_service_name = 'openstack-glare-api'
}
'Debian': {
$glare_package_name = 'glare'
$glare_service_name = 'glare-api'
}
default: {
fail("Unsupported osfamily: ${::osfamily} operatingsystem")

View File

@ -0,0 +1,83 @@
require 'spec_helper_acceptance'
describe 'basic glare config resource' do
context 'default parameters' do
it 'should work with no errors' do
pp= <<-EOS
Exec { logoutput => 'on_failure' }
File <||> -> Glare_config <||>
File <||> -> Glare_paste_ini <||>
file { '/etc/glare' :
ensure => directory,
}
file { '/etc/glare/glare.conf' :
ensure => file,
}
file { '/etc/glare/glare-paste.ini' :
ensure => file,
}
glare_config { 'DEFAULT/thisshouldexist' :
value => 'foo',
}
glare_config { 'DEFAULT/thisshouldnotexist' :
value => '<SERVICE DEFAULT>',
}
glare_config { 'DEFAULT/thisshouldexist2' :
value => '<SERVICE DEFAULT>',
ensure_absent_val => 'toto',
}
glare_config { 'DEFAULT/thisshouldnotexist2' :
value => 'toto',
ensure_absent_val => 'toto',
}
glare_paste_ini { 'DEFAULT/thisshouldexist' :
value => 'foo',
}
glare_paste_ini { 'DEFAULT/thisshouldnotexist' :
value => '<SERVICE DEFAULT>',
}
glare_paste_ini { 'DEFAULT/thisshouldexist2' :
value => '<SERVICE DEFAULT>',
ensure_absent_val => 'toto',
}
glare_paste_ini { 'DEFAULT/thisshouldnotexist2' :
value => 'toto',
ensure_absent_val => 'toto',
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file('/etc/glare/glare.conf') do
it { is_expected.to exist }
it { is_expected.to contain('thisshouldexist=foo') }
it { is_expected.to contain('thisshouldexist2=<SERVICE DEFAULT>') }
describe '#content' do
subject { super().content }
it { is_expected.not_to match /thisshouldnotexist/ }
end
end
describe file('/etc/glare/glare-paste.ini') do
it { is_expected.to exist }
it { is_expected.to contain('thisshouldexist=foo') }
it { is_expected.to contain('thisshouldexist2=<SERVICE DEFAULT>') }
describe '#content' do
subject { super().content }
it { is_expected.not_to match /thisshouldnotexist/ }
end
end
end
end

View File

@ -0,0 +1,87 @@
require 'spec_helper'
describe 'glare' do
shared_examples 'glare' do
context 'with default parameters' do
let :pre_condition do
"class { '::glare::keystone::authtoken':
password => 'ChangeMe' }"
end
it 'contains the params class' do
is_expected.to contain_class('glare::params')
end
it 'contains the db class' do
is_expected.to contain_class('glare::db')
end
it 'contains the logging class' do
is_expected.to contain_class('glare::logging')
end
it 'installs package' do
is_expected.to contain_package('glare').with(
:ensure => 'present',
:name => platform_params[:glare_package_name]
)
end
it { is_expected.to contain_glare_config('DEFAULT/bind_host').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_glare_config('DEFAULT/bind_port').with_value('<SERVICE DEFAULT>') }
it { is_expected.to contain_glare_config('DEFAULT/backlog').with_value('<SERVICE DEFAULT>') }
it 'configures storage' do
is_expected.to contain_glare_config('glance_store/os_region_name').with_value('RegionOne')
is_expected.to contain_glare_config('glance_store/stores').with_value('<SERVICE DEFAULT>')
is_expected.to contain_glare_config('glance_store/default_store').with_value('<SERVICE DEFAULT>')
is_expected.to contain_glare_config('glance_store/filesystem_store_datadir').with_value('/var/lib/glare/images')
end
it 'is_expected.to configure itself for keystone if it needed' do
if :auth_strategy == 'keystone'
is_expected.to contain_class('glare::authtoken')
end
end
it 'configures ssl' do
is_expected.to contain_glare_config('DEFAULT/cert_file').with_value('<SERVICE DEFAULT>')
is_expected.to contain_glare_config('DEFAULT/key_file').with_value('<SERVICE DEFAULT>')
is_expected.to contain_glare_config('DEFAULT/ca_file').with_value('<SERVICE DEFAULT>')
end
it { is_expected.to contain_service('glare').with(
'ensure' => 'running',
'name' => platform_params[:glare_service_name],
'enable' => true,
) }
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
case facts[:osfamily]
when 'Debian'
let (:platform_params) do
{ :glare_package_name => 'glare',
:glare_service_name => 'glare-api' }
end
when 'RedHat'
let (:platform_params) do
{ :glare_package_name => 'openstack-glare',
:glare_service_name => 'openstack-glare-api' }
end
end
it_behaves_like 'glare'
end
end
end

View File

@ -0,0 +1,67 @@
#
# 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(:glare_paste_ini).provider(:ini_setting)
describe provider_class do
it 'should default to the default setting when no other one is specified' do
resource = Puppet::Type::Glare_paste_ini.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::Glare_paste_ini.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::Glare_paste_ini.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::Glare_paste_ini.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,62 @@
require 'puppet'
require 'puppet/type/glare_config'
describe 'Puppet::Type.type(:glare_paste_ini)' do
before :each do
@glare_paste_ini = Puppet::Type.type(:glare_paste_ini).new(:name => 'DEFAULT/foo', :value => 'bar')
end
it 'should require a name' do
expect {
Puppet::Type.type(:glare_paste_ini).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(:glare_paste_ini).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(:glare_paste_ini).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(:glare_paste_ini).new(:name => 'DEFAULT/foo', :ensure => :absent)
end
it 'should accept a valid value' do
@glare_paste_ini[:value] = 'bar'
expect(@glare_paste_ini[:value]).to eq('bar')
end
it 'should not accept a value with whitespace' do
@glare_paste_ini[:value] = 'b ar'
expect(@glare_paste_ini[:value]).to eq('b ar')
end
it 'should accept valid ensure values' do
@glare_paste_ini[:ensure] = :present
expect(@glare_paste_ini[:ensure]).to eq(:present)
@glare_paste_ini[:ensure] = :absent
expect(@glare_paste_ini[:ensure]).to eq(:absent)
end
it 'should not accept invalid ensure values' do
expect {
@glare_paste_ini[: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
package = Puppet::Type.type(:package).new(:name => 'glare')
catalog.add_resource package, @glare_paste_ini
dependency = @glare_paste_ini.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@glare_paste_ini)
expect(dependency[0].source).to eq(package)
end
end