summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Bode <dan@puppetlabs.com>2012-10-02 18:53:53 -0700
committerDan Bode <dan@puppetlabs.com>2012-10-02 18:53:53 -0700
commitcbc90d38347f8ca61de2208b16ffc76f9fd5938c (patch)
treee000b4755f7157439d48aaeab0fe081685ae0e59
parent1564c473a93105399bd777e78090463156948f2e (diff)
downloadpuppet-inifile-cbc90d38347f8ca61de2208b16ffc76f9fd5938c.tar.gz
puppet-inifile-cbc90d38347f8ca61de2208b16ffc76f9fd5938c.tar.bz2
Make value a property
This commit converts value to a property so that it can be managed and modified when a file already has a value set. It was previously treating the line creation state the same as the update case, which is not in alignment with Puppet's model.
-rw-r--r--lib/puppet/provider/ini_setting/ruby.rb12
-rw-r--r--lib/puppet/type/ini_setting.rb9
-rw-r--r--spec/unit/puppet/provider/ini_setting/ruby_spec.rb57
3 files changed, 47 insertions, 31 deletions
diff --git a/lib/puppet/provider/ini_setting/ruby.rb b/lib/puppet/provider/ini_setting/ruby.rb
index aca8ba2..946685e 100644
--- a/lib/puppet/provider/ini_setting/ruby.rb
+++ b/lib/puppet/provider/ini_setting/ruby.rb
@@ -1,8 +1,9 @@
require File.expand_path('../../../util/ini_file', __FILE__)
Puppet::Type.type(:ini_setting).provide(:ruby) do
+
def exists?
- ini_file.get_value(resource[:section], resource[:setting]) == resource[:value].to_s
+ ini_file.get_value(section, setting)
end
def create
@@ -11,6 +12,15 @@ Puppet::Type.type(:ini_setting).provide(:ruby) do
@ini_file = nil
end
+ def value
+ ini_file.get_value(section, setting)
+ end
+
+ def value=(value)
+ ini_file.set_value(section, setting, resource[:value])
+ ini_file.save
+ end
+
def section
resource[:section]
end
diff --git a/lib/puppet/type/ini_setting.rb b/lib/puppet/type/ini_setting.rb
index 50b6b38..4506231 100644
--- a/lib/puppet/type/ini_setting.rb
+++ b/lib/puppet/type/ini_setting.rb
@@ -17,10 +17,6 @@ Puppet::Type.newtype(:ini_setting) do
desc 'The name of the setting to be defined.'
end
- newparam(:value) do
- desc 'The value of the setting to be defined.'
- end
-
newparam(:path) do
desc 'The ini file Puppet will ensure contains the specified setting.'
validate do |value|
@@ -43,4 +39,9 @@ Puppet::Type.newtype(:ini_setting) do
end
end
+ newproperty(:value) do
+ desc 'The value of the setting to be defined.'
+ end
+
+
end
diff --git a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb
index 20882fd..4062205 100644
--- a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb
+++ b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb
@@ -54,7 +54,7 @@ subby=bar
resource = Puppet::Type::Ini_setting.new(common_params.merge(
:setting => 'yahoo', :value => 'yippee'))
provider = described_class.new(resource)
- provider.exists?.should == false
+ provider.exists?.should be_nil
provider.create
validate_file(<<-EOS
# This is a comment
@@ -82,7 +82,7 @@ subby=bar
resource = Puppet::Type::Ini_setting.new(common_params.merge(
:section => 'section:sub', :setting => 'yahoo', :value => 'yippee'))
provider = described_class.new(resource)
- provider.exists?.should == false
+ provider.exists?.should be_nil
provider.create
validate_file(<<-EOS
# This is a comment
@@ -110,8 +110,8 @@ yahoo = yippee
resource = Puppet::Type::Ini_setting.new(common_params.merge(
:setting => 'baz', :value => 'bazvalue2'))
provider = described_class.new(resource)
- provider.exists?.should == false
- provider.create
+ provider.exists?.should == 'bazvalue'
+ provider.value=('bazvalue2')
validate_file(<<-EOS
# This is a comment
[section1]
@@ -137,8 +137,9 @@ subby=bar
resource = Puppet::Type::Ini_setting.new(common_params.merge(
:section => 'section:sub', :setting => 'subby', :value => 'foo'))
provider = described_class.new(resource)
- provider.exists?.should == false
- provider.create
+ provider.exists?.should == 'bar'
+ provider.value.should == 'bar'
+ provider.value=('foo')
validate_file(<<-EOS
# This is a comment
[section1]
@@ -164,8 +165,9 @@ subby = foo
resource = Puppet::Type::Ini_setting.new(common_params.merge(
:setting => 'url', :value => 'http://192.168.0.1:8080'))
provider = described_class.new(resource)
- provider.exists?.should == false
- provider.create
+ provider.exists?.should == 'http://192.168.1.1:8080'
+ provider.value.should == 'http://192.168.1.1:8080'
+ provider.value=('http://192.168.0.1:8080')
validate_file( <<-EOS
# This is a comment
@@ -192,14 +194,14 @@ subby=bar
resource = Puppet::Type::Ini_setting.new(common_params.merge(
:setting => 'baz', :value => 'bazvalue'))
provider = described_class.new(resource)
- provider.exists?.should == true
+ provider.exists?.should == 'bazvalue'
end
it "should add a new section if the section does not exist" do
resource = Puppet::Type::Ini_setting.new(common_params.merge(
:section => "section3", :setting => 'huzzah', :value => 'shazaam'))
provider = described_class.new(resource)
- provider.exists?.should == false
+ provider.exists?.should be_nil
provider.create
validate_file(<<-EOS
# This is a comment
@@ -229,7 +231,7 @@ huzzah = shazaam
resource = Puppet::Type::Ini_setting.new(common_params.merge(
:section => "section:subsection", :setting => 'huzzah', :value => 'shazaam'))
provider = described_class.new(resource)
- provider.exists?.should == false
+ provider.exists?.should be_nil
provider.create
validate_file(<<-EOS
# This is a comment
@@ -259,7 +261,7 @@ huzzah = shazaam
resource = Puppet::Type::Ini_setting.new(common_params.merge(
:section => "section1", :setting => 'setting1', :value => 'hellowworld', :path => emptyfile))
provider = described_class.new(resource)
- provider.exists?.should == false
+ provider.exists?.should be_nil
provider.create
validate_file("
[section1]
@@ -271,7 +273,7 @@ setting1 = hellowworld
resource = Puppet::Type::Ini_setting.new(common_params.merge(
:section => "section:subsection", :setting => 'setting1', :value => 'hellowworld', :path => emptyfile))
provider = described_class.new(resource)
- provider.exists?.should == false
+ provider.exists?.should be_nil
provider.create
validate_file("
[section:subsection]
@@ -283,8 +285,8 @@ setting1 = hellowworld
resource = Puppet::Type::Ini_setting.new(common_params.merge(
:section => "section1", :setting => 'master', :value => true))
provider = described_class.new(resource)
- provider.exists?.should == true
- provider.create
+ provider.exists?.should == 'true'
+ provider.value.should == 'true'
end
end
@@ -305,7 +307,7 @@ foo = http://192.168.1.1:8080
resource = Puppet::Type::Ini_setting.new(common_params.merge(
:section => '', :setting => 'bar', :value => 'yippee'))
provider = described_class.new(resource)
- provider.exists?.should == false
+ provider.exists?.should be_nil
provider.create
validate_file(<<-EOS
# This is a comment
@@ -322,8 +324,9 @@ foo = http://192.168.1.1:8080
resource = Puppet::Type::Ini_setting.new(common_params.merge(
:section => '', :setting => 'foo', :value => 'yippee'))
provider = described_class.new(resource)
- provider.exists?.should == false
- provider.create
+ provider.exists?.should == 'blah'
+ provider.value.should == 'blah'
+ provider.value=('yippee')
validate_file(<<-EOS
# This is a comment
foo = yippee
@@ -338,7 +341,7 @@ foo = http://192.168.1.1:8080
resource = Puppet::Type::Ini_setting.new(common_params.merge(
:section => '', :setting => 'foo', :value => 'blah'))
provider = described_class.new(resource)
- provider.exists?.should == true
+ provider.exists?.should == 'blah'
end
end
@@ -354,7 +357,7 @@ foo = http://192.168.1.1:8080
resource = Puppet::Type::Ini_setting.new(common_params.merge(
:section => '', :setting => 'foo', :value => 'yippee'))
provider = described_class.new(resource)
- provider.exists?.should == false
+ provider.exists?.should be_nil
provider.create
validate_file(<<-EOS
foo = yippee
@@ -368,8 +371,9 @@ foo = http://192.168.1.1:8080
resource = Puppet::Type::Ini_setting.new(common_params.merge(
:section => 'section2', :setting => 'foo', :value => 'yippee'))
provider = described_class.new(resource)
- provider.exists?.should == false
- provider.create
+ provider.exists?.should == 'http://192.168.1.1:8080'
+ provider.value.should == 'http://192.168.1.1:8080'
+ provider.value=('yippee')
validate_file(<<-EOS
[section2]
foo = yippee
@@ -381,7 +385,7 @@ foo = yippee
resource = Puppet::Type::Ini_setting.new(common_params.merge(
:section => 'section2', :setting => 'bar', :value => 'baz'))
provider = described_class.new(resource)
- provider.exists?.should == false
+ provider.exists?.should be_nil
provider.create
validate_file(<<-EOS
[section2]
@@ -427,8 +431,9 @@ foo=bar
:value => 'yippee',
:key_val_separator => '='))
provider = described_class.new(resource)
- provider.exists?.should == false
- provider.create
+ provider.exists?.should == 'bar'
+ provider.value.should == 'bar'
+ provider.value=('yippee')
validate_file(<<-EOS
[section2]
foo=yippee
@@ -443,7 +448,7 @@ foo=yippee
:value => 'baz',
:key_val_separator => '='))
provider = described_class.new(resource)
- provider.exists?.should == false
+ provider.exists?.should be_nil
provider.create
validate_file(<<-EOS
[section2]