summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser
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/parser
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/parser')
-rw-r--r--lib/puppet/parser/collector.rb36
-rw-r--r--lib/puppet/parser/interpreter.rb5
-rw-r--r--lib/puppet/parser/resource.rb2
3 files changed, 35 insertions, 8 deletions
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