diff --git a/test/lib/exetest.rb b/test/lib/exetest.rb index 8e1568851..6efd93792 100644 --- a/test/lib/exetest.rb +++ b/test/lib/exetest.rb @@ -1,120 +1,120 @@ require 'servertest' module ExeTest include ServerTest def setup super setbindir setlibdir end def bindir File.join($puppetbase, "bin") end def setbindir - unless ENV["PATH"] =~ /puppet/ - ENV["PATH"] += ":" + bindir + unless ENV["PATH"].split(":").include?(bindir) + ENV["PATH"] = [bindir, ENV["PATH"]].join(":") end end def setlibdir ENV["RUBYLIB"] = $:.find_all { |dir| dir =~ /puppet/ or dir =~ /\.\./ }.join(":") end # Run a ruby command. This explicitly uses ruby to run stuff, since we # don't necessarily know where our ruby binary is, dernit. # Currently unused, because I couldn't get it to work. def rundaemon(*cmd) @ruby ||= %x{which ruby}.chomp cmd = cmd.unshift(@ruby).join(" ") out = nil Dir.chdir(bindir()) { out = %x{#{@ruby} #{cmd}} } return out end def startmasterd(args = "") output = nil manifest = mktestmanifest() args += " --manifest %s" % manifest args += " --confdir %s" % Puppet[:confdir] args += " --vardir %s" % Puppet[:vardir] args += " --masterport %s" % @@port args += " --user %s" % Process.uid args += " --group %s" % Process.gid args += " --nonodes" args += " --autosign true" #if Puppet[:debug] # args += " --debug" #end cmd = "puppetmasterd %s" % args assert_nothing_raised { output = %x{#{cmd}}.chomp } assert_equal("", output, "Puppetmasterd produced output %s" % output) assert($? == 0, "Puppetmasterd exit status was %s" % $?) sleep(1) cleanup do stopmasterd sleep(1) end return manifest end def stopmasterd(running = true) ps = Facter["ps"].value || "ps -ef" pidfile = File.join(Puppet[:vardir], "run", "puppetmasterd.pid") pid = nil if FileTest.exists?(pidfile) pid = File.read(pidfile).chomp.to_i File.unlink(pidfile) end return unless running if running or pid runningpid = nil %x{#{ps}}.chomp.split(/\n/).each { |line| if line =~ /ruby.+puppetmasterd/ next if line =~ /\.rb/ # skip the test script itself next if line =~ /^puppet/ # skip masters running as 'puppet' ary = line.sub(/^\s+/, '').split(/\s+/) pid = ary[1].to_i end } end # we default to mandating that it's running, but teardown # doesn't require that if pid if pid == $$ raise Puppet::Error, "Tried to kill own pid" end begin Process.kill(:INT, pid) rescue # ignore it end end end def teardown stopmasterd(false) super end end diff --git a/test/lib/fakes.rb b/test/lib/fakes.rb index d81c1fa5b..2b1d7c913 100644 --- a/test/lib/fakes.rb +++ b/test/lib/fakes.rb @@ -1,99 +1,146 @@ module PuppetTestFakes # A baseclass for the faketypes. - class FakeModel < Hash + class FakeModel class << self attr_accessor :name @name = :fakemodel end def self.validstates Puppet::Type.type(@name).validstates end def self.validstate?(name) Puppet::Type.type(@name).validstate?(name) end + def self.to_s + "Fake%s" % @name.to_s.capitalize + end + + def [](param) + if @realmodel.attrtype(param) == :state + @is[param] + else + @params[param] + end + end + + def []=(param, value) + unless @realmodel.attrtype(param) + raise Puppet::DevError, "Invalid attribute %s for %s" % + [param, @realmodel.name] + end + if @realmodel.attrtype(param) == :state + @should[param] = value + else + @params[param] = value + end + end + def initialize(name) + @realmodel = Puppet::Type.type(self.class.name) + raise "Could not find type #{self.class.name}" unless @realmodel + @is = {} + @should = {} + @params = {} self[:name] = name end def inspect "%s(%s)" % [self.class.to_s.sub(/.+::/, ''), super()] end + def is(param) + @is[param] + end + + def should(param) + @should[param] + end + def name self[:name] end end class FakeProvider attr_accessor :model class << self attr_accessor :name, :model, :methods end # A very low number, so these never show up as defaults via the standard # algorithms. def self.defaultnum -50 end # Set up methods to fake things def self.apimethods(*ary) @model.validstates.each do |state| ary << state unless ary.include? state end attr_accessor(*ary) @methods = ary end + def self.default? + false + end + def self.initvars @calls = Hash.new do |hash, key| hash[key] = 0 end end def self.suitable? true end + def clear + @model = nil + end + def initialize(model) @model = model end end @@fakemodels = {} @@fakeproviders = {} def fakemodel(type, name, options = {}) type = type.intern if type.is_a? String unless @@fakemodels.include? type @@fakemodels[type] = Class.new(FakeModel) @@fakemodels[type].name = type end obj = @@fakemodels[type].new(name) obj[:name] = name options.each do |name, val| obj[name] = val end obj end module_function :fakemodel def fakeprovider(type, model) type = type.intern if type.is_a? String unless @@fakeproviders.include? type @@fakeproviders[type] = Class.new(FakeModel) do @name = type end end @@fakeproviders[type].new(model) end module_function :fakeprovider end + +# $Id$