summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-11-18 11:21:22 -0600
committerLuke Kanies <luke@madstop.com>2007-11-18 11:21:22 -0600
commitc19835ce9f8a5138b30a1a32ca741c996b0916d2 (patch)
tree1a7b05839f013cc8a610f7c9493e206606fab977
parent9290cc89a2206fb5204578f8e91208857a48b147 (diff)
downloadpuppet-c19835ce9f8a5138b30a1a32ca741c996b0916d2.tar.gz
puppet-c19835ce9f8a5138b30a1a32ca741c996b0916d2.tar.xz
puppet-c19835ce9f8a5138b30a1a32ca741c996b0916d2.zip
Fixed most failing tests, but there are still over thirty failing.
At this point, I'm holding the experiment until after the release, so I'm committing this for now and will take it back up after 0.24.0 is out.
-rw-r--r--lib/puppet/metatype/relationships.rb12
-rw-r--r--lib/puppet/metatype/schedules.rb4
-rwxr-xr-xlib/puppet/network/handler/fileserver.rb7
-rwxr-xr-xlib/puppet/network/handler/resource.rb31
-rw-r--r--lib/puppet/node/configuration.rb16
-rw-r--r--lib/puppet/type.rb12
-rw-r--r--lib/puppet/type/pfile.rb60
-rwxr-xr-xlib/puppet/type/pfilebucket.rb11
-rwxr-xr-xlib/puppet/type/schedule.rb4
-rwxr-xr-xlib/puppet/util/filetype.rb2
-rwxr-xr-xspec/unit/network/client/master.rb23
-rwxr-xr-xspec/unit/node/configuration.rb40
-rwxr-xr-xtest/language/snippets.rb23
-rw-r--r--test/lib/puppettest/support/utils.rb2
-rwxr-xr-xtest/network/client/client.rb29
-rwxr-xr-xtest/network/client/master.rb51
-rwxr-xr-xtest/network/handler/fileserver.rb19
-rwxr-xr-xtest/network/handler/resource.rb5
-rwxr-xr-xtest/other/overrides.rb33
-rwxr-xr-xtest/other/relationships.rb18
-rwxr-xr-xtest/other/transactions.rb36
-rwxr-xr-xtest/ral/types/basic.rb7
-rwxr-xr-xtest/ral/types/cron.rb14
-rwxr-xr-xtest/ral/types/exec.rb13
-rwxr-xr-xtest/ral/types/file.rb130
-rwxr-xr-xtest/ral/types/file/target.rb26
-rwxr-xr-xtest/ral/types/filebucket.rb24
-rwxr-xr-xtest/ral/types/fileignoresource.rb7
-rwxr-xr-xtest/ral/types/filesources.rb10
-rwxr-xr-xtest/ral/types/host.rb4
-rwxr-xr-xtest/ral/types/package.rb1
-rwxr-xr-xtest/ral/types/parameter.rb5
-rwxr-xr-xtest/ral/types/schedule.rb39
-rwxr-xr-xtest/ral/types/sshkey.rb18
-rwxr-xr-xtest/ral/types/tidy.rb14
-rwxr-xr-xtest/util/filetype.rb3
36 files changed, 326 insertions, 427 deletions
diff --git a/lib/puppet/metatype/relationships.rb b/lib/puppet/metatype/relationships.rb
index 332702a25..2a5341e5e 100644
--- a/lib/puppet/metatype/relationships.rb
+++ b/lib/puppet/metatype/relationships.rb
@@ -29,16 +29,16 @@ class Puppet::Type
# Collect the current prereqs
list.each { |dep|
- obj = nil
# Support them passing objects directly, to save some effort.
- unless dep.is_a? Puppet::Type
+ if dep.is_a?(Puppet::Type)
+ next unless configuration.resource(type, dep.title)
+ resource = dep
+ else
# Skip autorequires that we aren't managing
- unless dep = configuration.resource(type, dep)
- next
- end
+ next unless resource = configuration.resource(type, dep)
end
- reqs << Puppet::Relationship.new(dep, self)
+ reqs << Puppet::Relationship.new(resource, self)
}
}
diff --git a/lib/puppet/metatype/schedules.rb b/lib/puppet/metatype/schedules.rb
index 96ebce0ab..4d4f93764 100644
--- a/lib/puppet/metatype/schedules.rb
+++ b/lib/puppet/metatype/schedules.rb
@@ -4,8 +4,8 @@ class Puppet::Type
# file.
def schedule
unless defined? @schedule
- if name = self[:schedule]
- if sched = Puppet.type(:schedule)[name]
+ if name = self[:schedule] and self.configuration
+ if sched = configuration.resource(:schedule, name)
@schedule = sched
else
self.fail "Could not find schedule %s" % name
diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb
index dd00450be..7a5a1fe9a 100755
--- a/lib/puppet/network/handler/fileserver.rb
+++ b/lib/puppet/network/handler/fileserver.rb
@@ -551,22 +551,25 @@ class Puppet::Network::Handler
@path = nil
end
+ @cache = {}
+
super()
end
def fileobj(path, links)
obj = nil
- if obj = Puppet.type(:file)[path]
+ if obj = @cache[path]
# This can only happen in local fileserving, but it's an
# important one. It'd be nice if we didn't just set
# the check params every time, but I'm not sure it's worth
# the effort.
obj[:check] = CHECKPARAMS
else
- obj = Puppet.type(:file).create(
+ obj = Puppet::Type.type(:file).create(
:name => path,
:check => CHECKPARAMS
)
+ @cache[path] = obj
end
if links == :manage
diff --git a/lib/puppet/network/handler/resource.rb b/lib/puppet/network/handler/resource.rb
index 0fcd694fb..c96bdf6a6 100755
--- a/lib/puppet/network/handler/resource.rb
+++ b/lib/puppet/network/handler/resource.rb
@@ -53,8 +53,8 @@ class Puppet::Network::Handler
return "success"
end
- # Describe a given object. This returns the 'is' values for every property
- # available on the object type.
+ # Describe a given resource. This returns the 'is' values for every property
+ # available on the resource type.
def describe(type, name, retrieve = nil, ignore = [], format = "yaml", client = nil, clientip = nil)
Puppet.info "Describing %s[%s]" % [type.to_s.capitalize, name]
@local = true unless client
@@ -63,29 +63,23 @@ class Puppet::Network::Handler
raise Puppet::Error, "Puppet type %s is unsupported" % type
end
- obj = nil
-
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
+ resource = 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
+ unless resource
raise XMLRPC::FaultException.new(
1, "Could not create %s[%s]" % [type, name]
)
end
- trans = obj.to_trans
+ trans = resource.to_trans
# Now get rid of any attributes they specifically don't want
ignore.each do |st|
@@ -138,11 +132,10 @@ class Puppet::Network::Handler
bucket = Puppet::TransBucket.new
bucket.type = typeklass.name
- typeklass.instances.each do |obj|
- next if ignore.include? obj.name
+ typeklass.instances.each do |resource|
+ next if ignore.include? resource.name
- #object = Puppet::TransObject.new(obj.name, typeklass.name)
- bucket << obj.to_trans
+ bucket << resource.to_trans
end
unless @local
diff --git a/lib/puppet/node/configuration.rb b/lib/puppet/node/configuration.rb
index 061e83f4b..e131839df 100644
--- a/lib/puppet/node/configuration.rb
+++ b/lib/puppet/node/configuration.rb
@@ -60,11 +60,22 @@ class Puppet::Node::Configuration < Puppet::PGraph
end
ref = resource.ref
+
if @resource_table.include?(ref)
raise ArgumentError, "Resource %s is already defined" % ref
else
@resource_table[ref] = resource
end
+
+ # If the name and title differ, set up an alias
+ if ! resource.is_a?(Puppet::Type::Component) and resource.respond_to?(:title) and resource.name != resource.title
+ if obj = resource(resource.class.name, resource.name)
+ raise Puppet::Error, "%s already exists with name %s" % [obj.title, self.name] if resource.class.isomorphic?
+ else
+ self.alias(resource, resource.name)
+ end
+ end
+
resource.configuration = self unless is_relationship_graph
add_vertex!(resource)
end
@@ -183,6 +194,11 @@ class Puppet::Node::Configuration < Puppet::PGraph
unless klass = Puppet::Type.type(type)
raise ArgumentError, "Unknown resource type %s" % type
end
+ if options.is_a?(Puppet::TransObject)
+ options.configuration = self
+ else
+ options[:configuration] = self
+ end
return unless resource = klass.create(options)
@transient_resources << resource if applying?
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 02e04653c..3f69bc8b1 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -228,18 +228,6 @@ class Type
self.devfail "I was not passed a namevar"
end
- # If the name and title differ, set up an alias
- if self.configuration and (self.name != self.title)
- if obj = self.configuration.resource(self.class.name, self.name)
- if self.class.isomorphic?
- raise Puppet::Error, "%s already exists with name %s" %
- [obj.title, self.name]
- end
- else
- self.configuration.alias(self, self.name)
- end
- end
-
if hash.include?(:provider)
self[:provider] = hash[:provider]
hash.delete(:provider)
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index 723fecde2..d6dfd86e0 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -73,10 +73,8 @@ module Puppet
"
defaultto do
- if resource.configuration
- # Make sure the default file bucket exists.
- obj = resource.configuration.resource(:filebucket, "puppet") || resource.configuration.create_resource(:filebucket, :name => "puppet")
- obj.bucket
+ if resource.configuration and bucket_resource = resource.configuration.resource(:filebucket, "puppet")
+ bucket_resource.bucket
else
nil
end
@@ -98,7 +96,7 @@ module Puppet
# We can't depend on looking this up right now,
# we have to do it after all of the objects
# have been instantiated.
- if bucketobj = Puppet::Type.type(:filebucket)[value]
+ if @resource.configuration and bucketobj = @resource.configuration.resource(:filebucket, value)
@resource.bucket = bucketobj.bucket
bucketobj.title
else
@@ -256,11 +254,6 @@ module Puppet
end
end
- def self.[](path)
- return nil unless path
- super(path.gsub(/\/+/, '/').sub(/\/$/, ''))
- end
-
# List files, but only one level deep.
def self.instances(base = "/")
unless FileTest.directory?(base)
@@ -316,31 +309,32 @@ module Puppet
# a couple of these buckets
@@filebuckets ||= {}
+ super
+
# Look up our bucket, if there is one
- if bucket = self.bucket
- case bucket
- when String:
- if obj = @@filebuckets[bucket]
- # This sets the @value on :backup, too
- self.bucket = obj
- elsif bucket == "puppet"
- obj = Puppet::Network::Client.client(:Dipper).new(
- :Path => Puppet[:clientbucketdir]
- )
- self.bucket = obj
- @@filebuckets[bucket] = obj
- elsif obj = Puppet::Type.type(:filebucket).bucket(bucket)
- @@filebuckets[bucket] = obj
- self.bucket = obj
- else
- self.fail "Could not find filebucket %s" % bucket
- end
- when Puppet::Network::Client.client(:Dipper): # things are hunky-dorey
- else
- self.fail "Invalid bucket type %s" % bucket.class
- end
+ return unless bucket_name = self.bucket
+
+ return if bucket_name.is_a?(Puppet::Network::Client.dipper)
+
+ self.fail("Invalid bucket type %s" % bucket_name.class) unless bucket_name.is_a?(String)
+
+ return self.bucket = bucket if bucket = @@filebuckets[bucket_name]
+
+ if configuration and bucket_resource = configuration.resource(:filebucket, bucket_name)
+ @@filebuckets[bucket_name] = bucket_resource.bucket
+ self.bucket = bucket
+ return
+ end
+
+ if bucket_name == "puppet"
+ puts "Creating default bucket"
+ bucket_resource = Puppet::Type.type(:filebucket).create_default_resources
+ self.bucket = bucket_resource.bucket
+ configuration.add_resource(bucket_resource) if configuration
+ @@filebuckets[bucket_name] = bucket
+ else
+ self.fail "Could not find filebucket '%s'" % bucket_name
end
- super
end
# Create any children via recursion or whatever.
diff --git a/lib/puppet/type/pfilebucket.rb b/lib/puppet/type/pfilebucket.rb
index 5ce81858b..27fea6ac8 100755
--- a/lib/puppet/type/pfilebucket.rb
+++ b/lib/puppet/type/pfilebucket.rb
@@ -53,20 +53,11 @@ module Puppet
defaultto { Puppet[:clientbucketdir] }
end
-
- # get the actual filebucket object
- def self.bucket(name)
- if object = self[name]
- return object.bucket
- else
- return nil
- end
- end
# Create a default filebucket.
def self.create_default_resources
Puppet.debug "Creating default local filebucket"
- self.create :name => "puppet", :path => Puppet[:clientbucketdir]
+ [self.create(:name => "puppet", :path => Puppet[:clientbucketdir])]
end
def self.instances
diff --git a/lib/puppet/type/schedule.rb b/lib/puppet/type/schedule.rb
index 72d649584..3f4014cd8 100755
--- a/lib/puppet/type/schedule.rb
+++ b/lib/puppet/type/schedule.rb
@@ -311,7 +311,7 @@ module Puppet
[]
end
- def self.create_default_schedules
+ def self.create_default_resources
Puppet.debug "Creating default schedules"
resources = []
# Create our default schedule
@@ -323,7 +323,7 @@ module Puppet
# And then one for every period
@parameters.find { |p| p.name == :period }.values.each { |value|
- resources << self.create(:schedule,
+ resources << self.create(
:name => value.to_s,
:period => value
)
diff --git a/lib/puppet/util/filetype.rb b/lib/puppet/util/filetype.rb
index 2f1dabe62..b1b2c1d96 100755
--- a/lib/puppet/util/filetype.rb
+++ b/lib/puppet/util/filetype.rb
@@ -74,7 +74,7 @@ class Puppet::Util::FileType
# Pick or create a filebucket to use.
def bucket
- Puppet::Type.type(:filebucket).mkdefaultbucket.bucket
+ Puppet::Type.type(:filebucket).create_default_resources[0].bucket
end
def initialize(path)
diff --git a/spec/unit/network/client/master.rb b/spec/unit/network/client/master.rb
index 8354b5521..fda729cae 100755
--- a/spec/unit/network/client/master.rb
+++ b/spec/unit/network/client/master.rb
@@ -450,6 +450,27 @@ describe Puppet::Network::Client::Master, " when adding default resources" do
end
end
- it "should only add default resources if no similarly named resource does not exist" do
+ it "should only add a default filebucket if no similarly named bucket already exists" do
+ config = mock 'config'
+ Puppet::Type.type(:schedule).stubs(:create_default_resources).returns([])
+ one = stub 'one', :title => "one"
+ Puppet::Type.type(:filebucket).expects(:create_default_resources).with().returns([one])
+ config.expects(:resource).with(:filebucket, "one").returns(true)
+ config.expects(:add_resource).with(one).never
+ Puppet::Network::Client::Master.publicize_methods :add_default_resources do
+ @client.add_default_resources(config)
+ end
+ end
+
+ it "should only add default schedules if no similarly named schedule already exists" do
+ config = mock 'config'
+ one = stub 'one', :title => "one"
+ Puppet::Type.type(:schedule).stubs(:create_default_resources).returns([one])
+ Puppet::Type.type(:filebucket).stubs(:create_default_resources).with().returns([])
+ config.expects(:resource).with(:schedule, "one").returns(true)
+ config.expects(:add_resource).with(one).never
+ Puppet::Network::Client::Master.publicize_methods :add_default_resources do
+ @client.add_default_resources(config)
+ end
end
end
diff --git a/spec/unit/node/configuration.rb b/spec/unit/node/configuration.rb
index 7fda4e9a8..44b98dddb 100755
--- a/spec/unit/node/configuration.rb
+++ b/spec/unit/node/configuration.rb
@@ -301,9 +301,9 @@ end
describe Puppet::Node::Configuration, " when functioning as a resource container" do
before do
@config = Puppet::Node::Configuration.new("host")
- @one = stub 'resource1', :ref => "Me[one]", :configuration= => nil
- @two = stub 'resource2', :ref => "Me[two]", :configuration= => nil
- @dupe = stub 'resource3', :ref => "Me[one]", :configuration= => nil
+ @one = stub 'resource1', :ref => "Me[one]", :configuration= => nil, :title => "one", :name => "one"
+ @two = stub 'resource2', :ref => "Me[two]", :configuration= => nil, :title => "two", :name => "two"
+ @dupe = stub 'resource3', :ref => "Me[one]", :configuration= => nil, :title => "one", :name => "one"
end
it "should provide a method to add one or more resources" do
@@ -412,6 +412,25 @@ describe Puppet::Node::Configuration, " when functioning as a resource container
@config.remove_resource(@one)
@config.resource("me", "other").should be_nil
end
+
+ it "should alias resources whose names are not equal to their titles" do
+ resource = stub("resource", :name => "one", :title => "two", :ref => "Me[two]", :configuration= => nil)
+ @config.expects(:alias).with(resource, "one")
+ @config.add_resource resource
+ end
+
+ it "should fail to add resources whose names conflict with an existing resource even when the title does not conflict" do
+ conflict = stub("resource", :name => "one", :ref => "Me[one]", :configuration= => nil)
+ resource = stub("resource", :name => "one", :title => "other", :ref => "Me[other]", :configuration= => nil)
+ @config.expects(:alias).with(resource, "one")
+ @config.add_resource resource
+ end
+
+ it "should not alias components whose names do not match their titles" do
+ comp = Puppet::Type::Component.create :name => "one", :title => "two"
+ @config.expects(:alias).never
+ @config.add_resource comp
+ end
end
module ApplyingConfigurations
@@ -538,19 +557,18 @@ end
describe Puppet::Node::Configuration, " when creating a relationship graph" do
before do
@config = Puppet::Node::Configuration.new("host")
- @compone = Puppet::Type::Component.create :name => "one"
- @comptwo = Puppet::Type::Component.create :name => "two", :require => ["class", "one"]
+ @compone = @config.create_resource :component, :name => "one"
+ @comptwo = @config.create_resource :component, :name => "two", :require => ["class", "one"]
@file = Puppet::Type.type(:file)
- @one = @file.create :path => "/one"
- @two = @file.create :path => "/two"
+ @one = @config.create_resource :file, :path => "/one"
+ @two = @config.create_resource :file, :path => "/two"
@config.add_edge! @compone, @one
@config.add_edge! @comptwo, @two
- @three = @file.create :path => "/three"
- @four = @file.create :path => "/four", :require => ["file", "/three"]
- @five = @file.create :path => "/five"
- @config.add_resource @compone, @comptwo, @one, @two, @three, @four, @five
+ @three = @config.create_resource :file, :path => "/three"
+ @four = @config.create_resource :file, :path => "/four", :require => ["file", "/three"]
+ @five = @config.create_resource :file, :path => "/five"
@relationships = @config.relationship_graph
end
diff --git a/test/language/snippets.rb b/test/language/snippets.rb
index 0806a40b4..05597cdec 100755
--- a/test/language/snippets.rb
+++ b/test/language/snippets.rb
@@ -22,14 +22,14 @@ class TestSnippets < Test::Unit::TestCase
end
def assert_file(path, msg = nil)
- unless file = @file[path]
+ unless file = @configuration.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 = @configuration.resource(:file, path)
raise "Could not find file %s" % path
end
@@ -211,8 +211,8 @@ class TestSnippets < Test::Unit::TestCase
path1 = "/tmp/argumenttest1"
path2 = "/tmp/argumenttest2"
- file1 = @file[path1]
- file2 = @file[path2]
+ file1 = @configuration.resource(:file, path1)
+ file2 = @configuration.resource(:file, path2)
assert_file(path1)
assert_mode_equal(0755, path1)
@@ -231,7 +231,7 @@ class TestSnippets < Test::Unit::TestCase
}
paths.each { |path|
- file = @file[path]
+ file = @configuration.resource(:file, path)
assert(file, "File %s is missing" % path)
assert_mode_equal(0755, path)
}
@@ -241,7 +241,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 = @configuration.resource(:file, path)
assert_file(path)
assert_mode_equal(0755, path)
}
@@ -262,7 +262,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, @configuration.resource(:file, dir).should(:ensure), "Directory is not set to be a directory")
end
def snippet_scopetest
@@ -349,7 +349,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, @configuration.resource(:file, path).should(:content))
}
end
@@ -387,21 +387,20 @@ class TestSnippets < Test::Unit::TestCase
end
def snippet_emptyexec
- assert(Puppet::Type.type(:exec)["touch /tmp/emptyexectest"],
- "Did not create exec")
+ assert(@configuration.resource(:exec, "touch /tmp/emptyexectest"), "Did not create exec")
end
def snippet_multisubs
path = "/tmp/multisubtest"
assert_file(path)
- file = @file[path]
+ file = @configuration.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(@configuration.resource(:file, "/tmp/colltest2"), "Incorrectly collected file")
end
def snippet_virtualresources
diff --git a/test/lib/puppettest/support/utils.rb b/test/lib/puppettest/support/utils.rb
index d9bd6b2b6..83509733e 100644
--- a/test/lib/puppettest/support/utils.rb
+++ b/test/lib/puppettest/support/utils.rb
@@ -27,7 +27,7 @@ module PuppetTest::Support::Utils
if resources[0].is_a?(Puppet::Node::Configuration)
config = resources.shift
unless resources.empty?
- resources.each { |r| config.add_resource r }
+ resources.each { |r| config.add_resource(r) unless config.resource(r.class.name, r.title) }
end
elsif resources[0].is_a?(Puppet.type(:component))
raise ArgumentError, "resource2config() no longer accpts components"
diff --git a/test/network/client/client.rb b/test/network/client/client.rb
index 4a7e9cdb6..8d08bd3d7 100755
--- a/test/network/client/client.rb
+++ b/test/network/client/client.rb
@@ -140,35 +140,6 @@ class TestClient < Test::Unit::TestCase
}
end
- def test_classfile
- Puppet[:code] = "class yaytest {}\n class bootest {}\n include yaytest, bootest"
-
- Puppet::Node::Facts.indirection.stubs(:save)
-
- master = client = nil
- assert_nothing_raised() {
- master = Puppet::Network::Handler.master.new(
- :Local => false
- )
- }
- assert_nothing_raised() {
- client = Puppet::Network::Client.master.new(
- :Master => master
- )
- }
-
- # Fake that it's local, so it creates the class file
- client.local = false
-
- # We can't guarantee class ordering
- client.expects(:setclasses).with do |array|
- array.length == 2 and array.include?("yaytest") and array.include?("bootest")
- end
- assert_nothing_raised {
- client.getconfig
- }
- end
-
def test_client_loading
# Make sure we don't get a failure but that we also get nothing back
assert_nothing_raised do
diff --git a/test/network/client/master.rb b/test/network/client/master.rb
index 7216af936..0caba4bd2 100755
--- a/test/network/client/master.rb
+++ b/test/network/client/master.rb
@@ -332,39 +332,6 @@ end
assert(FileTest.exists?(file), "file was not created on second run")
end
- def test_default_objects
- # Make sure they start out missing
- assert_nil(Puppet::Type.type(:filebucket)["puppet"],
- "default filebucket already exists")
- assert_nil(Puppet::Type.type(:schedule)["daily"],
- "default schedules already exists")
-
- master = mkclient()
-
- # Now make sure they got created
- assert(Puppet::Type.type(:filebucket)["puppet"],
- "default filebucket not found")
- assert(Puppet::Type.type(:schedule)["daily"],
- "default schedules not found")
-
- # clear everything, and make sure we can recreate them
- Puppet::Type.allclear
- assert_nil(Puppet::Type.type(:filebucket)["puppet"],
- "default filebucket not removed")
- assert_nil(Puppet::Type.type(:schedule)["daily"],
- "default schedules not removed")
- assert_nothing_raised { master.mkdefault_objects }
- assert(Puppet::Type.type(:filebucket)["puppet"],
- "default filebucket not found")
- assert(Puppet::Type.type(:schedule)["daily"],
- "default schedules not found")
-
-
- # Make sure we've got schedules
- assert(Puppet::Type.type(:schedule)["hourly"], "Could not retrieve hourly schedule")
- assert(Puppet::Type.type(:filebucket)["puppet"], "Could not retrieve default bucket")
- end
-
# #540 - make sure downloads aren't affected by noop
def test_download_in_noop
source = tempfile
@@ -550,24 +517,6 @@ end
assert_equal(facts["environment"], Puppet[:environment], "Did not add environment to client facts")
end
- # This is partially to fix #532, but also to save on memory.
- def test_remove_objects_after_every_run
- client = mkclient
-
- ftype = Puppet::Type.type(:file)
- file = ftype.create :title => "/what/ever", :ensure => :present
- config = Puppet::Node::Configuration.new
- config.add_resource(file)
-
- config.expects :apply
-
- client.configuration = config
- client.expects(:getconfig)
- client.run
-
- assert_nil(ftype[@createdfile], "file object was not removed from memory")
- end
-
# #685
def test_http_failures_do_not_kill_puppetd
client = mkclient
diff --git a/test/network/handler/fileserver.rb b/test/network/handler/fileserver.rb
index 3539169dc..8703700ea 100755
--- a/test/network/handler/fileserver.rb
+++ b/test/network/handler/fileserver.rb
@@ -8,6 +8,11 @@ require 'puppet/network/handler/fileserver'
class TestFileServer < Test::Unit::TestCase
include PuppetTest
+ def setup
+ super
+ Facter.stubs(:to_hash).returns({})
+ end
+
def mkmount(path = nil)
mount = nil
name = "yaytest"
@@ -146,10 +151,6 @@ class TestFileServer < Test::Unit::TestCase
list = server.list(sfile, :ignore, true, false)
}
- assert_nothing_raised {
- file = Puppet.type(:file)[tmpfile]
- }
-
output = "/\tfile"
# verify it got listed as a file
@@ -943,10 +944,11 @@ allow *
end
# Now, check that they use Facter info
- Puppet.notice "The following messages are normal"
+ Facter.stubs(:value).with("hostname").returns("myhost")
+ Facter.stubs(:value).with("domain").returns("mydomain")
+ local = "myhost"
+ domain = "mydomain"
client = nil
- local = Facter["hostname"].value
- domain = Facter["domain"].value
fqdn = [local, domain].join(".")
{"%h" => local, # Short name
"%H" => fqdn, # Full name
@@ -954,6 +956,7 @@ allow *
"%%" => "%", # escape
"%o" => "%o" # other
}.each do |pat, repl|
+ Puppet.expects(:notice)
check.call(client, pat, repl)
end
@@ -1132,6 +1135,8 @@ allow *
def test_failures
# create a server with the file
server = nil
+ Facter.stubs(:[]).with("hostname").returns("myhost")
+ Facter.stubs(:[]).with("domain").returns("mydomain")
config = tempfile
[
diff --git a/test/network/handler/resource.rb b/test/network/handler/resource.rb
index 0d6373160..247014a47 100755
--- a/test/network/handler/resource.rb
+++ b/test/network/handler/resource.rb
@@ -3,10 +3,12 @@
require File.dirname(__FILE__) + '/../../lib/puppettest'
require 'puppettest'
+require 'puppettest/support/utils'
require 'base64'
require 'cgi'
class TestResourceServer < Test::Unit::TestCase
+ include PuppetTest
include PuppetTest::ServerTest
def verify_described(type, described)
@@ -179,9 +181,6 @@ class TestResourceServer < Test::Unit::TestCase
require 'etc'
- # Make the example schedules, for testing
- Puppet::Type.type(:schedule).mkdefaultschedules
-
Puppet::Type.eachtype do |type|
unless type.respond_to? :instances
Puppet.warning "%s does not respond to :instances" % type.name
diff --git a/test/other/overrides.rb b/test/other/overrides.rb
index 272f78e30..800eab1b7 100755
--- a/test/other/overrides.rb
+++ b/test/other/overrides.rb
@@ -25,28 +25,27 @@ class TestOverrides < Test::Unit::TestCase
baseobj = nil
basefile = File.join(basedir, "file")
- assert_nothing_raised("Could not create base obj") {
- baseobj = Puppet.type(:file).create(
- :title => "base",
- :path => basedir,
- :recurse => true,
- :mode => "755"
- )
- }
+ config = mk_configuration
+
+ baseobj = config.create_resource(:file,
+ :title => "base",
+ :path => basedir,
+ :recurse => true,
+ :mode => "755"
+ )
subobj = nil
subdir = File.join(basedir, "0")
subfile = File.join(subdir, "file")
- assert_nothing_raised("Could not create sub obj") {
- subobj = Puppet.type(:file).create(
- :title => "sub",
- :path => subdir,
- :recurse => true,
- :mode => "644"
- )
- }
- assert_apply(baseobj, subobj)
+ subobj = config.create_resource(:file,
+ :title => "sub",
+ :path => subdir,
+ :recurse => true,
+ :mode => "644"
+ )
+
+ config.apply
assert(File.stat(basefile).mode & 007777 == 0755)
assert(File.stat(subfile).mode & 007777 == 0644)
diff --git a/test/other/relationships.rb b/test/other/relationships.rb
index 0f2a103fe..fe1ae1ac4 100755
--- a/test/other/relationships.rb
+++ b/test/other/relationships.rb
@@ -61,19 +61,20 @@ class TestRelationships < Test::Unit::TestCase
:notify => true, :before => true}
refreshers = [:subscribe, :notify]
[:require, :subscribe, :notify, :before].each do |param|
+ config = mk_configuration
# Create three files to generate our events and three
# execs to receive them
files = []
execs = []
3.times do |i|
- files << Puppet::Type.newfile(
+ files << config.create_resource(:file,
:title => "file#{i}",
:path => tempfile(),
:ensure => :file
)
path = tempfile()
- execs << Puppet::Type.newexec(
+ execs << config.create_resource(:exec,
:title => "notifytest#{i}",
:path => "/usr/bin:/bin",
:command => "touch #{path}",
@@ -165,7 +166,9 @@ class TestRelationships < Test::Unit::TestCase
:ensure => :directory)
exec = Puppet::Type.newexec(:title => "myexec", :cwd => path,
:command => "/bin/echo")
-
+
+ config = mk_configuration(file, exec)
+
reqs = nil
assert_nothing_raised do
reqs = exec.autorequire
@@ -173,13 +176,10 @@ class TestRelationships < Test::Unit::TestCase
assert_instance_of(Puppet::Relationship, reqs[0], "Did not return a relationship edge")
assert_equal(file, reqs[0].source, "Did not set the autorequire source correctly")
assert_equal(exec, reqs[0].target, "Did not set the autorequire target correctly")
-
+
# Now make sure that these relationships are added to the
# relationship graph
- config = mk_configuration(file, exec)
- config.apply do |trans|
- assert(config.relationship_graph.edge?(file, exec), "autorequire edge was not created")
- end
+ assert(config.relationship_graph.edge?(file, exec), "autorequire edge was not created")
end
def test_requires?
@@ -210,7 +210,7 @@ class TestRelationships < Test::Unit::TestCase
file = Puppet::Type.newfile :path => tempfile, :require => ["file", "/no/such/file"]
assert_raise(Puppet::Error) do
- file.builddepends
+ config = mk_configuration(file)
end
end
end
diff --git a/test/other/transactions.rb b/test/other/transactions.rb
index 8156ba478..2498cc014 100755
--- a/test/other/transactions.rb
+++ b/test/other/transactions.rb
@@ -6,8 +6,10 @@ require 'puppet'
require 'puppettest'
require 'mocha'
require 'puppettest/support/resources'
+require 'puppettest/support/utils'
class TestTransactions < Test::Unit::TestCase
+ include PuppetTest
include PuppetTest::FileTesting
include PuppetTest::Support::Resources
class Fakeprop <Puppet::Property
@@ -429,26 +431,25 @@ class TestTransactions < Test::Unit::TestCase
# Make sure that unscheduled and untagged objects still respond to events
def test_unscheduled_and_untagged_response
- Puppet::Type.type(:schedule).mkdefaultschedules
+ config = mk_configuration
+ config.add_resource(*(Puppet::Type.type(:schedule).create_default_resources))
Puppet[:ignoreschedules] = false
- file = Puppet.type(:file).create(
+ file = config.create_resource(:file,
:name => tempfile(),
:ensure => "file",
:backup => false
)
fname = tempfile()
- exec = Puppet.type(:exec).create(
+ exec = config.create_resource(:exec,
:name => "touch %s" % fname,
:path => "/usr/bin:/bin",
:schedule => "monthly",
:subscribe => ["file", file.name]
)
- config = mk_configuration(file, exec)
-
# Run it once
- assert_apply(config)
+ config.apply
assert(FileTest.exists?(fname), "File did not get created")
assert(!exec.scheduled?, "Exec is somehow scheduled")
@@ -604,8 +605,7 @@ class TestTransactions < Test::Unit::TestCase
end
%w{ya ra y r}.each do |name|
- assert(trans.configuration.vertex?(Puppet::Type.type(:generator)[name]),
- "Generated %s was not a vertex" % name)
+ assert(trans.configuration.vertex?(config.resource(:generator, name)), "Generated %s was not a vertex" % name)
assert($finished.include?(name), "%s was not finished" % name)
end
@@ -615,10 +615,8 @@ class TestTransactions < Test::Unit::TestCase
end
%w{ya ra y r}.each do |name|
- assert(!trans.configuration.vertex?(Puppet::Type.type(: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)
+ assert(!trans.configuration.vertex?(config.resource(:generator, name)), "Generated vertex %s was not removed from graph" % name)
+ assert_nil(config.resource(:generator, name), "Generated vertex %s was not removed from class" % name)
end
end
@@ -645,7 +643,7 @@ class TestTransactions < Test::Unit::TestCase
assert_nothing_raised("failed to apply yay") do
trans.eval_resource(yay)
end
- ya = type["ya"]
+ ya = config.resource(:generator, "ya")
assert(ya, "Did not generate ya")
assert(trans.relationship_graph.vertex?(ya),
"Did not add ya to rel_graph")
@@ -658,11 +656,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(config.resource(:generator, "ya"))
end
%w{y}.each do |name|
- res = type[name]
+ res = config.resource(:generator, name)
assert(res, "Did not generate %s" % name)
assert(trans.relationship_graph.vertex?(res),
"Did not add %s to rel_graph" % name)
@@ -670,7 +668,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(config.resource(:generator, "y"))
end
assert(trans.relationship_graph.edge?(yay, ya), "no edge was created for ya => yay")
@@ -678,7 +676,7 @@ class TestTransactions < Test::Unit::TestCase
trans.eval_resource(rah)
end
- ra = type["ra"]
+ ra = config.resource(:generator, "ra")
assert(ra, "Did not generate ra")
assert(trans.relationship_graph.vertex?(ra),
"Did not add ra to rel_graph" % name)
@@ -697,9 +695,9 @@ 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?(config.resource(:generator, name)),
"Generated vertex %s was not removed from graph" % name)
- assert_nil(type[name],
+ assert_nil(config.resource(:generator, name),
"Generated vertex %s was not removed from class" % name)
end
diff --git a/test/ral/types/basic.rb b/test/ral/types/basic.rb
index 4427238bf..862beeadc 100755
--- a/test/ral/types/basic.rb
+++ b/test/ral/types/basic.rb
@@ -68,13 +68,6 @@ class TestBasic < Test::Unit::TestCase
assert_equal("echo", @command.title)
end
- def test_object_retrieval
- [@command, @configfile].each { |obj|
- assert_equal(obj.class[obj.name].object_id, obj.object_id,
- "%s did not match class version" % obj.ref)
- }
- end
-
def test_paths
[@configfile, @command, @component].each { |obj|
assert_nothing_raised {
diff --git a/test/ral/types/cron.rb b/test/ral/types/cron.rb
index a9a00240c..d6f29efe4 100755
--- a/test/ral/types/cron.rb
+++ b/test/ral/types/cron.rb
@@ -150,20 +150,6 @@ class TestCron < Test::Unit::TestCase
end
end
- def test_makeandretrievecron
- %w{storeandretrieve a-name another-name more_naming SomeName}.each do |name|
- cron = mkcron(name)
- comp = mk_configuration(name, cron)
- trans = assert_events([:cron_created], comp, name)
-
- cron.provider.class.prefetch
- cron = nil
-
- assert(cron = Puppet.type(:cron)[name], "Could not retrieve named cron")
- assert_instance_of(Puppet.type(:cron), cron)
- end
- end
-
# Do input validation testing on all of the parameters.
def test_arguments
values = {
diff --git a/test/ral/types/exec.rb b/test/ral/types/exec.rb
index 11a6d4055..ed0ea9980 100755
--- a/test/ral/types/exec.rb
+++ b/test/ral/types/exec.rb
@@ -203,42 +203,45 @@ class TestExec < Test::Unit::TestCase
)
comp = mk_configuration("Testing", file, exec)
+ Puppet::Node::Facts.indirection.stubs(:terminus_class).returns(:memory)
assert_events([:file_created, :executed_command], comp)
end
# Verify that we auto-require any managed scripts.
def test_autorequire_files
+ config = mk_configuration
+
exe = tempfile()
oexe = tempfile()
sh = %x{which sh}
File.open(exe, "w") { |f| f.puts "#!#{sh}\necho yup" }
- file = Puppet.type(:file).create(
+ file = config.create_resource(:file,
:path => oexe,
:source => exe,
:mode => 755
)
basedir = File.dirname(oexe)
- baseobj = Puppet.type(:file).create(
+ baseobj = config.create_resource(:file,
:path => basedir,
:source => exe,
:mode => 755
)
- ofile = Puppet.type(:file).create(
+ ofile = config.create_resource(:file,
:path => exe,
:mode => 755
)
- exec = Puppet.type(:exec).create(
+ exec = config.create_resource(:exec,
:command => oexe,
:path => ENV["PATH"],
:cwd => basedir
)
- cat = Puppet.type(:exec).create(
+ cat = config.create_resource(:exec,
:command => "cat %s %s" % [exe, oexe],
:path => ENV["PATH"]
)
diff --git a/test/ral/types/file.rb b/test/ral/types/file.rb
index 73095a783..8435855e6 100755
--- a/test/ral/types/file.rb
+++ b/test/ral/types/file.rb
@@ -3,10 +3,12 @@
require File.dirname(__FILE__) + '/../../lib/puppettest'
require 'puppettest'
+require 'puppettest/support/utils'
require 'fileutils'
class TestFile < Test::Unit::TestCase
include PuppetTest::FileTesting
+ include PuppetTest::Support::Utils
# hmmm
# this is complicated, because we store references to the created
# objects in a central store
@@ -32,6 +34,8 @@ class TestFile < Test::Unit::TestCase
@file = Puppet::Type.type(:file)
$method = @method_name
Puppet[:filetimeout] = -1
+ Facter.stubs(:each)
+ Facter.stubs(:to_hash).returns({})
end
def teardown
@@ -514,7 +518,7 @@ class TestFile < Test::Unit::TestCase
test = File.join(path, "file")
File.open(test, "w") { |f| f.puts "yay" }
assert_nothing_raised() { ret = dir.localrecurse(true) }
- fileobj = @file[test]
+ fileobj = config.resource(:file, test)
assert(fileobj, "child object was not created")
assert_equal([fileobj], ret, "child object was not returned")
@@ -558,7 +562,7 @@ class TestFile < Test::Unit::TestCase
assert_nothing_raised() { ret = dir.localrecurse(true) }
assert_equal([bad], ret.collect { |f| f.title }, "purge failed")
- badobj = @file[bad]
+ badobj = config.resource(:file, bad)
assert(badobj, "did not create bad object")
end
@@ -754,43 +758,6 @@ class TestFile < Test::Unit::TestCase
assert(file.insync?(currentvalues))
end
- def test_remove
- basedir = tempfile()
- subdir = File.join(basedir, "this")
- FileUtils.mkdir_p(subdir)
-
- dir = nil
- assert_nothing_raised {
- dir = Puppet.type(:file).create(
- :path => basedir,
- :recurse => true,
- :check => %w{owner mode group}
- )
- }
- mk_configuration dir
-
- assert_nothing_raised {
- dir.eval_generate
- }
-
- obj = nil
- assert_nothing_raised {
- obj = Puppet.type(:file)[subdir]
- }
-
- assert(obj, "Could not retrieve subdir object")
-
- assert_nothing_raised {
- obj.remove(true)
- }
-
- assert_nothing_raised {
- obj = Puppet.type(:file)[subdir]
- }
-
- assert_nil(obj, "Retrieved removed object")
- end
-
def test_path
dir = tempfile()
@@ -810,14 +777,14 @@ class TestFile < Test::Unit::TestCase
:check => %w{mode owner group}
)
}
- mk_configuration dirobj
+ config = mk_configuration dirobj
assert_nothing_raised {
dirobj.eval_generate
}
assert_nothing_raised {
- file = dirobj.class[path]
+ file = config.resource(:file, path)
}
assert(file, "Could not retrieve file object")
@@ -829,12 +796,14 @@ class TestFile < Test::Unit::TestCase
basedir = tempfile()
subfile = File.join(basedir, "subfile")
- baseobj = Puppet.type(:file).create(
+ config = Puppet::Node::Configuration.new
+
+ baseobj = config.create_resource(:file,
:name => basedir,
:ensure => "directory"
)
- subobj = Puppet.type(:file).create(
+ subobj = config.create_resource(:file,
:name => subfile,
:ensure => "file"
)
@@ -1129,18 +1098,17 @@ class TestFile < Test::Unit::TestCase
file = tempfile()
newfile = tempfile()
+ config = mk_configuration
+
File.open(file, "w", 0411) { |f| f.puts "yayness" }
- obj = nil
- assert_nothing_raised {
- obj = Puppet::Type.type(:file).create(
- :path => file, :content => "rahness\n", :backup => ".puppet-bak"
- )
- }
+ resource = config.create_resource(:file,
+ :path => file, :content => "rahness\n", :backup => ".puppet-bak"
+ )
- assert_apply(obj)
+ assert_apply(config)
- backupfile = file + obj[:backup]
+ backupfile = file + resource[:backup]
@@tmpfiles << backupfile
assert(FileTest.exists?(backupfile),
"Backup file %s does not exist" % backupfile)
@@ -1151,13 +1119,15 @@ class TestFile < Test::Unit::TestCase
bucket = "bucket"
bpath = tempfile()
Dir.mkdir(bpath)
- Puppet::Type.type(:filebucket).create(
+ config.create_resource(:filebucket,
:title => bucket, :path => bpath
)
- obj[:backup] = bucket
- obj[:content] = "New content"
- assert_apply(obj)
+ resource[:backup] = bucket
+ resource[:content] = "New content"
+
+ resource.finish
+ assert_apply(config)
md5 = "18cc17fa3047fcc691fdf49c0a7f539a"
dir, file, pathfile = Puppet::Network::Handler.filebucket.paths(bpath, md5)
@@ -1286,19 +1256,20 @@ class TestFile < Test::Unit::TestCase
# this file should get removed
File.open(purgee, "w") { |f| f.puts "footest" }
- lfobj = Puppet::Type.newfile(
+ config = mk_configuration
+
+ lfobj = config.create_resource(:file,
:title => "localfile",
:path => localfile,
:content => "rahtest",
:backup => false
)
- destobj = Puppet::Type.newfile(:title => "destdir", :path => destdir,
+ destobj = config.create_resource(:file, :title => "destdir", :path => destdir,
:source => sourcedir,
:backup => false,
:recurse => true)
- config = mk_configuration(lfobj, destobj)
config.apply
assert(FileTest.exists?(dsourcefile), "File did not get copied")
@@ -1431,10 +1402,11 @@ class TestFile < Test::Unit::TestCase
:link => proc { File.symlink(linkdest, path) }
}
- bucket = Puppet::Type.newfilebucket :name => "main", :path => tempfile()
+ config = mk_configuration
+
+ bucket = config.create_resource :filebucket, :name => "main", :path => tempfile()
- obj = Puppet::Type.newfile :path => path, :force => true,
- :links => :manage
+ obj = config.create_resource :file, :path => path, :force => true, :links => :manage
Puppet[:trace] = true
["main", false].each do |backup|
@@ -1557,15 +1529,17 @@ class TestFile < Test::Unit::TestCase
dfiles = [File.join(dest, "1"), File.join(dest, "dir", "2")]
bpath = tempfile
- bucket = Puppet::Type.type(:filebucket).create :name => "rtest", :path => bpath
+
+ config = mk_configuration
+ bucket = config.create_resource :filebucket, :name => "rtest", :path => bpath
dipper = bucket.bucket
dipper = Puppet::Network::Handler.filebucket.new(
:Path => bpath
)
assert(dipper, "did not receive bucket client")
- file = Puppet::Type.newfile :path => dest, :source => source, :recurse => true, :backup => "rtest"
+ file = config.create_resource :file, :path => dest, :source => source, :recurse => true, :backup => "rtest"
- assert_apply(file)
+ config.apply
dfiles.each do |f|
assert(FileTest.exists?(f), "destfile %s was not created" % f)
end
@@ -1575,7 +1549,7 @@ class TestFile < Test::Unit::TestCase
f.puts "boo: %s" % File.basename(sf)
} }
- assert_apply(file)
+ config.apply
dfiles.each do |f|
assert_equal("boo: %s\n" % File.basename(f), File.read(f),
"file was not copied correctly")
@@ -1600,7 +1574,8 @@ class TestFile < Test::Unit::TestCase
def test_backup
path = tempfile()
- file = Puppet::Type.newfile :path => path, :content => "yay"
+ config = Puppet::Node::Configuration.new
+ file = config.create_resource :file, :path => path, :content => "yay"
[false, :false, "false"].each do |val|
assert_nothing_raised do
@@ -1629,7 +1604,7 @@ class TestFile < Test::Unit::TestCase
assert_equal("main", file.bucket, "file's bucket was not set")
# And then an existing bucket
- obj = Puppet::Type.type(:filebucket).create :name => "testing"
+ obj = config.create_resource :filebucket, :name => "testing"
bucket = obj.bucket
assert_nothing_raised do
@@ -1645,12 +1620,12 @@ class TestFile < Test::Unit::TestCase
file = File.join(dir, "file")
File.open(file, "w") { |f| f.puts "" }
obj = Puppet::Type.newfile :path => dir, :recurse => true, :mode => 0755
- mk_configuration obj
+ config = mk_configuration obj
assert_equal("/%s" % obj.ref, obj.path)
list = obj.eval_generate
- fileobj = obj.class[file]
+ fileobj = config.resource(:file, file)
assert(fileobj, "did not generate file object")
assert_equal("/%s" % fileobj.ref, fileobj.path, "did not generate correct subfile path")
end
@@ -1667,7 +1642,8 @@ class TestFile < Test::Unit::TestCase
# Testing #434
def test_stripping_extra_slashes_during_lookup
- file = Puppet::Type.newfile(:path => "/one/two")
+ config = mk_configuration
+ file = config.create_resource(:file, :path => "/one/two")
%w{/one/two/ /one/two /one//two //one//two//}.each do |path|
assert(Puppet::Type.type(:file)[path], "could not look up file via path %s" % path)
end
@@ -1762,14 +1738,14 @@ class TestFile < Test::Unit::TestCase
assert_nothing_raised("Failure when recursing") do
children = obj.eval_generate
end
- assert(obj.class[subdir], "did not create subdir object")
+ assert(config.resource(:file, subdir), "did not create subdir object")
children.each do |c|
assert_nothing_raised("Failure when recursing on %s" % c) do
c.configuration = config
others = c.eval_generate
end
end
- oobj = obj.class[other]
+ oobj = config.resource(:file, other)
assert(oobj, "did not create other object")
assert_nothing_raised do
@@ -1780,12 +1756,14 @@ class TestFile < Test::Unit::TestCase
# Make sure we default to the "puppet" filebucket, rather than a string
def test_backup_defaults_to_bucket
path = tempfile
- file = Puppet::Type.newfile(:path => path, :content => 'some content')
+ config = Puppet::Node::Configuration.new
+ config.add_resource(Puppet::Type.type(:filebucket).create_default_resources)
+ file = config.create_resource :file, :path => path, :content => 'some content'
file.finish
- assert_instance_of(Puppet::Network::Client::Dipper, file.bucket,
+ assert_instance_of(Puppet::Network::Client.dipper, file.bucket,
"did not default to a filebucket for backups")
- assert_equal(Puppet::Type.type(:filebucket)["puppet"].bucket, file.bucket,
+ assert_equal(config.resource(:filebucket, "puppet").bucket, file.bucket,
"did not default to the 'puppet' filebucket")
end
@@ -1804,7 +1782,7 @@ class TestFile < Test::Unit::TestCase
assert_nothing_raised do
children = obj.eval_generate
end
- fobj = obj.class[file]
+ fobj = config.resource(:file,file)
assert(fobj, "did not create file object")
assert(fobj.should(:ensure) != :directory, "ensure was passed to child")
end
diff --git a/test/ral/types/file/target.rb b/test/ral/types/file/target.rb
index f5cbe4a45..cc53e2645 100755
--- a/test/ral/types/file/target.rb
+++ b/test/ral/types/file/target.rb
@@ -3,9 +3,11 @@
require File.dirname(__FILE__) + '/../../../lib/puppettest'
require 'puppettest'
+require 'puppettest/support/assertions'
require 'fileutils'
class TestFileTarget < Test::Unit::TestCase
+ include PuppetTest
include PuppetTest::FileTesting
def setup
@@ -44,7 +46,7 @@ class TestFileTarget < Test::Unit::TestCase
def test_linkrecurse
dest = tempfile()
link = @file.create :path => tempfile(), :recurse => true, :ensure => dest
- mk_configuration link
+ config = mk_configuration link
ret = nil
@@ -62,7 +64,8 @@ class TestFileTarget < Test::Unit::TestCase
assert_equal(:directory, link.should(:ensure), "ensure was not set to directory")
assert_equal([File.join(link.title, "one")], ret.collect { |f| f.title },
"Did not get linked file")
- oneobj = @file[File.join(link.title, "one")]
+ oneobj = config.resource(:file, File.join(link.title, "one"))
+
assert_equal(one, oneobj.should(:target), "target was not set correctly")
oneobj.remove
@@ -81,7 +84,7 @@ class TestFileTarget < Test::Unit::TestCase
"Did not get links back")
returns.each do |path|
- obj = @file[path]
+ obj = config.resource(:file, path)
assert(path, "did not get obj for %s" % path)
sdest = File.join(dest, File.basename(path))
assert_equal(sdest, obj.should(:target),
@@ -99,15 +102,14 @@ class TestFileTarget < Test::Unit::TestCase
system("touch %s" % file)
link = nil
- assert_nothing_raised {
- link = Puppet.type(:file).create(
- :ensure => source,
- :path => path,
- :recurse => true
- )
- }
+ config = mk_configuration
+ link = config.create_resource(:file,
+ :ensure => source,
+ :path => path,
+ :recurse => true
+ )
- assert_apply(link)
+ config.apply
sublink = File.join(path, "subdir")
linkpath = File.join(sublink, "file")
@@ -116,7 +118,7 @@ class TestFileTarget < Test::Unit::TestCase
assert(File.symlink?(linkpath), "path is not a link")
assert_equal(file, File.readlink(linkpath))
- assert_nil(@file[sublink], "objects were not removed")
+ assert_nil(config.resource(:file, sublink), "objects were not removed")
assert_equal([], link.evaluate, "Link is not in sync")
end
diff --git a/test/ral/types/filebucket.rb b/test/ral/types/filebucket.rb
index ecfe0e167..3681febf4 100755
--- a/test/ral/types/filebucket.rb
+++ b/test/ral/types/filebucket.rb
@@ -3,10 +3,12 @@
require File.dirname(__FILE__) + '/../../lib/puppettest'
require 'puppettest'
+require 'puppettest/support/utils'
require 'fileutils'
class TestFileBucket < Test::Unit::TestCase
include PuppetTest::FileTesting
+ include PuppetTest::Support::Utils
# hmmm
# this is complicated, because we store references to the created
# objects in a central store
@@ -63,14 +65,9 @@ class TestFileBucket < Test::Unit::TestCase
def test_simplebucket
name = "yayness"
bucketpath = tempfile()
- mkbucket(name, bucketpath)
+ bucket_resource = mkbucket(name, bucketpath)
- bucket = nil
- assert_nothing_raised {
- bucket = Puppet.type(:filebucket).bucket(name)
- }
-
- assert_instance_of(Puppet::Network::Client.dipper, bucket)
+ bucket = bucket_resource.bucket
md5 = nil
newpath = tempfile()
@@ -109,15 +106,16 @@ class TestFileBucket < Test::Unit::TestCase
end
def test_fileswithbuckets
+ Facter.stubs(:to_hash).returns({})
name = "yayness"
- mkbucket(name, tempfile())
+ resource = mkbucket(name, tempfile())
- bucket = nil
- assert_nothing_raised {
- bucket = Puppet.type(:filebucket).bucket(name)
- }
+ config = mk_configuration resource
+
+ bucket = resource.bucket
file = mktestfile()
+ config.add_resource(file)
assert_nothing_raised {
file[:backup] = name
}
@@ -133,7 +131,7 @@ class TestFileBucket < Test::Unit::TestCase
# file[:backup] = true
#}
- assert_apply(file)
+ config.apply
# so, we've now replaced the file with the opath file
assert_equal(
diff --git a/test/ral/types/fileignoresource.rb b/test/ral/types/fileignoresource.rb
index 5c7536453..501672ab7 100755
--- a/test/ral/types/fileignoresource.rb
+++ b/test/ral/types/fileignoresource.rb
@@ -3,11 +3,13 @@
require File.dirname(__FILE__) + '/../../lib/puppettest'
require 'puppettest'
+require 'puppettest/support/utils'
require 'cgi'
require 'fileutils'
class TestFileIgnoreSources < Test::Unit::TestCase
include PuppetTest::FileTesting
+ include PuppetTest::Support::Utils
def setup
super
@@ -18,7 +20,7 @@ class TestFileIgnoreSources < Test::Unit::TestCase
end
end
-#This is not needed unless using md5 (correct me if I'm wrong)
+ #This is not needed unless using md5 (correct me if I'm wrong)
def initstorage
Puppet::Util::Storage.init
Puppet::Util::Storage.load
@@ -30,6 +32,7 @@ class TestFileIgnoreSources < Test::Unit::TestCase
end
def test_ignore_simple_source
+ Facter.stubs(:to_hash).returns({})
#Temp directory to run tests in
path = tempfile()
@@ -89,6 +92,7 @@ class TestFileIgnoreSources < Test::Unit::TestCase
end
def test_ignore_with_wildcard
+ Facter.stubs(:to_hash).returns({})
#Temp directory to run tests in
path = tempfile()
@@tmpfiles.push path
@@ -158,6 +162,7 @@ class TestFileIgnoreSources < Test::Unit::TestCase
end
def test_ignore_array
+ Facter.stubs(:to_hash).returns({})
#Temp directory to run tests in
path = tempfile()
@@tmpfiles.push path
diff --git a/test/ral/types/filesources.rb b/test/ral/types/filesources.rb
index 1f22fc9e0..bfbc185e3 100755
--- a/test/ral/types/filesources.rb
+++ b/test/ral/types/filesources.rb
@@ -3,11 +3,13 @@
require File.dirname(__FILE__) + '/../../lib/puppettest'
require 'puppettest'
+require 'puppettest/support/assertions'
require 'cgi'
require 'fileutils'
require 'mocha'
class TestFileSources < Test::Unit::TestCase
+ include PuppetTest
include PuppetTest::FileTesting
def setup
super
@@ -285,7 +287,7 @@ class TestFileSources < Test::Unit::TestCase
end
assert_equal([destfile], sourced, "Did not get correct list of sourced objects")
- dfileobj = @file[destfile]
+ dfileobj = config.resource(:file, destfile)
assert(dfileobj, "Did not create destfile object")
assert_equal([dfileobj], result)
@@ -301,7 +303,7 @@ class TestFileSources < Test::Unit::TestCase
result, sourced = obj.sourcerecurse(true)
end
assert_equal([destfile], sourced, "Did not get correct list of sourced objects")
- dfileobj = @file[destfile]
+ dfileobj = config.resource(:file, destfile)
assert(dfileobj, "Did not create destfile object with a missing source")
assert_equal([dfileobj], result)
dfileobj.remove
@@ -415,9 +417,6 @@ class TestFileSources < Test::Unit::TestCase
def test_sources_with_deleted_destfiles
fromdir, todir, one, two = run_complex_sources
assert(FileTest.exists?(todir))
-
- # We shouldn't have a 'two' file object in memory
- assert_nil(@file[two], "object for 'two' is still in memory")
# then delete a file
File.unlink(two)
@@ -939,7 +938,6 @@ class TestFileSources < Test::Unit::TestCase
end
File.unlink(file1)
File.unlink(file3)
- Puppet.err :yay
assert_apply(obj)
assert(FileTest.exists?(file1), "File from source 1 was not copied")
diff --git a/test/ral/types/host.rb b/test/ral/types/host.rb
index 1013651c5..5e91a8c58 100755
--- a/test/ral/types/host.rb
+++ b/test/ral/types/host.rb
@@ -154,11 +154,13 @@ class TestHost < Test::Unit::TestCase
def test_puppetalias
host = mkhost()
+ config = mk_configuration(host)
+
assert_nothing_raised {
host[:alias] = "testing"
}
- same = host.class["testing"]
+ same = config.resource(:host, "testing")
assert(same, "Could not retrieve by alias")
end
end
diff --git a/test/ral/types/package.rb b/test/ral/types/package.rb
index 7d0caa0ba..d09f7d9b7 100755
--- a/test/ral/types/package.rb
+++ b/test/ral/types/package.rb
@@ -9,6 +9,7 @@ require 'mocha'
$platform = Facter["operatingsystem"].value
class TestPackages < Test::Unit::TestCase
+ include PuppetTest
include PuppetTest::FileTesting
def setup
super
diff --git a/test/ral/types/parameter.rb b/test/ral/types/parameter.rb
index 1d402cb85..7eda05bb5 100755
--- a/test/ral/types/parameter.rb
+++ b/test/ral/types/parameter.rb
@@ -113,8 +113,7 @@ class TestParameter < Test::Unit::TestCase
inst = type.create(:name => "test")
- config = mk_configuration
- inst.configuration = config
+ config = mk_configuration(inst)
assert_nothing_raised("Could not create shadowed param") {
inst[:alias] = "foo"
@@ -131,7 +130,7 @@ class TestParameter < Test::Unit::TestCase
assert_instance_of(param, obj, "alias is an instance of the wrong class")
# Make sure the alias got created
- assert(type["foo"], "Did not retrieve object by its alias")
+ assert(config.resource(inst.class.name, "foo"), "Did not retrieve object by its alias")
# Now try it during initialization
other = nil
diff --git a/test/ral/types/schedule.rb b/test/ral/types/schedule.rb
index 2870b8db6..06698f288 100755
--- a/test/ral/types/schedule.rb
+++ b/test/ral/types/schedule.rb
@@ -242,24 +242,23 @@ class TestSchedule < Test::Unit::TestCase
s = mksched
s[:period] = :hourly
- f = nil
path = tempfile()
- assert_nothing_raised {
- f = Puppet.type(:file).create(
- :name => path,
- :schedule => s.name,
- :ensure => "file"
- )
- }
+ f = Puppet.type(:file).create(
+ :name => path,
+ :schedule => s.name,
+ :ensure => "file"
+ )
+
+ config = mk_configuration(s, f)
assert(f.scheduled?, "File is not scheduled to run")
- assert_apply(f)
+ config.apply
assert(! f.scheduled?, "File is scheduled to run already")
File.unlink(path)
- assert_apply(f)
+ config.apply
assert(! FileTest.exists?(path), "File was created when not scheduled")
end
@@ -287,25 +286,17 @@ class TestSchedule < Test::Unit::TestCase
# Verify that each of our default schedules exist
def test_defaultschedules
- assert_nothing_raised do
- Puppet.type(:schedule).mkdefaultschedules
+ defaults = nil
+ assert_nothing_raised("Could not create default schedules") do
+ defaults = Puppet.type(:schedule).create_default_resources
end
s = {}
%w{puppet hourly daily weekly monthly}.each { |period|
- obj = Puppet.type(:schedule)[period]
- assert(obj, "Could not find %s schedule" %
+ schedule = defaults.find { |r| r.title == period }
+ assert(schedule, "Could not find %s schedule" %
period)
- s[period] = obj
+ s[period] = schedule
}
- assert_nothing_raised("Could not rerun mkdefaultschedules") do
- Puppet.type(:schedule).mkdefaultschedules
- end
- s.each do |period, obj|
- newobj = Puppet.type(:schedule)[period]
- assert(newobj, "somehow lost schedule for %s" % period)
- assert_equal(obj.object_id, newobj.object_id,
- "created a new schedule instead of reusing existing one")
- end
end
def test_period_with_repeat
diff --git a/test/ral/types/sshkey.rb b/test/ral/types/sshkey.rb
index c99f7562a..a2daf6cfb 100755
--- a/test/ral/types/sshkey.rb
+++ b/test/ral/types/sshkey.rb
@@ -102,6 +102,8 @@ class TestSSHKey < Test::Unit::TestCase
def test_moddingkey
key = mkkey()
+ config = mk_configuration(key)
+
assert_events([:sshkey_created], key)
key.retrieve
@@ -113,7 +115,7 @@ class TestSSHKey < Test::Unit::TestCase
assert_events([:sshkey_changed], key)
aliases.each do |name|
- assert_equal(key, key.class[name],
+ assert_equal(key, config.resource(:sshkey, name),
"alias was not set")
end
end
@@ -131,12 +133,13 @@ class TestSSHKey < Test::Unit::TestCase
def test_puppetalias
key = mkkey()
+ config = mk_configuration(key)
assert_nothing_raised {
key[:alias] = "testing"
}
- same = key.class["testing"]
+ same = config.resource(:sshkey, "testing")
assert(same, "Could not retrieve by alias")
end
@@ -168,13 +171,14 @@ class TestSSHKey < Test::Unit::TestCase
keys << k
names << k.name
}
- assert_apply(*keys)
- keys.clear
- Puppet.type(:sshkey).clear
+ config = mk_configuration(*keys)
+ config.apply
+
newkey = mkkey()
- #newkey[:ensure] = :present
+ config = mk_configuration(newkey)
names << newkey.name
- assert_apply(newkey)
+
+ config.apply
# Verify we can retrieve that info
assert_nothing_raised("Could not retrieve after second write") {
diff --git a/test/ral/types/tidy.rb b/test/ral/types/tidy.rb
index e95f26b95..6cdf0f050 100755
--- a/test/ral/types/tidy.rb
+++ b/test/ral/types/tidy.rb
@@ -3,8 +3,10 @@
require File.dirname(__FILE__) + '/../../lib/puppettest'
require 'puppettest'
+require 'puppettest/support/utils'
class TestTidy < Test::Unit::TestCase
+ include PuppetTest
include PuppetTest::FileTesting
def mktmpfile
# because luke's home directory is on nfs, it can't be used for testing
@@ -201,16 +203,10 @@ class TestTidy < Test::Unit::TestCase
path = tempfile()
File.open(path, "w") { |f| 10.times { f.puts "yayness " } }
tidy = Puppet::Type.type(:tidy).create :path => path, :size => "1b"
-
- assert_apply(tidy)
- assert(! FileTest.exists?(path), "file did not get tidied")
-
- # Now try one with just an age attribute.
- File.open(path, "w") { |f| 10.times { f.puts "yayness " } }
- tidy = Puppet::Type.type(:tidy).create :path => path, :age => "5s"
-
+ config = mk_configuration(tidy)
+
+ config.apply
- assert_apply(tidy)
assert(! FileTest.exists?(path), "file did not get tidied")
end
diff --git a/test/util/filetype.rb b/test/util/filetype.rb
index 6c7ede07b..a53fb385f 100755
--- a/test/util/filetype.rb
+++ b/test/util/filetype.rb
@@ -85,8 +85,7 @@ class TestFileType < Test::Unit::TestCase
assert_nothing_raised("Could not call backup with no buckets") do
obj.backup
end
- puppet = type["puppet"]
- assert(puppet, "Did not create default filebucket")
+ puppet = Puppet::Type.type(:filebucket).create_default_resources
assert_equal("one", puppet.bucket.getfile(Digest::MD5.hexdigest(File.read(path))), "Could not get file from backup")