change nova_config to use ini_file
This commit refactors the nova_config type to use the ini_file provider. This will ensure that this type is consistent with other types. It also completely removes the parsed and parsed_config types. The usage of inifile from nova_config is slightly difference from other similar types. It does not require a section name, and assumes that settings supplied without a section name belong in the default section. This is for backwards compatibility with the other types and will likely change in the next major version. this commit also updates nova_paste_int to support purging.
This commit is contained in:
parent
16bbb76f48
commit
ac5fb1ca8a
34
lib/puppet/provider/nova_config/ini_setting.rb
Normal file
34
lib/puppet/provider/nova_config/ini_setting.rb
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
Puppet::Type.type(:nova_config).provide(
|
||||||
|
:ini_setting,
|
||||||
|
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
|
||||||
|
) do
|
||||||
|
|
||||||
|
# the setting is always default
|
||||||
|
# this if for backwards compat with the old puppet providers for nova_config
|
||||||
|
def section
|
||||||
|
section_setting = resource[:name].split('/', 2)
|
||||||
|
section_setting.size == 2 ? section_setting.first : 'DEFAULT'
|
||||||
|
end
|
||||||
|
|
||||||
|
# assumes that the name was the setting
|
||||||
|
# this is to maintain backwards compat with the the older
|
||||||
|
# stuff
|
||||||
|
def setting
|
||||||
|
section_setting = resource[:name].split('/', 2)
|
||||||
|
section_setting.size == 2 ? section_setting.last : resource[:name]
|
||||||
|
end
|
||||||
|
|
||||||
|
def separator
|
||||||
|
'='
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.file_path
|
||||||
|
'/etc/nova/nova.conf'
|
||||||
|
end
|
||||||
|
|
||||||
|
# this needs to be removed. This has been replaced with the class method
|
||||||
|
def file_path
|
||||||
|
self.class.file_path
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -1,38 +0,0 @@
|
|||||||
require 'puppet/provider/parsedfile'
|
|
||||||
|
|
||||||
Puppet::Type.type(:nova_config).provide(
|
|
||||||
:parsed,
|
|
||||||
:parent => Puppet::Provider::ParsedFile,
|
|
||||||
:default_target => Puppet::Type.type(:nova_config).default_target,
|
|
||||||
:filetype => :flat
|
|
||||||
) do
|
|
||||||
|
|
||||||
|
|
||||||
#confine :exists => novaconf
|
|
||||||
text_line :comment, :match => /^\s*#/;
|
|
||||||
text_line :blank, :match => /^\s*$/;
|
|
||||||
|
|
||||||
record_line :parsed,
|
|
||||||
:fields => %w{line},
|
|
||||||
:match => /--(.*)/ ,
|
|
||||||
:post_parse => proc { |hash|
|
|
||||||
Puppet.debug("nova config line:#{hash[:line]} has been parsed")
|
|
||||||
if hash[:line] =~ /^\s*(\S+?)\s*=\s*([\S ]+)\s*$/
|
|
||||||
hash[:name]=$1
|
|
||||||
hash[:value]=$2
|
|
||||||
elsif hash[:line] =~ /^\s*no(\S+)\s*$/
|
|
||||||
hash[:name]=$1
|
|
||||||
hash[:value]=false
|
|
||||||
elsif hash[:line] =~ /^\s*(\S+)\s*$/
|
|
||||||
hash[:name]=$1
|
|
||||||
hash[:value]=true
|
|
||||||
else
|
|
||||||
raise Puppet::Error, "Invalid line: #{hash[:line]}"
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
def self.to_line(hash)
|
|
||||||
"--#{hash[:name]}=#{hash[:value]}"
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
@ -1,43 +0,0 @@
|
|||||||
require 'puppet/provider/parsedfile'
|
|
||||||
|
|
||||||
Puppet::Type.type(:nova_config).provide(
|
|
||||||
:configfile,
|
|
||||||
:parent => Puppet::Provider::ParsedFile,
|
|
||||||
:default_target => Puppet::Type.type(:nova_config).default_target,
|
|
||||||
:filetype => :flat
|
|
||||||
) do
|
|
||||||
|
|
||||||
confine :osfamily => [:debian, :redhat]
|
|
||||||
defaultfor :operatingsystem => :debian
|
|
||||||
|
|
||||||
#confine :exists => novaconf
|
|
||||||
text_line :comment, :match => /#|\[.*/;
|
|
||||||
text_line :blank, :match => /^\s*$/;
|
|
||||||
|
|
||||||
record_line :parsed,
|
|
||||||
:fields => %w{line},
|
|
||||||
:match => /(.*)/ ,
|
|
||||||
:post_parse => proc { |hash|
|
|
||||||
Puppet.debug("nova config line:#{hash[:line]} has been parsed")
|
|
||||||
if hash[:line] =~ /^\s*(\S+?)\s*=\s*([\S ]+?)\s*$/
|
|
||||||
hash[:name]=$1
|
|
||||||
hash[:value]=$2
|
|
||||||
elsif hash[:line] =~ /^\s*(\S+)\s*$/
|
|
||||||
hash[:name]=$1
|
|
||||||
hash[:value]=false
|
|
||||||
else
|
|
||||||
raise Puppet::Error, "Invalid line: #{hash[:line]}"
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
def self.to_line(hash)
|
|
||||||
if hash[:name] and hash[:value]
|
|
||||||
"#{hash[:name]}=#{hash[:value]}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.header
|
|
||||||
"# Auto Genarated Nova Config File\n[DEFAULT]\n"
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
@ -15,8 +15,13 @@ Puppet::Type.type(:nova_paste_api_ini).provide(
|
|||||||
'='
|
'='
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_path
|
def self.file_path
|
||||||
'/etc/nova/api-paste.ini'
|
'/etc/nova/api-paste.ini'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# this needs to be removed. This has been replaced with the class method
|
||||||
|
def file_path
|
||||||
|
self.class.file_path
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
Puppet::Type.newtype(:nova_config) do
|
Puppet::Type.newtype(:nova_config) do
|
||||||
|
|
||||||
def self.default_target
|
# def self.default_target
|
||||||
"/etc/nova/nova.conf"
|
# "/etc/nova/nova.conf"
|
||||||
end
|
# end
|
||||||
|
|
||||||
ensurable
|
ensurable
|
||||||
|
|
||||||
newparam(:name, :namevar => true) do
|
newparam(:name, :namevar => true) do
|
||||||
newvalues(/^\S+$/)
|
newvalues(/^\S+$/, /\S+\/\S+/)
|
||||||
end
|
end
|
||||||
|
|
||||||
newproperty(:value) do
|
newproperty(:value) do
|
||||||
@ -17,12 +17,12 @@ Puppet::Type.newtype(:nova_config) do
|
|||||||
newvalues(/^[\S ]+$/)
|
newvalues(/^[\S ]+$/)
|
||||||
end
|
end
|
||||||
|
|
||||||
newproperty(:target) do
|
#newproperty(:target) do
|
||||||
desc "Path to our nova config file"
|
# desc "Path to our nova config file"
|
||||||
defaultto {
|
# defaultto {
|
||||||
Puppet::Type.type(:nova_config).default_target
|
# Puppet::Type.type(:nova_config).default_target
|
||||||
}
|
# }
|
||||||
end
|
#end
|
||||||
|
|
||||||
validate do
|
validate do
|
||||||
if self[:ensure] == :present
|
if self[:ensure] == :present
|
||||||
|
@ -1,57 +1,38 @@
|
|||||||
require 'puppet'
|
#
|
||||||
require 'mocha'
|
# these tests are a little concerning b/c they are hacking around the
|
||||||
require 'tempfile'
|
# modulepath, so these tests will not catch issues that may eventually arise
|
||||||
RSpec.configure do |config|
|
# related to loading these plugins.
|
||||||
config.mock_with :mocha
|
# I could not, for the life of me, figure out how to programatcally set the modulepath
|
||||||
end
|
$LOAD_PATH.push(
|
||||||
provider_class = Puppet::Type.type(:nova_config).provider(:parsed)
|
File.join(
|
||||||
|
File.dirname(__FILE__),
|
||||||
|
'..',
|
||||||
|
'..',
|
||||||
|
'..',
|
||||||
|
'fixtures',
|
||||||
|
'modules',
|
||||||
|
'inifile',
|
||||||
|
'lib')
|
||||||
|
)
|
||||||
|
require 'spec_helper'
|
||||||
|
provider_class = Puppet::Type.type(:nova_config).provider(:ini_setting)
|
||||||
describe provider_class do
|
describe provider_class do
|
||||||
before :each do
|
|
||||||
@nova_config = Tempfile.new('nova.conf')
|
it 'should default to the default setting when no other one is specified' do
|
||||||
@resource = Puppet::Type::Nova_config.new(
|
resource = Puppet::Type::Nova_config.new(
|
||||||
{:target => @nova_config, :name => 'foo', :value => 'bar'}
|
{:name => 'foo', :value => 'bar'}
|
||||||
)
|
)
|
||||||
@provider = provider_class.new(@resource)
|
provider = provider_class.new(resource)
|
||||||
|
provider.section.should == 'DEFAULT'
|
||||||
|
provider.setting.should == 'foo'
|
||||||
end
|
end
|
||||||
it 'should be able to parse lines into records' do
|
|
||||||
record = @provider.class.parse('--foo = bar').first
|
it 'should allow setting to be set explicitly' do
|
||||||
record[:name].should == 'foo'
|
resource = Puppet::Type::Nova_config.new(
|
||||||
record[:value].should == 'bar'
|
{:name => 'dude/foo', :value => 'bar'}
|
||||||
record[:record_type].should == :parsed
|
)
|
||||||
end
|
provider = provider_class.new(resource)
|
||||||
it 'should be able to parse settings without values' do
|
provider.section.should == 'dude'
|
||||||
record = @provider.class.parse('--foo').first
|
provider.setting.should == 'foo'
|
||||||
record[:name].should == 'foo'
|
|
||||||
record[:value].should == true
|
|
||||||
record[:record_type].should == :parsed
|
|
||||||
end
|
|
||||||
it 'should be able to parse negated settings without values' do
|
|
||||||
record = @provider.class.parse('--nofoo').first
|
|
||||||
record[:name].should == 'foo'
|
|
||||||
record[:value].should == false
|
|
||||||
record[:record_type].should == :parsed
|
|
||||||
end
|
|
||||||
it 'should be able to parse values that have spaces' do
|
|
||||||
record = @provider.class.parse('--foo = bar or baz').first
|
|
||||||
record[:name].should == 'foo'
|
|
||||||
record[:value].should == 'bar or baz'
|
|
||||||
record[:record_type].should == :parsed
|
|
||||||
end
|
|
||||||
it 'should be able to parse values with equal signs' do
|
|
||||||
record = @provider.class.parse('--foo = bar=baz').first
|
|
||||||
record[:name].should == 'foo'
|
|
||||||
record[:value].should == 'bar=baz'
|
|
||||||
record[:record_type].should == :parsed
|
|
||||||
end
|
|
||||||
it 'should be able to create a valid line from a resource' do
|
|
||||||
provider_class.to_line({:name => 'foo', :value => 'bar'}).should == '--foo=bar'
|
|
||||||
end
|
|
||||||
it 'should parse empty lines' do
|
|
||||||
record = @provider.class.parse(' ').first
|
|
||||||
record[:record_type].should == :blank
|
|
||||||
end
|
|
||||||
it 'should parse comment lines' do
|
|
||||||
record = @provider.class.parse(' #--foo = bar').first
|
|
||||||
record[:record_type].should == :comment
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user