diff --git a/ext/puppetstoredconfigclean.rb b/ext/puppetstoredconfigclean.rb index dcbefa816..efd0b54bf 100644 --- a/ext/puppetstoredconfigclean.rb +++ b/ext/puppetstoredconfigclean.rb @@ -1,91 +1,91 @@ #!/usr/bin/env ruby # Script to clean up stored configs for (a) given host(s) # # Credits: # Script was taken from http://reductivelabs.com/trac/puppet/attachment/wiki/UsingStoredConfiguration/kill_node_in_storedconfigs_db.rb (link no longer valid), # which haven been initially posted by James Turnbull # duritong adapted and improved the script a bit. require 'getoptlong' config = '/etc/puppet/puppet.conf' def printusage(error_code) puts "Usage: #{$0} [ list of hostnames as stored in hosts table ]" puts "\n Options:" puts "--config " exit(error_code) end opts = GetoptLong.new( [ "--config", "-c", GetoptLong::REQUIRED_ARGUMENT ], [ "--help", "-h", GetoptLong::NO_ARGUMENT ], [ "--usage", "-u", GetoptLong::NO_ARGUMENT ], [ "--version", "-v", GetoptLong::NO_ARGUMENT ] ) begin opts.each do |opt, arg| case opt when "--config" config = arg when "--help" printusage(0) when "--usage" printusage(0) when "--version" puts "#{Puppet.version}" exit end end rescue GetoptLong::InvalidOption => detail $stderr.puts "Try '#{$0} --help'" exit(1) end printusage(1) unless ARGV.size > 0 require 'puppet/rails' Puppet[:config] = config Puppet.parse_config pm_conf = Puppet.settings.instance_variable_get(:@values)[:master] adapter = pm_conf[:dbadapter] args = {:adapter => adapter, :log_level => pm_conf[:rails_loglevel]} case adapter when "sqlite3" args[:dbfile] = pm_conf[:dblocation] - when "mysql", "postgresql" + when "mysql", "mysql2", "postgresql" args[:host] = pm_conf[:dbserver] unless pm_conf[:dbserver].to_s.empty? args[:username] = pm_conf[:dbuser] unless pm_conf[:dbuser].to_s.empty? args[:password] = pm_conf[:dbpassword] unless pm_conf[:dbpassword].to_s.empty? args[:database] = pm_conf[:dbname] unless pm_conf[:dbname].to_s.empty? args[:port] = pm_conf[:dbport] unless pm_conf[:dbport].to_s.empty? socket = pm_conf[:dbsocket] args[:socket] = socket unless socket.to_s.empty? else raise ArgumentError, "Invalid db adapter #{adapter}" end args[:database] = "puppet" unless not args[:database].to_s.empty? ActiveRecord::Base.establish_connection(args) ARGV.each { |hostname| if @host = Puppet::Rails::Host.find_by_name(hostname.strip) print "Killing #{hostname}..." $stdout.flush @host.destroy puts "done." else puts "Can't find host #{hostname}." end } exit 0 diff --git a/lib/puppet/rails.rb b/lib/puppet/rails.rb index f74e63f20..c52b6871b 100644 --- a/lib/puppet/rails.rb +++ b/lib/puppet/rails.rb @@ -1,132 +1,132 @@ # Load the appropriate libraries, or set a class indicating they aren't available require 'facter' require 'puppet' require 'logger' module Puppet::Rails TIME_DEBUG = true def self.connect # This global init does not work for testing, because we remove # the state dir on every test. return if ActiveRecord::Base.connected? Puppet.settings.use(:main, :rails, :master) ActiveRecord::Base.logger = Logger.new(Puppet[:railslog]) begin loglevel = Logger.const_get(Puppet[:rails_loglevel].upcase) ActiveRecord::Base.logger.level = loglevel rescue => detail Puppet.warning "'#{Puppet[:rails_loglevel]}' is not a valid Rails log level; using debug" ActiveRecord::Base.logger.level = Logger::DEBUG end # 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! begin args = database_arguments Puppet.info "Connecting to #{args[:adapter]} database: #{args[:database]}" ActiveRecord::Base.establish_connection(args) rescue => detail puts detail.backtrace if Puppet[:trace] raise Puppet::Error, "Could not connect to database: #{detail}" end end # The arguments for initializing the database connection. def self.database_arguments adapter = Puppet[:dbadapter] args = {:adapter => adapter, :log_level => Puppet[:rails_loglevel]} case adapter when "sqlite3" args[:database] = Puppet[:dblocation] - when "mysql", "postgresql" + when "mysql", "mysql2", "postgresql" args[:host] = Puppet[:dbserver] unless Puppet[:dbserver].to_s.empty? 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 socket = Puppet[:dbsocket] args[:socket] = socket unless socket.to_s.empty? when "oracle_enhanced" 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 args end # Set up our database connection. It'd be nice to have a "use" system # that could make callbacks. def self.init raise Puppet::DevError, "No activerecord, cannot init Puppet::Rails" unless Puppet.features.rails? connect unless ActiveRecord::Base.connection.tables.include?("resources") require 'puppet/rails/database/schema' Puppet::Rails::Schema.init end migrate if Puppet[:dbmigrate] end # Migrate to the latest db schema. def self.migrate dbdir = nil $LOAD_PATH.each { |d| tmp = File.join(d, "puppet/rails/database") if FileTest.directory?(tmp) dbdir = tmp break end } raise Puppet::Error, "Could not find Puppet::Rails database dir" unless dbdir raise Puppet::Error, "Database has problems, can't migrate." unless ActiveRecord::Base.connection.tables.include?("resources") Puppet.notice "Migrating" begin ActiveRecord::Migrator.migrate(dbdir) rescue => detail puts detail.backtrace if Puppet[:trace] raise Puppet::Error, "Could not migrate database: #{detail}" end end # Tear down the database. Mostly only used during testing. def self.teardown raise Puppet::DevError, "No activerecord, cannot init Puppet::Rails" unless Puppet.features.rails? Puppet.settings.use(:master, :rails) begin ActiveRecord::Base.establish_connection(database_arguments) rescue => detail puts detail.backtrace if Puppet[:trace] raise Puppet::Error, "Could not connect to database: #{detail}" end ActiveRecord::Base.connection.tables.each do |t| ActiveRecord::Base.connection.drop_table t end end end require 'puppet/rails/host' if Puppet.features.rails? diff --git a/lib/puppet/rails/database/schema.rb b/lib/puppet/rails/database/schema.rb index 7b75f4216..3eb2589f1 100644 --- a/lib/puppet/rails/database/schema.rb +++ b/lib/puppet/rails/database/schema.rb @@ -1,131 +1,131 @@ class Puppet::Rails::Schema def self.init oldout = nil Puppet::Util.benchmark(Puppet, :notice, "Initialized database") do # We want to rewrite stdout, so we don't get migration messages. oldout = $stdout $stdout = File.open("/dev/null", "w") ActiveRecord::Schema.define do create_table :resources do |t| t.column :title, :text, :null => false t.column :restype, :string, :null => false t.column :host_id, :integer t.column :source_file_id, :integer t.column :exported, :boolean t.column :line, :integer t.column :updated_at, :datetime t.column :created_at, :datetime end add_index :resources, :host_id, :integer => true add_index :resources, :source_file_id, :integer => true # Thanks, mysql! MySQL requires a length on indexes in text fields. # So, we provide them for mysql and handle everything else specially. # Oracle doesn't index on CLOB fields, so we skip it - if Puppet[:dbadapter] == "mysql" + if ['mysql','mysql2'].include? Puppet[:dbadapter] execute "CREATE INDEX typentitle ON resources (restype,title(50));" elsif Puppet[:dbadapter] != "oracle_enhanced" add_index :resources, [:title, :restype] end create_table :source_files do |t| t.column :filename, :string t.column :path, :string t.column :updated_at, :datetime t.column :created_at, :datetime end add_index :source_files, :filename create_table :resource_tags do |t| t.column :resource_id, :integer t.column :puppet_tag_id, :integer t.column :updated_at, :datetime t.column :created_at, :datetime end add_index :resource_tags, :resource_id, :integer => true add_index :resource_tags, :puppet_tag_id, :integer => true create_table :puppet_tags do |t| t.column :name, :string t.column :updated_at, :datetime t.column :created_at, :datetime end # Oracle automatically creates a primary key index add_index :puppet_tags, :id, :integer => true if Puppet[:dbadapter] != "oracle_enhanced" create_table :hosts do |t| t.column :name, :string, :null => false t.column :ip, :string t.column :environment, :text t.column :last_compile, :datetime t.column :last_freshcheck, :datetime t.column :last_report, :datetime #Use updated_at to automatically add timestamp on save. t.column :updated_at, :datetime t.column :source_file_id, :integer t.column :created_at, :datetime end add_index :hosts, :source_file_id, :integer => true add_index :hosts, :name create_table :fact_names do |t| t.column :name, :string, :null => false t.column :updated_at, :datetime t.column :created_at, :datetime end add_index :fact_names, :name create_table :fact_values do |t| t.column :value, :text, :null => false t.column :fact_name_id, :integer, :null => false t.column :host_id, :integer, :null => false t.column :updated_at, :datetime t.column :created_at, :datetime end add_index :fact_values, :fact_name_id, :integer => true add_index :fact_values, :host_id, :integer => true create_table :param_values do |t| t.column :value, :text, :null => false t.column :param_name_id, :integer, :null => false t.column :line, :integer t.column :resource_id, :integer t.column :updated_at, :datetime t.column :created_at, :datetime end add_index :param_values, :param_name_id, :integer => true add_index :param_values, :resource_id, :integer => true create_table :param_names do |t| t.column :name, :string, :null => false t.column :updated_at, :datetime t.column :created_at, :datetime end add_index :param_names, :name create_table :inventory_nodes do |t| t.column :name, :string, :null => false t.column :timestamp, :datetime, :null => false t.column :updated_at, :datetime t.column :created_at, :datetime end add_index :inventory_nodes, :name, :unique => true create_table :inventory_facts, :id => false do |t| t.column :node_id, :integer, :null => false t.column :name, :string, :null => false t.column :value, :text, :null => false end add_index :inventory_facts, [:node_id, :name], :unique => true end end ensure $stdout.close $stdout = oldout if oldout oldout = nil end end diff --git a/spec/unit/rails_spec.rb b/spec/unit/rails_spec.rb index fe7fd8e29..60062db1c 100755 --- a/spec/unit/rails_spec.rb +++ b/spec/unit/rails_spec.rb @@ -1,313 +1,244 @@ #!/usr/bin/env rspec require 'spec_helper' require 'puppet/rails' describe Puppet::Rails, "when initializing any connection", :if => Puppet.features.rails? do before do Puppet.settings.stubs(:use) @logger = mock 'logger' @logger.stub_everything Logger.stubs(:new).returns(@logger) ActiveRecord::Base.stubs(:logger).returns(@logger) ActiveRecord::Base.stubs(:connected?).returns(false) end it "should use settings" do Puppet.settings.expects(:use).with(:main, :rails, :master) Puppet::Rails.connect end it "should set up a logger with the appropriate Rails log file" do logger = mock 'logger' Logger.expects(:new).with(Puppet[:railslog]).returns(logger) ActiveRecord::Base.expects(:logger=).with(logger) Puppet::Rails.connect end it "should set the log level to whatever the value is in the settings" do Puppet.settings.stubs(:use) Puppet.settings.stubs(:value).with(:rails_loglevel).returns("debug") Puppet.settings.stubs(:value).with(:railslog).returns("/my/file") logger = mock 'logger' Logger.stubs(:new).returns(logger) ActiveRecord::Base.stubs(:logger).returns(logger) logger.expects(:level=).with(Logger::DEBUG) ActiveRecord::Base.stubs(:allow_concurrency=) ActiveRecord::Base.stubs(:verify_active_connections!) ActiveRecord::Base.stubs(:establish_connection) Puppet::Rails.stubs(:database_arguments).returns({}) Puppet::Rails.connect end describe "ActiveRecord Version" do it "should set ActiveRecord::Base.allow_concurrency if ActiveRecord is 2.1" do Puppet::Util.stubs(:activerecord_version).returns(2.1) ActiveRecord::Base.expects(:allow_concurrency=).with(true) Puppet::Rails.connect end it "should not set ActiveRecord::Base.allow_concurrency if ActiveRecord is >= 2.2" do Puppet::Util.stubs(:activerecord_version).returns(2.2) ActiveRecord::Base.expects(:allow_concurrency=).never Puppet::Rails.connect end end it "should call ActiveRecord::Base.verify_active_connections!" do ActiveRecord::Base.expects(:verify_active_connections!) Puppet::Rails.connect end it "should call ActiveRecord::Base.establish_connection with database_arguments" do Puppet::Rails.expects(:database_arguments).returns({}) ActiveRecord::Base.expects(:establish_connection) Puppet::Rails.connect end end describe Puppet::Rails, "when initializing a sqlite3 connection", :if => Puppet.features.rails? do it "should provide the adapter, log_level, and database arguments" do Puppet.settings.expects(:value).with(:dbadapter).returns("sqlite3") Puppet.settings.expects(:value).with(:rails_loglevel).returns("testlevel") Puppet.settings.expects(:value).with(:dblocation).returns("testlocation") Puppet::Rails.database_arguments.should == { :adapter => "sqlite3", :log_level => "testlevel", :database => "testlocation" } end end -describe Puppet::Rails, "when initializing a mysql connection", :if => Puppet.features.rails? do - it "should provide the adapter, log_level, and host, port, username, password, database, and reconnect 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(: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("") - - Puppet::Rails.database_arguments.should == { - :adapter => "mysql", - :log_level => "testlevel", - :host => "testserver", - :username => "testuser", - :password => "testpassword", - :pool => pool_size, - :database => "testname", - :reconnect => true - } - end - - it "should provide the adapter, log_level, and host, port, username, password, database, socket, connections, and reconnect 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(: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") - - Puppet::Rails.database_arguments.should == { - :adapter => "mysql", - :log_level => "testlevel", - :host => "testserver", - :port => "9999", - :username => "testuser", - :password => "testpassword", - :pool => pool_size, - :database => "testname", - :socket => "testsocket", - :reconnect => true - } - end - - it "should provide the adapter, log_level, and host, port, 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(: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") - - Puppet::Rails.database_arguments.should == { - :adapter => "mysql", - :log_level => "testlevel", - :host => "testserver", - :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", :if => Puppet.features.rails? do - it "should provide the adapter, log_level, and host, port, username, password, connections, and database arguments" do - Puppet.settings.stubs(:value).with(:dbadapter).returns("postgresql") - 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(:dbconnections).returns((pool_size = 200).to_s) - Puppet.settings.stubs(:value).with(:dbname).returns("testname") - Puppet.settings.stubs(:value).with(:dbsocket).returns("") - - Puppet::Rails.database_arguments.should == { - :adapter => "postgresql", - :log_level => "testlevel", - :host => "testserver", - :port => "9999", - :username => "testuser", - :password => "testpassword", - :pool => pool_size, - :database => "testname", - :reconnect => true - } - end +['mysql','mysql2','postgresql'].each do |dbadapter| + describe Puppet::Rails, "when initializing a #{dbadapter} connection", :if => Puppet.features.rails? do + it "should provide the adapter, log_level, and host, port, username, password, database, and reconnect arguments" do + Puppet.settings.stubs(:value).with(:dbadapter).returns(dbadapter) + Puppet.settings.stubs(:value).with(:rails_loglevel).returns("testlevel") + Puppet.settings.stubs(:value).with(:dbserver).returns("testserver") + 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("") + + Puppet::Rails.database_arguments.should == { + :adapter => dbadapter, + :log_level => "testlevel", + :host => "testserver", + :username => "testuser", + :password => "testpassword", + :pool => pool_size, + :database => "testname", + :reconnect => true + } + end - it "should provide the adapter, log_level, and host, port, username, password, database, connections, and socket arguments" do - Puppet.settings.stubs(:value).with(:dbadapter).returns("postgresql") - 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(:dbconnections).returns((pool_size = 122).to_s) - Puppet.settings.stubs(:value).with(:dbname).returns("testname") - Puppet.settings.stubs(:value).with(:dbsocket).returns("testsocket") + it "should provide the adapter, log_level, and host, port, username, password, database, socket, connections, and reconnect arguments" do + Puppet.settings.stubs(:value).with(:dbadapter).returns(dbadapter) + 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(:dbconnections).returns((pool_size = 12).to_s) + Puppet.settings.stubs(:value).with(:dbname).returns("testname") + Puppet.settings.stubs(:value).with(:dbsocket).returns("testsocket") + + Puppet::Rails.database_arguments.should == { + :adapter => dbadapter, + :log_level => "testlevel", + :host => "testserver", + :port => "9999", + :username => "testuser", + :password => "testpassword", + :pool => pool_size, + :database => "testname", + :socket => "testsocket", + :reconnect => true + } + end - Puppet::Rails.database_arguments.should == { - :adapter => "postgresql", - :log_level => "testlevel", - :host => "testserver", - :port => "9999", - :username => "testuser", - :password => "testpassword", - :pool => pool_size, - :database => "testname", - :socket => "testsocket", - :reconnect => true - } - end + it "should provide the adapter, log_level, and host, port, username, password, database, socket, and connections arguments" do + Puppet.settings.stubs(:value).with(:dbadapter).returns(dbadapter) + 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(:dbconnections).returns((pool_size = 23).to_s) + Puppet.settings.stubs(:value).with(:dbname).returns("testname") + Puppet.settings.stubs(:value).with(:dbsocket).returns("testsocket") + + Puppet::Rails.database_arguments.should == { + :adapter => dbadapter, + :log_level => "testlevel", + :host => "testserver", + :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") + it "should not provide the pool if dbconnections is 0, '0', or ''" do + Puppet.settings.stubs(:value).with(:dbadapter).returns(dbadapter) + 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('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) + Puppet.settings.stubs(:value).with(:dbconnections).returns('') + Puppet::Rails.database_arguments.should_not be_include(:pool) + end end end describe Puppet::Rails, "when initializing an Oracle connection", :if => Puppet.features.rails? do it "should provide the adapter, log_level, and username, password, and database arguments" do Puppet.settings.stubs(:value).with(:dbadapter).returns("oracle_enhanced") 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 == { :adapter => "oracle_enhanced", :log_level => "testlevel", :username => "testuser", :password => "testpassword", :pool => pool_size, :database => "testname" } end it "should provide the adapter, log_level, and host, username, password, database and socket arguments" do Puppet.settings.stubs(:value).with(:dbadapter).returns("oracle_enhanced") 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 == { :adapter => "oracle_enhanced", :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(:dbadapter).returns("oracle_enhanced") 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