summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-12-12 20:11:35 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-12-12 20:11:35 +0000
commit4abbdc13f4a1762eb5d848763dde1780f6408de8 (patch)
tree32c95243992a42465a02ae3194dd98cfd4baea89 /lib/puppet
parent8fee5383eb214b7e4aa38b0438f23d2a326fb103 (diff)
downloadpuppet-4abbdc13f4a1762eb5d848763dde1780f6408de8.tar.gz
puppet-4abbdc13f4a1762eb5d848763dde1780f6408de8.tar.xz
puppet-4abbdc13f4a1762eb5d848763dde1780f6408de8.zip
Working some on the export/collect problem. It actually works now, but there are not yet sufficient tests for it, so I will leave the bug open until we have got the new work in place. I also added a "rails" feature, so I do not have to keep testing whether ActiveRecord is defined.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1911 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/feature.rb7
-rw-r--r--lib/puppet/feature/rails.rb44
-rw-r--r--lib/puppet/parser/collector.rb36
-rw-r--r--lib/puppet/parser/interpreter.rb5
-rw-r--r--lib/puppet/parser/resource.rb2
-rw-r--r--lib/puppet/rails.rb36
-rw-r--r--lib/puppet/rails/rails_resource.rb1
-rw-r--r--lib/puppet/util.rb2
8 files changed, 85 insertions, 48 deletions
diff --git a/lib/puppet/feature.rb b/lib/puppet/feature.rb
index 55fab5d3c..2d965ed47 100644
--- a/lib/puppet/feature.rb
+++ b/lib/puppet/feature.rb
@@ -20,10 +20,7 @@ class Puppet::Feature
begin
result = yield
rescue => detail
- if Puppet[:trace]
- puts detail.backtrace
- Puppet.err "Failed to load %s: %s" % [name, detail]
- end
+ warn "Failed to load feature test for %s: %s" % [name, detail]
result = false
end
end
@@ -61,4 +58,4 @@ class Puppet::Feature
end
end
-# $Id$ \ No newline at end of file
+# $Id$
diff --git a/lib/puppet/feature/rails.rb b/lib/puppet/feature/rails.rb
new file mode 100644
index 000000000..288f02f82
--- /dev/null
+++ b/lib/puppet/feature/rails.rb
@@ -0,0 +1,44 @@
+# Created by Luke Kanies on 2006-11-07.
+# Copyright (c) 2006. All rights reserved.
+
+require 'puppet/feature'
+
+Puppet.features.add(:rails) do
+ begin
+ require 'active_record'
+ rescue LoadError => detail
+ if Facter["operatingsystem"].value == "Debian" and
+ FileTest.exists?("/usr/share/rails")
+ count = 0
+ Dir.entries("/usr/share/rails").each do |dir|
+ libdir = File.join("/usr/share/rails", dir, "lib")
+ if FileTest.exists?(libdir) and ! $:.include?(libdir)
+ count += 1
+ $: << libdir
+ end
+ end
+
+ if count > 0
+ retry
+ end
+ end
+ end
+
+ # If we couldn't find it the normal way, try using a Gem.
+ unless defined? ActiveRecord
+ begin
+ require 'rubygems'
+ require_gem 'rails'
+ rescue LoadError
+ # Nothing
+ end
+ end
+
+ if defined? ActiveRecord
+ true
+ else
+ false
+ end
+end
+
+# $Id$
diff --git a/lib/puppet/parser/collector.rb b/lib/puppet/parser/collector.rb
index 61807717d..71213ee6a 100644
--- a/lib/puppet/parser/collector.rb
+++ b/lib/puppet/parser/collector.rb
@@ -6,11 +6,12 @@ class Puppet::Parser::Collector
# Collect exported objects.
def collect_exported
require 'puppet/rails'
+ Puppet.info "collecting %s" % @type
# First get everything from the export table. Just reuse our
# collect_virtual method but tell it to use 'exported? for the test.
resources = collect_virtual(true)
- count = resources.length
+ count = 0
# We're going to collect objects from rails, but we don't want any
# objects from this host.
@@ -22,28 +23,53 @@ class Puppet::Parser::Collector
else
#Puppet.info "Host %s is uninitialized" % @scope.host
end
+ Puppet.info "collecting %s" % @type
# Now look them up in the rails db. When we support attribute comparison
# and such, we'll need to vary the conditions, but this works with no
# attributes, anyway.
- Puppet::Util.benchmark(:debug, "Collected #{self.type} resources") do
+ time = Puppet::Util.thinmark do
Puppet::Rails::RailsResource.find_all_by_restype_and_exported(@type, true,
args
).each do |obj|
+ if existing = @scope.findresource(obj.restype, obj.title)
+ # See if we exported it; if so, just move on
+ if @scope.host == obj.host.name
+ next
+ else
+ # Next see if we've already collected this resource
+ if existing.rails_id == obj.id
+ # This is the one we've already collected
+ next
+ else
+ raise Puppet::ParseError,
+ "Exported resource %s[%s] cannot override local resource" %
+ [obj.restype, obj.title]
+ end
+ end
+ end
count += 1
+ begin
resource = obj.to_resource(self.scope)
# XXX Because the scopes don't expect objects to return values,
# we have to manually add our objects to the scope. This is
# uber-lame.
- scope.setresource(resource)
+ scope.setresource(resource)
+ rescue => detail
+ if Puppet[:trace]
+ puts detail.backtrace
+ end
+ raise
+ end
+ resource.exported = false
resources << resource
end
end
- scope.debug("Collected %s objects of type %s" %
- [count, @convertedtype])
+ scope.debug("Collected %s %s resources in %.2f seconds" %
+ [count, @type, time])
return resources
end
diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb
index 4480a123a..d2ec1b92c 100644
--- a/lib/puppet/parser/interpreter.rb
+++ b/lib/puppet/parser/interpreter.rb
@@ -4,6 +4,7 @@
require 'puppet'
require 'timeout'
+require 'puppet/rails'
require 'puppet/parser/parser'
require 'puppet/parser/scope'
@@ -142,7 +143,7 @@ class Puppet::Parser::Interpreter
scope.name = "top"
scope.type = "main"
- scope.host = facts["hostname"] || Facter.value("hostname")
+ scope.host = client
classes = @classes.dup
@@ -358,7 +359,7 @@ class Puppet::Parser::Interpreter
end
# The class won't always be defined during testing.
- if Puppet[:storeconfigs] and defined? ActiveRecord::Base
+ if Puppet[:storeconfigs] and Puppet.features.rails?
Puppet::Rails.init
end
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index cb339e38d..751b9c0c7 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -9,7 +9,7 @@ class Puppet::Parser::Resource
include Puppet::Util::Errors
include Puppet::Util::Logging
- attr_accessor :source, :line, :file, :scope
+ attr_accessor :source, :line, :file, :scope, :rails_id
attr_accessor :virtual, :override, :params, :translated
attr_reader :exported
diff --git a/lib/puppet/rails.rb b/lib/puppet/rails.rb
index 959ea5628..77afe6be1 100644
--- a/lib/puppet/rails.rb
+++ b/lib/puppet/rails.rb
@@ -3,36 +3,6 @@
require 'facter'
require 'puppet'
-begin
- require 'active_record'
-rescue LoadError => detail
- if Facter["operatingsystem"].value == "Debian" and
- FileTest.exists?("/usr/share/rails")
- count = 0
- Dir.entries("/usr/share/rails").each do |dir|
- libdir = File.join("/usr/share/rails", dir, "lib")
- if FileTest.exists?(libdir) and ! $:.include?(libdir)
- count += 1
- $: << libdir
- end
- end
-
- if count > 0
- retry
- end
- end
-end
-
-# If we couldn't find it the normal way, try using a Gem.
-unless defined? ActiveRecord
- begin
- require 'rubygems'
- require_gem 'rails'
- rescue LoadError
- # Nothing
- end
-end
-
module Puppet::Rails
Puppet.config.setdefaults(:puppetmaster,
:dblocation => { :default => "$statedir/clientconfigs.sqlite3",
@@ -65,11 +35,9 @@ module Puppet::Rails
# Set up our database connection. It'd be nice to have a "use" system
# that could make callbacks.
def self.init
- unless defined? ActiveRecord::Base
+ unless Puppet.features.rails?
raise Puppet::DevError, "No activerecord, cannot init Puppet::Rails"
end
-
-
# This global init does not work for testing, because we remove
# the state dir on every test.
@@ -137,7 +105,7 @@ module Puppet::Rails
end
end
-if defined? ActiveRecord::Base
+if Puppet.features.rails?
require 'puppet/rails/host'
end
diff --git a/lib/puppet/rails/rails_resource.rb b/lib/puppet/rails/rails_resource.rb
index caad1b460..0b981f963 100644
--- a/lib/puppet/rails/rails_resource.rb
+++ b/lib/puppet/rails/rails_resource.rb
@@ -22,6 +22,7 @@ class Puppet::Rails::RailsResource < ActiveRecord::Base
end
hash[:scope] = scope
hash[:source] = scope.source
+ hash[:rails_id] = self.id
obj = Puppet::Parser::Resource.new(hash)
rails_parameters.each do |param|
obj.set(param.to_resourceparam(scope.source))
diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb
index 0d409e430..6b65a4cbc 100644
--- a/lib/puppet/util.rb
+++ b/lib/puppet/util.rb
@@ -351,7 +351,7 @@ module Util
return seconds
end
- module_function :memory
+ module_function :memory, :thinmark
end
end