Renaming the "Catalog#to_type" method to "Catalog#to_ral"
Signed-off-by: Luke Kanies <luke@madstop.com>
This commit is contained in:
Родитель
6b14000ae5
Коммит
60062e4b9a
|
@ -327,8 +327,8 @@ class Puppet::Parser::Resource
|
|||
|
||||
# Convert this resource to a RAL resource. We hackishly go via the
|
||||
# transportable stuff.
|
||||
def to_type
|
||||
to_resource.to_type
|
||||
def to_ral
|
||||
to_resource.to_ral
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -385,7 +385,7 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
|
|||
|
||||
# Convert our catalog into a RAL catalog.
|
||||
def to_ral
|
||||
to_catalog :to_type
|
||||
to_catalog :to_ral
|
||||
end
|
||||
|
||||
# Turn our parser catalog into a transportable catalog.
|
||||
|
@ -463,11 +463,14 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
|
|||
#Aliases aren't working in the ral catalog because the current instance of the resource
|
||||
#has a reference to the catalog being converted. . . So, give it a reference to the new one
|
||||
#problem solved. . .
|
||||
if resource.is_a?(Puppet::TransObject)
|
||||
if resource.is_a?(Puppet::Resource)
|
||||
resource = resource.dup
|
||||
resource.catalog = result
|
||||
elsif resource.is_a?(Puppet::TransObject)
|
||||
resource = resource.dup
|
||||
resource.catalog = result
|
||||
elsif resource.is_a?(Puppet::Parser::Resource)
|
||||
resource = resource.to_transobject
|
||||
resource = resource.to_resource
|
||||
resource.catalog = result
|
||||
end
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ module Puppet
|
|||
ref
|
||||
end
|
||||
|
||||
def to_type
|
||||
def to_ral
|
||||
if typeklass = Puppet::Type.type(self.type)
|
||||
return typeklass.create(self)
|
||||
else
|
||||
|
@ -189,13 +189,13 @@ module Puppet
|
|||
delver = proc do |obj|
|
||||
obj.catalog = catalog
|
||||
unless container = catalog.resource(obj.to_ref)
|
||||
container = obj.to_type
|
||||
container = obj.to_ral
|
||||
catalog.add_resource container
|
||||
end
|
||||
obj.each do |child|
|
||||
child.catalog = catalog
|
||||
unless resource = catalog.resource(child.to_ref)
|
||||
resource = child.to_type
|
||||
resource = child.to_ral
|
||||
catalog.add_resource resource
|
||||
end
|
||||
|
||||
|
@ -233,7 +233,7 @@ module Puppet
|
|||
@ref.to_s if @ref
|
||||
end
|
||||
|
||||
def to_type
|
||||
def to_ral
|
||||
Puppet.debug("TransBucket '%s' has no type" % @name) unless defined? @type
|
||||
|
||||
# Nodes have the same name and type
|
||||
|
|
|
@ -12,7 +12,7 @@ describe Puppet::TransBucket do
|
|||
@bucket.type = "user"
|
||||
|
||||
resource = nil
|
||||
proc { resource = @bucket.to_type }.should_not raise_error
|
||||
proc { resource = @bucket.to_ral }.should_not raise_error
|
||||
resource.should be_instance_of(Puppet::Type::Component)
|
||||
resource.title.should == "User[luke]"
|
||||
end
|
||||
|
@ -99,7 +99,7 @@ describe Puppet::TransBucket, " when generating a catalog" do
|
|||
end
|
||||
|
||||
it "should fail if any transportable resources fail to convert to RAL resources" do
|
||||
@bottomobj.expects(:to_type).raises ArgumentError
|
||||
@bottomobj.expects(:to_ral).raises ArgumentError
|
||||
lambda { @bottom.to_catalog }.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
|
@ -120,12 +120,12 @@ describe Puppet::TransBucket, " when generating a catalog" do
|
|||
@catalog.vertices.each do |vertex| vertex.should be_finalized end
|
||||
end
|
||||
|
||||
it "should only call to_type on each resource once" do
|
||||
it "should only call to_ral on each resource once" do
|
||||
# We just raise exceptions here because we're not interested in
|
||||
# what happens with the result, only that the method only
|
||||
# gets called once.
|
||||
resource = @topobj.to_type
|
||||
@topobj.expects(:to_type).once.returns resource
|
||||
resource = @topobj.to_ral
|
||||
@topobj.expects(:to_ral).once.returns resource
|
||||
@top.to_catalog
|
||||
end
|
||||
|
||||
|
|
|
@ -50,13 +50,13 @@ describe Puppet::TransObject, " when converting to a RAL resource" do
|
|||
type = mock 'resource type'
|
||||
type.expects(:create).with(@resource).returns(:myresource)
|
||||
Puppet::Type.expects(:type).with("file").returns(type)
|
||||
@resource.to_type.should == :myresource
|
||||
@resource.to_ral.should == :myresource
|
||||
end
|
||||
|
||||
it "should convert to a component instance if the resource type cannot be found" do
|
||||
Puppet::Type.expects(:type).with("file").returns(nil)
|
||||
@resource.expects(:to_component).returns(:mycomponent)
|
||||
@resource.to_type.should == :mycomponent
|
||||
@resource.to_ral.should == :mycomponent
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -65,10 +65,10 @@ describe Puppet::Parser::Resource do
|
|||
end
|
||||
|
||||
it "should use a Puppet::Resource for converting to a ral resource" do
|
||||
trans = mock 'resource', :to_type => "yay"
|
||||
trans = mock 'resource', :to_ral => "yay"
|
||||
@resource = mkresource
|
||||
@resource.expects(:to_resource).returns trans
|
||||
@resource.to_type.should == "yay"
|
||||
@resource.to_ral.should == "yay"
|
||||
end
|
||||
|
||||
describe "when initializing" do
|
||||
|
|
|
@ -325,7 +325,7 @@ describe Puppet::Resource::Catalog, "when compiling" do
|
|||
|
||||
#changer is going to get duplicated as part of a fix for aliases 1094
|
||||
changer.expects(:dup).returns(changer)
|
||||
changer.expects(:to_type).returns(resource)
|
||||
changer.expects(:to_ral).returns(resource)
|
||||
|
||||
newconfig = nil
|
||||
|
||||
|
|
|
@ -34,6 +34,9 @@ describe Puppet::Type do
|
|||
resource.parameter(:fstype).must be_instance_of(Puppet::Type.type(:mount).attrclass(:fstype))
|
||||
end
|
||||
|
||||
describe "when initializing" do
|
||||
end
|
||||
|
||||
describe "when retrieving current property values" do
|
||||
# Use 'mount' as an example, because it doesn't override 'retrieve'
|
||||
before do
|
||||
|
|
|
@ -17,7 +17,7 @@ module PuppetTest::Support::Utils
|
|||
transport[:path] = path
|
||||
transport[:ensure] = "file"
|
||||
assert_nothing_raised {
|
||||
file = transport.to_type
|
||||
file = transport.to_ral
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ class TestResourceClient < Test::Unit::TestCase
|
|||
|
||||
resource = nil
|
||||
assert_nothing_raised {
|
||||
resource = tresource.to_type
|
||||
resource = tresource.to_ral
|
||||
}
|
||||
assert_events([], resource)
|
||||
p resource.instance_variable_get("@stat")
|
||||
|
@ -75,7 +75,7 @@ class TestResourceClient < Test::Unit::TestCase
|
|||
|
||||
resource = nil
|
||||
assert_nothing_raised {
|
||||
resource = tresource2.to_type
|
||||
resource = tresource2.to_ral
|
||||
}
|
||||
assert_events([], resource)
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ class TestResourceServer < Test::Unit::TestCase
|
|||
described.each do |name, trans|
|
||||
obj = nil
|
||||
assert_nothing_raised do
|
||||
obj = trans.to_type
|
||||
obj = trans.to_ral
|
||||
end
|
||||
|
||||
assert(obj, "Could not create object")
|
||||
|
@ -61,7 +61,7 @@ class TestResourceServer < Test::Unit::TestCase
|
|||
|
||||
object = nil
|
||||
assert_nothing_raised do
|
||||
object = result.to_type
|
||||
object = result.to_ral
|
||||
end
|
||||
|
||||
assert(object, "Could not create type")
|
||||
|
@ -110,7 +110,7 @@ class TestResourceServer < Test::Unit::TestCase
|
|||
|
||||
object = nil
|
||||
assert_nothing_raised do
|
||||
object = result.to_type
|
||||
object = result.to_ral
|
||||
end
|
||||
|
||||
catalog = mk_catalog(object)
|
||||
|
|
|
@ -140,7 +140,7 @@ class TestType < Test::Unit::TestCase
|
|||
def test_catalogs_are_set_during_initialization_if_present_on_the_transobject
|
||||
trans = Puppet::TransObject.new("/path/to/some/file", :file)
|
||||
trans.catalog = stub 'catalog', :resource => nil
|
||||
resource = trans.to_type
|
||||
resource = trans.to_ral
|
||||
assert_equal(resource.catalog, trans.catalog, "Did not set catalog on initialization")
|
||||
end
|
||||
|
||||
|
@ -375,75 +375,6 @@ class TestType < Test::Unit::TestCase
|
|||
assert_equal(path, file[:name], "Did not get correct name")
|
||||
end
|
||||
|
||||
# Make sure the "create" class method behaves appropriately.
|
||||
def test_class_create
|
||||
title = "Myfile"
|
||||
validate = proc do |element|
|
||||
assert(element, "Did not create file")
|
||||
assert_instance_of(Puppet::Type.type(:file), element)
|
||||
assert_equal(title, element.title, "Title is not correct")
|
||||
end
|
||||
type = :file
|
||||
args = {:path => tempfile(), :owner => "root"}
|
||||
|
||||
trans = Puppet::TransObject.new(title, type)
|
||||
args.each do |name, val| trans[name] = val end
|
||||
|
||||
# First call it on the appropriate typeclass
|
||||
obj = nil
|
||||
assert_nothing_raised do
|
||||
obj = Puppet::Type.type(:file).create(trans)
|
||||
end
|
||||
|
||||
validate.call(obj)
|
||||
|
||||
# Now try it using the class method on Type
|
||||
oldid = obj.object_id
|
||||
obj = nil
|
||||
|
||||
assert_nothing_raised {
|
||||
obj = Puppet::Type.create(trans)
|
||||
}
|
||||
|
||||
validate.call(obj)
|
||||
assert(oldid != obj.object_id, "Got same object back")
|
||||
|
||||
# Now try the same things with hashes instead of a transobject
|
||||
oldid = obj.object_id
|
||||
obj = nil
|
||||
hash = {
|
||||
:type => :file,
|
||||
:title => "Myfile",
|
||||
:path => tempfile(),
|
||||
:owner => "root"
|
||||
}
|
||||
|
||||
# First call it on the appropriate typeclass
|
||||
obj = nil
|
||||
assert_nothing_raised do
|
||||
obj = Puppet::Type.type(:file).create(hash)
|
||||
end
|
||||
|
||||
validate.call(obj)
|
||||
assert_equal(:file, obj.should(:type),
|
||||
"Type param did not pass through")
|
||||
|
||||
assert(oldid != obj.object_id, "Got same object back")
|
||||
|
||||
# Now try it using the class method on Type
|
||||
oldid = obj.object_id
|
||||
obj = nil
|
||||
|
||||
assert_nothing_raised {
|
||||
obj = Puppet::Type.create(hash)
|
||||
}
|
||||
|
||||
validate.call(obj)
|
||||
assert(oldid != obj.object_id, "Got same object back")
|
||||
assert_nil(obj.should(:type),
|
||||
"Type param passed through")
|
||||
end
|
||||
|
||||
def test_multiplenames
|
||||
obj = nil
|
||||
path = tempfile()
|
||||
|
|
|
@ -51,7 +51,7 @@ class TestSettings < Test::Unit::TestCase
|
|||
|
||||
comp = nil
|
||||
assert_nothing_raised("Could not convert transportable to component") {
|
||||
comp = trans.to_type
|
||||
comp = trans.to_ral
|
||||
}
|
||||
|
||||
assert_nothing_raised("Could not retrieve transported config") {
|
||||
|
|
Загрузка…
Ссылка в новой задаче