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 | |
| 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.
| -rw-r--r-- | lib/puppet/dsl.rb | 22 | ||||
| -rw-r--r-- | lib/puppet/network/handler.rb | 6 | ||||
| -rw-r--r-- | lib/puppet/network/handler/configuration.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/network/handler/master.rb | 16 | ||||
| -rw-r--r-- | lib/puppet/network/handler/node.rb | 3 | ||||
| -rw-r--r-- | lib/puppet/parser/configuration.rb | 14 | ||||
| -rw-r--r-- | lib/puppet/parser/interpreter.rb | 1 | ||||
| -rw-r--r-- | lib/puppet/parser/resource.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/parser/scope.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/rails/host.rb | 14 | ||||
| -rw-r--r-- | lib/puppet/rails/resource.rb | 8 | ||||
| -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 |
22 files changed, 141 insertions, 228 deletions
diff --git a/lib/puppet/dsl.rb b/lib/puppet/dsl.rb index 9c652f082..3a7a7f059 100644 --- a/lib/puppet/dsl.rb +++ b/lib/puppet/dsl.rb @@ -113,10 +113,6 @@ module Puppet @aspects = {} - # For now, just do some hackery so resources work - @@interp = Puppet::Parser::Interpreter.new :Code => "" - @@scope = Puppet::Parser::Scope.new(:interp => @@interp) - @@objects = Hash.new do |hash, key| hash[key] = {} end @@ -237,7 +233,7 @@ module Puppet end unless obj = @@objects[type][name] obj = Resource.new :title => name, :type => type.name, - :source => source, :scope => @@scope + :source => source, :scope => scope @@objects[type][name] = obj @resources << obj @@ -250,12 +246,26 @@ module Puppet :source => source ) - obj.set(param) + obj.send(:set_parameter, param) end obj end + def scope + unless defined?(@scope) + @interp = Puppet::Parser::Interpreter.new :Code => "" + # Load the class, so the node object class is available. + require 'puppet/network/handler/node' + @node = Puppet::Network::Handler::Node::SimpleNode.new(Facter.value(:hostname)) + @node.parameters = Facter.to_hash + @interp = Puppet::Parser::Interpreter.new :Code => "" + @config = Puppet::Parser::Configuration.new(@node, @interp.parser) + @scope = @config.topscope + end + @scope + end + def type self.name end diff --git a/lib/puppet/network/handler.rb b/lib/puppet/network/handler.rb index 33343e4fe..c2fbfcba5 100644 --- a/lib/puppet/network/handler.rb +++ b/lib/puppet/network/handler.rb @@ -10,7 +10,7 @@ module Puppet::Network # This is so that the handlers can subclass just 'Handler', rather # then having to specify the full class path. Handler = self - attr_accessor :server + attr_accessor :server, :local extend Puppet::Util::SubclassLoader extend Puppet::Util @@ -44,6 +44,10 @@ module Puppet::Network # Create an empty init method with the same signature. def initialize(hash = {}) end + + def local? + self.local + end end end diff --git a/lib/puppet/network/handler/configuration.rb b/lib/puppet/network/handler/configuration.rb index f1a20ee74..3539ab9a4 100644 --- a/lib/puppet/network/handler/configuration.rb +++ b/lib/puppet/network/handler/configuration.rb @@ -57,7 +57,7 @@ class Puppet::Network::Handler # Return the configuration version. def version(client = nil, clientip = nil) - v = interpreter.configuration_version + v = interpreter.parsedate # If we can find the node, then store the fact that the node # has checked in. if client and node = node_handler.details(client) diff --git a/lib/puppet/network/handler/master.rb b/lib/puppet/network/handler/master.rb index 0aa50a426..acc6c4cda 100644 --- a/lib/puppet/network/handler/master.rb +++ b/lib/puppet/network/handler/master.rb @@ -13,7 +13,7 @@ class Puppet::Network::Handler include Puppet::Util - attr_accessor :ast, :local + attr_accessor :ast attr_reader :ca @interface = XMLRPC::Service::Interface.new("puppetmaster") { |iface| @@ -23,7 +23,7 @@ class Puppet::Network::Handler # Tell a client whether there's a fresh config for it def freshness(client = nil, clientip = nil) - config_handler.version(client) + config_handler.version(client, clientip) end def initialize(hash = {}) @@ -42,7 +42,7 @@ class Puppet::Network::Handler @local = false end - args[:Local] = @local + args[:Local] = local? if hash.include?(:CA) and hash[:CA] @ca = Puppet::SSLCertificates::CA.new() @@ -79,12 +79,10 @@ class Puppet::Network::Handler return config_handler.configuration(client) end - def local? - if defined? @local and @local - return true - else - return false - end + def local=(val) + @local = val + config_handler.local = val + fact_handler.local = val end private diff --git a/lib/puppet/network/handler/node.rb b/lib/puppet/network/handler/node.rb index 0d685b1f1..a21d571b0 100644 --- a/lib/puppet/network/handler/node.rb +++ b/lib/puppet/network/handler/node.rb @@ -15,6 +15,9 @@ class Puppet::Network::Handler::Node < Puppet::Network::Handler def initialize(name, options = {}) @name = name + # Provide a default value. + @names = [name] + if classes = options[:classes] if classes.is_a?(String) @classes = [classes] diff --git a/lib/puppet/parser/configuration.rb b/lib/puppet/parser/configuration.rb index ddfc3606f..26553d443 100644 --- a/lib/puppet/parser/configuration.rb +++ b/lib/puppet/parser/configuration.rb @@ -77,6 +77,10 @@ class Puppet::Parser::Configuration finish() + if Puppet[:storeconfigs] + store() + end + return extract() end @@ -444,7 +448,7 @@ class Puppet::Parser::Configuration end # Store the configuration into the database. - def store(options) + def store unless Puppet.features.rails? raise Puppet::Error, "storeconfigs is enabled but rails is unavailable" @@ -456,16 +460,16 @@ class Puppet::Parser::Configuration # We used to have hooks here for forking and saving, but I don't # think it's worth retaining at this point. - store_to_active_record(options) + store_to_active_record(@node, @resource_table.values) end # Do the actual storage. - def store_to_active_record(options) + def store_to_active_record(node, resources) begin # We store all of the objects, even the collectable ones - benchmark(:info, "Stored configuration for #{options[:name]}") do + benchmark(:info, "Stored configuration for #{node.name}") do Puppet::Rails::Host.transaction do - Puppet::Rails::Host.store(options) + Puppet::Rails::Host.store(node, resources) end end rescue => detail diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb index 54cd9b023..e37ef5efe 100644 --- a/lib/puppet/parser/interpreter.rb +++ b/lib/puppet/parser/interpreter.rb @@ -14,6 +14,7 @@ class Puppet::Parser::Interpreter include Puppet::Util attr_accessor :usenodes + attr_reader :parser include Puppet::Util::Errors diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index 9d3e962f0..f946c1328 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -103,6 +103,8 @@ class Puppet::Parser::Resource end end + options = symbolize_options(options) + # Set up our reference. if type = options[:type] and title = options[:title] options.delete(:type) diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index 527ed4dcd..9e6739c53 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -200,7 +200,7 @@ class Puppet::Parser::Scope end # Create a new scope and set these options. - def newscope(options) + def newscope(options = {}) configuration.newscope(self, options) end diff --git a/lib/puppet/rails/host.rb b/lib/puppet/rails/host.rb index ca1e10c93..b7ca4c2e4 100644 --- a/lib/puppet/rails/host.rb +++ b/lib/puppet/rails/host.rb @@ -28,7 +28,7 @@ class Puppet::Rails::Host < ActiveRecord::Base end # Store our host in the database. - def self.store(hash) + def self.store(node, resources) unless name = hash[:name] raise ArgumentError, "You must specify the hostname for storage" end @@ -40,23 +40,19 @@ class Puppet::Rails::Host < ActiveRecord::Base #unless host = find_by_name(name) seconds = Benchmark.realtime { unless host = find_by_name(name) - host = new(:name => name) + host = new(:name => node.name) end } Puppet.notice("Searched for host in %0.2f seconds" % seconds) if defined?(Puppet::TIME_DEBUG) - if ip = hash[:facts]["ipaddress"] + if ip = node.parameters["ipaddress"] host.ip = ip end # Store the facts into the database. - host.setfacts(hash[:facts]) - - unless hash[:resources] - raise ArgumentError, "You must pass resources" - end + host.setfacts node.parameters seconds = Benchmark.realtime { - host.setresources(hash[:resources]) + host.setresources(resources) } Puppet.notice("Handled resources in %0.2f seconds" % seconds) if defined?(Puppet::TIME_DEBUG) diff --git a/lib/puppet/rails/resource.rb b/lib/puppet/rails/resource.rb index 19aeb9205..785c63419 100644 --- a/lib/puppet/rails/resource.rb +++ b/lib/puppet/rails/resource.rb @@ -104,16 +104,16 @@ class Puppet::Rails::Resource < ActiveRecord::Base end hash[:scope] = scope hash[:source] = scope.source - obj = Puppet::Parser::Resource.new(hash) - + hash[:params] = [] names = [] self.param_names.each do |pname| # We can get the same name multiple times because of how the # db layout works. next if names.include?(pname.name) names << pname.name - obj.set(pname.to_resourceparam(self, scope.source)) + hash[:params] << pname.to_resourceparam(self, scope.source) end + obj = Puppet::Parser::Resource.new(hash) # Store the ID, so we can check if we're re-collecting the same resource. obj.rails_id = self.id @@ -121,5 +121,3 @@ class Puppet::Rails::Resource < ActiveRecord::Base return obj end end - -# $Id$ 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") |
