From 782bc4d3b037684f472e1db53c1878390b8c9a32 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 3 Oct 2007 19:34:45 -0500 Subject: Fixing the yaml path so that it is correctly created for puppetmasterd. --- lib/puppet/defaults.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index f76ae9b84..45fe0f5b0 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -131,7 +131,9 @@ module Puppet :diff => ["diff", "Which diff command to use when printing differences between files."], :show_diff => [false, "Whether to print a contextual diff when files are being replaced. The diff is printed on stdout, so this option is meaningless unless you are running Puppet interactively. - This feature currently requires the ``diff/lcs`` Ruby library."] + This feature currently requires the ``diff/lcs`` Ruby library."], + :yamldir => {:default => "$vardir/yaml", :owner => "$user", :group => "$user", :mode => "750", + :desc => "The directory in which YAML data is stored, usually in a subdirectory."} ) hostname = Facter["hostname"].value @@ -503,11 +505,6 @@ module Puppet "The backend store to use for storing files by checksum (i.e., filebuckets)."] ) - self.setdefaults(:yaml, - :yamldir => ["$vardir/yaml", - "The directory in which YAML data is stored, usually in a subdirectory."] - ) - self.setdefaults(:rails, :dblocation => { :default => "$statedir/clientconfigs.sqlite3", :mode => 0660, -- cgit From bb3b3cedf4082dc884e41b864fa755057d20e228 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 3 Oct 2007 19:36:35 -0500 Subject: I finally tracked down the problem that was causing providers to sometimes suddenly disappear and thus tests to fail -- Kernel.require was not loading the normal ruby path (e.g., 'puppet/type/cron'), so if someone else loaded that then it would replace the in-memory type with a new one, but that new one couldn't load its own providers, because the Kernel would ignore the providers, thinking they were already loaded. This doesn't fix all of the autoloading problems, but at least we won't suddenly break a ton of tests. --- lib/puppet/dsl.rb | 104 ------------------------------------- lib/puppet/provider/parsedfile.rb | 2 +- lib/puppet/util/autoload.rb | 9 +--- test/other/dsl.rb | 1 - test/ral/providers/cron/crontab.rb | 17 +++--- test/ral/types/cron.rb | 6 +-- test/util/autoload.rb | 21 ++++++++ 7 files changed, 33 insertions(+), 127 deletions(-) diff --git a/lib/puppet/dsl.rb b/lib/puppet/dsl.rb index 3696cd9ee..166745359 100644 --- a/lib/puppet/dsl.rb +++ b/lib/puppet/dsl.rb @@ -270,108 +270,4 @@ end @aspects = {} -class Puppet::DisabledDSL - @@subs = {} - @name = :DSLClass - class << self - include Enumerable - attr_accessor :included, :name, :objects - - def each - @@subs.each do |name, sub| - yield name, sub - end - end - - def export - bucket = nil - if superclass() != Puppet::DSL - bucket = superclass.export - else - bucket = Puppet::TransBucket.new - bucket.keyword = "class" - bucket.type = self.name - end - - @objects.each do |type, ary| - ary.each do |name, obj| - if pobj = bucket.find { |sobj| obj.name == sobj.name && obj.type == sobj.type } - obj.each do |param, value| - pobj[param] = value - end - else - bucket.push obj - end - end - end - - return bucket - end - - def include(name) - if ary = @@subs.find { |n, s| n == name } - ary[1].included = true - else - raise "Could not find class %s" % name - end - end - - def inherited(sub) - name = sub.to_s.downcase.gsub(/.+::/, '').intern - @@subs[name] = sub - sub.name = name - sub.initvars - - sub - end - - def initvars - #if superclass() == Puppet::DSL - @objects = {} - #else - # @objects = superclass.objects - #end - end - - - def import(file) - text = File.read(file) - # If they don't specify a parent class, then specify one - # for them. - text.gsub!(/^class \S+\s*$/) do |match| - "#{match} < Puppet::DSL" - end - eval(text, binding) - end - - def method_missing(method, *args) - if klass = Puppet::Type.type(method) - method = method.intern if method.is_a? String - @objects[method] ||= {} - - names = args.shift - hash = args.shift - names = [names] unless names.is_a? Array - names.each do |name| - unless obj = @objects[method][name] - obj = Puppet::TransObject.new(name, method) - @objects[method][name] = obj - end - - hash.each do |param, value| - if obj[param] - raise "Cannot override %s in %s[%s]" % - [param, method, name] - else - obj[param] = value - end - end - end - else - raise "No type %s" % method - end - end - end -end - # $Id$ diff --git a/lib/puppet/provider/parsedfile.rb b/lib/puppet/provider/parsedfile.rb index 338694fff..b0c0f4d44 100755 --- a/lib/puppet/provider/parsedfile.rb +++ b/lib/puppet/provider/parsedfile.rb @@ -245,7 +245,7 @@ class Puppet::Provider::ParsedFile < Puppet::Provider # Initialize the object if necessary. def self.target_object(target) - @target_objects[target] ||= @filetype.new(target) + @target_objects[target] ||= filetype.new(target) @target_objects[target] end diff --git a/lib/puppet/util/autoload.rb b/lib/puppet/util/autoload.rb index 280961837..a52575522 100644 --- a/lib/puppet/util/autoload.rb +++ b/lib/puppet/util/autoload.rb @@ -107,16 +107,11 @@ class Puppet::Util::Autoload # Load every instance of everything we can find. eachdir do |dir| Dir.glob("#{dir}/*.rb").each do |file| - # Load here, rather than require, so that facts - # can be reloaded. This has some short-comings, I - # believe, but it works as long as real classes - # aren't used. name = File.basename(file).sub(".rb", '').intern next if loaded?(name) - next if $".include?(File.join(@path, name.to_s + ".rb")) - filepath = File.join(@path, name.to_s + ".rb") + rubypath = File.join(@path, name.to_s) begin - Kernel.require file + Kernel.require rubypath loaded(name, file) rescue => detail if Puppet[:trace] diff --git a/test/other/dsl.rb b/test/other/dsl.rb index 59610cd0f..0d891bf1a 100755 --- a/test/other/dsl.rb +++ b/test/other/dsl.rb @@ -4,7 +4,6 @@ $:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ require 'puppet' require 'puppet/dsl' -require 'puppet/util/autoload' require 'puppettest' class TestDSL < Test::Unit::TestCase diff --git a/test/ral/providers/cron/crontab.rb b/test/ral/providers/cron/crontab.rb index 7df7bab3d..d32a9527a 100755 --- a/test/ral/providers/cron/crontab.rb +++ b/test/ral/providers/cron/crontab.rb @@ -52,7 +52,6 @@ class TestCronParsedProvider < Test::Unit::TestCase def teardown Puppet::Util::FileType.filetype(:ram).clear - @provider.filetype = @oldfiletype @provider.clear super end @@ -211,7 +210,7 @@ class TestCronParsedProvider < Test::Unit::TestCase # Take our sample files, and make sure we can entirely parse them, # then that we can generate them again and we get the same data. def test_parse_and_generate_sample_files - @provider.filetype = :ram + @provider.stubs(:filetype).returns(Puppet::Util::FileType.filetype(:ram)) crondir = datadir(File.join(%w{providers cron})) files = Dir.glob("%s/crontab.*" % crondir) @@ -306,7 +305,7 @@ class TestCronParsedProvider < Test::Unit::TestCase str = "# this is a comment\n#and another comment\n" user = "fakeuser" records = nil - target = @provider.filetype = :ram + @provider.stubs(:filetype).returns(Puppet::Util::FileType.filetype(:ram)) target = @provider.target_object(user) target.write(str) assert_nothing_raised { @@ -320,7 +319,7 @@ class TestCronParsedProvider < Test::Unit::TestCase end def test_simpleparsing - @provider.filetype = :ram + @provider.stubs(:filetype).returns(Puppet::Util::FileType.filetype(:ram)) text = "5 1,2 * 1 0 /bin/echo funtest" records = nil @@ -376,7 +375,7 @@ class TestCronParsedProvider < Test::Unit::TestCase # Make sure we correctly bidirectionally parse things. def test_records_and_strings - @provider.filetype = :ram + @provider.stubs(:filetype).returns(Puppet::Util::FileType.filetype(:ram)) setme target = @provider.target_object(@me) @@ -426,7 +425,7 @@ class TestCronParsedProvider < Test::Unit::TestCase 0,30 * * 1 * fooness " setme - @provider.filetype = :ram + @provider.stubs(:filetype).returns(Puppet::Util::FileType.filetype(:ram)) you = "you" # Write the same tab to multiple targets @@ -486,7 +485,7 @@ class TestCronParsedProvider < Test::Unit::TestCase def test_data setme - @provider.filetype = :ram + @provider.stubs(:filetype).returns(Puppet::Util::FileType.filetype(:ram)) target = @provider.target_object(@me) fakedata("data/providers/cron/examples").each do |file| text = File.read(file) @@ -518,7 +517,7 @@ class TestCronParsedProvider < Test::Unit::TestCase # Match freebsd's annoying @daily stuff. def test_match_freebsd_special - @provider.filetype = :ram + @provider.stubs(:filetype).returns(Puppet::Util::FileType.filetype(:ram)) setme target = @provider.target_object(@me) @@ -561,7 +560,7 @@ class TestCronParsedProvider < Test::Unit::TestCase # Testing #669. def test_environment_settings - @provider.filetype = :ram + @provider.stubs(:filetype).returns(Puppet::Util::FileType.filetype(:ram)) setme target = @provider.target_object(@me) diff --git a/test/ral/types/cron.rb b/test/ral/types/cron.rb index 1695befac..519ff1d28 100755 --- a/test/ral/types/cron.rb +++ b/test/ral/types/cron.rb @@ -17,8 +17,7 @@ class TestCron < Test::Unit::TestCase @crontype = Puppet::Type.type(:cron) @provider = @crontype.defaultprovider if @provider.respond_to?(:filetype=) - @oldfiletype = @provider.filetype - @provider.filetype = :ram + @provider.stubs(:filetype).returns(Puppet::Util::FileType.filetype(:ram)) end @crontype = Puppet::Type.type(:cron) end @@ -26,9 +25,6 @@ class TestCron < Test::Unit::TestCase def teardown super @crontype.defaultprovider = nil - if defined? @oldfiletype - @provider.filetype = @oldfiletype - end Puppet::Util::FileType.filetype(:ram).clear end diff --git a/test/util/autoload.rb b/test/util/autoload.rb index bae6d37d4..ca77572c2 100755 --- a/test/util/autoload.rb +++ b/test/util/autoload.rb @@ -102,4 +102,25 @@ TestAutoload.newthing(:#{name.to_s}) assert(loader.send(:searchpath).include?(dir), "searchpath does not include the libdir") end + + # This causes very strange behaviour in the tests. We need to make sure we + # require the same path that a user would use, otherwise we'll result in + # a reload of the + def test_require_does_not_cause_reload + loadname = "testing" + loader = Puppet::Util::Autoload.new(self.class, loadname) + + basedir = "/some/dir" + dir = File.join(basedir, loadname) + loader.expects(:eachdir).yields(dir) + + subname = "instance" + + file = File.join(dir, subname) + ".rb" + + Dir.expects(:glob).with("#{dir}/*.rb").returns(file) + + Kernel.expects(:require).with(File.join(loadname, subname)) + loader.loadall + end end -- cgit