From: Richard Soderberg <[email protected]>

This sets the ActiveRecords connection pool size, when connecting to remote 
databases (mysql, postgres).  default is 0; the 'pool' argument is only passed 
to ActiveRecords when the value is 1 or greater.

Signed-off-by: James Turnbull <[email protected]>
---
 ext/puppetstoredconfigclean.rb |    2 ++
 lib/puppet/defaults.rb         |    3 +++
 lib/puppet/rails.rb            |   14 ++++++++++----
 man/man8/puppet.conf.8         |    4 ++++
 spec/unit/rails.rb             |   22 ++++++++++++++++++++++
 5 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/ext/puppetstoredconfigclean.rb b/ext/puppetstoredconfigclean.rb
index 439d743..978e083 100644
--- a/ext/puppetstoredconfigclean.rb
+++ b/ext/puppetstoredconfigclean.rb
@@ -66,6 +66,8 @@ case adapter
         args[:database] = pm_conf[:dbname] unless pm_conf[:dbname].to_s.empty?
         socket          = pm_conf[:dbsocket]
         args[:socket]   = socket unless socket.to_s.empty?
+        connections     = pm_conf[:dbconnections].to_i
+        args[:pool]     = connections if connections > 0
     else
         raise ArgumentError, "Invalid db adapter %s" % adapter
 end
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index ef194bc..9d992dd 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -655,6 +655,9 @@ module Puppet
             used when networked databases are used."],
         :dbsocket => [ "", "The database socket location. Only used when 
networked
             databases are used.  Will be ignored if the value is an empty 
string."],
+        :dbconnections => [ 0, "The number of database connections. Only used 
when
+            networked databases are used.  Will be ignored if the value is an 
empty
+            string or is less than 1."],
         :railslog => {:default => "$logdir/rails.log",
             :mode => 0600,
             :owner => "service",
diff --git a/lib/puppet/rails.rb b/lib/puppet/rails.rb
index ec2d618..c941d8f 100644
--- a/lib/puppet/rails.rb
+++ b/lib/puppet/rails.rb
@@ -51,10 +51,16 @@ module Puppet::Rails
 
             socket          = Puppet[:dbsocket]
             args[:socket]   = socket unless socket.empty?
-       when "oracle_enhanced":
-           args[:database] = Puppet[:dbname] unless Puppet[:dbname].empty?
-           args[:username] = Puppet[:dbuser] unless Puppet[:dbuser].empty?
-           args[:password] = Puppet[:dbpassword] unless 
Puppet[:dbpassword].empty?
+               
+            connections     = Puppet[:dbconnections].to_i
+            args[:pool]     = connections if connections > 0 
+        when "oracle_enhanced":
+               args[:database] = Puppet[:dbname] unless Puppet[:dbname].empty?
+               args[:username] = Puppet[:dbuser] unless Puppet[:dbuser].empty?
+               args[:password] = Puppet[:dbpassword] unless 
Puppet[:dbpassword].empty?
+
+            connections     = Puppet[:dbconnections].to_i
+            args[:pool]     = connections if connections > 0
         else
             raise ArgumentError, "Invalid db adapter %s" % adapter
         end
diff --git a/man/man8/puppet.conf.8 b/man/man8/puppet.conf.8
index 21c94f8..75577b9 100644
--- a/man/man8/puppet.conf.8
+++ b/man/man8/puppet.conf.8
@@ -588,6 +588,10 @@ The type of database to use.
 Default: sqlite3
 
 
+.SS dbconnections
+The number of database connections. Only used when networked databases are 
used.  Will be ignored if the value is an empty string or is less than 1.
+
+
 .SS dblocation
 The database cache for client configurations.  Used for querying within the 
language.
 
diff --git a/spec/unit/rails.rb b/spec/unit/rails.rb
index d838f0b..8ecd77a 100755
--- a/spec/unit/rails.rb
+++ b/spec/unit/rails.rb
@@ -117,6 +117,28 @@ describe Puppet::Rails, "when initializing a mysql 
connection" do
             :socket => "testsocket"
         }
     end
+
+    it "should provide the adapter, log_level, and host, username, password, 
database, socket, and connections arguments" do
+        Puppet.settings.stubs(:value).with(:dbadapter).returns("mysql")
+        
Puppet.settings.stubs(:value).with(:rails_loglevel).returns("testlevel")
+        Puppet.settings.stubs(:value).with(:dbserver).returns("testserver")
+        Puppet.settings.stubs(:value).with(:dbuser).returns("testuser")
+        Puppet.settings.stubs(:value).with(:dbpassword).returns("testpassword")
+        Puppet.settings.stubs(:value).with(:dbname).returns("testname")
+        Puppet.settings.stubs(:value).with(:dbsocket).returns("testsocket")
+        Puppet.settings.stubs(:value).with(:dbconnections).returns(1)
+
+        Puppet::Rails.database_arguments.should == {
+            :adapter => "mysql",
+            :log_level => "testlevel",
+            :host => "testserver",
+            :username => "testuser",
+            :password => "testpassword",
+            :database => "testname",
+            :socket => "testsocket",
+            :pool => 1
+        }
+    end
 end
 
 describe Puppet::Rails, "when initializing a postgresql connection" do
-- 
1.6.5.2

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.


Reply via email to