Control: tags -1 patch

The attached patch works for me. I did a test using
`puppet master --compile` for a given host and cross-checked the entries 
with those on my real puppet master and everything seems to be working 
fine. Also, exported resources are now being collected.

If anyone can, please give it a try :) Note that you have to install 
ruby-activerecord-deprecated-finders.

Cheers,
Apollon
From 70597df8cc7560236cff59b2835ff0341021a227 Mon Sep 17 00:00:00 2001
From: Apollon Oikonomopoulos <apoi...@debian.org>
Date: Sat, 28 Feb 2015 11:56:44 +0200
Subject: [PATCH] Storeconfigs compatibility with ActiveRecord 4
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Make ActiveRecord-based stored configs work again with ActiveRecord 4.x:

 • Use AR::Base.clear_active_connections! instead of
   AR::Base.verify_active_connections!

 • Always call AR::Base.connection as a class method, never as an
   instance method.

 • Require 'activerecord/deprecated_finders' to make all #find(:all)
   and #find_by_x methods work again.

 • Silence AR's deprecation warnings. We know we are using deprecated
   finders so these warnings are just (a lot of) noise.
---
 lib/puppet/rails.rb              | 5 ++++-
 lib/puppet/rails/fact_name.rb    | 1 +
 lib/puppet/rails/fact_value.rb   | 1 +
 lib/puppet/rails/param_value.rb  | 4 ++--
 lib/puppet/rails/resource_tag.rb | 4 ++--
 5 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/lib/puppet/rails.rb b/lib/puppet/rails.rb
index 2c97c02..adb20fb 100644
--- a/lib/puppet/rails.rb
+++ b/lib/puppet/rails.rb
@@ -8,6 +8,9 @@ module Puppet::Rails
   TIME_DEBUG = true
 
   def self.connect
+    # Silence activerecord deprecation warnings
+    ActiveSupport::Deprecation.silenced = true
+
     # This global init does not work for testing, because we remove
     # the state dir on every test.
     return if ActiveRecord::Base.connected?
@@ -26,7 +29,7 @@ module Puppet::Rails
     # As of ActiveRecord 2.2 allow_concurrency has been deprecated and no longer has any effect.
     ActiveRecord::Base.allow_concurrency = true if Puppet::Util.activerecord_version < 2.2
 
-    ActiveRecord::Base.verify_active_connections!
+    ActiveRecord::Base.clear_active_connections!
 
     begin
       args = database_arguments
diff --git a/lib/puppet/rails/fact_name.rb b/lib/puppet/rails/fact_name.rb
index 073bbcb..e5e1cff 100644
--- a/lib/puppet/rails/fact_name.rb
+++ b/lib/puppet/rails/fact_name.rb
@@ -1,4 +1,5 @@
 require 'active_record'
+require 'active_record/deprecated_finders'
 require 'puppet/rails'
 require 'puppet/rails/fact_value'
 
diff --git a/lib/puppet/rails/fact_value.rb b/lib/puppet/rails/fact_value.rb
index 918c0ac..3d69d59 100644
--- a/lib/puppet/rails/fact_value.rb
+++ b/lib/puppet/rails/fact_value.rb
@@ -1,4 +1,5 @@
 require 'active_record'
+require 'active_record/deprecated_finders'
 
 class Puppet::Rails::FactValue < ActiveRecord::Base
   belongs_to :fact_name
diff --git a/lib/puppet/rails/param_value.rb b/lib/puppet/rails/param_value.rb
index d7c88f8..e082ed8 100644
--- a/lib/puppet/rails/param_value.rb
+++ b/lib/puppet/rails/param_value.rb
@@ -48,7 +48,7 @@ class Puppet::Rails::ParamValue < ActiveRecord::Base
 
   # returns an array of hash containing all the parameters of a given resource
   def self.find_all_params_from_resource(db_resource)
-    params = db_resource.connection.select_all("SELECT v.id, v.value, v.line, v.resource_id, v.param_name_id, n.name FROM param_values v INNER JOIN param_names n ON v.param_name_id=n.id WHERE v.resource_id=#{db_resource.id}")
+    params = ActiveRecord::Base.connection.select_all("SELECT v.id, v.value, v.line, v.resource_id, v.param_name_id, n.name FROM param_values v INNER JOIN param_names n ON v.param_name_id=n.id WHERE v.resource_id=#{db_resource.id}")
     params.each do |val|
       val['value'] = unserialize_value(val['value'])
       val['line'] = val['line'] ? Integer(val['line']) : nil
@@ -59,7 +59,7 @@ class Puppet::Rails::ParamValue < ActiveRecord::Base
 
   # returns an array of hash containing all the parameters of a given host
   def self.find_all_params_from_host(db_host)
-    params = db_host.connection.select_all("SELECT v.id, v.value,  v.line, v.resource_id, v.param_name_id, n.name FROM param_values v INNER JOIN resources r ON v.resource_id=r.id INNER JOIN param_names n ON v.param_name_id=n.id WHERE r.host_id=#{db_host.id}")
+    params = ActiveRecord::Base.connection.select_all("SELECT v.id, v.value,  v.line, v.resource_id, v.param_name_id, n.name FROM param_values v INNER JOIN resources r ON v.resource_id=r.id INNER JOIN param_names n ON v.param_name_id=n.id WHERE r.host_id=#{db_host.id}")
     params.each do |val|
       val['value'] = unserialize_value(val['value'])
       val['line'] = val['line'] ? Integer(val['line']) : nil
diff --git a/lib/puppet/rails/resource_tag.rb b/lib/puppet/rails/resource_tag.rb
index 1c1aa45..1493d3e 100644
--- a/lib/puppet/rails/resource_tag.rb
+++ b/lib/puppet/rails/resource_tag.rb
@@ -8,7 +8,7 @@ class Puppet::Rails::ResourceTag < ActiveRecord::Base
 
   # returns an array of hash containing tags of resource
   def self.find_all_tags_from_resource(db_resource)
-    tags = db_resource.connection.select_all("SELECT t.id, t.resource_id, p.name FROM resource_tags t INNER JOIN puppet_tags p ON t.puppet_tag_id=p.id WHERE t.resource_id=#{db_resource.id}")
+    tags = ActiveRecord::Base.connection.select_all("SELECT t.id, t.resource_id, p.name FROM resource_tags t INNER JOIN puppet_tags p ON t.puppet_tag_id=p.id WHERE t.resource_id=#{db_resource.id}")
     tags.each do |val|
       val['resource_id'] = Integer(val['resource_id'])
     end
@@ -17,7 +17,7 @@ class Puppet::Rails::ResourceTag < ActiveRecord::Base
 
   # returns an array of hash containing tags of a host
   def self.find_all_tags_from_host(db_host)
-    tags = db_host.connection.select_all("SELECT t.id, t.resource_id, p.name FROM resource_tags t INNER JOIN resources r ON t.resource_id=r.id INNER JOIN puppet_tags p ON t.puppet_tag_id=p.id WHERE r.host_id=#{db_host.id}")
+    tags = ActiveRecord::Base.connection.select_all("SELECT t.id, t.resource_id, p.name FROM resource_tags t INNER JOIN resources r ON t.resource_id=r.id INNER JOIN puppet_tags p ON t.puppet_tag_id=p.id WHERE r.host_id=#{db_host.id}")
     tags.each do |val|
       val['resource_id'] = Integer(val['resource_id'])
     end
-- 
2.1.4

Attachment: signature.asc
Description: Digital signature

Reply via email to