summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-12-15 00:11:00 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-12-15 00:11:00 +0000
commit0cd579997a8ea619968c58a39493d28b9af87e6d (patch)
tree7dae1fec31ee2545b98fd10c0a581c641270c950
parent6d9ae0cf32f43cbcffa2ac8fb355c65d8ceeb9a0 (diff)
downloadpuppet-0cd579997a8ea619968c58a39493d28b9af87e6d.tar.gz
puppet-0cd579997a8ea619968c58a39493d28b9af87e6d.tar.xz
puppet-0cd579997a8ea619968c58a39493d28b9af87e6d.zip
Some rails modifications
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1931 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/rails.rb10
-rw-r--r--lib/puppet/rails/database/01_puppet_initialize.rb45
-rw-r--r--lib/puppet/rails/host.rb33
-rw-r--r--test/lib/puppettest/railstesting.rb4
-rwxr-xr-xtest/rails/rails.rb17
5 files changed, 38 insertions, 71 deletions
diff --git a/lib/puppet/rails.rb b/lib/puppet/rails.rb
index 90330c2f2..2ad25a003 100644
--- a/lib/puppet/rails.rb
+++ b/lib/puppet/rails.rb
@@ -12,7 +12,8 @@ module Puppet::Rails
:desc => "The database cache for client configurations. Used for
querying within the language."
},
- :dbadapter => [ "mysql", "The type of database to use." ],
+ :dbadapter => [ "sqlite3", "The type of database to use." ],
+ :dbmigrate => [ false, "Whether to automatically migrate the database." ],
:dbname => [ "puppet", "The name of the database to use." ],
:dbserver => [ "localhost", "The database server for Client caching. Only
used when networked databases are used."],
@@ -108,20 +109,19 @@ module Puppet::Rails
end
unless ActiveRecord::Base.connection.tables.include?("resources")
require 'puppet/rails/database/schema'
- Puppet::Rails::Schema.init
- #puts "Database initialized: #{@inited.inspect} "
+ Puppet::Rails::Schema.init
end
@inited = true
end
ActiveRecord::Base.logger = Logger.new(Puppet[:railslog])
- if Puppet[:dbadapter] == "sqlite3" and ! FileTest.exists?(Puppet[:dblocation])
-
+ if Puppet[:dbmigrate]
dbdir = nil
$:.each { |d|
tmp = File.join(d, "puppet/rails/database")
if FileTest.directory?(tmp)
dbdir = tmp
+ break
end
}
diff --git a/lib/puppet/rails/database/01_puppet_initialize.rb b/lib/puppet/rails/database/01_puppet_initialize.rb
deleted file mode 100644
index 485634004..000000000
--- a/lib/puppet/rails/database/01_puppet_initialize.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-class PuppetInitialize < ActiveRecord::Migration
- require 'sqlite3'
-
- def self.up
- if ActiveRecord::Migration.respond_to?(:verbose)
- ActiveRecord::Migration.verbose = false
- end
-
- # 'type' cannot be a column name, apparently
- create_table :rails_resources do |table|
- table.column :title, :string, :null => false
- table.column :restype, :string, :null => false
- table.column :tags, :string
- table.column :file, :string
- table.column :line, :integer
- table.column :host_id, :integer
- table.column :exported, :boolean
- end
-
- create_table :rails_parameters do |table|
- table.column :name, :string, :null => false
- table.column :value, :string, :null => false
- table.column :file, :string
- table.column :line, :integer
- table.column :rails_resource_id, :integer
- end
-
- create_table :hosts do |table|
- table.column :name, :string, :null => false
- table.column :ip, :string
- table.column :facts, :string
- table.column :connect, :date
- table.column :success, :date
- table.column :classes, :string
- end
- end
-
- def self.down
- drop_table :rails_resources
- drop_table :rails_parameters
- drop_table :hosts
- end
-end
-
-# $Id$
diff --git a/lib/puppet/rails/host.rb b/lib/puppet/rails/host.rb
index dd6ffce0e..441b9ee54 100644
--- a/lib/puppet/rails/host.rb
+++ b/lib/puppet/rails/host.rb
@@ -36,7 +36,10 @@ class Puppet::Rails::Host < ActiveRecord::Base
if hash[:facts].include?("ipaddress")
args[:ip] = hash[:facts]["ipaddress"]
end
- host = self.find_or_create_by_name(hash[:facts]["hostname"], args)
+ host = nil
+ Puppet::Util.benchmark(:info, "Found/created host") do
+ host = self.find_or_create_by_name(hash[:facts]["hostname"], args)
+ end
hash[:facts].each do |name, value|
fn = host.fact_names.find_or_create_by_name(name)
@@ -48,27 +51,29 @@ class Puppet::Rails::Host < ActiveRecord::Base
raise ArgumentError, "You must pass resources"
end
- typenames = []
+ typenames = []
Puppet::Type.loadall
Puppet::Type.eachtype do |type|
typenames << type.name.to_s
end
- hash[:resources].each do |resource|
- resargs = resource.to_hash.stringify_keys
+ Puppet::Util.benchmark(:info, "Converted resources") do
+ hash[:resources].each do |resource|
+ resargs = resource.to_hash.stringify_keys
- if typenames.include?(resource.type)
- rtype = "Puppet#{resource.type.to_s.capitalize}"
- end
+ if typenames.include?(resource.type)
+ rtype = "Puppet#{resource.type.to_s.capitalize}"
+ end
- res = host.resources.find_or_create_by_title(resource[:title])
- res.type = rtype
- res.save
- resargs.each do |param, value|
- pn = res.param_names.find_or_create_by_name(param)
- pv = pn.param_values.find_or_create_by_value(value)
- res.param_names << pn
+ res = host.resources.find_or_create_by_title(resource[:title])
+ res.type = rtype
+ res.save
+ resargs.each do |param, value|
+ pn = res.param_names.find_or_create_by_name(param)
+ pv = pn.param_values.find_or_create_by_value(value)
+ res.param_names << pn
+ end
end
end
diff --git a/test/lib/puppettest/railstesting.rb b/test/lib/puppettest/railstesting.rb
index 3b65f5b34..baac6e03a 100644
--- a/test/lib/puppettest/railstesting.rb
+++ b/test/lib/puppettest/railstesting.rb
@@ -8,7 +8,9 @@ module PuppetTest::RailsTesting
end
def railsteardown
- Puppet::Rails.teardown
+ if Puppet[:dbadapter] != "sqlite3"
+ Puppet::Rails.teardown
+ end
end
def railsresource(type = "file", title = "/tmp/testing", params = {})
diff --git a/test/rails/rails.rb b/test/rails/rails.rb
index 381150be3..05fad4c87 100755
--- a/test/rails/rails.rb
+++ b/test/rails/rails.rb
@@ -24,7 +24,17 @@ class TestRails < Test::Unit::TestCase
end
# Don't do any tests w/out this class
- if defined? ActiveRecord::Base
+ if Puppet.features.rails?
+ def setup
+ super
+ railsinit
+ end
+
+ def teardown
+ super
+ railsteardown
+ end
+
def test_hostcache
railsinit
@interp, @scope, @source = mkclassframing
@@ -38,11 +48,6 @@ class TestRails < Test::Unit::TestCase
# Now collect our facts
facts = Facter.to_hash
- assert_nothing_raised {
- Puppet::Rails.teardown
- Puppet::Rails.init
- }
-
# Now try storing our crap
host = nil
assert_nothing_raised {