summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/metatype/instances.rb5
-rw-r--r--lib/puppet/metatype/metaparams.rb3
-rw-r--r--lib/puppet/metatype/relationships.rb7
-rw-r--r--lib/puppet/metatype/schedules.rb6
-rw-r--r--lib/puppet/network/client/master.rb1
-rwxr-xr-xlib/puppet/network/handler/resource.rb14
-rw-r--r--lib/puppet/node/catalog.rb11
-rw-r--r--lib/puppet/transaction.rb2
-rwxr-xr-xspec/unit/node/catalog.rb57
-rwxr-xr-xspec/unit/other/transbucket.rb7
-rwxr-xr-xspec/unit/ral/provider/mount/parsed.rb4
-rwxr-xr-xspec/unit/ral/types/file.rb4
-rwxr-xr-xspec/unit/ral/types/interface.rb2
-rwxr-xr-xspec/unit/ral/types/mount.rb8
-rwxr-xr-xspec/unit/ral/types/package.rb9
-rwxr-xr-xspec/unit/ral/types/schedule.rb4
-rwxr-xr-xspec/unit/ral/types/service.rb10
-rwxr-xr-xtest/language/snippets.rb36
-rwxr-xr-xtest/lib/puppettest.rb1
-rwxr-xr-xtest/other/relationships.rb7
-rwxr-xr-xtest/other/transactions.rb32
-rwxr-xr-xtest/ral/manager/instances.rb16
-rwxr-xr-xtest/ral/manager/type.rb161
-rwxr-xr-xtest/ral/types/sshkey.rb39
-rwxr-xr-xtest/ral/types/user.rb1
25 files changed, 150 insertions, 297 deletions
diff --git a/lib/puppet/metatype/instances.rb b/lib/puppet/metatype/instances.rb
index 9d4fce909..34d542c5d 100644
--- a/lib/puppet/metatype/instances.rb
+++ b/lib/puppet/metatype/instances.rb
@@ -46,6 +46,7 @@ class Puppet::Type
# Create an alias. We keep these in a separate hash so that we don't encounter
# the objects multiple times when iterating over them.
def self.alias(name, obj)
+ raise "Global resource aliasing is deprecated"
if @objects.include?(name)
unless @objects[name] == obj
raise Puppet::Error.new(
@@ -69,6 +70,7 @@ class Puppet::Type
# remove all of the instances of a single type
def self.clear
+ raise "Global resource removal is deprecated"
if defined? @objects
@objects.each do |name, obj|
obj.remove(true)
@@ -150,6 +152,7 @@ class Puppet::Type
# remove a specified object
def self.delete(resource)
+ raise "Global resource removal is deprecated"
return unless defined? @objects
if @objects.include?(resource.title)
@objects.delete(resource.title)
@@ -170,6 +173,7 @@ class Puppet::Type
# iterate across each of the type's instances
def self.each
+ raise "Global resource iteration is deprecated"
return unless defined? @objects
@objects.each { |name,instance|
yield instance
@@ -178,6 +182,7 @@ class Puppet::Type
# does the type have an object with the given name?
def self.has_key?(name)
+ raise "Global resource access is deprecated"
return @objects.has_key?(name)
end
diff --git a/lib/puppet/metatype/metaparams.rb b/lib/puppet/metatype/metaparams.rb
index b0a4cfce5..9e4cb089c 100644
--- a/lib/puppet/metatype/metaparams.rb
+++ b/lib/puppet/metatype/metaparams.rb
@@ -207,9 +207,6 @@ class Puppet::Type
next
end
- # LAK:FIXME Old-school, add the alias to the class.
- @resource.class.alias(other, @resource)
-
# Newschool, add it to the catalog.
@resource.catalog.alias(@resource, other)
end
diff --git a/lib/puppet/metatype/relationships.rb b/lib/puppet/metatype/relationships.rb
index 3433c4884..0070c6efb 100644
--- a/lib/puppet/metatype/relationships.rb
+++ b/lib/puppet/metatype/relationships.rb
@@ -17,8 +17,9 @@ class Puppet::Type
# Figure out of there are any objects we can automatically add as
# dependencies.
- def autorequire
- raise(Puppet::DevError, "You cannot add relationships without a catalog") unless catalog
+ def autorequire(rel_catalog = nil)
+ rel_catalog ||= catalog
+ raise(Puppet::DevError, "You cannot add relationships without a catalog") unless rel_catalog
reqs = []
self.class.eachautorequire { |type, block|
@@ -37,7 +38,7 @@ class Puppet::Type
# Support them passing objects directly, to save some effort.
unless dep.is_a? Puppet::Type
# Skip autorequires that we aren't managing
- unless dep = catalog.resource(type, dep)
+ unless dep = rel_catalog.resource(type, dep)
next
end
end
diff --git a/lib/puppet/metatype/schedules.rb b/lib/puppet/metatype/schedules.rb
index 96ebce0ab..b4782f852 100644
--- a/lib/puppet/metatype/schedules.rb
+++ b/lib/puppet/metatype/schedules.rb
@@ -3,9 +3,13 @@ class Puppet::Type
# the instantiation phase, so that the schedule can be anywhere in the
# file.
def schedule
+ unless catalog
+ warning "Cannot schedule without a schedule-containing catalog"
+ return nil
+ end
unless defined? @schedule
if name = self[:schedule]
- if sched = Puppet.type(:schedule)[name]
+ if sched = catalog.resource(:schedule, name)
@schedule = sched
else
self.fail "Could not find schedule %s" % name
diff --git a/lib/puppet/network/client/master.rb b/lib/puppet/network/client/master.rb
index 6d1a0235f..a920afec6 100644
--- a/lib/puppet/network/client/master.rb
+++ b/lib/puppet/network/client/master.rb
@@ -69,7 +69,6 @@ class Puppet::Network::Client::Master < Puppet::Network::Client
def clear
@catalog.clear(true) if @catalog
- Puppet::Type.allclear
@catalog = nil
end
diff --git a/lib/puppet/network/handler/resource.rb b/lib/puppet/network/handler/resource.rb
index f2a339751..7ec27b4dc 100755
--- a/lib/puppet/network/handler/resource.rb
+++ b/lib/puppet/network/handler/resource.rb
@@ -68,15 +68,11 @@ class Puppet::Network::Handler
retrieve ||= :all
ignore ||= []
- if obj = typeklass[name]
- obj[:check] = retrieve
- else
- begin
- obj = typeklass.create(:name => name, :check => retrieve)
- rescue Puppet::Error => detail
- raise Puppet::Error, "%s[%s] could not be created: %s" %
- [type, name, detail]
- end
+ begin
+ obj = typeklass.create(:name => name, :check => retrieve)
+ rescue Puppet::Error => detail
+ raise Puppet::Error, "%s[%s] could not be created: %s" %
+ [type, name, detail]
end
unless obj
diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb
index 0dcfbaefc..4d5100c1d 100644
--- a/lib/puppet/node/catalog.rb
+++ b/lib/puppet/node/catalog.rb
@@ -64,6 +64,10 @@ class Puppet::Node::Catalog < Puppet::PGraph
else
@resource_table[ref] = resource
end
+
+ if resource.is_a?(Puppet::Type) and resource.class.isomorphic? and resource.title != resource.ref and resource.title != resource[:name]
+ self.alias(resource, resource[:name])
+ end
resource.catalog = self unless is_relationship_graph
add_vertex!(resource)
end
@@ -74,7 +78,10 @@ class Puppet::Node::Catalog < Puppet::PGraph
resource.ref =~ /^(.+)\[/
newref = "%s[%s]" % [$1 || resource.class.name, name]
- raise(ArgumentError, "Cannot alias %s to %s; resource %s already exists" % [resource.ref, name, newref]) if @resource_table[newref]
+ if res = @resource_table[newref]
+ return if res == resource
+ raise(ArgumentError, "Cannot alias %s to %s; resource %s already exists" % [resource.ref, name, newref])
+ end
@resource_table[newref] = resource
@aliases[resource.ref] << newref
end
@@ -321,7 +328,7 @@ class Puppet::Node::Catalog < Puppet::PGraph
# Lastly, add in any autorequires
@relationship_graph.vertices.each do |vertex|
- vertex.autorequire.each do |edge|
+ vertex.autorequire(@relationship_graph).each do |edge|
unless @relationship_graph.edge?(edge.source, edge.target) # don't let automatic relationships conflict with manual ones.
unless @relationship_graph.edge?(edge.target, edge.source)
vertex.debug "Autorequiring %s" % [edge.source]
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index 6a4981298..e1ad6eb58 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -155,7 +155,7 @@ class Transaction
# contained resources might never get cleaned up.
def cleanup
if defined? @generated
- relationship_graph.remove_resource(*@generated)
+ catalog.remove_resource(*@generated)
end
end
diff --git a/spec/unit/node/catalog.rb b/spec/unit/node/catalog.rb
index 3833890f7..6f246f6b3 100755
--- a/spec/unit/node/catalog.rb
+++ b/spec/unit/node/catalog.rb
@@ -308,8 +308,6 @@ describe Puppet::Node::Catalog, " when converting to a RAL catalog" do
newconfig = nil
- Puppet::Type.allclear
-
proc { @catalog = config.to_ral }.should_not raise_error
@catalog.resource("Test[changer2]").should equal(resource)
end
@@ -323,9 +321,9 @@ end
describe Puppet::Node::Catalog, " when functioning as a resource container" do
before do
@catalog = Puppet::Node::Catalog.new("host")
- @one = stub 'resource1', :ref => "Me[one]", :catalog= => nil
- @two = stub 'resource2', :ref => "Me[two]", :catalog= => nil
- @dupe = stub 'resource3', :ref => "Me[one]", :catalog= => nil
+ @one = stub 'resource1', :ref => "Me[one]", :catalog= => nil, :title => "one", :[] => "one"
+ @two = stub 'resource2', :ref => "Me[two]", :catalog= => nil, :title => "two", :[] => "two"
+ @dupe = stub 'resource3', :ref => "Me[one]", :catalog= => nil, :title => "one", :[] => "one"
end
it "should provide a method to add one or more resources" do
@@ -437,6 +435,28 @@ describe Puppet::Node::Catalog, " when functioning as a resource container" do
@catalog.resource("me", "other").should equal(@one)
end
+ it "should ignore conflicting aliases that point to the aliased resource" do
+ @catalog.alias(@one, "other")
+ lambda { @catalog.alias(@one, "other") }.should_not raise_error
+ end
+
+ it "should create aliases for resources isomorphic resources whose names do not match their titles" do
+ resource = Puppet::Type::File.create(:title => "testing", :path => "/something")
+
+ @catalog.add_resource(resource)
+
+ @catalog.resource(:file, "/something").should equal(resource)
+ end
+
+ it "should not create aliases for resources non-isomorphic resources whose names do not match their titles" do
+ resource = Puppet::Type.type(:exec).create(:title => "testing", :command => "echo", :path => %w{/bin /usr/bin /usr/local/bin})
+
+ @catalog.add_resource(resource)
+
+ # Yay, I've already got a 'should' method
+ @catalog.resource(:exec, "echo").object_id.should == nil.object_id
+ end
+
# This test is the same as the previous, but the behaviour should be explicit.
it "should alias using the class name from the resource reference, not the resource class name" do
@catalog.add_resource @one
@@ -444,11 +464,16 @@ describe Puppet::Node::Catalog, " when functioning as a resource container" do
@catalog.resource("me", "other").should equal(@one)
end
- it "should fail to add an alias if the aliased name already exists" do
+ it "should fail to add an alias if the aliased name already exists as a resource" do
@catalog.add_resource @one
proc { @catalog.alias @two, "one" }.should raise_error(ArgumentError)
end
+ it "should fail to add an alias if the aliased name already exists as an alias" do
+ @catalog.alias(@one, "yayness")
+ proc { @catalog.alias @two, "yayness" }.should raise_error(ArgumentError)
+ end
+
it "should remove resource aliases when the target resource is removed" do
@catalog.add_resource @one
@catalog.alias(@one, "other")
@@ -457,8 +482,10 @@ describe Puppet::Node::Catalog, " when functioning as a resource container" do
@catalog.resource("me", "other").should be_nil
end
- after do
- Puppet::Type.allclear
+ it "should return aliased resources when asked for the resource by the alias" do
+ @catalog.add_resource @one
+ @catalog.alias(@one, "other")
+ @catalog.resource("Me[other]").should equal(@one)
end
end
@@ -645,14 +672,14 @@ describe Puppet::Node::Catalog, " when creating a relationship graph" do
end
it "should look up resources in the relationship graph if not found in the main catalog" do
- five = stub 'five', :ref => "File[five]", :catalog= => nil
+ five = stub 'five', :ref => "File[five]", :catalog= => nil, :title => "five", :[] => "five"
@relationships.add_resource five
@catalog.resource(five.ref).should equal(five)
end
it "should provide a method to create additional resources that also registers the resource" do
args = {:name => "/yay", :ensure => :file}
- resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog
+ resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog, :title => "/yay", :[] => "/yay"
Puppet::Type.type(:file).expects(:create).with(args).returns(resource)
@catalog.create_resource :file, args
@catalog.resource("File[/yay]").should equal(resource)
@@ -660,7 +687,7 @@ describe Puppet::Node::Catalog, " when creating a relationship graph" do
it "should provide a mechanism for creating implicit resources" do
args = {:name => "/yay", :ensure => :file}
- resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog
+ resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog, :title => "/yay", :[] => "/yay"
Puppet::Type.type(:file).expects(:create).with(args).returns(resource)
resource.expects(:implicit=).with(true)
@catalog.create_implicit_resource :file, args
@@ -669,7 +696,7 @@ describe Puppet::Node::Catalog, " when creating a relationship graph" do
it "should add implicit resources to the relationship graph if there is one" do
args = {:name => "/yay", :ensure => :file}
- resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog
+ resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog, :title => "/yay", :[] => "/yay"
resource.expects(:implicit=).with(true)
Puppet::Type.type(:file).expects(:create).with(args).returns(resource)
# build the graph
@@ -681,7 +708,7 @@ describe Puppet::Node::Catalog, " when creating a relationship graph" do
it "should remove resources created mid-transaction" do
args = {:name => "/yay", :ensure => :file}
- resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog
+ resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog, :title => "/yay", :[] => "/yay"
@transaction = mock 'transaction'
Puppet::Transaction.stubs(:new).returns(@transaction)
@transaction.stubs(:evaluate)
@@ -700,10 +727,6 @@ describe Puppet::Node::Catalog, " when creating a relationship graph" do
@catalog.remove_resource(@one)
@catalog.relationship_graph.vertex?(@one).should be_false
end
-
- after do
- Puppet::Type.allclear
- end
end
describe Puppet::Node::Catalog, " when writing dot files" do
diff --git a/spec/unit/other/transbucket.rb b/spec/unit/other/transbucket.rb
index 3904e39fe..89f48ad41 100755
--- a/spec/unit/other/transbucket.rb
+++ b/spec/unit/other/transbucket.rb
@@ -116,13 +116,11 @@ describe Puppet::TransBucket, " when generating a catalog" do
it "should only call to_type on each resource once" do
@topobj.expects(:to_type)
@bottomobj.expects(:to_type)
- Puppet::Type.allclear
@top.to_catalog
end
it "should set each TransObject's catalog before converting to a RAL resource" do
@middleobj.expects(:catalog=).with { |c| c.is_a?(Puppet::Node::Catalog) }
- Puppet::Type.allclear
@top.to_catalog
end
@@ -130,13 +128,8 @@ describe Puppet::TransBucket, " when generating a catalog" do
# each bucket is seen twice in the loop, so we have to handle the case where the config
# is set twice
@bottom.expects(:catalog=).with { |c| c.is_a?(Puppet::Node::Catalog) }.at_least_once
- Puppet::Type.allclear
@top.to_catalog
end
-
- after do
- Puppet::Type.allclear
- end
end
describe Puppet::TransBucket, " when serializing" do
diff --git a/spec/unit/ral/provider/mount/parsed.rb b/spec/unit/ral/provider/mount/parsed.rb
index 89928891a..2fd15a543 100755
--- a/spec/unit/ral/provider/mount/parsed.rb
+++ b/spec/unit/ral/provider/mount/parsed.rb
@@ -165,10 +165,6 @@ describe provider_class, " when parsing information about the root filesystem" d
@provider_class.prefetch("/" => @mount)
@mount.provider.should be_mounted
end
-
- after do
- Puppet::Type.allclear
- end
end
describe provider_class, " when mounting and unmounting" do
diff --git a/spec/unit/ral/types/file.rb b/spec/unit/ral/types/file.rb
index 1e20b06f4..5ade79012 100755
--- a/spec/unit/ral/types/file.rb
+++ b/spec/unit/ral/types/file.rb
@@ -25,8 +25,4 @@ describe Puppet::Type::File, " when used with replace=>false and content" do
it "should not be insync if the file doesnot exist" do
@file.property(:content).insync?(:nil).should be_false
end
-
- after do
- Puppet::Type::File.clear
- end
end
diff --git a/spec/unit/ral/types/interface.rb b/spec/unit/ral/types/interface.rb
index 2e0176152..e51465a0c 100755
--- a/spec/unit/ral/types/interface.rb
+++ b/spec/unit/ral/types/interface.rb
@@ -90,6 +90,4 @@ describe interface do
it "should have a target parameter" do
@class.attrtype(:target).should == :param
end
-
- after { @class.clear }
end
diff --git a/spec/unit/ral/types/mount.rb b/spec/unit/ral/types/mount.rb
index 7d01022b5..5965908cb 100755
--- a/spec/unit/ral/types/mount.rb
+++ b/spec/unit/ral/types/mount.rb
@@ -13,8 +13,6 @@ describe Puppet::Type::Mount do
mount = Puppet::Type::Mount.create(:name => "yay")
mount.should(:ensure).should be_nil
end
-
- after { Puppet::Type::Mount.clear }
end
describe Puppet::Type::Mount, "when validating attributes" do
@@ -53,8 +51,6 @@ describe Puppet::Type::Mount::Ensure, "when validating values" do
it "should support :mounted as a value to :ensure" do
Puppet::Type::Mount.create(:name => "yay", :ensure => :mounted)
end
-
- after { Puppet::Type::Mount.clear }
end
module MountEvaluationTesting
@@ -78,10 +74,6 @@ module MountEvaluationTesting
@provider.stubs(param).returns(value)
end
end
-
- def teardown
- Puppet::Type::Mount.clear
- end
end
describe Puppet::Type::Mount::Ensure, "when retrieving its current state" do
diff --git a/spec/unit/ral/types/package.rb b/spec/unit/ral/types/package.rb
index f14a792b9..e9e3b9e4e 100755
--- a/spec/unit/ral/types/package.rb
+++ b/spec/unit/ral/types/package.rb
@@ -29,8 +29,6 @@ describe Puppet::Type::Package do
pkg = Puppet::Type::Package.create(:name => "yay")
pkg.should(:ensure).should == :present
end
-
- after { Puppet::Type::Package.clear }
end
describe Puppet::Type::Package, "when validating attributes" do
@@ -97,8 +95,6 @@ describe Puppet::Type::Package, "when validating attribute values" do
it "should only accept files and URLs as values to :source" do
proc { Puppet::Type::Package.create(:name => "yay", :source => "stuff") }.should raise_error(Puppet::Error)
end
-
- after { Puppet::Type::Package.clear }
end
module PackageEvaluationTesting
@@ -114,11 +110,6 @@ module PackageEvaluationTesting
def setprops(properties)
@provider.stubs(:properties).returns(properties)
end
-
- def teardown
- @catalog.clear(true)
- Puppet::Type::Package.clear
- end
end
describe Puppet::Type::Package, "when it should be purged" do
diff --git a/spec/unit/ral/types/schedule.rb b/spec/unit/ral/types/schedule.rb
index 73b3a0bd1..856a73186 100755
--- a/spec/unit/ral/types/schedule.rb
+++ b/spec/unit/ral/types/schedule.rb
@@ -43,10 +43,6 @@ module ScheduleTesting
def sec(method, count)
diff(:sec, 1, method, count)
end
-
- def teardown
- Puppet::Type::Schedule.clear
- end
end
describe Puppet::Type::Schedule do
diff --git a/spec/unit/ral/types/service.rb b/spec/unit/ral/types/service.rb
index 981d38a15..3944f146c 100755
--- a/spec/unit/ral/types/service.rb
+++ b/spec/unit/ral/types/service.rb
@@ -117,8 +117,6 @@ describe Puppet::Type::Service, "when validating attribute values" do
svc = Puppet::Type::Service.create(:name => "yay", :path => ["/one:/two", "/three:/four"])
svc[:path].should == %w{/one /two /three /four}
end
-
- after { Puppet::Type::Service.clear }
end
describe Puppet::Type::Service, "when setting default attribute values" do
@@ -141,8 +139,6 @@ describe Puppet::Type::Service, "when setting default attribute values" do
svc = Puppet::Type::Service.create(:name => "other")
svc[:pattern].should == "other"
end
-
- after { Puppet::Type::Service.clear }
end
describe Puppet::Type::Service, "when retrieving the host's current state" do
@@ -162,8 +158,6 @@ describe Puppet::Type::Service, "when retrieving the host's current state" do
@service[:enable] = true
@service.property(:enable).retrieve.should == :yepper
end
-
- after { Puppet::Type::Service.clear }
end
describe Puppet::Type::Service, "when changing the host" do
@@ -210,8 +204,6 @@ describe Puppet::Type::Service, "when changing the host" do
@service.property(:ensure).sync
end
-
- after { Puppet::Type::Service.clear }
end
describe Puppet::Type::Service, "when refreshing the service" do
@@ -244,6 +236,4 @@ describe Puppet::Type::Service, "when refreshing the service" do
@service.provider.expects(:restart)
@service.refresh
end
-
- after { Puppet::Type::Service.clear }
end
diff --git a/test/language/snippets.rb b/test/language/snippets.rb
index 2a4ba0220..01d77c265 100755
--- a/test/language/snippets.rb
+++ b/test/language/snippets.rb
@@ -14,7 +14,8 @@ class TestSnippets < Test::Unit::TestCase
def setup
super
- @file = Puppet::Type.type(:file)
+ Facter.stubs(:to_hash).returns({})
+ Facter.stubs(:value).returns("whatever")
end
def self.snippetdir
@@ -22,14 +23,14 @@ class TestSnippets < Test::Unit::TestCase
end
def assert_file(path, msg = nil)
- unless file = @file[path]
+ unless file = @catalog.resource(:file, path)
msg ||= "Could not find file %s" % path
raise msg
end
end
def assert_mode_equal(mode, path)
- unless file = @file[path]
+ unless file = @catalog.resource(:file, path)
raise "Could not find file %s" % path
end
@@ -211,8 +212,8 @@ class TestSnippets < Test::Unit::TestCase
path1 = "/tmp/argumenttest1"
path2 = "/tmp/argumenttest2"
- file1 = @file[path1]
- file2 = @file[path2]
+ file1 = @catalog.resource(:file, path1)
+ file2 = @catalog.resource(:file, path2)
assert_file(path1)
assert_mode_equal(0755, path1)
@@ -231,7 +232,7 @@ class TestSnippets < Test::Unit::TestCase
}
paths.each { |path|
- file = @file[path]
+ file = @catalog.resource(:file, path)
assert(file, "File %s is missing" % path)
assert_mode_equal(0755, path)
}
@@ -241,7 +242,7 @@ class TestSnippets < Test::Unit::TestCase
paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration%stest" % l }
paths.each { |path|
- file = @file[path]
+ file = @catalog.resource(:file, path)
assert_file(path)
assert_mode_equal(0755, path)
}
@@ -262,7 +263,7 @@ class TestSnippets < Test::Unit::TestCase
dir = "/tmp/testdirtest"
assert_file(file)
assert_file(dir)
- assert_equal(:directory, @file[dir].should(:ensure), "Directory is not set to be a directory")
+ assert_equal(:directory, @catalog.resource(:file, dir).should(:ensure), "Directory is not set to be a directory")
end
def snippet_scopetest
@@ -349,7 +350,7 @@ class TestSnippets < Test::Unit::TestCase
}.each { |count, str|
path = "/tmp/singlequote%s" % count
assert_file(path)
- assert_equal(str, @file[path].should(:content))
+ assert_equal(str, @catalog.resource(:file, path).should(:content))
}
end
@@ -387,21 +388,20 @@ class TestSnippets < Test::Unit::TestCase
end
def snippet_emptyexec
- assert(Puppet::Type.type(:exec)["touch /tmp/emptyexectest"],
- "Did not create exec")
+ assert(@catalog.resource(:exec, "touch /tmp/emptyexectest"), "Did not create exec")
end
def snippet_multisubs
path = "/tmp/multisubtest"
assert_file(path)
- file = @file[path]
+ file = @catalog.resource(:file, path)
assert_equal("sub2", file.should(:content), "sub2 did not override content")
assert_mode_equal(0755, path)
end
def snippet_collection
assert_file("/tmp/colltest1")
- assert_nil(@file["/tmp/colltest2"], "Incorrectly collected file")
+ assert_nil(@catalog.resource(:file, "/tmp/colltest2"), "Incorrectly collected file")
end
def snippet_virtualresources
@@ -469,16 +469,6 @@ class TestSnippets < Test::Unit::TestCase
catalog = catalog.to_ral
}
- Puppet::Type.eachtype { |type|
- type.each { |obj|
- # don't worry about this for now
- #unless obj.name == "puppet[top]" or
- # obj.is_a?(Puppet.type(:schedule))
- # assert(obj.parent, "%s has no parent" % obj.name)
- #end
- assert(obj.name)
- }
- }
@catalog = catalog
assert_nothing_raised {
self.send(mname)
diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb
index 76ae96e02..68add6dd5 100755
--- a/test/lib/puppettest.rb
+++ b/test/lib/puppettest.rb
@@ -278,7 +278,6 @@ module PuppetTest
}
@@tmppids.clear
- Puppet::Type.allclear
Puppet::Util::Storage.clear
Puppet.clear
Puppet.settings.clear
diff --git a/test/other/relationships.rb b/test/other/relationships.rb
index dd51e3165..88d35ce1f 100755
--- a/test/other/relationships.rb
+++ b/test/other/relationships.rb
@@ -81,6 +81,9 @@ class TestRelationships < Test::Unit::TestCase
)
end
+ catalog = mk_catalog(*files)
+ catalog.add_resource(*execs)
+
# Add our first relationship
if out[param]
files[0][param] = execs[0]
@@ -177,8 +180,8 @@ class TestRelationships < Test::Unit::TestCase
# Now make sure that these relationships are added to the
# relationship graph
- config.apply do |trans|
- assert(config.relationship_graph.edge?(file, exec), "autorequire edge was not created")
+ catalog.apply do |trans|
+ assert(catalog.relationship_graph.edge?(file, exec), "autorequire edge was not created")
end
end
diff --git a/test/other/transactions.rb b/test/other/transactions.rb
index 79971a28b..649a3cd32 100755
--- a/test/other/transactions.rb
+++ b/test/other/transactions.rb
@@ -6,10 +6,12 @@ require 'puppet'
require 'puppettest'
require 'mocha'
require 'puppettest/support/resources'
+require 'puppettest/support/utils'
class TestTransactions < Test::Unit::TestCase
include PuppetTest::FileTesting
include PuppetTest::Support::Resources
+ include PuppetTest::Support::Utils
class Fakeprop <Puppet::Property
attr_accessor :path, :is, :should, :name
def should_to_s(value)
@@ -596,15 +598,15 @@ class TestTransactions < Test::Unit::TestCase
yay = Puppet::Type.newgenerator :title => "yay"
rah = Puppet::Type.newgenerator :title => "rah"
- config = mk_catalog(yay, rah)
- trans = Puppet::Transaction.new(config)
+ catalog = mk_catalog(yay, rah)
+ trans = Puppet::Transaction.new(catalog)
assert_nothing_raised do
trans.generate
end
%w{ya ra y r}.each do |name|
- assert(trans.catalog.vertex?(Puppet::Type.type(:generator)[name]),
+ assert(catalog.resource(:generator, name),
"Generated %s was not a vertex" % name)
assert($finished.include?(name), "%s was not finished" % name)
end
@@ -615,10 +617,8 @@ class TestTransactions < Test::Unit::TestCase
end
%w{ya ra y r}.each do |name|
- assert(!trans.catalog.vertex?(Puppet::Type.type(:generator)[name]),
+ assert(! catalog.resource(:generator, name),
"Generated vertex %s was not removed from graph" % name)
- assert_nil(Puppet::Type.type(:generator)[name],
- "Generated vertex %s was not removed from class" % name)
end
end
@@ -635,8 +635,8 @@ class TestTransactions < Test::Unit::TestCase
yay = Puppet::Type.newgenerator :title => "yay"
rah = Puppet::Type.newgenerator :title => "rah", :subscribe => yay
- config = mk_catalog(yay, rah)
- trans = Puppet::Transaction.new(config)
+ catalog = mk_catalog(yay, rah)
+ trans = Puppet::Transaction.new(catalog)
trans.prepare
@@ -645,7 +645,7 @@ class TestTransactions < Test::Unit::TestCase
assert_nothing_raised("failed to apply yay") do
trans.eval_resource(yay)
end
- ya = type["ya"]
+ ya = catalog.resource(type.name, "ya")
assert(ya, "Did not generate ya")
assert(trans.relationship_graph.vertex?(ya),
"Did not add ya to rel_graph")
@@ -658,11 +658,11 @@ class TestTransactions < Test::Unit::TestCase
# Now make sure it in turn eval_generates appropriately
assert_nothing_raised("failed to apply yay") do
- trans.eval_resource(type["ya"])
+ trans.eval_resource(catalog.resource(type.name, "ya"))
end
%w{y}.each do |name|
- res = type[name]
+ res = catalog.resource(type.name, "ya")
assert(res, "Did not generate %s" % name)
assert(trans.relationship_graph.vertex?(res),
"Did not add %s to rel_graph" % name)
@@ -670,7 +670,7 @@ class TestTransactions < Test::Unit::TestCase
end
assert_nothing_raised("failed to eval_generate with nil response") do
- trans.eval_resource(type["y"])
+ trans.eval_resource(catalog.resource(type.name, "y"))
end
assert(trans.relationship_graph.edge?(yay, ya), "no edge was created for ya => yay")
@@ -678,7 +678,7 @@ class TestTransactions < Test::Unit::TestCase
trans.eval_resource(rah)
end
- ra = type["ra"]
+ ra = catalog.resource(type.name, "ra")
assert(ra, "Did not generate ra")
assert(trans.relationship_graph.vertex?(ra),
"Did not add ra to rel_graph" % name)
@@ -697,14 +697,12 @@ class TestTransactions < Test::Unit::TestCase
end
%w{ya ra y r}.each do |name|
- assert(!trans.relationship_graph.vertex?(type[name]),
+ assert(!trans.relationship_graph.vertex?(catalog.resource(type.name, name)),
"Generated vertex %s was not removed from graph" % name)
- assert_nil(type[name],
- "Generated vertex %s was not removed from class" % name)
end
# Now, start over and make sure that everything gets evaluated.
- trans = Puppet::Transaction.new(config)
+ trans = Puppet::Transaction.new(catalog)
$evaluated.clear
assert_nothing_raised do
trans.evaluate
diff --git a/test/ral/manager/instances.rb b/test/ral/manager/instances.rb
index a50ecb213..5305b3ff3 100755
--- a/test/ral/manager/instances.rb
+++ b/test/ral/manager/instances.rb
@@ -89,21 +89,5 @@ class TestTypeInstances < Test::Unit::TestCase
# Now make sure the resources have an 'ensure' property to go with the value in the provider
assert(resources[:one].send(:instance_variable_get, "@parameters").include?(:ensure), "Did not create ensure property")
end
-
- # Make sure resources are entirely deleted.
- def test_delete
- aliases = %w{one}
- catalog = mk_catalog
- obj = @type.create(:name => "testing", :alias => "two", :catalog => catalog)
- aliases << "two"
-
- @type.alias("two", obj)
-
- obj.remove
- assert_nil(@type["testing"], "Object was not removed from objects hash")
- assert_nil(@type["one"], "Object's alias was not removed")
- assert_nil(@type["two"], "Object's second alias was not removed")
-
- end
end
diff --git a/test/ral/manager/type.rb b/test/ral/manager/type.rb
index 6a044687e..bb13a7b78 100755
--- a/test/ral/manager/type.rb
+++ b/test/ral/manager/type.rb
@@ -65,7 +65,6 @@ class TestType < Test::Unit::TestCase
assert_nothing_raised() {
file.evaluate
}
- Puppet.type(:file).clear
assert_nothing_raised() {
system("rm -f %s" % path)
file = Puppet.type(:file).create(
@@ -110,47 +109,7 @@ class TestType < Test::Unit::TestCase
assert_equal("testing", group.name, "Could not retrieve name")
end
- # Verify that values get merged correctly
- def test_mergepropertyvalues
- file = tempfile()
-
- # Create the first version
- assert_nothing_raised {
- Puppet.type(:file).create(
- :path => file,
- :owner => ["root", "bin"]
- )
- }
-
- # Make sure no other statements are allowed
- assert_raise(Puppet::Error) {
- Puppet.type(:file).create(
- :path => file,
- :group => "root"
- )
- }
- end
-
- def test_aliases_to_self_are_not_failures
- resource = Puppet.type(:file).create(
- :name => "/path/to/some/missing/file",
- :ensure => "file"
- )
- resource.stubs(:path).returns("")
-
- catalog = stub 'catalog'
- catalog.expects(:resource).with(:file, "/path/to/some/missing/file").returns(resource)
- resource.catalog = catalog
-
- # Verify our adding ourselves as an alias isn't an error.
- assert_nothing_raised("Could not add alias") {
- resource[:alias] = "/path/to/some/missing/file"
- }
-
- assert_equal(resource.object_id, Puppet.type(:file)["/path/to/some/missing/file"].object_id, "Could not retrieve alias to self")
- end
-
- def test_aliases_are_added_to_class_and_catalog
+ def test_aliases_are_added_to_catalog
resource = Puppet.type(:file).create(
:name => "/path/to/some/missing/file",
:ensure => "file"
@@ -165,8 +124,6 @@ class TestType < Test::Unit::TestCase
assert_nothing_raised("Could not add alias") {
resource[:alias] = "funtest"
}
-
- assert_equal(resource.object_id, Puppet.type(:file)["funtest"].object_id, "Could not retrieve alias")
end
def test_aliasing_fails_without_a_catalog
@@ -182,7 +139,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 = :my_config
+ trans.catalog = stub 'catalog', :resource => nil
resource = trans.to_type
assert_equal(resource.catalog, trans.catalog, "Did not set catalog on initialization")
end
@@ -217,37 +174,6 @@ class TestType < Test::Unit::TestCase
assert(twoobj.requires?(oneobj), "Requirement was not created")
end
- # Verify that names are aliases, not equivalents
- def test_nameasalias
- file = nil
- # Create the parent dir, so we make sure autorequiring the parent dir works
- parentdir = tempfile()
- dir = Puppet.type(:file).create(
- :name => parentdir,
- :ensure => "directory"
- )
- assert_apply(dir)
- path = File.join(parentdir, "subdir")
- name = "a test file"
- transport = Puppet::TransObject.new(name, "file")
- transport[:path] = path
- transport[:ensure] = "file"
- assert_nothing_raised {
- file = transport.to_type
- }
-
- assert_equal(path, file[:path])
- assert_equal(name, file.title)
-
- assert_nothing_raised {
- file.retrieve
- }
-
- assert_apply(file)
-
- assert(Puppet.type(:file)[name], "Could not look up object by name")
- end
-
def test_ensuredefault
user = nil
assert_nothing_raised {
@@ -434,7 +360,6 @@ class TestType < Test::Unit::TestCase
assert_equal(path, file[:name], "Did not get correct name")
file = nil
- Puppet::Type.type(:file).clear
# Now make sure we can specify both and still get the right answers
assert_nothing_raised do
@@ -475,7 +400,6 @@ class TestType < Test::Unit::TestCase
# Now try it using the class method on Type
oldid = obj.object_id
obj = nil
- Puppet::Type.type(:file).clear
assert_nothing_raised {
obj = Puppet::Type.create(trans)
@@ -487,7 +411,6 @@ class TestType < Test::Unit::TestCase
# Now try the same things with hashes instead of a transobject
oldid = obj.object_id
obj = nil
- Puppet::Type.type(:file).clear
hash = {
:type => :file,
:title => "Myfile",
@@ -510,7 +433,6 @@ class TestType < Test::Unit::TestCase
# Now try it using the class method on Type
oldid = obj.object_id
obj = nil
- Puppet::Type.type(:file).clear
assert_nothing_raised {
obj = Puppet::Type.create(hash)
@@ -533,25 +455,6 @@ class TestType < Test::Unit::TestCase
end
end
- def test_title_and_name
- obj = nil
- path = tempfile()
- fileobj = Puppet::Type.type(:file)
-
- assert_nothing_raised do
- obj = fileobj.create(
- :title => "myfile",
- :path => path
- )
- end
-
- assert_equal(obj, fileobj["myfile"],
- "Could not retrieve obj by title")
-
- assert_equal(obj, fileobj[path],
- "Could not retrieve obj by name")
- end
-
# Make sure default providers behave correctly
def test_defaultproviders
# Make a fake type
@@ -577,6 +480,7 @@ class TestType < Test::Unit::TestCase
# Make sure that we can have multiple isomorphic objects with the same name,
# but not with non-isomorphic objects.
def test_isomorphic_names
+ catalog = mk_catalog
# First do execs, since they're not isomorphic.
echo = Puppet::Util.binary "echo"
exec1 = exec2 = nil
@@ -586,37 +490,31 @@ class TestType < Test::Unit::TestCase
:command => "#{echo} funtest"
)
end
+ catalog.add_resource(exec1)
assert_nothing_raised do
exec2 = Puppet::Type.type(:exec).create(
:title => "exec2",
:command => "#{echo} funtest"
)
end
-
- assert_apply(exec1, exec2)
+ catalog.add_resource(exec2)
# Now do files, since they are. This should fail.
file1 = file2 = nil
path = tempfile()
- assert_nothing_raised do
- file1 = Puppet::Type.type(:file).create(
- :title => "file1",
- :path => path,
- :content => "yayness"
- )
- end
-
- # This will fail, but earlier systems will catch it.
- assert_raise(Puppet::Error) do
- file2 = Puppet::Type.type(:file).create(
- :title => "file2",
- :path => path,
- :content => "rahness"
- )
- end
+ file1 = Puppet::Type.type(:file).create(
+ :title => "file1",
+ :path => path,
+ :content => "yayness"
+ )
+ catalog.add_resource(file1)
- assert(file1, "Did not create first file")
- assert_nil(file2, "Incorrectly created second file")
+ file2 = Puppet::Type.type(:file).create(
+ :title => "file2",
+ :path => path,
+ :content => "rahness"
+ )
+ assert_raise(ArgumentError) { catalog.add_resource(file2) }
end
def test_tags
@@ -654,20 +552,6 @@ class TestType < Test::Unit::TestCase
end
end
- # Make sure that classes behave like hashes.
- def test_class_hash_behaviour
- path = tempfile()
-
- filetype = Puppet::Type.type(:file)
- one = Puppet::Type.newfile :path => path
-
- assert_equal(one, filetype[path], "Did not get file back")
-
- assert_raise(Puppet::Error) do
- filetype[path] = one
- end
- end
-
def test_ref
path = tempfile()
Puppet::Type.type(:exec) # uggh, the methods need to load the types
@@ -701,7 +585,7 @@ class TestType < Test::Unit::TestCase
type = Puppet::Type.type(:exec)
mk = Proc.new do |i, hash|
hash[:title] = "exec%s" % i
- hash[:command] = "/bin/echo"
+ hash[:command] = "/bin/echo %s" % i
if parent = hash[:parent]
hash.delete(:parent)
end
@@ -769,7 +653,8 @@ class TestType < Test::Unit::TestCase
# Partially test #704, but also cover the rest of the schedule management bases.
def test_schedule
- Puppet::Type.type(:schedule).create(:name => "maint")
+ schedule = Puppet::Type.type(:schedule).create(:name => "maint")
+ catalog = mk_catalog(schedule)
{"maint" => true, nil => false, :fail => :fail}.each do |name, should|
args = {:name => tempfile, :ensure => :file}
@@ -777,21 +662,27 @@ class TestType < Test::Unit::TestCase
args[:schedule] = name
end
resource = Puppet::Type.type(:file).create(args)
+ catalog.add_resource(resource)
if should == :fail
assert_raise(Puppet::Error, "Did not fail on missing schedule") do
resource.schedule
end
+ elsif should == false
+ assert_nil(resource.schedule, "Set the schedule tho it is set to nil")
else
sched = nil
assert_nothing_raised("Failed when schedule was %s" % sched) do
sched = resource.schedule
end
+ assert(sched, "Did not find schedule %s" % sched.inspect)
+
if should
assert_equal(name, sched.name, "did not get correct schedule back")
end
end
+ catalog.remove_resource(resource)
end
end
diff --git a/test/ral/types/sshkey.rb b/test/ral/types/sshkey.rb
index b9aed20e8..c68e4a271 100755
--- a/test/ral/types/sshkey.rb
+++ b/test/ral/types/sshkey.rb
@@ -49,26 +49,27 @@ class TestSSHKey < Test::Unit::TestCase
@catalog ||= mk_catalog
- assert_nothing_raised {
- key = @sshkeytype.create(
- :name => "host%s.madstop.com" % @kcount,
- :key => "%sAAAAB3NzaC1kc3MAAACBAMnhSiku76y3EGkNCDsUlvpO8tRgS9wL4Eh54WZfQ2lkxqfd2uT/RTT9igJYDtm/+UHuBRdNGpJYW1Nw2i2JUQgQEEuitx4QKALJrBotejGOAWxxVk6xsh9xA0OW8Q3ZfuX2DDitfeC8ZTCl4xodUMD8feLtP+zEf8hxaNamLlt/AAAAFQDYJyf3vMCWRLjTWnlxLtOyj/bFpwAAAIEAmRxxXb4jjbbui9GYlZAHK00689DZuX0EabHNTl2yGO5KKxGC6Esm7AtjBd+onfu4Rduxut3jdI8GyQCIW8WypwpJofCIyDbTUY4ql0AQUr3JpyVytpnMijlEyr41FfIb4tnDqnRWEsh2H7N7peW+8DWZHDFnYopYZJ9Yu4/jHRYAAACAERG50e6aRRb43biDr7Ab9NUCgM9bC0SQscI/xdlFjac0B/kSWJYTGVARWBDWug705hTnlitY9cLC5Ey/t/OYOjylTavTEfd/bh/8FkAYO+pWdW3hx6p97TBffK0b6nrc6OORT2uKySbbKOn0681nNQh4a6ueR3JRppNkRPnTk5c=" % @kcount,
- :type => "ssh-dss",
- :alias => ["192.168.0.%s" % @kcount],
- :catalog => @catalog
- )
- }
+ key = @sshkeytype.create(
+ :name => "host%s.madstop.com" % @kcount,
+ :key => "%sAAAAB3NzaC1kc3MAAACBAMnhSiku76y3EGkNCDsUlvpO8tRgS9wL4Eh54WZfQ2lkxqfd2uT/RTT9igJYDtm/+UHuBRdNGpJYW1Nw2i2JUQgQEEuitx4QKALJrBotejGOAWxxVk6xsh9xA0OW8Q3ZfuX2DDitfeC8ZTCl4xodUMD8feLtP+zEf8hxaNamLlt/AAAAFQDYJyf3vMCWRLjTWnlxLtOyj/bFpwAAAIEAmRxxXb4jjbbui9GYlZAHK00689DZuX0EabHNTl2yGO5KKxGC6Esm7AtjBd+onfu4Rduxut3jdI8GyQCIW8WypwpJofCIyDbTUY4ql0AQUr3JpyVytpnMijlEyr41FfIb4tnDqnRWEsh2H7N7peW+8DWZHDFnYopYZJ9Yu4/jHRYAAACAERG50e6aRRb43biDr7Ab9NUCgM9bC0SQscI/xdlFjac0B/kSWJYTGVARWBDWug705hTnlitY9cLC5Ey/t/OYOjylTavTEfd/bh/8FkAYO+pWdW3hx6p97TBffK0b6nrc6OORT2uKySbbKOn0681nNQh4a6ueR3JRppNkRPnTk5c=" % @kcount,
+ :type => "ssh-dss",
+ :alias => ["192.168.0.%s" % @kcount],
+ :catalog => @catalog
+ )
+
+ @catalog.add_resource(key)
return key
end
def test_instances
+ list = nil
assert_nothing_raised {
- Puppet.type(:sshkey).instances
+ list = Puppet.type(:sshkey).instances
}
count = 0
- @sshkeytype.each do |h|
+ list.each do |h|
count += 1
end
@@ -90,7 +91,6 @@ class TestSSHKey < Test::Unit::TestCase
# Now create a new key object
name = key.name
key = nil
- @sshkeytype.clear
key = @sshkeytype.create :name => name, :target => file, :provider => :parsed
key.retrieve
@@ -109,11 +109,10 @@ class TestSSHKey < Test::Unit::TestCase
aliases = %w{madstop kirby yayness}
key[:alias] = aliases
- params = key.instance_variable_get("@parameters")
assert_events([:sshkey_changed], key)
aliases.each do |name|
- assert_equal(key, key.class[name],
+ assert_equal(key, @catalog.resource(:sshkey, name),
"alias was not set")
end
end
@@ -136,7 +135,9 @@ class TestSSHKey < Test::Unit::TestCase
key[:alias] = "testing"
}
- same = key.class["testing"]
+ key.finish
+
+ same = @catalog.resource(:sshkey, "testing")
assert(same, "Could not retrieve by alias")
end
@@ -170,7 +171,10 @@ class TestSSHKey < Test::Unit::TestCase
}
assert_apply(*keys)
keys.clear
- Puppet.type(:sshkey).clear
+
+ @catalog.clear(true)
+ @catalog = nil
+
newkey = mkkey()
#newkey[:ensure] = :present
names << newkey.name
@@ -184,8 +188,7 @@ class TestSSHKey < Test::Unit::TestCase
# And verify that we have data for everything
names.each { |name|
- key = Puppet.type(:sshkey)[name] ||
- Puppet.type(:sshkey).create(:name => name)
+ key = @catalog.resource(:sshkey, name)
assert(key, "Could not retrieve key for %s" % name)
assert(key.provider.exists?, "key %s is missing" % name)
}
diff --git a/test/ral/types/user.rb b/test/ral/types/user.rb
index b280acfed..ec9b12923 100755
--- a/test/ral/types/user.rb
+++ b/test/ral/types/user.rb
@@ -449,6 +449,7 @@ class TestUser < Test::Unit::TestCase
# Testing #455
def test_autorequire_with_no_group_should
user = Puppet::Type.type(:user).create(:name => "yaytest", :check => :all)
+ catalog = mk_catalog(user)
assert_nothing_raised do
user.autorequire