summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2009-07-09 20:59:41 +0200
committerJames Turnbull <james@lovedthanlost.net>2009-07-18 10:31:10 +1000
commitb2a008e30ea57f0c94d605de855c45c0fdf0e5ce (patch)
treec64527d7d056c9d67e0ed78e44234b07e3082c36 /lib/puppet
parent8f8240763b0a8ab74b5b78eeb2372a2aa7848049 (diff)
downloadpuppet-b2a008e30ea57f0c94d605de855c45c0fdf0e5ce.tar.gz
puppet-b2a008e30ea57f0c94d605de855c45c0fdf0e5ce.tar.xz
puppet-b2a008e30ea57f0c94d605de855c45c0fdf0e5ce.zip
Fix #2391 - Exported resources never make to the storeconfigs db
The issue is that when we convert Puppet::Parser::Resource catalog to a Puppet::Resource catalog before storing it to the database, we don't allow virtual resource to be converted. Unfortunately exported resources are virtual by design, and as such aren't converted, and we lose them, so it isn't possible to store them in the database. Unfortunately, the client will get the exported resources too. The fix is dual-fold: * we make sure exported resource are skipped when the transaction is applied as a last safeguard * we filter-out the catalog through the catalog compiler terminus before the catalog is returned to the client Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/indirector/catalog/compiler.rb6
-rw-r--r--lib/puppet/indirector/indirection.rb2
-rw-r--r--lib/puppet/resource/catalog.rb14
-rw-r--r--lib/puppet/transaction.rb2
-rw-r--r--lib/puppet/type.rb9
5 files changed, 30 insertions, 3 deletions
diff --git a/lib/puppet/indirector/catalog/compiler.rb b/lib/puppet/indirector/catalog/compiler.rb
index c9a216da1..12da4de32 100644
--- a/lib/puppet/indirector/catalog/compiler.rb
+++ b/lib/puppet/indirector/catalog/compiler.rb
@@ -41,6 +41,12 @@ class Puppet::Resource::Catalog::Compiler < Puppet::Indirector::Code
end
end
+ # filter-out a catalog to remove exported resources
+ def filter(catalog)
+ return catalog.filter { |r| r.exported? } if catalog.respond_to?(:filter)
+ catalog
+ end
+
def initialize
set_server_facts
end
diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb
index f16a9b5dc..dc7e58f36 100644
--- a/lib/puppet/indirector/indirection.rb
+++ b/lib/puppet/indirector/indirection.rb
@@ -202,7 +202,7 @@ class Puppet::Indirector::Indirection
cache.save request(:save, result, *args)
end
- return result
+ return terminus.respond_to?(:filter) ? terminus.filter(result) : result
end
return nil
diff --git a/lib/puppet/resource/catalog.rb b/lib/puppet/resource/catalog.rb
index 42e92f407..bb82906f3 100644
--- a/lib/puppet/resource/catalog.rb
+++ b/lib/puppet/resource/catalog.rb
@@ -468,6 +468,13 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
to_catalog :to_resource
end
+ # filter out the catalog, applying +block+ to each resource.
+ # If the block result is false, the resource will
+ # be kept otherwise it will be skipped
+ def filter(&block)
+ to_catalog :to_resource, &block
+ end
+
# Store the classes in the classfile.
def write_class_file
begin
@@ -534,7 +541,8 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
map = {}
vertices.each do |resource|
- next if resource.respond_to?(:virtual?) and resource.virtual?
+ next if virtual_not_exported?(resource)
+ next if block_given? and yield resource
#This is hackity hack for 1094
#Aliases aren't working in the ral catalog because the current instance of the resource
@@ -589,4 +597,8 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
return result
end
+
+ def virtual_not_exported?(resource)
+ resource.respond_to?(:virtual?) and resource.virtual? and (resource.respond_to?(:exported?) and not resource.exported?)
+ end
end
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index f09ca804b..ea283d8bb 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -592,6 +592,8 @@ class Transaction
resource.debug "Not scheduled"
elsif failed_dependencies?(resource)
resource.warning "Skipping because of failed dependencies"
+ elsif resource.exported?
+ resource.debug "Skipping because exported"
else
return false
end
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 6c41d79e3..91f991814 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -1847,6 +1847,9 @@ class Type
# The catalog that this resource is stored in.
attr_accessor :catalog
+ # is the resource exported
+ attr_accessor :exported
+
# create a log at specified level
def log(msg)
Puppet::Util::Log.create(
@@ -1880,7 +1883,7 @@ class Type
self.title = resource.ref
end
- [:file, :line, :catalog].each do |getter|
+ [:file, :line, :catalog, :exported].each do |getter|
setter = getter.to_s + "="
if val = resource.send(getter)
self.send(setter, val)
@@ -2061,6 +2064,10 @@ class Type
return trans
end
+ def exported?
+ exported
+ end
+
end # Puppet::Type
end