diff options
| author | James Turnbull <james@lovedthanlost.net> | 2008-03-03 11:59:14 +1100 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2008-03-03 11:59:14 +1100 |
| commit | 281448fb47a7c88bf8d1c3222d03264ecfaeb183 (patch) | |
| tree | 1e8bb91ed20fd1385c63cff8d5aa77db7eb1f68d | |
| parent | f1d75c8bc2604ea396c6d88ba7eef866f48f6046 (diff) | |
| parent | ba803a1fb8190997f277b83d50c531b446b2a67f (diff) | |
| download | puppet-281448fb47a7c88bf8d1c3222d03264ecfaeb183.tar.gz puppet-281448fb47a7c88bf8d1c3222d03264ecfaeb183.tar.xz puppet-281448fb47a7c88bf8d1c3222d03264ecfaeb183.zip | |
Merge branch '0.24.x' of git://reductivelabs.com/puppet into 0.24.x
26 files changed, 77 insertions, 164 deletions
diff --git a/bin/puppetmasterd b/bin/puppetmasterd index a00186b68..33e4f436d 100755 --- a/bin/puppetmasterd +++ b/bin/puppetmasterd @@ -81,6 +81,7 @@ end require 'getoptlong' require 'puppet' +require 'puppet/network/handler' require 'puppet/sslcertificates' options = [ diff --git a/lib/puppet.rb b/lib/puppet.rb index 18037cdc1..57f84d5f7 100644 --- a/lib/puppet.rb +++ b/lib/puppet.rb @@ -423,6 +423,7 @@ module Puppet end require 'puppet/type' +require 'puppet/network' require 'puppet/module' require 'puppet/util/storage' require 'puppet/parser/interpreter' diff --git a/lib/puppet/network.rb b/lib/puppet/network.rb new file mode 100644 index 000000000..8993b8869 --- /dev/null +++ b/lib/puppet/network.rb @@ -0,0 +1,3 @@ +# Just a stub, so we can correctly scope other classes. +module Puppet::Network # :nodoc: +end diff --git a/lib/puppet/network/client/master.rb b/lib/puppet/network/client/master.rb index 390f3d4e2..913c51b3d 100644 --- a/lib/puppet/network/client/master.rb +++ b/lib/puppet/network/client/master.rb @@ -26,14 +26,15 @@ class Puppet::Network::Client::Master < Puppet::Network::Client down = Puppet[:downcasefacts] - facts = {} - Facter.each { |name,fact| + facts = Facter.to_hash.inject({}) do |newhash, array| + name, fact = array if down - facts[name] = fact.to_s.downcase + newhash[name] = fact.to_s.downcase else - facts[name] = fact.to_s + newhash[name] = fact.to_s end - } + newhash + end # Add our client version to the list of facts, so people can use it # in their manifests diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index 46be89ca2..b001e165b 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -82,12 +82,19 @@ class Puppet::Parser::Resource # Do any finishing work on this object, called before evaluation or # before storage/translation. def finish + return if finished? + @finished = true add_defaults() add_metaparams() add_scope_tags() validate() end + # Has this resource already been finished? + def finished? + defined?(@finished) and @finished + end + def initialize(options) # Set all of the options we can. options.each do |option, value| diff --git a/lib/puppet/rails.rb b/lib/puppet/rails.rb index a1192bf20..a021c773a 100644 --- a/lib/puppet/rails.rb +++ b/lib/puppet/rails.rb @@ -91,6 +91,10 @@ module Puppet::Rails raise Puppet::Error, "Could not find Puppet::Rails database dir" end + unless ActiveRecord::Base.connection.tables.include?("resources") + raise Puppet::Error, "Database has problems, can't migrate." + end + Puppet.notice "Migrating" begin diff --git a/lib/puppet/rails/database/001_add_created_at_to_all_tables.rb b/lib/puppet/rails/database/001_add_created_at_to_all_tables.rb new file mode 100644 index 000000000..71ee6aeed --- /dev/null +++ b/lib/puppet/rails/database/001_add_created_at_to_all_tables.rb @@ -0,0 +1,17 @@ +class AddCreatedAtToAllTables < ActiveRecord::Migration + def self.up + ActiveRecord::Base.connection.tables.each do |t| + unless ActiveRecord::Base.connection.columns(t).collect {|c| c.name}.include?("created_at") + add_column t.to_s, :created_at, :datetime + end + end + end + + def self.down + ActiveRecord::Base.connection.tables.each do |t| + unless ActiveRecord::Base.connection.columns(t).collect {|c| c.name}.include?("created_at") + remove_column t.to_s, :created_at + end + end + end +end diff --git a/lib/puppet/rails/external/tagging/README b/lib/puppet/rails/external/tagging/README deleted file mode 100644 index 8d2f90822..000000000 --- a/lib/puppet/rails/external/tagging/README +++ /dev/null @@ -1,4 +0,0 @@ -Acts As Taggable -================= - -Allows for tags to be added to multiple classes.
\ No newline at end of file diff --git a/lib/puppet/rails/external/tagging/acts_as_taggable.rb b/lib/puppet/rails/external/tagging/acts_as_taggable.rb deleted file mode 100644 index 7fd7f6b12..000000000 --- a/lib/puppet/rails/external/tagging/acts_as_taggable.rb +++ /dev/null @@ -1,62 +0,0 @@ -module ActiveRecord
- module Acts #:nodoc:
- module Taggable #:nodoc:
- def self.included(base)
- base.extend(ClassMethods)
- end
-
- module ClassMethods
- def acts_as_taggable(options = {})
- write_inheritable_attribute(:acts_as_taggable_options, {
- :taggable_type => ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s,
- :from => options[:from]
- })
-
- class_inheritable_reader :acts_as_taggable_options
-
- has_many :taggings, :as => :taggable, :dependent => :destroy
- has_many :tags, :through => :taggings
-
- include ActiveRecord::Acts::Taggable::InstanceMethods
- extend ActiveRecord::Acts::Taggable::SingletonMethods
- end
- end
-
- module SingletonMethods
- def find_tagged_with(list)
- find_by_sql([
- "SELECT #{table_name}.* FROM #{table_name}, tags, taggings " +
- "WHERE #{table_name}.#{primary_key} = taggings.taggable_id " +
- "AND taggings.taggable_type = ? " +
- "AND taggings.tag_id = tags.id AND tags.name IN (?)",
- acts_as_taggable_options[:taggable_type], list
- ])
- end
- def tags(options = {})
- options.merge!(:taggable_type => self.to_s)
- Tag.tags(options)
- end
- end
-
- module InstanceMethods
- def tag_with(list)
- Tag.transaction do
- taggings.destroy_all
-
- Tag.parse(list).each do |name|
- if acts_as_taggable_options[:from]
- send(acts_as_taggable_options[:from]).tags.find_or_create_by_name(name).on(self)
- else
- Tag.find_or_create_by_name(name).on(self)
- end
- end
- end
- end
-
- def tag_list
- tags.collect { |tag| tag.name.include?(" ") ? "'#{tag.name}'" : tag.name }.join(" ")
- end
- end
- end
- end
-end
diff --git a/lib/puppet/rails/external/tagging/init.rb b/lib/puppet/rails/external/tagging/init.rb deleted file mode 100644 index 5069d8040..000000000 --- a/lib/puppet/rails/external/tagging/init.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'puppet/rails/external/tagging/acts_as_taggable' -ActiveRecord::Base.send(:include, ActiveRecord::Acts::Taggable) - -require 'puppet/rails/external/tagging/tagging' -require 'puppet/rails/external/tagging/tag' diff --git a/lib/puppet/rails/external/tagging/tag.rb b/lib/puppet/rails/external/tagging/tag.rb deleted file mode 100644 index c6bf4ca78..000000000 --- a/lib/puppet/rails/external/tagging/tag.rb +++ /dev/null @@ -1,50 +0,0 @@ -class Tag < ActiveRecord::Base - has_many :taggings - - def self.tags(options = {}) - query = "select tags.id, name, count(*) as count" - query << " from taggings, tags" - query << " where tags.id = tag_id" - query << " group by tag_id" - query << " order by #{options[:order]}" if options[:order] != nil - query << " limit #{options[:limit]}" if options[:limit] != nil - tags = Tag.find_by_sql(query) - end - - def self.parse(list) - tag_names = [] - - # first, pull out the quoted tags - list.gsub!(/\"(.*?)\"\s*/ ) { tag_names << $1; "" } - - # then, replace all commas with a space - list.gsub!(/,/, " ") - - # then, get whatever's left - tag_names.concat list.split(/\s/) - - # strip whitespace from the names - tag_names = tag_names.map { |t| t.strip } - - # delete any blank tag names - tag_names = tag_names.delete_if { |t| t.empty? } - - return tag_names - end - - def tagged - @tagged ||= taggings.collect { |tagging| tagging.taggable } - end - - def on(taggable) - taggings.build :taggable => taggable - end - - def ==(comparison_object) - super || name == comparison_object.to_s - end - - def to_s - name - end -end diff --git a/lib/puppet/rails/external/tagging/tagging.rb b/lib/puppet/rails/external/tagging/tagging.rb deleted file mode 100644 index e06e88a14..000000000 --- a/lib/puppet/rails/external/tagging/tagging.rb +++ /dev/null @@ -1,12 +0,0 @@ -class Tagging < ActiveRecord::Base - belongs_to :tag - belongs_to :taggable, :polymorphic => true - - def self.tagged_class(taggable) - ActiveRecord::Base.send(:class_name_of_active_record_descendant, taggable.class).to_s - end - - def self.find_taggable(tagged_class, tagged_id) - tagged_class.constantize.find(tagged_id) - end -end
\ No newline at end of file diff --git a/lib/puppet/rails/fact_value.rb b/lib/puppet/rails/fact_value.rb index 0eb70be72..b53591d7e 100644 --- a/lib/puppet/rails/fact_value.rb +++ b/lib/puppet/rails/fact_value.rb @@ -1,6 +1,10 @@ class Puppet::Rails::FactValue < ActiveRecord::Base belongs_to :fact_name belongs_to :host + + def to_label + "#{self.fact_name.name}" + end end # $Id: fact_value.rb 1952 2006-12-19 05:47:57Z luke $ diff --git a/lib/puppet/rails/host.rb b/lib/puppet/rails/host.rb index 72898fd97..626edaa88 100644 --- a/lib/puppet/rails/host.rb +++ b/lib/puppet/rails/host.rb @@ -11,8 +11,7 @@ class Puppet::Rails::Host < ActiveRecord::Base has_many :fact_values, :dependent => :destroy has_many :fact_names, :through => :fact_values - belongs_to :puppet_classes - has_many :source_files + belongs_to :source_file has_many :resources, :include => :param_values, :dependent => :destroy diff --git a/lib/puppet/rails/param_value.rb b/lib/puppet/rails/param_value.rb index 02c29c540..fc00a43d4 100644 --- a/lib/puppet/rails/param_value.rb +++ b/lib/puppet/rails/param_value.rb @@ -20,5 +20,9 @@ class Puppet::Rails::ParamValue < ActiveRecord::Base self[:value] = val end end + + def to_label + "#{self.param_name.name}" + end end diff --git a/lib/puppet/rails/puppet_class.rb b/lib/puppet/rails/puppet_class.rb deleted file mode 100644 index 35cef8974..000000000 --- a/lib/puppet/rails/puppet_class.rb +++ /dev/null @@ -1,6 +0,0 @@ -class Puppet::Rails::PuppetClass < ActiveRecord::Base - has_many :resources - has_many :source_files - has_many :hosts -end - diff --git a/lib/puppet/rails/resource_tag.rb b/lib/puppet/rails/resource_tag.rb index d06711877..f9694e082 100644 --- a/lib/puppet/rails/resource_tag.rb +++ b/lib/puppet/rails/resource_tag.rb @@ -1,4 +1,8 @@ class Puppet::Rails::ResourceTag < ActiveRecord::Base belongs_to :puppet_tag belongs_to :resource + + def to_label + "#{self.puppet_tag.name}" + end end diff --git a/lib/puppet/rails/source_file.rb b/lib/puppet/rails/source_file.rb index 51d1b1fb5..3ccf87ac6 100644 --- a/lib/puppet/rails/source_file.rb +++ b/lib/puppet/rails/source_file.rb @@ -1,5 +1,8 @@ class Puppet::Rails::SourceFile < ActiveRecord::Base has_one :host - has_one :puppet_class has_one :resource + + def to_label + "#{self.filename}" + end end diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index 976bf7c68..14b2037f4 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -15,8 +15,6 @@ class Transaction # The list of events generated in this transaction. attr_reader :events - attr_writer :tags - include Puppet::Util # Add some additional times for reporting @@ -636,6 +634,11 @@ class Transaction @tags end + + def tags=(tags) + tags = [tags] unless tags.is_a?(Array) + @tags = tags + end # Is this resource tagged appropriately? def missing_tags?(resource) diff --git a/spec/unit/other/transaction.rb b/spec/unit/other/transaction.rb index e277a24c0..0db470d26 100755 --- a/spec/unit/other/transaction.rb +++ b/spec/unit/other/transaction.rb @@ -25,4 +25,9 @@ describe Puppet::Transaction, " when determining tags" do @transaction.tags = %w{one two} @transaction.tags.should == %w{one two} end + + it "should always convert assigned tags to an array" do + @transaction.tags = "one::two" + @transaction.tags.should == %w{one::two} + end end diff --git a/spec/unit/parser/resource.rb b/spec/unit/parser/resource.rb index 035590341..9ce7b391b 100755 --- a/spec/unit/parser/resource.rb +++ b/spec/unit/parser/resource.rb @@ -67,6 +67,12 @@ describe Puppet::Parser::Resource do @resource = Puppet::Parser::Resource.new(:type => "mydefine", :title => "whatever", :scope => @scope, :source => @source) end + it "should do nothing if it has already been finished" do + @resource.finish + @resource.expects(:add_metaparams).never + @resource.finish + end + it "should copy metaparams from its scope" do @scope.setvar("noop", "true") diff --git a/test/network/client/master.rb b/test/network/client/master.rb index 67c47fa6d..41796575f 100755 --- a/test/network/client/master.rb +++ b/test/network/client/master.rb @@ -216,15 +216,7 @@ end name = "environment" value = "test_environment" - Puppet[:filetimeout] = -1 - Puppet[:factsource] = tempfile() - Dir.mkdir(Puppet[:factsource]) - file = File.join(Puppet[:factsource], "#{name}.rb") - File.open(file, "w") do |f| - f.puts %{Facter.add("#{name}") do setcode { "#{value}" } end } - end - - Puppet::Network::Client.master.getfacts + Facter.stubs(:to_hash).returns(name => value) assert_equal(value, Puppet::Network::Client.master.facts[name]) end diff --git a/test/rails/railsparameter.rb b/test/rails/railsparameter.rb index d83115b1a..7c99ac38d 100755 --- a/test/rails/railsparameter.rb +++ b/test/rails/railsparameter.rb @@ -25,6 +25,8 @@ class TestRailsParameter < Test::Unit::TestCase source = parser.newclass "myclass" host = Puppet::Rails::Host.new(:name => "myhost") + + host.save resource = host.resources.create( :title => "/tmp/to_resource", diff --git a/test/rails/railsresource.rb b/test/rails/railsresource.rb index 58058472d..3df5001be 100755 --- a/test/rails/railsresource.rb +++ b/test/rails/railsresource.rb @@ -29,6 +29,7 @@ class TestRailsResource < Test::Unit::TestCase def mktest_resource # We need a host for resources host = Puppet::Rails::Host.new(:name => "myhost") + host.save # Now build a resource resource = host.resources.create( diff --git a/test/ral/type/file.rb b/test/ral/type/file.rb index cbbe818ae..5cf989aa3 100755 --- a/test/ral/type/file.rb +++ b/test/ral/type/file.rb @@ -185,12 +185,6 @@ class TestFile < Test::Unit::TestCase initgroup = File.stat(file).gid obj[:group] = group.name - assert_events([:file_changed], obj) - assert_equal(initgroup, File.stat(file).gid) - assert_equal(group.gid, File.lstat(link).gid) - File.chown(nil, initgroup, file) - File.lchown(nil, initgroup, link) - obj[:links] = :follow assert_events([:file_changed], obj) assert_equal(group.gid, File.stat(file).gid) diff --git a/test/ral/type/tidy.rb b/test/ral/type/tidy.rb index 60fad6516..17f98df22 100755 --- a/test/ral/type/tidy.rb +++ b/test/ral/type/tidy.rb @@ -4,6 +4,7 @@ require File.dirname(__FILE__) + '/../../lib/puppettest' require 'puppettest' require 'puppettest/support/utils' +require 'puppet/type/tidy' class TestTidy < Test::Unit::TestCase include PuppetTest::Support::Utils |
