summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-11-08 12:52:52 -0600
committerLuke Kanies <luke@madstop.com>2008-11-08 12:52:52 -0600
commitfe0b818c411344da894dc8d26787db8602f68c7a (patch)
tree0369146363b71d86c45a4b564b13e70b622f854f
parenteed37f7133a33577d1ebc8441db6090fb4c0b7f8 (diff)
downloadpuppet-fe0b818c411344da894dc8d26787db8602f68c7a.tar.gz
puppet-fe0b818c411344da894dc8d26787db8602f68c7a.tar.xz
puppet-fe0b818c411344da894dc8d26787db8602f68c7a.zip
Fixing tests broken by fileserving and other refactoring.
Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r--lib/puppet/property.rb3
-rwxr-xr-xlib/puppet/type/group.rb13
-rwxr-xr-xspec/unit/property.rb5
-rwxr-xr-xtest/network/client/resource.rb33
-rwxr-xr-xtest/other/transactions.rb211
-rwxr-xr-xtest/ral/type/file.rb47
6 files changed, 34 insertions, 278 deletions
diff --git a/lib/puppet/property.rb b/lib/puppet/property.rb
index b8dbd6e77..122fc00c4 100644
--- a/lib/puppet/property.rb
+++ b/lib/puppet/property.rb
@@ -362,10 +362,7 @@ class Puppet::Property < Puppet::Parameter
end
end
- # The default 'sync' method only selects among a list of registered # values.
def sync
- self.devfail("No values defined for %s" % self.class.name) if self.class.value_collection.empty?
-
if value = self.should
set(value)
else
diff --git a/lib/puppet/type/group.rb b/lib/puppet/type/group.rb
index cb11a60a4..250b1353b 100755
--- a/lib/puppet/type/group.rb
+++ b/lib/puppet/type/group.rb
@@ -49,19 +49,6 @@ module Puppet
def retrieve
return provider.exists? ? :present : :absent
end
-
- # The default 'sync' method only selects among a list of registered
- # values.
- def sync
- unless self.class.values
- self.devfail "No values defined for %s" %
- self.class.name
- end
-
- # Set ourselves to whatever our should value is.
- self.set(self.should)
- end
-
end
newproperty(:gid) do
diff --git a/spec/unit/property.rb b/spec/unit/property.rb
index 89b736cf4..e2ba83303 100755
--- a/spec/unit/property.rb
+++ b/spec/unit/property.rb
@@ -226,11 +226,6 @@ describe Puppet::Property do
end
describe "when syncing the 'should' value" do
- it "should fail if no values have been defined and the 'sync' method has not been overridden" do
- @property.should = "eh"
- lambda { @property.sync }.should raise_error(Puppet::DevError)
- end
-
it "should set the value" do
@class.newvalue(:foo)
@property.should = :foo
diff --git a/test/network/client/resource.rb b/test/network/client/resource.rb
index f3c564d9d..6a2e52471 100755
--- a/test/network/client/resource.rb
+++ b/test/network/client/resource.rb
@@ -29,28 +29,29 @@ class TestResourceClient < Test::Unit::TestCase
client = mkclient()
# Test describing
- tobj = nil
+ tresource = nil
assert_nothing_raised {
- tobj = client.describe("file", file)
+ tresource = client.describe("file", file)
}
- assert(tobj, "Did not get response")
+ assert(tresource, "Did not get response")
- assert_instance_of(Puppet::TransObject, tobj)
+ assert_instance_of(Puppet::TransObject, tresource)
- obj = nil
+ resource = nil
assert_nothing_raised {
- obj = tobj.to_type
+ resource = tresource.to_type
}
- assert_events([], obj)
+ assert_events([], resource)
+ p resource.instance_variable_get("@stat")
File.unlink(file)
- assert_events([:file_created], obj)
+ assert_events([:file_created], resource)
File.unlink(file)
# Now test applying
result = nil
assert_nothing_raised {
- result = client.apply(tobj)
+ result = client.apply(tresource)
}
assert(FileTest.exists?(file), "File was not created on apply")
@@ -63,20 +64,20 @@ class TestResourceClient < Test::Unit::TestCase
assert_instance_of(Puppet::TransBucket, list)
count = 0
- list.each do |tobj|
+ list.each do |tresource|
break if count > 3
- assert_instance_of(Puppet::TransObject, tobj)
+ assert_instance_of(Puppet::TransObject, tresource)
- tobj2 = nil
+ tresource2 = nil
assert_nothing_raised {
- tobj2 = client.describe(tobj.type, tobj.name)
+ tresource2 = client.describe(tresource.type, tresource.name)
}
- obj = nil
+ resource = nil
assert_nothing_raised {
- obj = tobj2.to_type
+ resource = tresource2.to_type
}
- assert_events([], obj)
+ assert_events([], resource)
count += 1
end
diff --git a/test/other/transactions.rb b/test/other/transactions.rb
index ad1375b13..04480c24c 100755
--- a/test/other/transactions.rb
+++ b/test/other/transactions.rb
@@ -156,12 +156,12 @@ class TestTransactions < Test::Unit::TestCase
firstpath = tempfile()
secondpath = tempfile()
file = Puppet::Type.type(:file).create(:title => "file", :path => path, :content => "yayness")
- first = Puppet::Type.newexec(:title => "first",
+ first = Puppet::Type.type(:exec).create(:title => "first",
:command => "/bin/echo first > #{firstpath}",
:subscribe => [:file, path],
:refreshonly => true
)
- second = Puppet::Type.newexec(:title => "second",
+ second = Puppet::Type.type(:exec).create(:title => "second",
:command => "/bin/echo second > #{secondpath}",
:subscribe => [:exec, "first"],
:refreshonly => true
@@ -513,204 +513,6 @@ class TestTransactions < Test::Unit::TestCase
"File got created even tho its deep dependency failed")
end
end
-
- def test_relationship_graph
- config = mktree
-
- config.meta_def(:f) do |name|
- self.resource("File[%s]" % name)
- end
-
- {"one" => "two", "File[f]" => "File[c]", "File[h]" => "middle"}.each do |source_ref, target_ref|
- source = config.resource(source_ref) or raise "Missing %s" % source_ref
- target = config.resource(target_ref) or raise "Missing %s" % target_ref
- target[:require] = source
- end
-
- trans = Puppet::Transaction.new(config)
-
- graph = nil
- assert_nothing_raised do
- graph = trans.relationship_graph
- end
-
- assert_instance_of(Puppet::Node::Catalog, graph,
- "Did not get relationship graph")
-
- # Make sure all of the components are gone
- comps = graph.vertices.find_all { |v| v.is_a?(Puppet::Type::Component)}
- assert(comps.empty?, "Deps graph still contains components %s" %
- comps.collect { |c| c.ref }.join(","))
-
- assert_equal([], comps, "Deps graph still contains components")
-
- # It must be reversed because of how topsort works
- sorted = graph.topsort.reverse
-
- # Now make sure the appropriate edges are there and are in the right order
- assert(graph.dependents(config.f(:f)).include?(config.f(:c)),
- "c not marked a dep of f")
- assert(sorted.index(config.f(:c)) < sorted.index(config.f(:f)),
- "c is not before f")
-
- config.resource("one").each do |o|
- config.resource("two").each do |t|
- assert(graph.dependents(o).include?(t),
- "%s not marked a dep of %s" % [t.ref, o.ref])
- assert(sorted.index(t) < sorted.index(o),
- "%s is not before %s" % [t.ref, o.ref])
- end
- end
-
- trans.catalog.leaves(config.resource("middle")).each do |child|
- assert(graph.dependents(config.f(:h)).include?(child),
- "%s not marked a dep of h" % [child.ref])
- assert(sorted.index(child) < sorted.index(config.f(:h)),
- "%s is not before h" % child.ref)
- end
-
- # Lastly, make sure our 'g' vertex made it into the relationship
- # graph, since it's not involved in any relationships.
- assert(graph.vertex?(config.f(:g)),
- "Lost vertexes with no relations")
-
- # Now make the reversal graph and make sure all of the vertices made it into that
- reverse = graph.reversal
- %w{a b c d e f g h}.each do |letter|
- file = config.f(letter)
- assert(reverse.vertex?(file), "%s did not make it into reversal" % letter)
- end
- end
-
- # Test pre-evaluation generation
- def test_generate
- mkgenerator() do
- def generate
- ret = []
- if title.length > 1
- ret << self.class.create(:title => title[0..-2])
- else
- return nil
- end
- ret
- end
- end
-
- yay = Puppet::Type.newgenerator :title => "yay"
- rah = Puppet::Type.newgenerator :title => "rah"
- 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(catalog.resource(:generator, name),
- "Generated %s was not a vertex" % name)
- assert($finished.include?(name), "%s was not finished" % name)
- end
-
- # Now make sure that cleanup gets rid of those generated types.
- assert_nothing_raised do
- trans.cleanup
- end
-
- %w{ya ra y r}.each do |name|
- assert(! catalog.resource(:generator, name),
- "Generated vertex %s was not removed from graph" % name)
- end
- end
-
- # Test mid-evaluation generation.
- def test_eval_generate
- $evaluated = []
- cleanup { $evaluated = nil }
- type = mkreducer() do
- def evaluate
- $evaluated << self.title
- return []
- end
- end
-
- yay = Puppet::Type.newgenerator :title => "yay"
- rah = Puppet::Type.newgenerator :title => "rah", :subscribe => yay
- catalog = mk_catalog(yay, rah)
- trans = Puppet::Transaction.new(catalog)
-
- trans.prepare
-
- # Now apply the resources, and make sure they appropriately generate
- # things.
- assert_nothing_raised("failed to apply yay") do
- trans.eval_resource(yay)
- end
- 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")
-
- # Now make sure the appropriate relationships were added
- assert(trans.relationship_graph.edge?(yay, ya),
- "parent was not required by child")
- assert(! trans.relationship_graph.edge?(ya, rah),
- "generated child ya inherited depencency on rah")
-
- # Now make sure it in turn eval_generates appropriately
- assert_nothing_raised("failed to apply yay") do
- trans.eval_resource(catalog.resource(type.name, "ya"))
- end
-
- %w{y}.each do |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)
- assert($finished.include?("y"), "y was not finished")
- end
-
- assert_nothing_raised("failed to eval_generate with nil response") do
- trans.eval_resource(catalog.resource(type.name, "y"))
- end
- assert(trans.relationship_graph.edge?(yay, ya), "no edge was created for ya => yay")
-
- assert_nothing_raised("failed to apply rah") do
- trans.eval_resource(rah)
- end
-
- 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)
- assert($finished.include?("ra"), "y was not finished")
-
- # Now make sure this generated resource has the same relationships as
- # the generating resource
- assert(! trans.relationship_graph.edge?(yay, ra),
- "rah passed its dependencies on to its children")
- assert(! trans.relationship_graph.edge?(ya, ra),
- "children have a direct relationship")
-
- # Now make sure that cleanup gets rid of those generated types.
- assert_nothing_raised do
- trans.cleanup
- end
-
- %w{ya ra y r}.each do |name|
- assert(!trans.relationship_graph.vertex?(catalog.resource(type.name, name)),
- "Generated vertex %s was not removed from graph" % name)
- end
-
- # Now, start over and make sure that everything gets evaluated.
- trans = Puppet::Transaction.new(catalog)
- $evaluated.clear
- assert_nothing_raised do
- trans.evaluate
- end
-
- assert_equal(%w{yay ya y rah ra r}, $evaluated,
- "Not all resources were evaluated or not in the right order")
- end
# We need to generate resources before we prefetch them, else generated
# resources that require prefetching don't work.
@@ -1105,11 +907,12 @@ class TestTransactions < Test::Unit::TestCase
end
def test_flush
- $state = "absent"
+ $state = :absent
$flushed = 0
type = Puppet::Type.newtype(:flushtest) do
newparam(:name)
newproperty(:ensure) do
+ newvalues :absent, :present, :other
def retrieve
$state
end
@@ -1126,12 +929,12 @@ class TestTransactions < Test::Unit::TestCase
cleanup { Puppet::Type.rmtype(:flushtest) }
- obj = type.create(:name => "test", :ensure => "present")
+ obj = type.create(:name => "test", :ensure => :present)
# first make sure it runs through and flushes
assert_apply(obj)
- assert_equal("present", $state, "Object did not make a change")
+ assert_equal(:present, $state, "Object did not make a change")
assert_equal(1, $flushed, "object was not flushed")
# Now run a noop and make sure we don't flush
@@ -1139,7 +942,7 @@ class TestTransactions < Test::Unit::TestCase
obj[:noop] = true
assert_apply(obj)
- assert_equal("present", $state, "Object made a change in noop")
+ assert_equal(:present, $state, "Object made a change in noop")
assert_equal(1, $flushed, "object was flushed in noop")
end
end
diff --git a/test/ral/type/file.rb b/test/ral/type/file.rb
index 348970fd7..56ae8a285 100755
--- a/test/ral/type/file.rb
+++ b/test/ral/type/file.rb
@@ -515,11 +515,12 @@ class TestFile < Test::Unit::TestCase
)
}
config = mk_catalog dir
+ transaction = Puppet::Transaction.new(config)
children = nil
assert_nothing_raised {
- children = dir.eval_generate
+ children = transaction.eval_generate(dir)
}
assert_equal([subdir], children.collect {|c| c.title },
@@ -533,7 +534,7 @@ class TestFile < Test::Unit::TestCase
File.open(tmpfile, "w") { |f| f.puts "yayness" }
assert_nothing_raised {
- children = dir.eval_generate
+ children = transaction.eval_generate(dir)
}
# And make sure we get both resources back.
@@ -605,10 +606,12 @@ class TestFile < Test::Unit::TestCase
)
}
catalog = mk_catalog dirobj
+ transaction = Puppet::Transaction.new(catalog)
+ transaction.eval_generate(dirobj)
- assert_nothing_raised {
- dirobj.eval_generate
- }
+ #assert_nothing_raised {
+ # dirobj.eval_generate
+ #}
file = catalog.resource(:file, path)
@@ -1194,10 +1197,11 @@ class TestFile < Test::Unit::TestCase
File.open(file, "w") { |f| f.puts "" }
obj = Puppet::Type.newfile :path => dir, :recurse => true, :mode => 0755
catalog = mk_catalog obj
+ transaction = Puppet::Transaction.new(catalog)
assert_equal("/%s" % obj.ref, obj.path)
- list = obj.eval_generate
+ list = transaction.eval_generate(obj)
fileobj = catalog.resource(:file, file)
assert(fileobj, "did not generate file object")
assert_equal("/%s" % fileobj.ref, fileobj.path, "did not generate correct subfile path")
@@ -1285,37 +1289,6 @@ class TestFile < Test::Unit::TestCase
end
end
- # #505
- def test_numeric_recurse
- dir = tempfile()
- subdir = File.join(dir, "subdir")
- other = File.join(subdir, "deeper")
- file = File.join(other, "file")
- [dir, subdir, other].each { |d| Dir.mkdir(d) }
- File.open(file, "w") { |f| f.puts "yay" }
- File.chmod(0644, file)
- obj = Puppet::Type.newfile(:path => dir, :mode => 0750, :recurse => "2")
- catalog = mk_catalog(obj)
-
- children = nil
- assert_nothing_raised("Failure when recursing") do
- children = obj.eval_generate
- end
- assert(catalog.resource(:file, subdir), "did not create subdir object")
- children.each do |c|
- assert_nothing_raised("Failure when recursing on %s" % c) do
- c.catalog = catalog
- others = c.eval_generate
- end
- end
- oobj = catalog.resource(:file, other)
- assert(oobj, "did not create other object")
-
- assert_nothing_raised do
- assert_nil(oobj.eval_generate, "recursed too far")
- end
- end
-
# Make sure we default to the "puppet" filebucket, rather than a string
def test_backup_defaults_to_bucket
path = tempfile