summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/defaults.rb2
-rw-r--r--lib/puppet/rails.rb2
-rwxr-xr-xspec/unit/rails_spec.rb74
3 files changed, 78 insertions, 0 deletions
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index 72b1af188..b8437fe29 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -663,6 +663,8 @@ module Puppet
used when networked databases are used."],
:dbpassword => [ "puppet", "The database password for caching. Only
used when networked databases are used."],
+ :dbconnections => [ '', "The number of database connections for networked
+ databases. Will be ignored unless the value is a positive integer."],
:dbsocket => [ "", "The database socket location. Only used when networked
databases are used. Will be ignored if the value is an empty string."],
:railslog => {:default => "$logdir/rails.log",
diff --git a/lib/puppet/rails.rb b/lib/puppet/rails.rb
index 44e7a8343..74805bb6f 100644
--- a/lib/puppet/rails.rb
+++ b/lib/puppet/rails.rb
@@ -52,6 +52,7 @@ module Puppet::Rails
args[:port] = Puppet[:dbport] unless Puppet[:dbport].to_s.empty?
args[:username] = Puppet[:dbuser] unless Puppet[:dbuser].to_s.empty?
args[:password] = Puppet[:dbpassword] unless Puppet[:dbpassword].to_s.empty?
+ args[:pool] = Puppet[:dbconnections].to_i unless Puppet[:dbconnections].to_i <= 0
args[:database] = Puppet[:dbname]
args[:reconnect]= true
@@ -61,6 +62,7 @@ module Puppet::Rails
args[:database] = Puppet[:dbname] unless Puppet[:dbname].to_s.empty?
args[:username] = Puppet[:dbuser] unless Puppet[:dbuser].to_s.empty?
args[:password] = Puppet[:dbpassword] unless Puppet[:dbpassword].to_s.empty?
+ args[:pool] = Puppet[:dbconnections].to_i unless Puppet[:dbconnections].to_i <= 0
else
raise ArgumentError, "Invalid db adapter #{adapter}"
end
diff --git a/spec/unit/rails_spec.rb b/spec/unit/rails_spec.rb
index 8dfc09b4a..d30e52b8a 100755
--- a/spec/unit/rails_spec.rb
+++ b/spec/unit/rails_spec.rb
@@ -103,6 +103,7 @@ describe Puppet::Rails, "when initializing a mysql connection" do
Puppet.settings.stubs(:value).with(:dbport).returns("")
Puppet.settings.stubs(:value).with(:dbuser).returns("testuser")
Puppet.settings.stubs(:value).with(:dbpassword).returns("testpassword")
+ Puppet.settings.stubs(:value).with(:dbconnections).returns((pool_size = 45).to_s)
Puppet.settings.stubs(:value).with(:dbname).returns("testname")
Puppet.settings.stubs(:value).with(:dbsocket).returns("")
@@ -112,6 +113,7 @@ describe Puppet::Rails, "when initializing a mysql connection" do
:host => "testserver",
:username => "testuser",
:password => "testpassword",
+ :pool => pool_size,
:database => "testname",
:reconnect => true
}
@@ -124,6 +126,7 @@ describe Puppet::Rails, "when initializing a mysql connection" do
Puppet.settings.stubs(:value).with(:dbport).returns("9999")
Puppet.settings.stubs(:value).with(:dbuser).returns("testuser")
Puppet.settings.stubs(:value).with(:dbpassword).returns("testpassword")
+ Puppet.settings.stubs(:value).with(:dbconnections).returns((pool_size = 12).to_s)
Puppet.settings.stubs(:value).with(:dbname).returns("testname")
Puppet.settings.stubs(:value).with(:dbsocket).returns("testsocket")
@@ -134,6 +137,7 @@ describe Puppet::Rails, "when initializing a mysql connection" do
:port => "9999",
:username => "testuser",
:password => "testpassword",
+ :pool => pool_size,
:database => "testname",
:socket => "testsocket",
:reconnect => true
@@ -147,6 +151,7 @@ describe Puppet::Rails, "when initializing a mysql connection" do
Puppet.settings.stubs(:value).with(:dbport).returns("9999")
Puppet.settings.stubs(:value).with(:dbuser).returns("testuser")
Puppet.settings.stubs(:value).with(:dbpassword).returns("testpassword")
+ Puppet.settings.stubs(:value).with(:dbconnections).returns((pool_size = 23).to_s)
Puppet.settings.stubs(:value).with(:dbname).returns("testname")
Puppet.settings.stubs(:value).with(:dbsocket).returns("testsocket")
@@ -157,11 +162,32 @@ describe Puppet::Rails, "when initializing a mysql connection" do
:port => "9999",
:username => "testuser",
:password => "testpassword",
+ :pool => pool_size,
:database => "testname",
:socket => "testsocket",
:reconnect => true
}
end
+
+ it "should not provide the pool if dbconnections is 0, '0', or ''" 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(:dbport).returns("9999")
+ 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(0)
+ Puppet::Rails.database_arguments.should_not be_include :pool
+
+ Puppet.settings.stubs(:value).with(:dbconnections).returns('0')
+ Puppet::Rails.database_arguments.should_not be_include :pool
+
+ Puppet.settings.stubs(:value).with(:dbconnections).returns('')
+ Puppet::Rails.database_arguments.should_not be_include :pool
+ end
end
describe Puppet::Rails, "when initializing a postgresql connection" do
@@ -174,6 +200,7 @@ describe Puppet::Rails, "when initializing a postgresql connection" do
Puppet.settings.stubs(:value).with(:dbport).returns("9999")
Puppet.settings.stubs(:value).with(:dbuser).returns("testuser")
Puppet.settings.stubs(:value).with(:dbpassword).returns("testpassword")
+ Puppet.settings.stubs(:value).with(:dbconnections).returns((pool_size = 200).to_s)
Puppet.settings.stubs(:value).with(:dbname).returns("testname")
Puppet.settings.stubs(:value).with(:dbsocket).returns("")
@@ -184,6 +211,7 @@ describe Puppet::Rails, "when initializing a postgresql connection" do
:port => "9999",
:username => "testuser",
:password => "testpassword",
+ :pool => pool_size,
:database => "testname",
:reconnect => true
}
@@ -196,6 +224,7 @@ describe Puppet::Rails, "when initializing a postgresql connection" do
Puppet.settings.stubs(:value).with(:dbport).returns("9999")
Puppet.settings.stubs(:value).with(:dbuser).returns("testuser")
Puppet.settings.stubs(:value).with(:dbpassword).returns("testpassword")
+ Puppet.settings.stubs(:value).with(:dbconnections).returns((pool_size = 122).to_s)
Puppet.settings.stubs(:value).with(:dbname).returns("testname")
Puppet.settings.stubs(:value).with(:dbsocket).returns("testsocket")
@@ -206,11 +235,32 @@ describe Puppet::Rails, "when initializing a postgresql connection" do
:port => "9999",
:username => "testuser",
:password => "testpassword",
+ :pool => pool_size,
:database => "testname",
:socket => "testsocket",
:reconnect => true
}
end
+
+ it "should not provide the pool if dbconnections is 0, '0', or ''" 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(:dbport).returns("9999")
+ 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(0)
+ Puppet::Rails.database_arguments.should_not be_include :pool
+
+ Puppet.settings.stubs(:value).with(:dbconnections).returns('0')
+ Puppet::Rails.database_arguments.should_not be_include :pool
+
+ Puppet.settings.stubs(:value).with(:dbconnections).returns('')
+ Puppet::Rails.database_arguments.should_not be_include :pool
+ end
end
describe Puppet::Rails, "when initializing an Oracle connection" do
@@ -221,6 +271,7 @@ describe Puppet::Rails, "when initializing an Oracle connection" do
Puppet.settings.stubs(:value).with(:rails_loglevel).returns("testlevel")
Puppet.settings.stubs(:value).with(:dbuser).returns("testuser")
Puppet.settings.stubs(:value).with(:dbpassword).returns("testpassword")
+ Puppet.settings.stubs(:value).with(:dbconnections).returns((pool_size = 123).to_s)
Puppet.settings.stubs(:value).with(:dbname).returns("testname")
Puppet::Rails.database_arguments.should == {
@@ -228,6 +279,7 @@ describe Puppet::Rails, "when initializing an Oracle connection" do
:log_level => "testlevel",
:username => "testuser",
:password => "testpassword",
+ :pool => pool_size,
:database => "testname"
}
end
@@ -237,6 +289,7 @@ describe Puppet::Rails, "when initializing an Oracle connection" do
Puppet.settings.stubs(:value).with(:rails_loglevel).returns("testlevel")
Puppet.settings.stubs(:value).with(:dbuser).returns("testuser")
Puppet.settings.stubs(:value).with(:dbpassword).returns("testpassword")
+ Puppet.settings.stubs(:value).with(:dbconnections).returns((pool_size = 124).to_s)
Puppet.settings.stubs(:value).with(:dbname).returns("testname")
Puppet::Rails.database_arguments.should == {
@@ -244,7 +297,28 @@ describe Puppet::Rails, "when initializing an Oracle connection" do
:log_level => "testlevel",
:username => "testuser",
:password => "testpassword",
+ :pool => pool_size,
:database => "testname"
}
end
+
+ it "should not provide the pool if dbconnections is 0, '0', or ''" 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(:dbport).returns("9999")
+ 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(0)
+ Puppet::Rails.database_arguments.should_not be_include :pool
+
+ Puppet.settings.stubs(:value).with(:dbconnections).returns('0')
+ Puppet::Rails.database_arguments.should_not be_include :pool
+
+ Puppet.settings.stubs(:value).with(:dbconnections).returns('')
+ Puppet::Rails.database_arguments.should_not be_include :pool
+ end
end