diff options
author | Luke Kanies <luke@reductivelabs.com> | 2010-01-21 22:00:10 -0800 |
---|---|---|
committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
commit | c8e89cc1a69ff5827ad40439a2c903c24ae42aba (patch) | |
tree | dafcbf3de176245cf4728b5a7c54bca4ea8e5e42 | |
parent | b7ea1806703df2976d5cd6fade5503c008332526 (diff) | |
download | puppet-c8e89cc1a69ff5827ad40439a2c903c24ae42aba.tar.gz puppet-c8e89cc1a69ff5827ad40439a2c903c24ae42aba.tar.xz puppet-c8e89cc1a69ff5827ad40439a2c903c24ae42aba.zip |
Changing the interface of Puppet::Resource
We need the ability to set the namespace and
environment at initialization so the resource
can look up qualified types.
Signed-off-by: Luke Kanies <luke@reductivelabs.com>
-rw-r--r-- | lib/puppet/resource.rb | 12 | ||||
-rw-r--r-- | lib/puppet/transportable.rb | 2 | ||||
-rw-r--r-- | lib/puppet/util/settings.rb | 4 | ||||
-rwxr-xr-x | spec/integration/util/settings.rb | 1 | ||||
-rwxr-xr-x | spec/unit/resource.rb | 25 | ||||
-rwxr-xr-x | spec/unit/type.rb | 8 |
6 files changed, 36 insertions, 16 deletions
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb index bdd11fcc5..e47501791 100644 --- a/lib/puppet/resource.rb +++ b/lib/puppet/resource.rb @@ -116,14 +116,20 @@ class Puppet::Resource end # Create our resource. - def initialize(type, title, parameters = {}) - @reference = Puppet::Resource::Reference.new(type, title) + def initialize(type, title, attributes = {}) @parameters = {} - parameters.each do |param, value| + (attributes[:parameters] || {}).each do |param, value| self[param] = value end + attributes.each do |attr, value| + next if attr == :parameters + send(attr.to_s + "=", value) + end + + @reference = Puppet::Resource::Reference.new(type, title) + tag(@reference.type) tag(@reference.title) if valid_tag?(@reference.title) end diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb index 85a75d453..68977dca0 100644 --- a/lib/puppet/transportable.rb +++ b/lib/puppet/transportable.rb @@ -80,7 +80,7 @@ module Puppet # Create a normalized resource from our TransObject. def to_resource - result = Puppet::Resource.new(type, name, @params.dup) + result = Puppet::Resource.new(type, name, :parameters => @params.dup) result.tag(*tags) result diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb index ad1b947b3..308abc2f9 100644 --- a/lib/puppet/util/settings.rb +++ b/lib/puppet/util/settings.rb @@ -815,14 +815,14 @@ Generated on #{Time.now}. next unless sections.nil? or sections.include?(setting.section) if user = setting.owner and user != "root" and catalog.resource(:user, user).nil? - resource = Puppet::Resource.new(:user, user, :ensure => :present) + resource = Puppet::Resource.new(:user, user, :parameters => {:ensure => :present}) if self[:group] resource[:gid] = self[:group] end catalog.add_resource resource end if group = setting.group and ! %w{root wheel}.include?(group) and catalog.resource(:group, group).nil? - catalog.add_resource Puppet::Resource.new(:group, group, :ensure => :present) + catalog.add_resource Puppet::Resource.new(:group, group, :parameters => {:ensure => :present}) end end end diff --git a/spec/integration/util/settings.rb b/spec/integration/util/settings.rb index 826bfc97e..536eab643 100755 --- a/spec/integration/util/settings.rb +++ b/spec/integration/util/settings.rb @@ -14,7 +14,6 @@ describe Puppet::Util::Settings do it "should be able to make needed directories" do settings = Puppet::Util::Settings.new settings.setdefaults :main, minimal_default_settings.update( :maindir => [tmpfile("main"), "a"] ) - settings.use(:main) File.should be_directory(settings[:maindir]) diff --git a/spec/unit/resource.rb b/spec/unit/resource.rb index 2b1d49d50..bc47fa7ed 100755 --- a/spec/unit/resource.rb +++ b/spec/unit/resource.rb @@ -23,10 +23,6 @@ describe Puppet::Resource do Puppet::Resource.new("file", "/f") end - it "should allow setting of parameters" do - Puppet::Resource.new("file", "/f", :noop => true)[:noop].should be_true - end - it "should tag itself with its type" do Puppet::Resource.new("file", "/f").should be_tagged("file") end @@ -38,6 +34,11 @@ describe Puppet::Resource do it "should not tag itself with its title if the title is a not valid tag" do Puppet::Resource.new("file", "/bar").should_not be_tagged("/bar") end + + it "should allow setting of attributes" do + Puppet::Resource.new("file", "/bar", :file => "/foo").file.should == "/foo" + Puppet::Resource.new("file", "/bar", :exported => true).should be_exported + end end it "should use the resource reference to determine its type" do @@ -89,16 +90,30 @@ describe Puppet::Resource do resource.should be_exported end + it "should support an environment attribute" + + it "should convert its environment into an environment instance if one is provided" + + it "should support a namespace attribute" + describe "when managing parameters" do before do @resource = Puppet::Resource.new("file", "/my/file") end + it "should be able to check whether parameters are valid when the resource models builtin resources" + + it "should be able to check whether parameters are valid when the resource models defined resources" + it "should allow setting and retrieving of parameters" do @resource[:foo] = "bar" @resource[:foo].should == "bar" end + it "should allow setting of parameters at initialization" do + Puppet::Resource.new("file", "/my/file", :parameters => {:foo => "bar"})[:foo].should == "bar" + end + it "should canonicalize retrieved parameter names to treat symbols and strings equivalently" do @resource[:foo] = "bar" @resource["foo"].should == "bar" @@ -255,7 +270,7 @@ describe Puppet::Resource do describe "when converting to puppet code" do before do - @resource = Puppet::Resource.new("one::two", "/my/file", :noop => true, :foo => %w{one two}) + @resource = Puppet::Resource.new("one::two", "/my/file", :parameters => {:noop => true, :foo => %w{one two}}) end it "should print the type and title" do diff --git a/spec/unit/type.rb b/spec/unit/type.rb index f5953aa9c..97dc113a6 100755 --- a/spec/unit/type.rb +++ b/spec/unit/type.rb @@ -164,7 +164,7 @@ describe Puppet::Type do describe "and passed a Puppet::Resource instance" do it "should set its title to the title of the resource if the resource type is equal to the current type" do - resource = Puppet::Resource.new(:mount, "/foo", :name => "/other") + resource = Puppet::Resource.new(:mount, "/foo", :parameters => {:name => "/other"}) Puppet::Type.type(:mount).new(resource).title.should == "/foo" end @@ -191,7 +191,7 @@ describe Puppet::Type do end it "should copy the resource's parameters as its own" do - resource = Puppet::Resource.new(:mount, "/foo", :atboot => true, :fstype => "boo") + resource = Puppet::Resource.new(:mount, "/foo", :parameters => {:atboot => true, :fstype => "boo"}) params = Puppet::Type.type(:mount).new(resource).to_hash params[:fstype].should == "boo" params[:atboot].should == true @@ -253,7 +253,7 @@ describe Puppet::Type do it "should set the attributes in the order returned by the class's :allattrs method" do Puppet::Type.type(:mount).stubs(:allattrs).returns([:name, :atboot, :noop]) - resource = Puppet::Resource.new(:mount, "/foo", :name => "myname", :atboot => "myboot", :noop => "whatever") + resource = Puppet::Resource.new(:mount, "/foo", :parameters => {:name => "myname", :atboot => "myboot", :noop => "whatever"}) set = [] @@ -270,7 +270,7 @@ describe Puppet::Type do it "should always set the name and then default provider before anything else" do Puppet::Type.type(:mount).stubs(:allattrs).returns([:provider, :name, :atboot]) - resource = Puppet::Resource.new(:mount, "/foo", :name => "myname", :atboot => "myboot") + resource = Puppet::Resource.new(:mount, "/foo", :parameters => {:name => "myname", :atboot => "myboot"}) set = [] |