diff options
| author | Luke Kanies <luke@madstop.com> | 2007-08-20 22:25:00 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-08-20 22:25:00 -0500 |
| commit | 4eb87ed7c8829a6fbc558595be9149e9b3cf5b36 (patch) | |
| tree | 5c8319949022f932eb6467b17b55debaa42fa125 /test | |
| parent | 2a4e1011dbc244754f434f7eb97f3d41463e5cd4 (diff) | |
| download | puppet-4eb87ed7c8829a6fbc558595be9149e9b3cf5b36.tar.gz puppet-4eb87ed7c8829a6fbc558595be9149e9b3cf5b36.tar.xz puppet-4eb87ed7c8829a6fbc558595be9149e9b3cf5b36.zip | |
A round of bugfixing. Many more tests now pass -- I think we are largely down to tests that (yay!) fail in trunk.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lib/puppettest/parsertesting.rb | 2 | ||||
| -rw-r--r-- | test/lib/puppettest/railstesting.rb | 8 | ||||
| -rw-r--r-- | test/lib/puppettest/resourcetesting.rb | 2 | ||||
| -rw-r--r-- | test/lib/spec/version.rb | 4 | ||||
| -rwxr-xr-x | test/network/client/master.rb | 3 | ||||
| -rwxr-xr-x | test/network/handler/configuration.rb | 4 | ||||
| -rwxr-xr-x | test/network/handler/master.rb | 129 | ||||
| -rwxr-xr-x | test/rails/collection.rb | 48 | ||||
| -rwxr-xr-x | test/rails/configuration.rb (renamed from test/rails/interpreter.rb) | 45 | ||||
| -rwxr-xr-x | test/rails/host.rb | 30 | ||||
| -rwxr-xr-x | test/rails/railsparameter.rb | 4 |
11 files changed, 88 insertions, 191 deletions
diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb index 0a695cbaa..3e2930728 100644 --- a/test/lib/puppettest/parsertesting.rb +++ b/test/lib/puppettest/parsertesting.rb @@ -51,7 +51,7 @@ module PuppetTest::ParserTesting def mknode(name = nil) name ||= "nodename" Puppet::Network::Handler.handler(:node) - Puppet::Network::Handler::Node::SimpleNode.new("nodename") + Puppet::Network::Handler::Node::SimpleNode.new(name) end def mkinterp(args = {}) diff --git a/test/lib/puppettest/railstesting.rb b/test/lib/puppettest/railstesting.rb index 8b5f074a2..403bdb756 100644 --- a/test/lib/puppettest/railstesting.rb +++ b/test/lib/puppettest/railstesting.rb @@ -40,12 +40,10 @@ module PuppetTest::RailsTesting # Now try storing our crap host = nil + node = mknode(facts["hostname"]) + node.parameters = facts assert_nothing_raised { - host = Puppet::Rails::Host.store( - :resources => resources, - :facts => facts, - :name => facts["hostname"] - ) + host = Puppet::Rails::Host.store(node, resources) } # Now save the whole thing diff --git a/test/lib/puppettest/resourcetesting.rb b/test/lib/puppettest/resourcetesting.rb index cbcfb0baf..e2176d5ef 100644 --- a/test/lib/puppettest/resourcetesting.rb +++ b/test/lib/puppettest/resourcetesting.rb @@ -28,7 +28,7 @@ module PuppetTest::ResourceTesting def mkresource(args = {}) args[:source] ||= "source" - args[:scope] ||= "scope" + args[:scope] ||= stub :tags => [] {:type => "resource", :title => "testing", :source => "source", :scope => "scope"}.each do |param, value| diff --git a/test/lib/spec/version.rb b/test/lib/spec/version.rb index 924d8458a..a0c0fdbbe 100644 --- a/test/lib/spec/version.rb +++ b/test/lib/spec/version.rb @@ -15,7 +15,7 @@ module Spec # RELEASE_CANDIDATE = "RC1"
# RANDOM_TOKEN: 0.375509844656552 - REV = "$LastChangedRevision$".match(/LastChangedRevision: (\d+)/)[1]
+ REV = "LastChangedRevision: 2283".match(/LastChangedRevision: (\d+)/)[1]
STRING = [MAJOR, MINOR, TINY].join('.')
FULL_VERSION = "#{STRING} (r#{REV})"
@@ -27,4 +27,4 @@ module Spec DESCRIPTION = "#{NAME}-#{FULL_VERSION} - BDD for Ruby\n#{URL}"
end
end
-end
\ No newline at end of file +end diff --git a/test/network/client/master.rb b/test/network/client/master.rb index 78a1a0a11..7746d20ff 100755 --- a/test/network/client/master.rb +++ b/test/network/client/master.rb @@ -75,7 +75,7 @@ class TestMasterClient < Test::Unit::TestCase def mk_fake_client server = Puppet::Network::Handler.master.new :Code => "" - master = Puppet::Network::Client.master.new :Server => server, :Local => true + master = Puppet::Network::Client.master.new :Master => server, :Local => true # Now create some objects objects = FakeComponent.new @@ -532,6 +532,7 @@ end master.local = false driver = master.send(:instance_variable_get, "@driver") driver.local = false + driver.send(:config_handler).local = false # Retrieve the configuration master.getconfig diff --git a/test/network/handler/configuration.rb b/test/network/handler/configuration.rb index 525db5e6a..98c3bdcde 100755 --- a/test/network/handler/configuration.rb +++ b/test/network/handler/configuration.rb @@ -170,7 +170,7 @@ class TestHandlerConfiguration < Test::Unit::TestCase handler.expects(:details).with(:client).returns(false) config.expects(:node_handler).returns(handler) interp = Object.new - interp.expects(:configuration_version).returns(:version) + interp.expects(:parsedate).returns(:version) config.expects(:interpreter).returns(interp) assert_equal(:version, config.version(:client), "Did not return configuration version") @@ -182,7 +182,7 @@ class TestHandlerConfiguration < Test::Unit::TestCase config.expects(:update_node_check).with(node) config.expects(:node_handler).returns(handler) interp = Object.new - interp.expects(:configuration_version).returns(:version) + interp.expects(:parsedate).returns(:version) config.expects(:interpreter).returns(interp) assert_equal(:version, config.version(:client), "Did not return configuration version") end diff --git a/test/network/handler/master.rb b/test/network/handler/master.rb index 9cf52b1cd..5ac8cbbbc 100755 --- a/test/network/handler/master.rb +++ b/test/network/handler/master.rb @@ -116,114 +116,39 @@ class TestMaster < Test::Unit::TestCase assert(FileTest.exists?(file2), "Second file %s does not exist" % file2) end - # Make sure we're using the hostname as configured with :node_name - def test_hostname_in_getconfig - master = nil - file = tempfile() - #@createdfile = File.join(tmpdir(), self.class.to_s + "manifesttesting" + - # "_" + @method_name) - file_cert = tempfile() - file_fact = tempfile() - - certname = "y4yn3ss" - factname = Facter.value("hostname") - - File.open(file, "w") { |f| - f.puts %{ - node #{certname} { file { "#{file_cert}": ensure => file, mode => 755 } } - node #{factname} { file { "#{file_fact}": ensure => file, mode => 755 } } -} - } - # create our master - assert_nothing_raised() { - # this is the default server setup - master = Puppet::Network::Handler.master.new( - :Manifest => file, - :UseNodes => true, - :Local => true - ) - } - - result = nil - - # Use the hostname from facter - Puppet[:node_name] = 'facter' - assert_nothing_raised { - result = master.getconfig({"hostname" => factname}, "yaml", certname, "127.0.0.1") - } - - result = result.flatten - - assert(result.find { |obj| obj.name == file_fact }, - "Could not find correct file") - assert(!result.find { |obj| obj.name == file_cert }, - "Found incorrect file") - - # Use the hostname from the cert - Puppet[:node_name] = 'cert' - assert_nothing_raised { - result = master.getconfig({"hostname" => factname}, "yaml", certname, "127.0.0.1") - } - - result = result.flatten - - assert(!result.find { |obj| obj.name == file_fact }, - "Could not find correct file") - assert(result.find { |obj| obj.name == file_cert }, - "Found incorrect file") - end - # Make sure we're correctly doing clientname manipulations. # Testing to make sure we always get a hostname and IP address. def test_clientname - master = nil - file = tempfile() - - File.open(file, "w") { |f| - f.puts %{ - node yay { file { "/something": ensure => file, mode => 755 } } -} - } # create our master - assert_nothing_raised() { - # this is the default server setup - master = Puppet::Network::Handler.master.new( - :Manifest => file, - :UseNodes => true, - :Local => true - ) - } + master = Puppet::Network::Handler.master.new( + :Manifest => tempfile, + :UseNodes => true, + :Local => true + ) + + # First check that 'cert' works Puppet[:node_name] = "cert" - # First act like we're local - fakename = nil - fakeip = nil - - name = ip = nil - facts = Facter.to_hash - assert_nothing_raised do - name, ip = master.clientname(fakename, fakeip, facts) - end - - assert(facts["hostname"], "Removed hostname fact") - assert(facts["ipaddress"], "Removed ipaddress fact") - - assert_equal(facts["hostname"], name) - assert_equal(facts["ipaddress"], ip) - - # Now set them to something real, and make sure we get them back - fakename = "yayness" - fakeip = "192.168.0.1" - facts = Facter.to_hash - assert_nothing_raised do - name, ip = master.clientname(fakename, fakeip, facts) - end - - assert(facts["hostname"], "Removed hostname fact") - assert(facts["ipaddress"], "Removed ipaddress fact") - - assert_equal(fakename, name) - assert_equal(fakeip, ip) + + # Make sure we get the fact data back when nothing is set + facts = {"hostname" => "fact_hostname", "ipaddress" => "fact_ip"} + certname = "cert_hostname" + certip = "cert_ip" + + resname, resip = master.send(:clientname, nil, nil, facts) + assert_equal(facts["hostname"], resname, "Did not use fact hostname when no certname was present") + assert_equal(facts["ipaddress"], resip, "Did not use fact ip when no certname was present") + + # Now try it with the cert stuff present + resname, resip = master.send(:clientname, certname, certip, facts) + assert_equal(certname, resname, "Did not use cert hostname when certname was present") + assert_equal(certip, resip, "Did not use cert ip when certname was present") + + # And reset the node_name stuff and make sure we use it. + Puppet[:node_name] = :facter + resname, resip = master.send(:clientname, certname, certip, facts) + assert_equal(facts["hostname"], resname, "Did not use fact hostname when nodename was set to facter") + assert_equal(facts["ipaddress"], resip, "Did not use fact ip when nodename was set to facter") end end diff --git a/test/rails/collection.rb b/test/rails/collection.rb index d878641be..18de3c77b 100755 --- a/test/rails/collection.rb +++ b/test/rails/collection.rb @@ -22,15 +22,12 @@ class TestRailsCollection < PuppetTest::TestCase def setup super Puppet[:trace] = false - @interp, @scope, @source = mkclassframing + @scope = mkscope end def test_collect_exported railsinit - # Set a hostname - @scope.host = Facter.value(:hostname) - # make an exported resource exported = mkresource(:type => "file", :title => "/tmp/exported", :exported => true, :params => {:owner => "root"}) @@ -51,10 +48,10 @@ class TestRailsCollection < PuppetTest::TestCase end # Set it in our scope - @scope.newcollection(coll) + @scope.configuration.add_collection(coll) # Make sure it's in the collections - assert_equal([coll], @scope.collections) + assert_equal([coll], @scope.configuration.collections) # And try to collect the virtual resources. ret = nil @@ -111,39 +108,39 @@ class TestRailsCollection < PuppetTest::TestCase # Now try storing our crap # Remark this as exported exported.exported = true - host = Puppet::Rails::Host.store( - :resources => [exported], - :facts => facts, - :name => facts["hostname"] - ) + exported.scope.stubs(:tags).returns([]) + node = mknode(facts["hostname"]) + node.parameters = facts + host = Puppet::Rails::Host.store(node, [exported]) assert(host, "did not get rails host") host.save # And make sure it's in there newres = host.resources.find_by_restype_and_title_and_exported("file", "/tmp/exported", true) assert(newres, "Did not find resource in db") - interp, scope, source = mkclassframing - scope.host = "two" + assert(newres.exported?, "Resource was not exported") + + # Make a new set with a different node name + node = mknode("other") + config = Puppet::Parser::Configuration.new(node, mkparser) + config.topscope.source = mock("source") + + # It's important that it's a different name, since same-name resources are ignored. + assert_equal("other", config.node.name, "Did not get correct node name") # Now make a collector coll = nil assert_nothing_raised do - coll = Puppet::Parser::Collector.new(scope, "file", nil, nil, :exported) + coll = Puppet::Parser::Collector.new(config.topscope, "file", nil, nil, :exported) end - # Set it in our scope - scope.newcollection(coll) - - # Make sure it's in the collections - assert_equal([coll], scope.collections) - # And try to collect the virtual resources. ret = nil - assert_nothing_raised do + assert_nothing_raised("Could not collect exported resources") do ret = coll.collect_exported end - assert_equal(["/tmp/exported"], ret.collect { |f| f.title }) + assert_equal(["/tmp/exported"], ret.collect { |f| f.title }, "Did not find resource in collction") # Make sure we can evaluate the same collection multiple times and # that later collections do nothing @@ -167,7 +164,6 @@ class TestRailsCollection < PuppetTest::TestCase normal = mkresource(:type => "file", :title => "/tmp/conflicttest", :params => {:owner => "root"}) @scope.setresource normal - @scope.host = "otherhost" # Now make a collector coll = nil @@ -186,15 +182,13 @@ class TestRailsCollection < PuppetTest::TestCase railsinit # Make our configuration - host = Puppet::Rails::Host.new(:name => "myhost") + host = Puppet::Rails::Host.new(:name => @scope.host) host.resources.build(:title => "/tmp/hosttest", :restype => "file", :exported => true) host.save - @scope.host = "myhost" - # Now make a collector coll = nil assert_nothing_raised do @@ -224,8 +218,6 @@ class TestRailsCollection < PuppetTest::TestCase host.save - @scope.host = "otherhost" - # Now make a collector coll = nil assert_nothing_raised do diff --git a/test/rails/interpreter.rb b/test/rails/configuration.rb index 0eba3f590..31d1cf779 100755 --- a/test/rails/interpreter.rb +++ b/test/rails/configuration.rb @@ -3,7 +3,6 @@ $:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ require 'puppettest' -require 'puppet/parser/interpreter' require 'puppet/parser/parser' require 'puppet/network/client' require 'puppet/rails' @@ -13,49 +12,39 @@ require 'puppettest/servertest' require 'puppettest/railstesting' -class InterpreterRailsTests < PuppetTest::TestCase +class ConfigurationRailsTests < PuppetTest::TestCase include PuppetTest include PuppetTest::ServerTest include PuppetTest::ParserTesting include PuppetTest::ResourceTesting include PuppetTest::RailsTesting AST = Puppet::Parser::AST - NodeDef = Puppet::Parser::Interpreter::NodeDef confine "No rails support" => Puppet.features.rails? # We need to make sure finished objects are stored in the db. def test_finish_before_store railsinit - interp = mkinterp + config = mkconfig + config.ast_nodes = true + parser = config.parser - node = interp.newnode ["myhost"], :code => AST::ASTArray.new(:children => [ + node = parser.newnode [config.node.name], :code => AST::ASTArray.new(:children => [ resourcedef("file", "/tmp/yay", :group => "root"), defaultobj("file", :owner => "root") ]) - interp.newclass "myclass", :code => AST::ASTArray.new(:children => [ - ]) - - interp.newclass "sub", :parent => "myclass", - :code => AST::ASTArray.new(:children => [ - resourceoverride("file", "/tmp/yay", :owner => "root") - ] - ) - # Now do the rails crap Puppet[:storeconfigs] = true - interp.evaluate("myhost", {}) - - # And then retrieve the object from rails - #res = Puppet::Rails::Resource.find_by_restype_and_title("file", "/tmp/yay", :include => {:param_values => :param_names}) - res = Puppet::Rails::Resource.find_by_restype_and_title("file", "/tmp/yay") - - assert(res, "Did not get resource from rails") - - params = res.parameters - - assert_equal(["root"], params["owner"], "Did not get correct value for owner param") + Puppet::Rails::Host.expects(:store).with do |node, resources| + if res = resources.find { |r| r.type == "file" and r.title == "/tmp/yay" } + assert_equal("root", res["owner"], "Did not set default on resource") + true + else + raise "Resource was not passed to store()" + end + end + config.compile end def test_hoststorage @@ -79,13 +68,15 @@ class InterpreterRailsTests < PuppetTest::TestCase facts = {} Facter.each { |fact, val| facts[fact] = val } + node = mknode(facts["hostname"]) + node.parameters = facts objects = nil assert_nothing_raised { - objects = interp.run(facts["hostname"], facts) + objects = interp.compile(node) } - obj = Puppet::Rails::Host.find_by_name(facts["hostname"]) + obj = Puppet::Rails::Host.find_by_name(node.name) assert(obj, "Could not find host object") end end diff --git a/test/rails/host.rb b/test/rails/host.rb index f3190c047..67095a18a 100755 --- a/test/rails/host.rb +++ b/test/rails/host.rb @@ -56,13 +56,10 @@ class TestRailsHost < PuppetTest::TestCase # Now try storing our crap host = nil + node = mknode(facts["hostname"]) + node.parameters = facts assert_nothing_raised { - host = Puppet::Rails::Host.store( - :resources => resources, - :facts => facts, - :name => facts["hostname"], - :classes => ["one", "two::three", "four"] - ) + host = Puppet::Rails::Host.store(node, resources) } assert(host, "Did not create host") @@ -110,7 +107,7 @@ class TestRailsHost < PuppetTest::TestCase # Change a few resources resources.find_all { |r| r.title =~ /file2/ }.each do |r| - r.set("loglevel", "notice", r.source) + r.send(:set_parameter, "loglevel", "notice") end # And add a new resource @@ -124,13 +121,10 @@ class TestRailsHost < PuppetTest::TestCase facts["test1"] = "changedfact" facts.delete("ipaddress") host = nil + node = mknode(facts["hostname"]) + node.parameters = facts assert_nothing_raised { - host = Puppet::Rails::Host.store( - :resources => resources, - :facts => facts, - :name => facts["hostname"], - :classes => ["one", "two::three", "four"] - ) + host = Puppet::Rails::Host.store(node, resources) } # Make sure it sets the last_compile time @@ -162,7 +156,7 @@ class TestRailsHost < PuppetTest::TestCase Puppet[:storeconfigs] = true # this is the default server setup - master = Puppet::Network::Handler.master.new( + master = Puppet::Network::Handler.configuration.new( :Code => "", :UseNodes => true, :Local => true @@ -172,7 +166,7 @@ class TestRailsHost < PuppetTest::TestCase Puppet::Rails::Host.new(:name => "test", :ip => "192.168.0.3").save assert_nothing_raised("Failed to update last_connect for unknown host") do - master.freshness("created",'192.168.0.1') + master.version("created",'192.168.0.1') end # Make sure it created the host @@ -180,12 +174,10 @@ class TestRailsHost < PuppetTest::TestCase assert(created, "Freshness did not create host") assert(created.last_freshcheck, "Did not set last_freshcheck on created host") - assert_equal("192.168.0.1", created.ip, - "Did not set IP address on created host") # Now check on the existing host assert_nothing_raised("Failed to update last_connect for unknown host") do - master.freshness("test",'192.168.0.2') + master.version("test",'192.168.0.2') end # Recreate it, so we're not using the cached object. @@ -194,8 +186,6 @@ class TestRailsHost < PuppetTest::TestCase # Make sure it created the host assert(host.last_freshcheck, "Did not set last_freshcheck on existing host") - assert_equal("192.168.0.3", host.ip, - "Overrode IP on found host") end end diff --git a/test/rails/railsparameter.rb b/test/rails/railsparameter.rb index 82d978bb4..89c81ad30 100755 --- a/test/rails/railsparameter.rb +++ b/test/rails/railsparameter.rb @@ -21,8 +21,8 @@ class TestRailsParameter < Test::Unit::TestCase railsinit # Now create a source - interp = mkinterp - source = interp.newclass "myclass" + parser = mkparser + source = parser.newclass "myclass" host = Puppet::Rails::Host.new(:name => "myhost") |
