Merge "Make Murano config providers inherit Openstack config provider"

This commit is contained in:
Jenkins 2015-10-21 12:16:03 +00:00 committed by Gerrit Code Review
commit 75d8e65f15
7 changed files with 147 additions and 30 deletions

View File

@ -1,21 +1,9 @@
Puppet::Type.type(:murano_config).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
:parent => Puppet::Type.type(:openstack_config).provider(:ini_setting)
) do
def section
resource[:name].split('/', 2).first
end
def setting
resource[:name].split('/', 2).last
end
def separator
'='
end
def file_path
def self.file_path
'/etc/murano/murano.conf'
end

View File

@ -1,21 +1,9 @@
Puppet::Type.type(:murano_paste_ini_config).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
:parent => Puppet::Type.type(:openstack_config).provider(:ini_setting)
) do
def section
resource[:name].split('/', 2).first
end
def setting
resource[:name].split('/', 2).last
end
def separator
'='
end
def file_path
def self.file_path
'/etc/murano/murano-paste.ini'
end

View File

@ -1,5 +1,4 @@
Puppet::Type.newtype(:murano_config) do
ensurable
newparam(:name, :namevar => true) do
@ -14,6 +13,36 @@ Puppet::Type.newtype(:murano_config) do
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

View File

@ -1,5 +1,4 @@
Puppet::Type.newtype(:murano_paste_ini_config) do
ensurable
newparam(:name, :namevar => true) do
@ -14,6 +13,39 @@ Puppet::Type.newtype(:murano_paste_ini_config) do
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
'murano-common'
end
end

View File

@ -1,3 +1,8 @@
#
# 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__),
@ -9,6 +14,17 @@ $LOAD_PATH.push(
'inifile',
'lib')
)
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'..',
'fixtures',
'modules',
'openstacklib',
'lib')
)
require 'spec_helper'
provider_class = Puppet::Type.type(:murano_config).provider(:ini_setting)
describe provider_class do
@ -30,4 +46,23 @@ describe provider_class do
expect(provider.section).to eq('dude')
expect(provider.setting).to eq('whoa')
end
it 'should ensure absent when <SERVICE DEFAULT> is specified as a value' do
resource = Puppet::Type::Murano_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::Murano_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

@ -1,3 +1,8 @@
#
# 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__),
@ -9,6 +14,17 @@ $LOAD_PATH.push(
'inifile',
'lib')
)
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'..',
'fixtures',
'modules',
'openstacklib',
'lib')
)
require 'spec_helper'
provider_class = Puppet::Type.type(:murano_paste_ini_config).provider(:ini_setting)
describe provider_class do
@ -30,4 +46,23 @@ describe provider_class do
expect(provider.section).to eq('dude')
expect(provider.setting).to eq('whoa')
end
it 'should ensure absent when <SERVICE DEFAULT> is specified as a value' do
resource = Puppet::Type::Murano_paste_ini_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::Murano_paste_ini_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

@ -49,4 +49,14 @@ describe 'Puppet::Type.type(:murano_paste_ini_config)' do
@murano_paste_ini_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
package = Puppet::Type.type(:package).new(:name => 'murano-common')
catalog.add_resource package, @murano_paste_ini_config
dependency = @murano_paste_ini_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@murano_paste_ini_config)
expect(dependency[0].source).to eq(package)
end
end