[#4110] Wrap Type#retrieve calls for backwards compatibility
This patch introduces Type#retrieve_resource as a wrapper for Type#resource, to coerce the return value from legacy types from Hash to Resource. Signed-off-by: Jesse Wolfe <jes5199@gmail.com>
This commit is contained in:
Родитель
5f8a2424bc
Коммит
4b00c6af91
|
@ -38,7 +38,7 @@ class Puppet::Transaction::ResourceHarness
|
|||
end
|
||||
|
||||
def changes_to_perform(status, resource)
|
||||
current = resource.retrieve
|
||||
current = resource.retrieve_resource
|
||||
|
||||
cache resource, :checked, Time.now
|
||||
|
||||
|
|
|
@ -743,6 +743,14 @@ class Type
|
|||
result
|
||||
end
|
||||
|
||||
def retrieve_resource
|
||||
resource = retrieve
|
||||
if resource.is_a? Hash
|
||||
resource = Resource.new(type, title, :parameters => resource)
|
||||
end
|
||||
resource
|
||||
end
|
||||
|
||||
# Get a hash of the current properties. Returns a hash with
|
||||
# the actual property instance as the key and the current value
|
||||
# as the, um, value.
|
||||
|
@ -1924,10 +1932,8 @@ class Type
|
|||
def to_trans(ret = true)
|
||||
trans = TransObject.new(self.title, self.class.name)
|
||||
|
||||
values = retrieve()
|
||||
values = retrieve_resource
|
||||
values.each do |name, value|
|
||||
# sometimes we get symbols and sometimes we get Properties
|
||||
# I think it's a bug, but I can't find it. ~JW
|
||||
name = name.name if name.respond_to? :name
|
||||
trans[name] = value
|
||||
end
|
||||
|
|
|
@ -67,7 +67,7 @@ module Puppet
|
|||
|
||||
def syncothers
|
||||
# We have to flush any changes to disk.
|
||||
currentvalues = @resource.retrieve
|
||||
currentvalues = @resource.retrieve_resource
|
||||
|
||||
# Determine if there are any out-of-sync properties.
|
||||
oos = @resource.send(:properties).find_all do |prop|
|
||||
|
|
|
@ -131,7 +131,7 @@ Puppet::Type.newtype(:resources) do
|
|||
return true unless self[:unless_system_user]
|
||||
|
||||
resource[:audit] = :uid
|
||||
current_values = resource.retrieve
|
||||
current_values = resource.retrieve_resource
|
||||
|
||||
if system_users().include?(resource[:name])
|
||||
return false
|
||||
|
|
|
@ -368,11 +368,11 @@ describe Puppet::Type do
|
|||
it "should fail if its provider is unsuitable" do
|
||||
@resource = Puppet::Type.type(:mount).new(:name => "foo", :fstype => "bar", :pass => 1, :ensure => :present)
|
||||
@resource.provider.class.expects(:suitable?).returns false
|
||||
lambda { @resource.retrieve }.should raise_error(Puppet::Error)
|
||||
lambda { @resource.retrieve_resource }.should raise_error(Puppet::Error)
|
||||
end
|
||||
|
||||
it "should return a Puppet::Resource instance with its type and title set appropriately" do
|
||||
result = @resource.retrieve
|
||||
result = @resource.retrieve_resource
|
||||
result.should be_instance_of(Puppet::Resource)
|
||||
result.type.should == "Mount"
|
||||
result.title.should == "foo"
|
||||
|
@ -381,11 +381,11 @@ describe Puppet::Type do
|
|||
it "should set the name of the returned resource if its own name and title differ" do
|
||||
@resource[:name] = "my name"
|
||||
@resource.title = "other name"
|
||||
@resource.retrieve[:name].should == "my name"
|
||||
@resource.retrieve_resource[:name].should == "my name"
|
||||
end
|
||||
|
||||
it "should provide a value for all set properties" do
|
||||
values = @resource.retrieve
|
||||
values = @resource.retrieve_resource
|
||||
[:ensure, :fstype, :pass].each { |property| values[property].should_not be_nil }
|
||||
end
|
||||
|
||||
|
@ -396,13 +396,13 @@ describe Puppet::Type do
|
|||
it "should not call retrieve on non-ensure properties if the resource is absent and should consider the property absent" do
|
||||
@resource.property(:ensure).expects(:retrieve).returns :absent
|
||||
@resource.property(:fstype).expects(:retrieve).never
|
||||
@resource.retrieve[:fstype].should == :absent
|
||||
@resource.retrieve_resource[:fstype].should == :absent
|
||||
end
|
||||
|
||||
it "should include the result of retrieving each property's current value if the resource is present" do
|
||||
@resource.property(:ensure).expects(:retrieve).returns :present
|
||||
@resource.property(:fstype).expects(:retrieve).returns 15
|
||||
@resource.retrieve[:fstype] == 15
|
||||
@resource.retrieve_resource[:fstype] == 15
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class TestMailAlias < Test::Unit::TestCase
|
|||
# This isn't much of a test, but then, it's not much of a type.
|
||||
def test_recipient_arrays
|
||||
resource = @type.new(:name => "luke", :recipient => "yay", :target => tempfile)
|
||||
values = resource.retrieve
|
||||
values = resource.retrieve_resource
|
||||
assert_equal(:absent, values[:recipient])
|
||||
resource.property(:recipient).expects(:set).with(%w{yay})
|
||||
assert_nothing_raised("Could not sync mailalias") do
|
||||
|
|
Загрузка…
Ссылка в новой задаче