diff options
34 files changed, 446 insertions, 415 deletions
@@ -1,3 +1,8 @@ + Somewhat refactored fileserving so that it no longer caches + any objects, nor does it use Puppet's RAL resources. In the + process, I fixed #894 (you can now copy links) and refactored + other classes as necessary. Mostly it was fixing tests. + Hopefully partially fixed #1010 -- clients should now fail to install files whose checksums do not match the checksum from the server. @@ -39,9 +44,9 @@ between the classes, definitions, and nodes, and the Compile class much cleaner. - Exec resources must now have unique names. This is easily accomplished by - just specifying a unique name with whatever (unique or otherwise) command - you need. + Exec resources must now have unique names, although the commands can still + be duplicated. This is easily accomplished by just specifying a unique + name with whatever (unique or otherwise) command you need. Fixed #989 -- missing CRL files are correctly ignored, and the value should be set to 'false' to explicitly not look for these diff --git a/lib/puppet/dsl.rb b/lib/puppet/dsl.rb index 4fbce556c..966feaf9b 100644 --- a/lib/puppet/dsl.rb +++ b/lib/puppet/dsl.rb @@ -46,58 +46,56 @@ # # apply -module Puppet - # Provide the actual commands for acting like a language. - module DSL - def aspect(name, options = {}, &block) - Puppet::Aspect.new(name, options, &block) - end +require 'puppet' - def acquire(*names) - names.each do |name| - if aspect = Puppet::Aspect[name] - unless aspect.evaluated? - aspect.evaluate - end - else - raise "Could not find aspect %s" % name +# Provide the actual commands for acting like a language. +module Puppet::DSL + def aspect(name, options = {}, &block) + Puppet::DSL::Aspect.new(name, options, &block) + end + + def acquire(*names) + names.each do |name| + if aspect = Puppet::DSL::Aspect[name] + unless aspect.evaluated? + aspect.evaluate end + else + raise "Could not find aspect %s" % name end end + end - def apply - bucket = export() - catalog = bucket.to_catalog - catalog.apply - end + def apply + bucket = export() + catalog = bucket.to_catalog + catalog.apply + end - def export - objects = Puppet::Aspect.collect do |name, aspect| - if aspect.evaluated? - aspect.export - end - end.reject { |a| a.nil? }.flatten.collect do |obj| - obj.to_trans + def export + objects = Puppet::DSL::Aspect.collect do |name, aspect| + if aspect.evaluated? + aspect.export end - bucket = Puppet::TransBucket.new(objects) - bucket.name = "top" - bucket.type = "class" - - return bucket + end.reject { |a| a.nil? }.flatten.collect do |obj| + obj.to_trans end + bucket = Puppet::TransBucket.new(objects) + bucket.name = "top" + bucket.type = "class" - def init - unless Process.uid == 0 - Puppet[:confdir] = File.expand_path("~/.puppet") - Puppet[:vardir] = File.expand_path("~/.puppet/var") - end - Puppet[:user] = Process.uid - Puppet[:group] = Process.gid - Puppet::Util::Log.newdestination(:console) - Puppet::Util::Log.level = :info - end + return bucket + end - private + def init + unless Process.uid == 0 + Puppet[:confdir] = File.expand_path("~/.puppet") + Puppet[:vardir] = File.expand_path("~/.puppet/var") + end + Puppet[:user] = Process.uid + Puppet[:group] = Process.gid + Puppet::Util::Log.newdestination(:console) + Puppet::Util::Log.level = :info end class Aspect @@ -224,10 +222,10 @@ module Puppet end def newresource(type, name, params = {}) - if self.is_a?(Puppet::Aspect) + if self.is_a?(Puppet::DSL::Aspect) source = self else - source = Puppet::Aspect[:main] + source = Puppet::DSL::Aspect[:main] end unless obj = @@objects[type][name] obj = Resource.new :title => name, :type => type.name, @@ -262,7 +260,7 @@ module Puppet env = nil end @node.parameters = Facter.to_hash - @compile = Puppet::Parser::Compile.new(@node, @interp.send(:parser, env)) + @compile = Puppet::Parser::Compiler.new(@node, @interp.send(:parser, env)) @scope = @compile.topscope end @scope diff --git a/lib/puppet/file_serving/file_base.rb b/lib/puppet/file_serving/file_base.rb index 7f169d1ea..06b3ad9ef 100644 --- a/lib/puppet/file_serving/file_base.rb +++ b/lib/puppet/file_serving/file_base.rb @@ -9,16 +9,28 @@ require 'puppet/file_serving' class Puppet::FileServing::FileBase attr_accessor :key + # Does our file exist? + def exist? + begin + stat + return true + rescue => detail + return false + end + end + # Return the full path to our file. Fails if there's no path set. def full_path raise(ArgumentError, "You must set a path to get a file's path") unless self.path - relative_path ? File.join(path, relative_path) : path + if relative_path.nil? or relative_path == "" + path + else + File.join(path, relative_path) + end end def initialize(key, options = {}) - raise ArgumentError.new("Files must not be fully qualified") if path =~ /^#{::File::SEPARATOR}/ - @key = key @links = :manage diff --git a/lib/puppet/file_serving/metadata.rb b/lib/puppet/file_serving/metadata.rb index e26e75844..56712122c 100644 --- a/lib/puppet/file_serving/metadata.rb +++ b/lib/puppet/file_serving/metadata.rb @@ -28,6 +28,25 @@ class Puppet::FileServing::Metadata < Puppet::FileServing::FileBase attr_reader :path, :owner, :group, :mode, :checksum_type, :checksum, :ftype, :destination + PARAM_ORDER = [:mode, :ftype, :owner, :group] + + def attributes_with_tabs + desc = [] + PARAM_ORDER.each { |check| + check = :ftype if check == :type + desc << send(check) + } + + case ftype + when "file", "directory": desc << checksum + when "link": desc << @destination + else + raise ArgumentError, "Cannot manage files of type %s" % ftype + end + + return desc.join("\t") + end + def checksum_type=(type) raise(ArgumentError, "Unsupported checksum type %s" % type) unless respond_to?("%s_file" % type) @@ -45,13 +64,19 @@ class Puppet::FileServing::Metadata < Puppet::FileServing::FileBase @ftype = stat.ftype - # Set the octal mode, but as a string. - @mode = "%o" % (stat.mode & 007777) + # We have to mask the mode, yay. + @mode = stat.mode & 007777 - if stat.ftype == "symlink" + case stat.ftype + when "file": + @checksum = ("{%s}" % @checksum_type) + send("%s_file" % @checksum_type, real_path) + when "directory": # Always just timestamp the directory. + sumtype = @checksum_type.to_s =~ /time/ ? @checksum_type : "ctime" + @checksum = ("{%s}" % sumtype) + send("%s_file" % sumtype, path).to_s + when "link": @destination = File.readlink(real_path) else - @checksum = get_checksum(real_path) + raise ArgumentError, "Cannot manage files of type %s" % stat.ftype end end @@ -59,11 +84,4 @@ class Puppet::FileServing::Metadata < Puppet::FileServing::FileBase @checksum_type = "md5" super end - - private - - # Retrieve our checksum. - def get_checksum(path) - ("{%s}" % @checksum_type) + send("%s_file" % @checksum_type, path) - end end diff --git a/lib/puppet/metatype/evaluation.rb b/lib/puppet/metatype/evaluation.rb index b3b6570b2..08756e988 100644 --- a/lib/puppet/metatype/evaluation.rb +++ b/lib/puppet/metatype/evaluation.rb @@ -125,26 +125,14 @@ class Puppet::Type raise Puppet::DevError, "Parameter ensure defined but missing from current values" end if @parameters.include?(:ensure) and ! ensureparam.insync?(currentvalues[ensureparam]) -# self.info "ensuring %s from %s" % -# [@parameters[:ensure].should, @parameters[:ensure].is] changes << Puppet::PropertyChange.new(ensureparam, currentvalues[ensureparam]) # Else, if the 'ensure' property is correctly absent, then do # nothing elsif @parameters.include?(:ensure) and currentvalues[ensureparam] == :absent - # self.info "Object is correctly absent" return [] else -# if @parameters.include?(:ensure) -# self.info "ensure: Is: %s, Should: %s" % -# [@parameters[:ensure].is, @parameters[:ensure].should] -# else -# self.info "no ensure property" -# end changes = properties().find_all { |property| - unless currentvalues.include?(property) - raise Puppet::DevError, "Property %s does not have a current value", - [property.name] - end + currentvalues[property] ||= :absent ! property.insync?(currentvalues[property]) }.collect { |property| Puppet::PropertyChange.new(property, currentvalues[property]) @@ -152,10 +140,7 @@ class Puppet::Type end if Puppet[:debug] and changes.length > 0 - self.debug("Changing " + changes.collect { |ch| - ch.property.name - }.join(",") - ) + self.debug("Changing " + changes.collect { |ch| ch.property.name }.join(",")) end changes diff --git a/lib/puppet/network/client.rb b/lib/puppet/network/client.rb index 283436e95..0a0a72345 100644 --- a/lib/puppet/network/client.rb +++ b/lib/puppet/network/client.rb @@ -95,9 +95,7 @@ class Puppet::Network::Client # We have to start the HTTP connection manually before we start # sending it requests or keep-alive won't work. - if @driver.respond_to? :start - @driver.start - end + @driver.start if @driver.respond_to? :start @local = false elsif hash.include?(driverparam) @@ -107,8 +105,7 @@ class Puppet::Network::Client end @local = true else - raise Puppet::Network::ClientError, "%s must be passed a Server or %s" % - [self.class, driverparam] + raise Puppet::Network::ClientError, "%s must be passed a Server or %s" % [self.class, driverparam] end end diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb index e6378bf01..a9a95bcfe 100755 --- a/lib/puppet/network/handler/fileserver.rb +++ b/lib/puppet/network/handler/fileserver.rb @@ -5,6 +5,9 @@ require 'cgi' require 'delegate' require 'sync' +require 'puppet/file_serving' +require 'puppet/file_serving/metadata' + class Puppet::Network::Handler AuthStoreError = Puppet::AuthStoreError class FileServerError < Puppet::Error; end @@ -59,40 +62,27 @@ class Puppet::Network::Handler # Describe a given file. This returns all of the manageable aspects # of that file. - def describe(url, links = :ignore, client = nil, clientip = nil) + def describe(url, links = :follow, client = nil, clientip = nil) links = links.intern if links.is_a? String - if links == :manage - raise Puppet::Network::Handler::FileServerError, "Cannot currently copy links" - end - mount, path = convert(url, client, clientip) - if client - mount.debug "Describing %s for %s" % [url, client] - end + mount.debug("Describing %s for %s" % [url, client]) if client + + # Remove any leading slashes, since Metadata doesn't like them, yo. + metadata = Puppet::FileServing::Metadata.new(url, :path => mount.path(client), :relative_path => path.sub(/^\//, ''), :links => links) - obj = nil - unless obj = mount.getfileobject(path, links, client) + return "" unless metadata.exist? + + begin + metadata.collect_attributes + rescue => detail + puts detail.backtrace if Puppet[:trace] + Puppet.err detail return "" end - currentvalues = mount.check(obj) - - desc = [] - CHECKPARAMS.each { |check| - if value = currentvalues[check] - desc << value - else - if check == "checksum" and currentvalues[:type] == "file" - mount.notice "File %s does not have data for %s" % - [obj.name, check] - end - desc << nil - end - } - - return desc.join("\t") + return metadata.attributes_with_tabs end # Create a new fileserving module. @@ -140,26 +130,18 @@ class Puppet::Network::Handler def list(url, links = :ignore, recurse = false, ignore = false, client = nil, clientip = nil) mount, path = convert(url, client, clientip) - if client - mount.debug "Listing %s for %s" % [url, client] - end + mount.debug "Listing %s for %s" % [url, client] if client - obj = nil - unless mount.path_exists?(path, client) - return "" - end + return "" unless mount.path_exists?(path, client) desc = mount.list(path, recurse, ignore, client) if desc.length == 0 - mount.notice "Got no information on //%s/%s" % - [mount, path] + mount.notice "Got no information on //%s/%s" % [mount, path] return "" end - - desc.collect { |sub| - sub.join("\t") - }.join("\n") + + desc.collect { |sub| sub.join("\t") }.join("\n") end def local? @@ -213,12 +195,7 @@ class Puppet::Network::Handler return "" end - str = nil - if links == :manage - raise Puppet::Error, "Cannot copy links yet." - else - str = mount.read_file(path, client) - end + str = mount.read_file(path, client) if @local return str diff --git a/lib/puppet/network/http_server/webrick.rb b/lib/puppet/network/http_server/webrick.rb index e4f00dd73..568b4e798 100644 --- a/lib/puppet/network/http_server/webrick.rb +++ b/lib/puppet/network/http_server/webrick.rb @@ -8,6 +8,7 @@ require 'puppet/sslcertificates/support' require 'puppet/network/xmlrpc/webrick_servlet' require 'puppet/network/http_server' require 'puppet/network/client' +require 'puppet/network/handler' module Puppet class ServerError < RuntimeError; end @@ -133,7 +134,7 @@ module Puppet handlers.collect { |handler, args| hclass = nil - unless hclass = Handler.handler(handler) + unless hclass = Puppet::Network::Handler.handler(handler) raise ServerError, "Invalid handler %s" % handler end hclass.new(args) diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb index ee4cedd4b..d680de9a0 100644 --- a/lib/puppet/node/catalog.rb +++ b/lib/puppet/node/catalog.rb @@ -1,4 +1,6 @@ require 'puppet/indirector' +require 'puppet/pgraph' +require 'puppet/transaction' require 'puppet/util/tagging' @@ -69,7 +71,10 @@ class Puppet::Node::Catalog < Puppet::PGraph @resource_table[ref] = resource # If the name and title differ, set up an alias - self.alias(resource, resource.name) if resource.respond_to?(:name) and resource.respond_to?(:title) and resource.name != resource.title + #self.alias(resource, resource.name) if resource.respond_to?(:name) and resource.respond_to?(:title) and resource.name != resource.title + if resource.respond_to?(:name) and resource.respond_to?(:title) and resource.name != resource.title + self.alias(resource, resource.name) if resource.class.isomorphic? + end resource.catalog = self if resource.respond_to?(:catalog=) and ! is_relationship_graph @@ -499,7 +504,7 @@ class Puppet::Node::Catalog < Puppet::PGraph map.clear - result.add_class *self.classes + result.add_class(*self.classes) result.tag(*self.tags) return result diff --git a/lib/puppet/provider/package/gem.rb b/lib/puppet/provider/package/gem.rb index f73694779..bb09bc5b0 100755 --- a/lib/puppet/provider/package/gem.rb +++ b/lib/puppet/provider/package/gem.rb @@ -78,7 +78,11 @@ Puppet::Type.type(:package).provide :gem, :parent => Puppet::Provider::Package d command << @resource[:name] end - gemcmd(*command) + output = gemcmd(*command) + # Apparently some stupid gem versions don't exit non-0 on failure + if output.include?("ERROR") + self.fail "Could not install: %s" % output.chomp + end end def latest diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index c4e154d47..09003e8f5 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -257,10 +257,7 @@ class Type rescue ArgumentError, Puppet::Error, TypeError raise rescue => detail - error = Puppet::DevError.new( - "Could not set %s on %s: %s" % - [attr, self.class.name, detail] - ) + error = Puppet::DevError.new( "Could not set %s on %s: %s" % [attr, self.class.name, detail]) error.set_backtrace(detail.backtrace) raise error end @@ -422,10 +419,6 @@ end require 'puppet/propertychange' require 'puppet/provider' -require 'puppet/type/component' -require 'puppet/type/file' -require 'puppet/type/filebucket' -require 'puppet/type/tidy' - - +# Always load these types. +require 'puppet/type/component' diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb index f093543d7..3518e8bb3 100644 --- a/lib/puppet/type/file.rb +++ b/lib/puppet/type/file.rb @@ -175,11 +175,9 @@ module Puppet recursion), and ``follow`` will manage the file to which the link points." - newvalues(:follow, :manage, :ignore) + newvalues(:follow, :manage) - # :ignore and :manage behave equivalently on local files, - # but don't copy remote links - defaultto :ignore + defaultto :manage end newparam(:purge, :boolean => true) do @@ -781,9 +779,7 @@ module Puppet def remove_existing(should) return unless s = stat(true) - unless handlebackup - self.fail "Could not back up; will not replace" - end + self.fail "Could not back up; will not replace" unless handlebackup unless should.to_s == "link" return if s.ftype.to_s == should.to_s @@ -792,8 +788,7 @@ module Puppet case s.ftype when "directory": if self[:force] == :true - debug "Removing existing directory for replacement with %s" % - should + debug "Removing existing directory for replacement with %s" % should FileUtils.rmtree(self[:path]) else notice "Not removing directory; use 'force' to override" diff --git a/lib/puppet/type/file/content.rb b/lib/puppet/type/file/content.rb index 687a83f14..1eb1423aa 100755 --- a/lib/puppet/type/file/content.rb +++ b/lib/puppet/type/file/content.rb @@ -1,5 +1,5 @@ module Puppet - Puppet.type(:file).newproperty(:content) do + Puppet::Type.type(:file).newproperty(:content) do include Puppet::Util::Diff desc "Specify the contents of a file as a string. Newlines, tabs, and @@ -47,23 +47,13 @@ module Puppet return result end - # We should probably take advantage of existing md5 sums if they're there, - # but I really don't feel like dealing with the complexity right now. def retrieve - stat = nil - unless stat = @resource.stat - return :absent - end + return :absent unless stat = @resource.stat - if stat.ftype == "link" and @resource[:links] == :ignore - return self.should - end + return self.should if stat.ftype == "link" and @resource[:links] == :ignore # Don't even try to manage the content on directories - if stat.ftype == "directory" and @resource[:links] == :ignore - @resource.delete(:content) - return nil - end + return nil if stat.ftype == "directory" begin currentvalue = File.read(@resource[:path]) diff --git a/lib/puppet/type/file/ensure.rb b/lib/puppet/type/file/ensure.rb index 028a7083d..0d2171216 100755 --- a/lib/puppet/type/file/ensure.rb +++ b/lib/puppet/type/file/ensure.rb @@ -99,9 +99,13 @@ module Puppet munge do |value| value = super(value) + # It doesn't make sense to try to manage links unless, well, + # we're managing links. + resource[:links] = :manage if value == :link return value if value.is_a? Symbol @resource[:target] = value + resource[:links] = :manage return :link end diff --git a/lib/puppet/type/file/source.rb b/lib/puppet/type/file/source.rb index 7fa5eb1a9..1b0dd3141 100755 --- a/lib/puppet/type/file/source.rb +++ b/lib/puppet/type/file/source.rb @@ -105,10 +105,13 @@ module Puppet return nil end + return nil if desc == "" + + # Collect everything except the checksum + values = desc.split("\t") + other = values.pop args = {} - pinparams.zip( - desc.split("\t") - ).each { |param, value| + pinparams.zip(values).each { |param, value| if value =~ /^[0-9]+$/ value = value.to_i end @@ -117,16 +120,19 @@ module Puppet end } - # we can't manage ownership as root, so don't even try - unless Puppet::Util::SUIDManager.uid == 0 - args.delete(:owner) + # Now decide whether we're doing checksums or symlinks + if args[:type] == "link" + args[:target] = other + else + args[:checksum] = other end - if args.empty? or (args[:type] == "link" and @resource[:links] == :ignore) - return nil - else - return args + # we can't manage ownership unless we're root, so don't even try + unless Puppet::Util::SUIDManager.uid == 0 + args.delete(:owner) end + + return args end # Have we successfully described the remote source? @@ -172,7 +178,7 @@ module Puppet end def pinparams - Puppet::Network::Handler.handler(:fileserver).params + [:mode, :type, :owner, :group] end # This basically calls describe() on our file, and then sets all @@ -201,7 +207,7 @@ module Puppet end case @stats[:type] - when "directory", "file": + when "directory", "file", "link": @resource[:ensure] = @stats[:type] unless @resource.deleting? else self.info @stats.inspect diff --git a/lib/puppet/util/filetype.rb b/lib/puppet/util/filetype.rb index 1c7734cc4..bbc837e75 100755 --- a/lib/puppet/util/filetype.rb +++ b/lib/puppet/util/filetype.rb @@ -165,7 +165,7 @@ class Puppet::Util::FileType # Remove a specific @path's cron tab. def remove - if Facter.value("operatingsystem") == "FreeBSD" + if %w{Darwin FreeBSD}.include?(Facter.value("operatingsystem")) %x{/bin/echo yes | #{cmdbase()} -r 2>/dev/null} else %x{#{cmdbase()} -r 2>/dev/null} diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb index cf15d3194..a91b0d6b1 100644 --- a/lib/puppet/util/settings.rb +++ b/lib/puppet/util/settings.rb @@ -1158,7 +1158,7 @@ Generated on #{Time.now}. return nil unless path.is_a?(String) return nil if path =~ /^\/dev/ - return nil if Puppet::Type::File[path] # skip files that are in our global resource list. + return nil if Puppet::Type.type(:file)[path] # skip files that are in our global resource list. objects = [] diff --git a/spec/unit/file_serving/file_base.rb b/spec/unit/file_serving/file_base.rb index 4c7724f7c..e1a61cd65 100755 --- a/spec/unit/file_serving/file_base.rb +++ b/spec/unit/file_serving/file_base.rb @@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/file_serving/file_base' -describe Puppet::FileServing::FileBase, " when initializing" do +describe Puppet::FileServing::FileBase do it "should accept a key in the form of a URI" do Puppet::FileServing::FileBase.new("puppet://host/module/dir/file").key.should == "puppet://host/module/dir/file" end @@ -30,72 +30,91 @@ describe Puppet::FileServing::FileBase, " when initializing" do FileTest.stubs(:exists?).returns(true) Puppet::FileServing::FileBase.new("puppet://host/module/dir/file", :relative_path => "my/file").relative_path.should == "my/file" end -end -describe Puppet::FileServing::FileBase, " when setting the base path" do - before do - @file = Puppet::FileServing::FileBase.new("puppet://host/module/dir/file") + it "should have a means of determining if the file exists" do + Puppet::FileServing::FileBase.new("blah").should respond_to(:exist?) end - it "should require that the base path be fully qualified" do - FileTest.stubs(:exists?).returns(true) - proc { @file.path = "unqualified/file" }.should raise_error(ArgumentError) + it "should correctly indicate if the file is present" do + File.expects(:lstat).with("/my/file").returns(mock("stat")) + Puppet::FileServing::FileBase.new("blah", :path => "/my/file").exist?.should be_true end -end -describe Puppet::FileServing::FileBase, " when setting the relative path" do - it "should require that the relative path be unqualified" do - @file = Puppet::FileServing::FileBase.new("puppet://host/module/dir/file") - FileTest.stubs(:exists?).returns(true) - proc { @file.relative_path = "/qualified/file" }.should raise_error(ArgumentError) + it "should correctly indicate if the file is asbsent" do + File.expects(:lstat).with("/my/file").raises RuntimeError + Puppet::FileServing::FileBase.new("blah", :path => "/my/file").exist?.should be_false end -end -describe Puppet::FileServing::FileBase, " when determining the full file path" do - before do - @file = Puppet::FileServing::FileBase.new("mykey", :path => "/this/file") - end + describe "when setting the base path" do + before do + @file = Puppet::FileServing::FileBase.new("puppet://host/module/dir/file") + end - it "should return the path if there is no relative path" do - @file.full_path.should == "/this/file" + it "should require that the base path be fully qualified" do + FileTest.stubs(:exists?).returns(true) + proc { @file.path = "unqualified/file" }.should raise_error(ArgumentError) + end end - it "should return the path joined with the relative path if there is a relative path" do - @file.relative_path = "not/qualified" - @file.full_path.should == "/this/file/not/qualified" + describe "when setting the relative path" do + it "should require that the relative path be unqualified" do + @file = Puppet::FileServing::FileBase.new("puppet://host/module/dir/file") + FileTest.stubs(:exists?).returns(true) + proc { @file.relative_path = "/qualified/file" }.should raise_error(ArgumentError) + end end - it "should should fail if there is no path set" do - @file = Puppet::FileServing::FileBase.new("not/qualified") - proc { @file.full_path }.should raise_error(ArgumentError) - end -end + describe "when determining the full file path" do + before do + @file = Puppet::FileServing::FileBase.new("mykey", :path => "/this/file") + end -describe Puppet::FileServing::FileBase, " when stat'ing files" do - before do - @file = Puppet::FileServing::FileBase.new("mykey", :path => "/this/file") - end + it "should return the path if there is no relative path" do + @file.full_path.should == "/this/file" + end - it "should stat the file's full path" do - @file.stubs(:full_path).returns("/this/file") - File.expects(:lstat).with("/this/file").returns stub("stat", :ftype => "file") - @file.stat - end + it "should return the path if the relative_path is set to ''" do + @file.relative_path = "" + @file.full_path.should == "/this/file" + end - it "should fail if the file does not exist" do - @file.stubs(:full_path).returns("/this/file") - File.expects(:lstat).with("/this/file").raises(Errno::ENOENT) - proc { @file.stat }.should raise_error(Errno::ENOENT) - end + it "should return the path joined with the relative path if there is a relative path and it is not set to '/' or ''" do + @file.relative_path = "not/qualified" + @file.full_path.should == "/this/file/not/qualified" + end - it "should use :lstat if :links is set to :manage" do - File.expects(:lstat).with("/this/file").returns stub("stat", :ftype => "file") - @file.stat + it "should should fail if there is no path set" do + @file = Puppet::FileServing::FileBase.new("not/qualified") + proc { @file.full_path }.should raise_error(ArgumentError) + end end - it "should use :stat if :links is set to :follow" do - File.expects(:stat).with("/this/file").returns stub("stat", :ftype => "file") - @file.links = :follow - @file.stat + describe "when stat'ing files" do + before do + @file = Puppet::FileServing::FileBase.new("mykey", :path => "/this/file") + end + + it "should stat the file's full path" do + @file.stubs(:full_path).returns("/this/file") + File.expects(:lstat).with("/this/file").returns stub("stat", :ftype => "file") + @file.stat + end + + it "should fail if the file does not exist" do + @file.stubs(:full_path).returns("/this/file") + File.expects(:lstat).with("/this/file").raises(Errno::ENOENT) + proc { @file.stat }.should raise_error(Errno::ENOENT) + end + + it "should use :lstat if :links is set to :manage" do + File.expects(:lstat).with("/this/file").returns stub("stat", :ftype => "file") + @file.stat + end + + it "should use :stat if :links is set to :follow" do + File.expects(:stat).with("/this/file").returns stub("stat", :ftype => "file") + @file.links = :follow + @file.stat + end end end diff --git a/spec/unit/file_serving/metadata.rb b/spec/unit/file_serving/metadata.rb index d31dd21f0..9743370c1 100755 --- a/spec/unit/file_serving/metadata.rb +++ b/spec/unit/file_serving/metadata.rb @@ -26,8 +26,8 @@ describe Puppet::FileServing::Metadata, " when finding the file to use for setti @metadata.path = @full - # Use a symlink because it's easier to test -- no checksumming - @stat = stub "stat", :uid => 10, :gid => 20, :mode => 0755, :ftype => "symlink" + # Use a link because it's easier to test -- no checksumming + @stat = stub "stat", :uid => 10, :gid => 20, :mode => 0755, :ftype => "link" end it "should accept a base path path to which the file should be relative" do @@ -55,17 +55,19 @@ end describe Puppet::FileServing::Metadata, " when collecting attributes" do before do @path = "/my/file" - @stat = stub 'stat', :uid => 10, :gid => 20, :mode => 0755, :ftype => "file" + # Use a real file mode, so we can validate the masking is done. + @stat = stub 'stat', :uid => 10, :gid => 20, :mode => 33261, :ftype => "file" File.stubs(:lstat).returns(@stat) - @filehandle = mock 'filehandle' - #@filehandle.expects(:read).with(512).returns("some content\n").then.returns(nil) - File.stubs(:open).with(@path, 'r').yields(@filehandle) @checksum = Digest::MD5.hexdigest("some content\n") @metadata = Puppet::FileServing::Metadata.new("file", :path => "/my/file") - @metadata.expects(:md5_file).returns(@checksum) + @metadata.stubs(:md5_file).returns(@checksum) @metadata.collect_attributes end + it "should be able to produce xmlrpc-style attribute information" do + @metadata.should respond_to(:attributes_with_tabs) + end + # LAK:FIXME This should actually change at some point it "should set the owner by id" do @metadata.owner.should be_instance_of(Fixnum) @@ -84,28 +86,63 @@ describe Puppet::FileServing::Metadata, " when collecting attributes" do @metadata.group.should == 20 end - it "should set the mode to a string version of the mode in octal" do - @metadata.mode.should == "755" - end - - it "should set the mode to the file's current mode" do - @metadata.mode.should == "755" + it "should set the mode to the file's masked mode" do + @metadata.mode.should == 0755 end it "should set the checksum to the file's current checksum" do @metadata.checksum.should == "{md5}" + @checksum end - it "should default to a checksum of type MD5" do - @metadata.checksum.should == "{md5}" + @checksum + describe "when managing files" do + it "should default to a checksum of type MD5" do + @metadata.checksum.should == "{md5}" + @checksum + end + + it "should produce tab-separated mode, type, owner, group, and checksum for xmlrpc" do + @metadata.attributes_with_tabs.should == "#{0755.to_s}\tfile\t10\t20\t{md5}#{@checksum}" + end + end + + describe "when managing directories" do + before do + @stat.stubs(:ftype).returns("directory") + @time = Time.now + @metadata.expects(:ctime_file).returns(@time) + @metadata.collect_attributes + end + + it "should only use checksums of type 'ctime' for directories" do + @metadata.checksum.should == "{ctime}" + @time.to_s + end + + it "should produce tab-separated mode, type, owner, group, and checksum for xmlrpc" do + @metadata.attributes_with_tabs.should == "#{0755.to_s}\tdirectory\t10\t20\t{ctime}#{@time.to_s}" + end + end + + describe "when managing links" do + before do + @stat.stubs(:ftype).returns("link") + File.expects(:readlink).with("/my/file").returns("/path/to/link") + @metadata.collect_attributes + end + + it "should read links instead of returning their checksums" do + @metadata.destination.should == "/path/to/link" + end + + it "should produce tab-separated mode, type, owner, group, and destination for xmlrpc" do + @metadata.attributes_with_tabs.should == "#{0755.to_s}\tlink\t10\t20\t/path/to/link" + end end end -describe Puppet::FileServing::Metadata, " when pointing to a symlink" do - it "should store the destination of the symlink in :destination if links are :manage" do +describe Puppet::FileServing::Metadata, " when pointing to a link" do + it "should store the destination of the link in :destination if links are :manage" do file = Puppet::FileServing::Metadata.new("mykey", :links => :manage, :path => "/base/path/my/file") - File.expects(:lstat).with("/base/path/my/file").returns stub("stat", :uid => 1, :gid => 2, :ftype => "symlink", :mode => 0755) + File.expects(:lstat).with("/base/path/my/file").returns stub("stat", :uid => 1, :gid => 2, :ftype => "link", :mode => 0755) File.expects(:readlink).with("/base/path/my/file").returns "/some/other/path" file.collect_attributes @@ -115,7 +152,7 @@ describe Puppet::FileServing::Metadata, " when pointing to a symlink" do it "should not collect the checksum" do file = Puppet::FileServing::Metadata.new("my/file", :links => :manage, :path => "/base/path/my/file") - File.expects(:lstat).with("/base/path/my/file").returns stub("stat", :uid => 1, :gid => 2, :ftype => "symlink", :mode => 0755) + File.expects(:lstat).with("/base/path/my/file").returns stub("stat", :uid => 1, :gid => 2, :ftype => "link", :mode => 0755) File.expects(:readlink).with("/base/path/my/file").returns "/some/other/path" file.collect_attributes diff --git a/spec/unit/node/catalog.rb b/spec/unit/node/catalog.rb index ecbd20487..b1bf5abaa 100755 --- a/spec/unit/node/catalog.rb +++ b/spec/unit/node/catalog.rb @@ -460,6 +460,12 @@ describe Puppet::Node::Catalog, " when functioning as a resource container" do proc { @catalog.alias @one, "one" }.should_not raise_error end + it "should be able to look resources up by their aliases" do + @catalog.add_resource @one + @catalog.alias @one, "two" + @catalog.resource(:me, "two").should equal(@one) + end + it "should remove resource aliases when the target resource is removed" do @catalog.add_resource @one @catalog.alias(@one, "other") @@ -468,12 +474,21 @@ describe Puppet::Node::Catalog, " when functioning as a resource container" do @catalog.resource("me", "other").should be_nil end - it "should add an alias for the namevar when the title and name differ" do - @one.stubs(:name).returns "other" + it "should add an alias for the namevar when the title and name differ on isomorphic resource types" do resource = Puppet::Type.type(:file).create :path => "/something", :title => "other", :content => "blah" @catalog.add_resource(resource) @catalog.resource(:file, "other").should equal(resource) - @catalog.resource(:file, "/something").should equal(resource) + @catalog.resource(:file, "/something").ref.should == resource.ref + end + + it "should not add an alias for the namevar when the title and name differ on non-isomorphic resource types" do + resource = Puppet::Type.type(:exec).create :command => "/bin/true", :title => "other" + @catalog.add_resource(resource) + @catalog.resource(:exec, resource.title).should equal(resource) + # We can't use .should here, because the resources respond to that method. + if @catalog.resource(:exec, resource.name) + raise "Aliased non-isomorphic resource" + end end after do @@ -601,6 +616,7 @@ end describe Puppet::Node::Catalog, " when creating a relationship graph" do before do + Puppet::Type.type(:component) @catalog = Puppet::Node::Catalog.new("host") @compone = Puppet::Type::Component.create :name => "one" @comptwo = Puppet::Type::Component.create :name => "two", :require => ["class", "one"] diff --git a/spec/unit/other/pgraph.rb b/spec/unit/other/pgraph.rb index 7d66ae331..10ab934a6 100755 --- a/spec/unit/other/pgraph.rb +++ b/spec/unit/other/pgraph.rb @@ -5,6 +5,7 @@ require File.dirname(__FILE__) + '/../../spec_helper' +require 'puppet/pgraph' require 'puppet/util/graph' class Container diff --git a/spec/unit/other/transaction.rb b/spec/unit/other/transaction.rb index d88f03005..e277a24c0 100755 --- a/spec/unit/other/transaction.rb +++ b/spec/unit/other/transaction.rb @@ -2,6 +2,8 @@ require File.dirname(__FILE__) + '/../../spec_helper' +require 'puppet/transaction' + describe Puppet::Transaction, " when determining tags" do before do @config = Puppet::Node::Catalog.new diff --git a/spec/unit/ral/types/file.rb b/spec/unit/ral/types/file.rb index 62fe2f677..b213987bb 100755 --- a/spec/unit/ral/types/file.rb +++ b/spec/unit/ral/types/file.rb @@ -56,6 +56,43 @@ describe Puppet::Type::File do end end + describe "when managing links" do + require 'puppettest/support/assertions' + include PuppetTest + + before do + @basedir = tempfile() + Dir.mkdir(@basedir) + @file = File.join(@basedir, "file") + @link = File.join(@basedir, "link") + + File.open(@file, "w", 0644) { |f| f.puts "yayness"; f.flush } + File.symlink(@file, @link) + + @resource = Puppet.type(:file).create( + :path => @link, + :mode => "755" + ) + end + + after do + teardown + end + + it "should default to managing the link" do + assert_events([], @resource) + # I convert them to strings so they display correctly if there's an error. + ("%o" % (File.stat(@file).mode & 007777)).should == "%o" % 0644 + end + + it "should be able to follow links" do + @resource[:links] = :follow + assert_events([:file_changed], @resource) + + ("%o" % (File.stat(@file).mode & 007777)).should == "%o" % 0755 + end + end + after do Puppet::Type::File.clear end diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb index 902831e68..e276bdf0f 100755 --- a/test/lib/puppettest.rb +++ b/test/lib/puppettest.rb @@ -36,9 +36,9 @@ class Class def publicize_methods(*methods) saved_private_instance_methods = methods.empty? ? self.private_instance_methods : methods - self.class_eval { public *saved_private_instance_methods } + self.class_eval { public(*saved_private_instance_methods) } yield - self.class_eval { private *saved_private_instance_methods } + self.class_eval { private(*saved_private_instance_methods) } end end @@ -198,7 +198,7 @@ module PuppetTest # If we're running under rake, then disable debugging and such. #if rake? or ! Puppet[:debug] - if defined?($puppet_debug) or ! rake? + #if defined?($puppet_debug) or ! rake? if textmate? Puppet[:color] = false end @@ -210,11 +210,11 @@ module PuppetTest end Puppet::Util::Log.level = :debug #$VERBOSE = 1 - else - Puppet::Util::Log.close - Puppet::Util::Log.newdestination(@logs) - Puppet[:httplog] = tempfile() - end + #else + # Puppet::Util::Log.close + # Puppet::Util::Log.newdestination(@logs) + # Puppet[:httplog] = tempfile() + #end Puppet[:ignoreschedules] = true @@ -267,11 +267,7 @@ module PuppetTest @tmpdir end - def teardown - #@stop = Time.now - #File.open("/tmp/test_times.log", ::File::WRONLY|::File::CREAT|::File::APPEND) { |f| f.puts "%0.4f %s %s" % [@stop - @start, @method_name, self.class] } - @@cleaners.each { |cleaner| cleaner.call() } - + def remove_tmp_files @@tmpfiles.each { |file| unless file =~ /tmp/ puts "Not deleting tmpfile %s" % file @@ -283,6 +279,14 @@ module PuppetTest end } @@tmpfiles.clear + end + + def teardown + #@stop = Time.now + #File.open("/tmp/test_times.log", ::File::WRONLY|::File::CREAT|::File::APPEND) { |f| f.puts "%0.4f %s %s" % [@stop - @start, @method_name, self.class] } + @@cleaners.each { |cleaner| cleaner.call() } + + remove_tmp_files @@tmppids.each { |pid| %x{kill -INT #{pid} 2>/dev/null} diff --git a/test/network/handler/fileserver.rb b/test/network/handler/fileserver.rb index 233e705c6..a705dbf4b 100755 --- a/test/network/handler/fileserver.rb +++ b/test/network/handler/fileserver.rb @@ -109,13 +109,13 @@ class TestFileServer < Test::Unit::TestCase # and verify different iterations of 'root' return the same value list = nil assert_nothing_raised { - list = server.list("/test/", :ignore, true, false) + list = server.list("/test/", :manage, true, false) } assert(list =~ pattern) assert_nothing_raised { - list = server.list("/test", :ignore, true, false) + list = server.list("/test", :manage, true, false) } assert(list =~ pattern) @@ -143,7 +143,7 @@ class TestFileServer < Test::Unit::TestCase list = nil sfile = "/test/tmpfile" assert_nothing_raised { - list = server.list(sfile, :ignore, true, false) + list = server.list(sfile, :manage, true, false) } assert_nothing_raised { @@ -200,7 +200,7 @@ class TestFileServer < Test::Unit::TestCase list = nil sfile = "/test/" assert_nothing_raised { - list = server.list(sfile, :ignore, true, false) + list = server.list(sfile, :manage, true, false) } # create the new file @@ -210,7 +210,7 @@ class TestFileServer < Test::Unit::TestCase newlist = nil assert_nothing_raised { - newlist = server.list(sfile, :ignore, true, false) + newlist = server.list(sfile, :manage, true, false) } # verify the list has changed @@ -239,12 +239,12 @@ class TestFileServer < Test::Unit::TestCase list = nil assert_nothing_raised { - list = server.list("/root/" + testdir, :ignore, true, false) + list = server.list("/root/" + testdir, :manage, true, false) } assert(list =~ pattern) assert_nothing_raised { - list = server.list("/root" + testdir, :ignore, true, false) + list = server.list("/root" + testdir, :manage, true, false) } assert(list =~ pattern) @@ -279,7 +279,7 @@ class TestFileServer < Test::Unit::TestCase # get our list list = nil assert_nothing_raised { - list = server.list("/test/with", :ignore, false, false) + list = server.list("/test/with", :manage, false, false) } # make sure we only got one line, since we're not recursing @@ -288,7 +288,7 @@ class TestFileServer < Test::Unit::TestCase # for each level of recursion, make sure we get the right list [0, 1, 2].each { |num| assert_nothing_raised { - list = server.list("/test/with", :ignore, num, false) + list = server.list("/test/with", :manage, num, false) } count = 0 @@ -332,13 +332,13 @@ class TestFileServer < Test::Unit::TestCase list = nil # and then check a few dirs assert_nothing_raised { - list = server.list("/localhost/with", :ignore, false, false) + list = server.list("/localhost/with", :manage, false, false) } assert(list !~ /with/) assert_nothing_raised { - list = server.list("/localhost/with/some/sub", :ignore, true, false) + list = server.list("/localhost/with/some/sub", :manage, true, false) } assert(list !~ /sub/) @@ -370,7 +370,7 @@ class TestFileServer < Test::Unit::TestCase list = nil assert_nothing_raised { - list = server.list("/localhost/", :ignore, 1, false) + list = server.list("/localhost/", :manage, 1, false) } assert_instance_of(String, list, "Server returned %s instead of string") list = list.split("\n") @@ -402,7 +402,7 @@ class TestFileServer < Test::Unit::TestCase list = nil sfile = "/test/" assert_nothing_raised { - list = server.list(sfile, :ignore, true, false) + list = server.list(sfile, :manage, true, false) } # and describe each file in the list @@ -492,7 +492,7 @@ class TestFileServer < Test::Unit::TestCase mounts.each { |mount, files| mount = "/#{mount}/" assert_nothing_raised { - list = server.list(mount, :ignore, true, false) + list = server.list(mount, :manage, true, false) } assert_nothing_raised { @@ -544,12 +544,12 @@ class TestFileServer < Test::Unit::TestCase assert_raise(Puppet::AuthorizationError, "Host %s, ip %s, allowed %s" % [host, ip, mount]) { - list = server.list(mount, :ignore, true, false, host, ip) + list = server.list(mount, :manage, true, false, host, ip) } when :allow: assert_nothing_raised("Host %s, ip %s, denied %s" % [host, ip, mount]) { - list = server.list(mount, :ignore, true, false, host, ip) + list = server.list(mount, :manage, true, false, host, ip) } end } @@ -602,7 +602,7 @@ class TestFileServer < Test::Unit::TestCase assert_raise(Puppet::Network::Handler::FileServerError, "Invalid mount was mounted") { - server.list(mount, :ignore) + server.list(mount, :manage) } } @@ -654,13 +654,13 @@ class TestFileServer < Test::Unit::TestCase list = nil assert_nothing_raised { - list = server.list("/thing/", :ignore, false, false, + list = server.list("/thing/", :manage, false, false, "test1.domain.com", "127.0.0.1") } assert(list != "", "List returned nothing in rereard test") assert_raise(Puppet::AuthorizationError, "List allowed invalid host") { - list = server.list("/thing/", :ignore, false, false, + list = server.list("/thing/", :manage, false, false, "test2.domain.com", "127.0.0.1") } @@ -675,12 +675,12 @@ class TestFileServer < Test::Unit::TestCase } assert_raise(Puppet::AuthorizationError, "List allowed invalid host") { - list = server.list("/thing/", :ignore, false, false, + list = server.list("/thing/", :manage, false, false, "test1.domain.com", "127.0.0.1") } assert_nothing_raised { - list = server.list("/thing/", :ignore, false, false, + list = server.list("/thing/", :manage, false, false, "test2.domain.com", "127.0.0.1") } @@ -735,7 +735,7 @@ class TestFileServer < Test::Unit::TestCase # Then not results = {} assert_nothing_raised { - server.describe("/mount/link", :ignore).split("\t").zip( + server.describe("/mount/link", :manage).split("\t").zip( Puppet::Network::Handler.fileserver::CHECKPARAMS ).each { |v,p| results[p] = v } } @@ -801,28 +801,28 @@ allow * list = nil sfile = "/host/file.txt" assert_nothing_raised { - list = server.list(sfile, :ignore, true, false, client1, ip) + list = server.list(sfile, :manage, true, false, client1, ip) } assert_equal("/\tfile", list) assert_nothing_raised { - list = server.list(sfile, :ignore, true, false, client2, ip) + list = server.list(sfile, :manage, true, false, client2, ip) } assert_equal("", list) sfile = "/fqdn/file.txt" assert_nothing_raised { - list = server.list(sfile, :ignore, true, false, client1, ip) + list = server.list(sfile, :manage, true, false, client1, ip) } assert_equal("", list) assert_nothing_raised { - list = server.list(sfile, :ignore, true, false, client2, ip) + list = server.list(sfile, :manage, true, false, client2, ip) } assert_equal("/\tfile", list) # check describe sfile = "/host/file.txt" assert_nothing_raised { - list = server.describe(sfile, :ignore, client1, ip).split("\t") + list = server.describe(sfile, :manage, client1, ip).split("\t") } assert_equal(5, list.size) assert_equal("file", list[1]) @@ -830,18 +830,18 @@ allow * assert_equal("{md5}#{md5}", list[4]) assert_nothing_raised { - list = server.describe(sfile, :ignore, client2, ip).split("\t") + list = server.describe(sfile, :manage, client2, ip).split("\t") } assert_equal([], list) sfile = "/fqdn/file.txt" assert_nothing_raised { - list = server.describe(sfile, :ignore, client1, ip).split("\t") + list = server.describe(sfile, :manage, client1, ip).split("\t") } assert_equal([], list) assert_nothing_raised { - list = server.describe(sfile, :ignore, client2, ip).split("\t") + list = server.describe(sfile, :manage, client2, ip).split("\t") } assert_equal(5, list.size) assert_equal("file", list[1]) @@ -851,23 +851,23 @@ allow * # Check retrieve sfile = "/host/file.txt" assert_nothing_raised { - list = server.retrieve(sfile, :ignore, client1, ip).chomp + list = server.retrieve(sfile, :manage, client1, ip).chomp } assert_equal(contents[client1_hostdir].chomp, list) assert_nothing_raised { - list = server.retrieve(sfile, :ignore, client2, ip).chomp + list = server.retrieve(sfile, :manage, client2, ip).chomp } assert_equal("", list) sfile = "/fqdn/file.txt" assert_nothing_raised { - list = server.retrieve(sfile, :ignore, client1, ip).chomp + list = server.retrieve(sfile, :manage, client1, ip).chomp } assert_equal("", list) assert_nothing_raised { - list = server.retrieve(sfile, :ignore, client2, ip).chomp + list = server.retrieve(sfile, :manage, client2, ip).chomp } assert_equal(contents[client2_fqdndir].chomp, list) end @@ -945,12 +945,14 @@ allow * # Now, check that they use Facter info Puppet.notice "The following messages are normal" client = nil - local = Facter["hostname"].value - domain = Facter["domain"].value - fqdn = [local, domain].join(".") - {"%h" => local, # Short name - "%H" => fqdn, # Full name - "%d" => domain, # domain + Facter.stubs(:value).with(:ipaddress).returns("127.0.0.1") + Facter.stubs(:value).with { |v| v.to_s == "hostname" }.returns("myhost") + Facter.stubs(:value).with { |v| v.to_s == "domain" }.returns("mydomain.com") + Facter.stubs(:value).with(:domain).returns("mydomain.com") + + {"%h" => "myhost", # Short name + "%H" => "myhost.mydomain.com", # Full name + "%d" => "mydomain.com", # domain "%%" => "%", # escape "%o" => "%o" # other }.each do |pat, repl| @@ -993,18 +995,18 @@ allow * ret = nil assert_nothing_raised do - ret = server.list("/name", :ignore, false, false, host, ip) + ret = server.list("/name", :manage, false, false, host, ip) end assert_equal("/\tfile", ret) assert_nothing_raised do - ret = server.describe("/name", :ignore, host, ip) + ret = server.describe("/name", :manage, host, ip) end - assert(ret =~ /\tfile\t/, "Did not get valid a description") + assert(ret =~ /\tfile\t/, "Did not get valid a description (#{ret.inspect})") assert_nothing_raised do - ret = server.retrieve("/name", :ignore, host, ip) + ret = server.retrieve("/name", :manage, host, ip) end assert_equal(ret, File.read(file)) @@ -1050,7 +1052,7 @@ allow * mount = "/#{mod.name}/" list = nil assert_nothing_raised { - list = server.list(mount, :ignore, true, false) + list = server.list(mount, :manage, true, false) } list = list.split("\n") if mod.name == "green" @@ -1063,7 +1065,7 @@ allow * end assert_nothing_raised("Host 'allow' denied #{mount}") { - server.list(mount, :ignore, true, false, + server.list(mount, :manage, true, false, 'allow.example.com', "192.168.0.1") } end @@ -1106,7 +1108,7 @@ allow * list = nil mount = "/#{mod.name}/" assert_nothing_raised { - list = server.list(mount, :ignore, true, false) + list = server.list(mount, :manage, true, false) } assert_nothing_raised { @@ -1121,11 +1123,11 @@ allow * # now let's check that things are being correctly forbidden assert_raise(Puppet::AuthorizationError, "Host 'deny' allowed #{mount}") { - server.list(mount, :ignore, true, false, + server.list(mount, :manage, true, false, 'deny.example.com', "192.168.1.1") } assert_nothing_raised("Host 'allow' denied #{mount}") { - server.list(mount, :ignore, true, false, + server.list(mount, :manage, true, false, 'allow.example.com', "192.168.0.1") } end diff --git a/test/network/server/webrick.rb b/test/network/server/webrick.rb index d3408c166..fe6d69ade 100755 --- a/test/network/server/webrick.rb +++ b/test/network/server/webrick.rb @@ -95,7 +95,7 @@ class TestWebrickServer < Test::Unit::TestCase # the client starts its connection immediately, thus throwing # the error. assert_raise(OpenSSL::SSL::SSLError) { - client = Puppet::Network::Client.status.new(:Server => "localhost", :Port => @@port) + Puppet::Network::HttpPool.http_instance("localhost", @@port).start } end diff --git a/test/other/dsl.rb b/test/other/dsl.rb index b4dd0659b..45b51982d 100755 --- a/test/other/dsl.rb +++ b/test/other/dsl.rb @@ -12,7 +12,7 @@ class TestDSL < Test::Unit::TestCase def teardown super - Puppet::Aspect.clear + Puppet::DSL::Aspect.clear end def test_aspect @@ -22,7 +22,7 @@ class TestDSL < Test::Unit::TestCase end end - assert_equal(a, Puppet::Aspect[:yaytest]) + assert_equal(a, Puppet::DSL::Aspect[:yaytest]) # Now make a child aspect b = nil @@ -154,8 +154,7 @@ class TestDSL < Test::Unit::TestCase resource = nil assert_nothing_raised do - resource = a.newresource filetype, path, - :content => "yay", :mode => "640" + resource = a.newresource filetype, path, :content => "yay", :mode => "640" end assert_instance_of(Puppet::Parser::Resource, resource) diff --git a/test/other/transactions.rb b/test/other/transactions.rb index 105698da1..ce2d0d52b 100755 --- a/test/other/transactions.rb +++ b/test/other/transactions.rb @@ -6,10 +6,12 @@ require 'puppet' require 'puppettest' require 'mocha' require 'puppettest/support/resources' +require 'puppettest/support/utils' class TestTransactions < Test::Unit::TestCase include PuppetTest::FileTesting include PuppetTest::Support::Resources + include PuppetTest::Support::Utils class Fakeprop <Puppet::Property attr_accessor :path, :is, :should, :name def should_to_s(value) diff --git a/test/rails/ast.rb b/test/rails/ast.rb index e51fa6cf7..1deaec0f4 100755 --- a/test/rails/ast.rb +++ b/test/rails/ast.rb @@ -44,12 +44,12 @@ class TestRailsAST < PuppetTest::TestCase # And if it is, make sure we throw an error. if bad assert_raise(Puppet::ParseError, "Evaluated '#{string}'") do - str, code = query.evaluate :scope => @scope + str, code = query.evaluate @scope end next else assert_nothing_raised("Could not evaluate '#{string}'") do - str, code = query.evaluate :scope => @scope + str, code = query.evaluate @scope end end assert_nothing_raised("Could not find resource") do diff --git a/test/rails/configuration.rb b/test/rails/configuration.rb index 9e2ddfedd..a878d1381 100755 --- a/test/rails/configuration.rb +++ b/test/rails/configuration.rb @@ -24,7 +24,7 @@ class ConfigurationRailsTests < PuppetTest::TestCase # We need to make sure finished objects are stored in the db. def test_finish_before_store railsinit - compile = mkcompile + compile = mkcompiler parser = compile.parser node = parser.newnode [compile.node.name], :code => AST::ASTArray.new(:children => [ diff --git a/test/ral/manager/type.rb b/test/ral/manager/type.rb index 6c5587ddd..324550acb 100755 --- a/test/ral/manager/type.rb +++ b/test/ral/manager/type.rb @@ -574,8 +574,8 @@ class TestType < Test::Unit::TestCase assert_equal(greater, type.defaultprovider) end - # Make sure that we can have multiple isomorphic objects with the same name, - # but not with non-isomorphic objects. + # Make sure that we can have multiple non-isomorphic objects with the same name, + # but not with isomorphic objects. def test_isomorphic_names # First do execs, since they're not isomorphic. echo = Puppet::Util.binary "echo" diff --git a/test/ral/providers/cron/crontab.rb b/test/ral/providers/cron/crontab.rb index 2da4b1b57..1ff1e34ef 100755 --- a/test/ral/providers/cron/crontab.rb +++ b/test/ral/providers/cron/crontab.rb @@ -344,7 +344,9 @@ class TestCronParsedProvider < Test::Unit::TestCase end end - # Make sure we can create a cron in an empty tab + # Make sure we can create a cron in an empty tab. + # LAK:FIXME This actually modifies the user's crontab, + # which is pretty heinous. def test_mkcron_if_empty setme @provider.filetype = @oldfiletype diff --git a/test/ral/types/file.rb b/test/ral/types/file.rb index c7872ccea..cbbe818ae 100755 --- a/test/ral/types/file.rb +++ b/test/ral/types/file.rb @@ -177,7 +177,7 @@ class TestFile < Test::Unit::TestCase assert_equal(inituser, File.stat(file).uid) obj.delete(:owner) - obj[:links] = :ignore + obj[:links] = :follow # And then test 'group' group = nonrootgroup @@ -1041,66 +1041,6 @@ class TestFile < Test::Unit::TestCase "directory mode is incorrect") end - def test_followlinks - File.umask(0022) - - basedir = tempfile() - Dir.mkdir(basedir) - file = File.join(basedir, "file") - link = File.join(basedir, "link") - - File.open(file, "w", 0644) { |f| f.puts "yayness"; f.flush } - File.symlink(file, link) - - obj = nil - assert_nothing_raised { - obj = Puppet.type(:file).create( - :path => link, - :mode => "755" - ) - } - obj.retrieve - - assert_events([], obj) - - # Assert that we default to not following links - assert_equal("%o" % 0644, "%o" % (File.stat(file).mode & 007777)) - - # Assert that we can manage the link directly, but modes still don't change - obj[:links] = :manage - assert_events([], obj) - - assert_equal("%o" % 0644, "%o" % (File.stat(file).mode & 007777)) - - obj[:links] = :follow - assert_events([:file_changed], obj) - - assert_equal("%o" % 0755, "%o" % (File.stat(file).mode & 007777)) - - # Now verify that content and checksum don't update, either - obj.delete(:mode) - obj[:checksum] = "md5" - obj[:links] = :ignore - - assert_events([], obj) - File.open(file, "w") { |f| f.puts "more text" } - assert_events([], obj) - obj[:links] = :follow - assert_events([], obj) - File.open(file, "w") { |f| f.puts "even more text" } - assert_events([:file_changed], obj) - - obj.delete(:checksum) - obj[:content] = "this is some content" - obj[:links] = :ignore - - assert_events([], obj) - File.open(file, "w") { |f| f.puts "more text" } - assert_events([], obj) - obj[:links] = :follow - assert_events([:file_changed, :file_changed], obj) - end - # If both 'ensure' and 'content' are used, make sure that all of the other # properties are handled correctly. def test_contentwithmode @@ -1383,8 +1323,7 @@ class TestFile < Test::Unit::TestCase File.symlink(dir, link) File.open(file, "w") { |f| f.puts "" } assert_equal(dir, File.readlink(link)) - obj = Puppet::Type.newfile :path => link, :ensure => :link, - :target => file, :recurse => false, :backup => "main" + obj = Puppet::Type.newfile :path => link, :ensure => :link, :target => file, :recurse => false, :backup => "main" assert_apply(obj) diff --git a/test/ral/types/filesources.rb b/test/ral/types/filesources.rb index 02bf8a5b3..a7bb6fefa 100755 --- a/test/ral/types/filesources.rb +++ b/test/ral/types/filesources.rb @@ -84,8 +84,7 @@ class TestFileSources < Test::Unit::TestCase source = tempfile() dest = tempfile() - file = Puppet::Type.newfile :path => dest, :source => source, - :title => "copier" + file = Puppet::Type.newfile :path => dest, :source => source, :title => "copier" property = file.property(:source) @@ -124,17 +123,10 @@ class TestFileSources < Test::Unit::TestCase File.open(target, "w") { |f| f.puts "yay" } File.symlink(target, source) - file[:links] = :ignore - assert_nil(property.describe(source), - "Links were not ignored") - file[:links] = :manage - # We can't manage links at this point - assert_raise(Puppet::Network::Handler::FileServerError) do - property.describe(source) - end + assert_equal("link", property.describe(source)[:type]) - # And then make sure links get followed, otherwise + # And then make sure links get followed file[:links] = :follow assert_equal("file", property.describe(source)[:type]) end @@ -753,29 +745,18 @@ class TestFileSources < Test::Unit::TestCase assert_nothing_raised { file = Puppet.type(:file).create( :name => dest, - :source => link + :source => link, + :links => :follow ) } - # Default to skipping links - assert_events([], file) - assert(! FileTest.exists?(dest), "Created link") - - # Now follow the links - file[:links] = :follow assert_events([:file_created], file) assert(FileTest.file?(dest), "Destination is not a file") # Now copy the links - #assert_raise(Puppet::Network::Handler::FileServerError) { - trans = nil - assert_nothing_raised { - file[:links] = :manage - comp = mk_catalog(file) - trans = comp.apply - } - - assert(trans.failed?(file), "Object did not fail to copy links") + file[:links] = :manage + assert_events([:link_created], file) + assert(FileTest.symlink?(dest), "Destination is not a link") end def test_changes |