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 /lib/puppet | |
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 'lib/puppet')
-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 |
11 files changed, 53 insertions, 37 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$ |