[PATCH 3/3] Switching to Indirected ActiveRecord

4 views
Skip to first unread message

Luke Kanies

unread,
Apr 11, 2009, 6:36:51 PM4/11/09
to puppe...@googlegroups.com
This is mostly a configuration change, with some
code getting removed.

Signed-off-by: Luke Kanies <lu...@madstop.com>
---
lib/puppet/defaults.rb | 17 ++++++++++++++---
lib/puppet/node/catalog.rb | 1 +
lib/puppet/parser/compiler.rb | 37 -------------------------------------
spec/unit/parser/compiler.rb | 20 --------------------
4 files changed, 15 insertions(+), 60 deletions(-)

diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index e36dd70..e34d945 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -659,9 +659,20 @@ module Puppet
)

setdefaults(:puppetmasterd,
- :storeconfigs => [false,
- "Whether to store each client's configuration. This
- requires ActiveRecord from Ruby on Rails."]
+ :storeconfigs => {:default => false, :desc => "Whether to store each client's configuration. This
+ requires ActiveRecord from Ruby on Rails.",
+ :call_on_define => true, # Call our hook with the default value, so we always get the libdir set.
+ :hook => proc do |value|
+ require 'puppet/node'
+ require 'puppet/node/facts'
+ require 'puppet/node/catalog'
+ if value
+ Puppet::Node::Catalog.cache_class = :active_record
+ Puppet::Node::Facts.cache_class = :active_record
+ Puppet::Node.cache_class = :active_record
+ end
+ end
+ }
)

# This doesn't actually work right now.
diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb
index 256bfd6..3473deb 100644
--- a/lib/puppet/node/catalog.rb
+++ b/lib/puppet/node/catalog.rb
@@ -1,3 +1,4 @@
+require 'puppet/node'
require 'puppet/indirector'
require 'puppet/pgraph'
require 'puppet/transaction'
diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb
index d67b3d2..6ea80a0 100644
--- a/lib/puppet/parser/compiler.rb
+++ b/lib/puppet/parser/compiler.rb
@@ -95,10 +95,6 @@ class Puppet::Parser::Compiler

fail_on_unevaluated()

- if Puppet[:storeconfigs]
- store()
- end
-
return @catalog
end

@@ -423,39 +419,6 @@ class Puppet::Parser::Compiler
end
end

- # Store the catalog into the database.
- def store
- unless Puppet.features.rails?
- raise Puppet::Error,
- "storeconfigs is enabled but rails is unavailable"
- end
-
- unless ActiveRecord::Base.connected?
- Puppet::Rails.connect
- end
-
- # 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(@node, @catalog.vertices)
- end
-
- # Do the actual storage.
- def store_to_active_record(node, resources)
- begin
- # We store all of the objects, even the collectable ones
- benchmark(:info, "Stored catalog for #{node.name}") do
- Puppet::Rails::Host.transaction do
- Puppet::Rails::Host.store(node, resources)
- end
- end
- rescue => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
- Puppet.err "Could not store configs: %s" % detail.to_s
- end
- end
-
# Return an array of all of the unevaluated resources. These will be definitions,
# which need to get evaluated into native resources.
def unevaluated_resources
diff --git a/spec/unit/parser/compiler.rb b/spec/unit/parser/compiler.rb
index 296c8a0..eb0a489 100755
--- a/spec/unit/parser/compiler.rb
+++ b/spec/unit/parser/compiler.rb
@@ -480,26 +480,6 @@ describe Puppet::Parser::Compiler do
end
end

- describe Puppet::Parser::Compiler, "when storing compiled resources" do
-
- it "should store the resources" do
- Puppet.features.expects(:rails?).returns(true)
- Puppet::Rails.expects(:connect)
-
- @compiler.catalog.expects(:vertices).returns(:resources)
-
- @compiler.expects(:store_to_active_record).with(@node, :resources)
- @compiler.send(:store)
- end
-
- it "should store to active_record" do
- @node.expects(:name).returns("myname")
- Puppet::Rails::Host.stubs(:transaction).yields
- Puppet::Rails::Host.expects(:store).with(@node, :resources)
- @compiler.send(:store_to_active_record, @node, :resources)
- end
- end
-
describe Puppet::Parser::Compiler, "when managing resource overrides" do

before do
--
1.6.1

Brice Figureau

unread,
Apr 12, 2009, 10:58:26 AM4/12/09
to puppe...@googlegroups.com
+1

That's good to see this code removed.


--
Brice Figureau
Days of Wonder
http://www.daysofwonder.com

Reply all
Reply to author
Forward
0 new messages