diff options
33 files changed, 335 insertions, 190 deletions
diff --git a/lib/puppet/client.rb b/lib/puppet/client.rb index 679db2c51..cbb7dbedc 100644 --- a/lib/puppet/client.rb +++ b/lib/puppet/client.rb @@ -245,6 +245,7 @@ module Puppet end end + # FIXME this should be in getconfig, not apply container = @objects.to_type #if @local # container = @objects.to_type diff --git a/lib/puppet/parser/ast.rb b/lib/puppet/parser/ast.rb index 1918f60e9..a4fcb301a 100644 --- a/lib/puppet/parser/ast.rb +++ b/lib/puppet/parser/ast.rb @@ -646,7 +646,7 @@ module Puppet # should we implicitly iterate here? # yes, i believe that we essentially have to... objnames.collect { |objname| - if object.is_a?(Component) + if object.is_a?(AST::Component) objname = "%s[%s]" % [objtype,objname] objtype = "component" end @@ -990,7 +990,7 @@ module Puppet begin scope.settype(name, - Component.new( + AST::Component.new( :name => name, :args => args, :code => @code diff --git a/lib/puppet/server/fileserver.rb b/lib/puppet/server/fileserver.rb index 04449c025..a666b4c7a 100755 --- a/lib/puppet/server/fileserver.rb +++ b/lib/puppet/server/fileserver.rb @@ -27,7 +27,7 @@ class Server obj = nil unless obj = Puppet::Type::PFile[dir] - obj = Puppet::Type::PFile.new( + obj = Puppet::Type::PFile.create( :name => dir, :check => CHECKPARAMS ) diff --git a/lib/puppet/sslcertificates.rb b/lib/puppet/sslcertificates.rb index da6853a8c..bc3382ab6 100755 --- a/lib/puppet/sslcertificates.rb +++ b/lib/puppet/sslcertificates.rb @@ -14,7 +14,7 @@ module SSLCertificates def self.mkdir(dir) # this is all a bunch of stupid hackery unless FileTest.exists?(dir) - comp = Puppet::Type::Component.new( + comp = Puppet::Type::Component.create( :name => "certdir creation" ) path = [''] @@ -26,7 +26,7 @@ module SSLCertificates raise "%s exists but is not a directory" % File.join(path) end else - obj = Puppet::Type.type(:file).new( + obj = Puppet::Type.type(:file).create( :name => File.join(path), :mode => "750", :create => "directory" diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb index 046522ca2..57e5f8377 100644 --- a/lib/puppet/transportable.rb +++ b/lib/puppet/transportable.rb @@ -53,7 +53,7 @@ module Puppet retobj = nil if type = Puppet::Type.type(self.type) begin - retobj = type.new(self) + retobj = type.create(self) rescue => detail # FIXME TransObject should be handling what happens when there's an error if Puppet[:debug] @@ -123,7 +123,7 @@ module Puppet else Puppet.debug "%s has no parameters" % @name end - container = Puppet::Type::Component.new(hash) + container = Puppet::Type::Component.create(hash) nametable = {} self.each { |child| diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 27f5c95b4..39050ca55 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -681,6 +681,32 @@ class Type < Puppet::Element public #--------------------------------------------------------------- + # force users to call this, so that we can merge objects if + # necessary + def self.create(hash) + if name = self["name"] || self[:name] + # if the object already exists + if retobj = self[name] + retobj.merge(self) + + return retobj + else + return new(hash) + end + else + return new(hash) + #raise Puppet::Error, "You must specify a name for objects of type %s" % + # self.to_s + end + end + #--------------------------------------------------------------- + + # and then make 'new' private + class << self + private :new + end + + #--------------------------------------------------------------- # initialize the type instance def initialize(hash) @children = [] @@ -769,6 +795,31 @@ class Type < Puppet::Element #--------------------------------------------------------------- #--------------------------------------------------------------- + # merge new information with an existing object, checking for conflicts + # and such + def merge(hash) + hash.each { |param, value| + if param.is_a?(String) + hash[param.intern] = value + hash.delete(param) + end + } + + hash.each { |param, value| + # FIXME we should really allow equal values, but for now, don't allow + # any values + + if oldval = self[param] + if self.parent.class == self.class # they're a result of recursion + end + unless oldval == value + end + end + } + end + #--------------------------------------------------------------- + + #--------------------------------------------------------------- # derive the instance name based on class.namevar def name unless defined? @name and @name diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb index 8694fcd07..7e0ae9fc4 100755 --- a/lib/puppet/type/cron.rb +++ b/lib/puppet/type/cron.rb @@ -8,51 +8,73 @@ require 'puppet/type/state' module Puppet module CronType module Default - def self.fields - return [:minute, :hour, :weekday, :monthday, :command] + def self.read(user) + %x{crontab -u #{user} -l} end - def self.retrieve(user) - %x{crontab -u #{user} -l 2>/dev/null}.split("\n").each { |line| - hash = {} - ary = line.split(" ") - fields().each { |param| - hash[param] = ary.shift - } - - if ary.length > 0 - hash[:command] += " " + ary.join(" ") - end - cron = nil - unless cron = Puppet::Type::Cron[hash[:command]] - cron = Puppet::Type::Cron.new - end - - hash.each { |param, value| - cron.is = [param, value] - } + def self.write(user, text) + IO.popen("crontab -u #{user} -") { |p| + p.print text } end + end - def self.sync(user) + module SunOS + def self.read(user) + %x{crontab -l #{user}} + end + + def self.write(user, text) + # FIXME this should use our user object, since it already does + # this for us + require 'etc' + + begin + obj = Etc.getpwnam(user) + rescue ArgumentError + raise Puppet::Error, "User %s not found" + end + + uid = obj.uid + + olduid = nil + if Process.uid == uid + olduid = Process.uid + Process.euid = uid + end + + IO.popen("crontab -") { |p| + p.print text + } + + if olduid + Process.euid = olduid + end end end end class State class CronCommand < Puppet::State + @name = :command @doc = "The command to execute in the cron job. The environment provided to the command varies by local system rules, and it is best to always provide a fully qualified command. The user's profile is not sourced when the command is run, so if the user's environment is desired it should be sourced manually." - @name = :command def retrieve # nothing... end def sync + @parent.store + + if @is == :notfound + return :cron_created + else + return :cron_changed + end end end end @@ -65,28 +87,30 @@ module Puppet @parameters = [ :name, - :command, :user, :minute, :hour, :weekday, + :month, :monthday ] @paramdoc[:name] = "The symbolic name of the cron job. This name - is used for human reference only and is optional." - @paramdoc[:user] = "The user to run the command as. This user - must be allowed to run cron jobs, which is not currently checked - by Puppet." + is used for human reference only." + @paramdoc[:user] = "The user to run the command as. This user must + be allowed to run cron jobs, which is not currently checked by + Puppet." @paramdoc[:minute] = "The minute at which to run the cron job. Optional; if specified, must be between 0 and 59, inclusive." @paramdoc[:hour] = "The hour at which to run the cron job. Optional; if specified, must be between 0 and 23, inclusive." @paramdoc[:weekday] = "The weekday on which to run the command. Optional; if specified, must be between 0 and 6, inclusive, with - 0 being Sunday." + 0 being Sunday, or must be the name of the day (e.g., Tuesday)." + @paramdoc[:month] = "The month of the year. Optional; if specified + must be between 1 and 12 or the month name (e.g., December)." @paramdoc[:monthday] = "The day of the month on which to run the - command. Optional; if specified, must be between 0 and 31." + command. Optional; if specified, must be between 1 and 31." @doc = "Installs cron jobs. All fields except the command and the user are optional, although specifying no periodic @@ -99,12 +123,76 @@ module Puppet @synced = {} + @instances = {} + case Facter["operatingsystem"].value - when "Stub": - # nothing + when "SunOS": + @crontype = Puppet::CronType::SunOS else - Puppet.err "including default" - include Puppet::CronType::Default + @crontype = Puppet::CronType::Default + end + + # FIXME so the fundamental problem is, what if the object + # already exists? + + def self.fields + return [:minute, :hour, :monthday, :month, :weekday, :command] + end + + def self.instance(obj) + @instances << obj + end + + def self.retrieve(user) + Puppet.err "Retrieving" + crons = [] + hash = {} + #%x{crontab -u #{user} -l 2>/dev/null}.split("\n").each { |line| + @crontype.read(user).split("\n").each { |line| + case line + when /^# Puppet Name: (\w+)$/: hash[:name] = $1 + when /^#/: # add other comments to the list as they are + crons << line + else + ary = line.split(" ") + fields().each { |param| + hash[param] = ary.shift + } + + if ary.length > 0 + hash[:command] += " " + ary.join(" ") + end + cron = nil + unless hash.include?(:name) + Puppet.info "Autogenerating name for %s" % hash[:command] + hash[:name] = "cron-%s" % hash.object_id + end + + unless cron = Puppet::Type::Cron[hash[:command]] + cron = Puppet::Type::Cron.create + end + + hash.each { |param, value| + cron.is = [param, value] + } + crons << cron + hash.clear + end + } + + @instances[user] = crons + @loaded[user] = Time.now + end + + def self.store(user) + if @instances.include?(user) + @crontype.write(user, + @instances[user].join("\n") + ) + @synced[user] = Time.now + else + Puppet.notice "No cron instances for %s" % user + end end def self.loaded?(user) @@ -116,9 +204,29 @@ module Puppet end def self.sync(user) + Puppet.err ary.length + str = ary.collect { |obj| + Puppet.err obj.name + self.to_cron(obj) + }.join("\n") + + puts str + end + + def self.to_cron(obj) + hash = {:command => obj.should(:command)} + self.fields().reject { |f| f == :command }.each { |param| + hash[param] = obj[param] || "*" + } + + self.fields.collect { |f| + hash[f] + }.join(" ") end def initialize(hash) + self.class.instance(self) + super end def is=(ary) @@ -127,20 +235,27 @@ module Puppet param = param.intern end unless @states.include?(param) - if stateklass = self.class.validstate?(name) - begin - @states[param] = stateklass.new( - :parent => self - ) - rescue => detail - end - else - raise Puppet::Error, "Invalid parameter %s" % [name] - end - + self.newstate(param) end @states[param].is = value end + + def paramuser=(user) + @parameters[:user] = user + end + + def retrieve + unless @parameters.include?(:user) + raise Puppet::Error, "You must specify the cron user" + end + + # look for the existing instance... + # and then set @is = :notfound + end + + def store + self.class.store(@parameters[:user]) + end end end end diff --git a/lib/puppet/type/package.rb b/lib/puppet/type/package.rb index 7155db3f1..a04346201 100644 --- a/lib/puppet/type/package.rb +++ b/lib/puppet/type/package.rb @@ -515,7 +515,7 @@ module Puppet } return object else # just create it - obj = self.new(:name => name) + obj = self.create(:name => name) hash.each { |var,value| obj.addis(var,value) } diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb index df22c59b2..f8f897017 100644 --- a/lib/puppet/type/pfile.rb +++ b/lib/puppet/type/pfile.rb @@ -1102,7 +1102,7 @@ module Puppet else # create it anew #notice "Creating new file with args %s" % args.inspect begin - child = klass.new(args) + child = klass.create(args) child.parent = self @children << child rescue Puppet::Error => detail diff --git a/lib/puppet/type/symlink.rb b/lib/puppet/type/symlink.rb index 0dcbc244a..050904297 100755 --- a/lib/puppet/type/symlink.rb +++ b/lib/puppet/type/symlink.rb @@ -167,7 +167,7 @@ module Puppet :source => @target } - dir = Puppet::Type::PFile.new(args) + dir = Puppet::Type::PFile.create(args) dir.parent = self Puppet.debug "Got dir %s" % dir.name self.push dir diff --git a/test/other/tc_events.rb b/test/other/tc_events.rb index b09436b55..5f3ddcd67 100755 --- a/test/other/tc_events.rb +++ b/test/other/tc_events.rb @@ -17,11 +17,11 @@ class TestEvents < TestPuppet end def test_simplesubscribe - file = Puppet::Type::PFile.new( + file = Puppet::Type::PFile.create( :name => "/tmp/eventtestingA", :create => true ) - exec = Puppet::Type::Exec.new( + exec = Puppet::Type::Exec.create( :name => "echo true", :path => "/usr/bin:/bin", :refreshonly => true, @@ -30,7 +30,7 @@ class TestEvents < TestPuppet @@tmpfiles << "/tmp/eventtestingA" - comp = Puppet::Type::Component.new( + comp = Puppet::Type::Component.create( :name => "eventtesting" ) comp.push exec @@ -46,11 +46,11 @@ class TestEvents < TestPuppet end def test_simplerequire - file = Puppet::Type::PFile.new( + file = Puppet::Type::PFile.create( :name => "/tmp/eventtestingA", :create => true ) - exec = Puppet::Type::Exec.new( + exec = Puppet::Type::Exec.create( :name => "echo true", :path => "/usr/bin:/bin", :refreshonly => true, @@ -59,7 +59,7 @@ class TestEvents < TestPuppet @@tmpfiles << "/tmp/eventtestingA" - comp = Puppet::Type::Component.new( + comp = Puppet::Type::Component.create( :name => "eventtesting" ) comp.push exec @@ -82,13 +82,13 @@ class TestEvents < TestPuppet case l when :a name = "/tmp/eventtesting%s" % l - objects[l] = Puppet::Type::PFile.new( + objects[l] = Puppet::Type::PFile.create( :name => name, :create => true ) @@tmpfiles << name when :b - objects[l] = Puppet::Type::Exec.new( + objects[l] = Puppet::Type::Exec.create( :name => "touch %s" % fname, :path => "/usr/bin:/bin", :refreshonly => true @@ -97,7 +97,7 @@ class TestEvents < TestPuppet end - comps[l] = Puppet::Type::Component.new( + comps[l] = Puppet::Type::Component.create( :name => "eventtesting%s" % l ) diff --git a/test/other/tc_relationships.rb b/test/other/tc_relationships.rb index 9b3270cfe..44960b569 100755 --- a/test/other/tc_relationships.rb +++ b/test/other/tc_relationships.rb @@ -32,7 +32,7 @@ class TestRelationships < Test::Unit::TestCase assert_nothing_raised() { cfile = File.join($puppetbase,"examples/root/etc/configfile") unless Puppet::Type::PFile.has_key?(cfile) - Puppet::Type::PFile.new( + Puppet::Type::PFile.create( :path => cfile, :check => [:mode, :owner, :group] ) @@ -44,7 +44,7 @@ class TestRelationships < Test::Unit::TestCase def newservice assert_nothing_raised() { unless Puppet::Type::Service.has_key?("sleeper") - Puppet::Type::Service.new( + Puppet::Type::Service.create( :name => "sleeper", :path => File.join($puppetbase,"examples/root/etc/init.d"), :check => [:running] diff --git a/test/other/tc_state.rb b/test/other/tc_state.rb index 9b2b4c575..6bbe76277 100644 --- a/test/other/tc_state.rb +++ b/test/other/tc_state.rb @@ -68,7 +68,7 @@ class TestStorage < TestPuppet file = nil state = nil assert_nothing_raised { - file = Puppet::Type::PFile.new( + file = Puppet::Type::PFile.create( :path => "/etc/passwd" ) } diff --git a/test/other/tc_transactions.rb b/test/other/tc_transactions.rb index 9a8523883..946d53279 100644 --- a/test/other/tc_transactions.rb +++ b/test/other/tc_transactions.rb @@ -65,13 +65,13 @@ class TestTransactions < FileTesting @@tmpfiles.push tmpfile hash[:name] = tmpfile assert_nothing_raised() { - return Puppet::Type::PFile.new(hash) + return Puppet::Type::PFile.create(hash) } end def newservice assert_nothing_raised() { - return Puppet::Type::Service.new( + return Puppet::Type::Service.create( :name => "sleeper", :path => File.join($puppetbase,"examples/root/etc/init.d"), :check => [:running] @@ -81,7 +81,7 @@ class TestTransactions < FileTesting def newexec(file) assert_nothing_raised() { - return Puppet::Type::Exec.new( + return Puppet::Type::Exec.create( :name => "touch %s" % file, :path => "/bin:/usr/bin:/sbin:/usr/sbin", :returns => 0 diff --git a/test/puppettest.rb b/test/puppettest.rb index fe00ee2ce..23d940d08 100644 --- a/test/puppettest.rb +++ b/test/puppettest.rb @@ -8,7 +8,7 @@ end class TestPuppet < Test::Unit::TestCase def newcomp(name,*ary) - comp = Puppet::Type::Component.new( + comp = Puppet::Type::Component.create( :name => name ) ary.each { |item| comp.push item } diff --git a/test/server/tc_server.rb b/test/server/tc_server.rb index 988a1e17a..b0afc6398 100644 --- a/test/server/tc_server.rb +++ b/test/server/tc_server.rb @@ -27,50 +27,6 @@ class TestServer < ServerTest print "\n\n\n\n" if Puppet[:debug] end - # just do a simple start test - def test_start - Puppet[:autosign] = true - server = nil - # make a test manifest - file = mktestmanifest() - - # create a simple server - # we can use threading here because we're not talking to the server, - # just starting and stopping it - assert_nothing_raised() { - server = Puppet::Server.new( - :Port => @@port, - :Handlers => { - :CA => {}, # so that certs autogenerate - :Master => { - :File => file, - }, - :Status => nil - } - ) - - } - - # start it - sthread = nil - assert_nothing_raised() { - trap(:INT) { server.shutdown } - sthread = Thread.new { - server.start - } - } - - # and stop it - assert_nothing_raised { - server.shutdown - } - - # and then wait - assert_nothing_raised { - sthread.join - } - end - # test that we can connect to the server # we have to use fork here, because we apparently can't use threads # to talk to other threads diff --git a/test/types/tc_basic.rb b/test/types/tc_basic.rb index 6910485ae..585caaa95 100644 --- a/test/types/tc_basic.rb +++ b/test/types/tc_basic.rb @@ -21,7 +21,7 @@ class TestBasic < Test::Unit::TestCase Puppet[:loglevel] = :debug if __FILE__ == $0 assert_nothing_raised() { - @component = Puppet::Type::Component.new( + @component = Puppet::Type::Component.create( :name => "yaytest", :type => "testing" ) @@ -30,14 +30,14 @@ class TestBasic < Test::Unit::TestCase assert_nothing_raised() { @filepath = "/tmp/testfile" system("rm -f %s" % @filepath) - @configfile = Puppet::Type::PFile.new( + @configfile = Puppet::Type::PFile.create( :path => @filepath, :create => true, :checksum => "md5" ) } assert_nothing_raised() { - @sleeper = Puppet::Type::Service.new( + @sleeper = Puppet::Type::Service.create( :name => "sleeper", :path => File.join($puppetbase,"examples/root/etc/init.d"), :running => 1 diff --git a/test/types/tc_component.rb b/test/types/tc_component.rb index 5fcee859c..8cf3ece4b 100755 --- a/test/types/tc_component.rb +++ b/test/types/tc_component.rb @@ -48,7 +48,7 @@ class TestComponent < TestPuppet end name = "/tmp/componentrandfile" + num.to_s - file = Puppet::Type::PFile.new( + file = Puppet::Type::PFile.create( :path => name, :checksum => "md5" ) @@ -57,7 +57,7 @@ class TestComponent < TestPuppet end def mkcomp - Puppet::Type::Component.new(:name => "component_" + randnum(1000).to_s) + Puppet::Type::Component.create(:name => "component_" + randnum(1000).to_s) end def mkrandcomp(numfiles, numdivs) @@ -120,12 +120,12 @@ class TestComponent < TestPuppet File.open(tmpfile, File::WRONLY|File::CREAT|File::TRUNC) { |of| of.puts rand(100) } - file = Puppet::Type::PFile.new( + file = Puppet::Type::PFile.create( :path => tmpfile, :checksum => "md5" ) assert_nothing_raised { - cmd = Puppet::Type::Exec.new( + cmd = Puppet::Type::Exec.create( :command => "pwd", :path => "/usr/bin:/bin:/usr/sbin:/sbin", :subscribe => [[file.class.name,file.name]], @@ -151,12 +151,12 @@ class TestComponent < TestPuppet File.open(tmpfile, File::WRONLY|File::CREAT|File::TRUNC) { |of| of.puts rand(100) } - file = Puppet::Type::PFile.new( + file = Puppet::Type::PFile.create( :path => tmpfile, :checksum => "md5" ) assert_nothing_raised { - cmd = Puppet::Type::Exec.new( + cmd = Puppet::Type::Exec.create( :command => "pwd", :path => "/usr/bin:/bin:/usr/sbin:/sbin", :subscribe => [[file.class.name,file.name]], @@ -164,7 +164,7 @@ class TestComponent < TestPuppet ) } - comp = Puppet::Type::Component.new(:name => "RefreshTest") + comp = Puppet::Type::Component.create(:name => "RefreshTest") [cmd, file].each { |obj| comp.push obj } @@ -189,12 +189,12 @@ class TestComponent < TestPuppet File.open(tmpfile, File::WRONLY|File::CREAT|File::TRUNC) { |of| of.puts rand(100) } - file = Puppet::Type::PFile.new( + file = Puppet::Type::PFile.create( :path => tmpfile, :checksum => "md5" ) assert_nothing_raised { - cmd = Puppet::Type::Exec.new( + cmd = Puppet::Type::Exec.create( :command => "pwd", :path => "/usr/bin:/bin:/usr/sbin:/sbin", :refreshonly => true @@ -230,12 +230,12 @@ class TestComponent < TestPuppet File.open(tmpfile, File::WRONLY|File::CREAT|File::TRUNC) { |of| of.puts rand(100) } - file = Puppet::Type::PFile.new( + file = Puppet::Type::PFile.create( :path => tmpfile, :checksum => "md5" ) assert_nothing_raised { - cmd = Puppet::Type::Exec.new( + cmd = Puppet::Type::Exec.create( :command => "pwd", :path => "/usr/bin:/bin:/usr/sbin:/sbin", :refreshonly => true @@ -244,7 +244,7 @@ class TestComponent < TestPuppet ocmd = nil assert_nothing_raised { - ocmd = Puppet::Type::Exec.new( + ocmd = Puppet::Type::Exec.create( :command => "echo true", :path => "/usr/bin:/bin:/usr/sbin:/sbin", :refreshonly => true diff --git a/test/types/tc_cron.rb b/test/types/tc_cron.rb index 6c6218a83..d35d873f3 100755 --- a/test/types/tc_cron.rb +++ b/test/types/tc_cron.rb @@ -14,8 +14,15 @@ require 'facter' class TestExec < TestPuppet def setup - @me = %x{whoami}.chomp - assert(@me != "", "Could not retrieve user name") + id = %x{id}.chomp + if id =~ /uid=\d+\(([^\)]+)\)/ + @me = $1 + else + puts id + end + unless defined? @me + raise "Could not retrieve user name; 'id' did not work" + end super end @@ -24,4 +31,19 @@ class TestExec < TestPuppet Puppet::Type::Cron.retrieve(@me) } end + + def test_mkcron + cron = nil + assert_nothing_raised { + cron = Puppet::Type::Cron.create( + :command => "date > %s/crontest" % tmpdir(), + :name => "testcron", + :user => @me + ) + } + + comp = newcomp("crontest", cron) + + trans = assert_events(comp, [:cron_created], "crontest") + end end diff --git a/test/types/tc_exec.rb b/test/types/tc_exec.rb index f2a8775b8..7e1f5f161 100755 --- a/test/types/tc_exec.rb +++ b/test/types/tc_exec.rb @@ -16,7 +16,7 @@ class TestExec < TestPuppet command = nil output = nil assert_nothing_raised { - command = Puppet::Type::Exec.new( + command = Puppet::Type::Exec.create( :command => "/bin/echo" ) } @@ -33,7 +33,7 @@ class TestExec < TestPuppet command = nil output = nil assert_nothing_raised { - command = Puppet::Type::Exec.new( + command = Puppet::Type::Exec.create( :command => "/bin/echo", :returns => 0 ) @@ -46,7 +46,7 @@ class TestExec < TestPuppet } Puppet::Type::Exec.clear assert_nothing_raised { - command = Puppet::Type::Exec.new( + command = Puppet::Type::Exec.create( :command => "/bin/echo", :returns => "0" ) @@ -63,26 +63,26 @@ class TestExec < TestPuppet command = nil output = nil assert_raise(TypeError) { - command = Puppet::Type::Exec.new( + command = Puppet::Type::Exec.create( :command => "echo" ) } Puppet::Type::Exec.clear assert_nothing_raised { - command = Puppet::Type::Exec.new( + command = Puppet::Type::Exec.create( :command => "echo", :path => "/usr/bin:/bin:/usr/sbin:/sbin" ) } Puppet::Type::Exec.clear assert_nothing_raised { - command = Puppet::Type::Exec.new( + command = Puppet::Type::Exec.create( :command => "/bin/echo" ) } Puppet::Type::Exec.clear assert_nothing_raised { - command = Puppet::Type::Exec.new( + command = Puppet::Type::Exec.create( :command => "/bin/echo", :path => "/usr/bin:/bin:/usr/sbin:/sbin" ) @@ -91,21 +91,21 @@ class TestExec < TestPuppet def test_nonzero_returns assert_nothing_raised { - command = Puppet::Type::Exec.new( + command = Puppet::Type::Exec.create( :command => "mkdir /this/directory/does/not/exist", :path => "/usr/bin:/bin:/usr/sbin:/sbin", :returns => 1 ) } assert_nothing_raised { - command = Puppet::Type::Exec.new( + command = Puppet::Type::Exec.create( :command => "touch /etc", :path => "/usr/bin:/bin:/usr/sbin:/sbin", :returns => 1 ) } assert_nothing_raised { - command = Puppet::Type::Exec.new( + command = Puppet::Type::Exec.create( :command => "thiscommanddoesnotexist", :path => "/usr/bin:/bin:/usr/sbin:/sbin", :returns => 127 @@ -120,7 +120,7 @@ class TestExec < TestPuppet Dir.getwd } assert_nothing_raised { - command = Puppet::Type::Exec.new( + command = Puppet::Type::Exec.create( :command => "pwd", :cwd => dir, :path => "/usr/bin:/bin:/usr/sbin:/sbin", @@ -145,12 +145,12 @@ class TestExec < TestPuppet File.open(tmpfile, File::WRONLY|File::CREAT|File::TRUNC) { |of| of.puts rand(100) } - file = Puppet::Type::PFile.new( + file = Puppet::Type::PFile.create( :path => tmpfile, :checksum => "md5" ) assert_nothing_raised { - cmd = Puppet::Type::Exec.new( + cmd = Puppet::Type::Exec.create( :command => "pwd", :path => "/usr/bin:/bin:/usr/sbin:/sbin", :subscribe => [[file.class.name,file.name]], @@ -158,7 +158,7 @@ class TestExec < TestPuppet ) } - comp = Puppet::Type::Component.new(:name => "RefreshTest") + comp = Puppet::Type::Component.create(:name => "RefreshTest") [file,cmd].each { |obj| comp.push obj } @@ -197,7 +197,7 @@ class TestExec < TestPuppet file = tempfile() exec = nil assert_nothing_raised { - exec = Puppet::Type::Exec.new( + exec = Puppet::Type::Exec.create( :command => "touch %s" % file, :path => "/usr/bin:/bin:/usr/sbin:/sbin", :creates => file diff --git a/test/types/tc_file.rb b/test/types/tc_file.rb index 303865f3f..169b32995 100644 --- a/test/types/tc_file.rb +++ b/test/types/tc_file.rb @@ -19,7 +19,7 @@ class TestFile < FileTesting def mkfile(hash) file = nil assert_nothing_raised { - file = Puppet::Type::PFile.new(hash) + file = Puppet::Type::PFile.create(hash) } return file end @@ -173,7 +173,7 @@ class TestFile < FileTesting %w{a b c d}.collect { |name| "/tmp/createst%s" % name }.each { |path| file =nil assert_nothing_raised() { - file = Puppet::Type::PFile.new( + file = Puppet::Type::PFile.create( :name => path, :create => true ) @@ -197,7 +197,7 @@ class TestFile < FileTesting %w{a b c d}.collect { |name| "/tmp/createst%s" % name }.each { |path| file = nil assert_nothing_raised() { - file = Puppet::Type::PFile.new( + file = Puppet::Type::PFile.create( :name => path, :create => "directory" ) @@ -264,13 +264,13 @@ class TestFile < FileTesting events = nil # okay, we now know that we have a file... assert_nothing_raised() { - file = Puppet::Type::PFile.new( + file = Puppet::Type::PFile.create( :name => path, :create => true, :checksum => type ) } - comp = Puppet::Type::Component.new( + comp = Puppet::Type::Component.create( :name => "componentfile" ) comp.push file @@ -304,12 +304,12 @@ class TestFile < FileTesting # now recreate the file assert_nothing_raised() { - file = Puppet::Type::PFile.new( + file = Puppet::Type::PFile.create( :name => path, :checksum => type ) } - comp = Puppet::Type::Component.new( + comp = Puppet::Type::Component.create( :name => "componentfile" ) comp.push file @@ -345,13 +345,13 @@ class TestFile < FileTesting initstorage assert_nothing_raised { - file = Puppet::Type::PFile.new( + file = Puppet::Type::PFile.create( param => path, :recurse => true, :checksum => "md5" ) } - comp = Puppet::Type::Component.new( + comp = Puppet::Type::Component.create( :name => "component" ) comp.push file @@ -424,7 +424,7 @@ class TestFile < FileTesting Puppet.err tmpdir() assert_nothing_raised { - file = Puppet::Type::PFile.new( + file = Puppet::Type::PFile.create( :name => tmpdir(), :check => :type ) @@ -437,7 +437,7 @@ class TestFile < FileTesting assert_equal("directory", file.state(:type).is) assert_nothing_raised { - file = Puppet::Type::PFile.new( + file = Puppet::Type::PFile.create( :name => "/etc/passwd", :check => :type ) diff --git a/test/types/tc_filebucket.rb b/test/types/tc_filebucket.rb index 48cb9fd17..6c57c8dab 100755 --- a/test/types/tc_filebucket.rb +++ b/test/types/tc_filebucket.rb @@ -18,7 +18,7 @@ class TestFileBucket < FileTesting def mkfile(hash) file = nil assert_nothing_raised { - file = Puppet::Type::PFile.new(hash) + file = Puppet::Type::PFile.create(hash) } return file end @@ -26,7 +26,7 @@ class TestFileBucket < FileTesting def mkbucket(name,path) bucket = nil assert_nothing_raised { - bucket = Puppet::Type::PFileBucket.new( + bucket = Puppet::Type::PFileBucket.create( :name => name, :path => path ) diff --git a/test/types/tc_fileignoresource.rb b/test/types/tc_fileignoresource.rb index 72d4ddb2b..2029b763f 100644 --- a/test/types/tc_fileignoresource.rb +++ b/test/types/tc_fileignoresource.rb @@ -74,7 +74,7 @@ class TestFileIgnoreSources < FileTesting #makes Puppet file Object assert_nothing_raised { - tofile = Puppet::Type::PFile.new( + tofile = Puppet::Type::PFile.create( :name => topath, :source => frompath, :recurse => true, @@ -83,7 +83,7 @@ class TestFileIgnoreSources < FileTesting } #make a component and adds the file - comp = Puppet::Type::Component.new( + comp = Puppet::Type::Component.create( :name => "component" ) comp.push tofile @@ -154,7 +154,7 @@ class TestFileIgnoreSources < FileTesting #makes Puppet file Object assert_nothing_raised { - tofile = Puppet::Type::PFile.new( + tofile = Puppet::Type::PFile.create( :name => topath, :source => frompath, :recurse => true, @@ -163,7 +163,7 @@ class TestFileIgnoreSources < FileTesting } #make a component and adds the file - comp = Puppet::Type::Component.new( + comp = Puppet::Type::Component.create( :name => "component" ) comp.push tofile diff --git a/test/types/tc_filesources.rb b/test/types/tc_filesources.rb index 1045cfc09..c4a35682c 100755 --- a/test/types/tc_filesources.rb +++ b/test/types/tc_filesources.rb @@ -19,7 +19,7 @@ class TestFileSources < FileTesting def mkfile(hash) file = nil assert_nothing_raised { - file = Puppet::Type::PFile.new(hash) + file = Puppet::Type::PFile.create(hash) } return file end @@ -69,7 +69,7 @@ class TestFileSources < FileTesting comp = nil trans = nil assert_nothing_raised { - file = Puppet::Type::PFile.new( + file = Puppet::Type::PFile.create( :name => path ) } @@ -101,12 +101,12 @@ class TestFileSources < FileTesting of.puts "yayness" } assert_nothing_raised { - tofile = Puppet::Type::PFile.new( + tofile = Puppet::Type::PFile.create( :name => topath, :source => frompath ) } - comp = Puppet::Type::Component.new( + comp = Puppet::Type::Component.create( :name => "component" ) comp.push tofile @@ -133,14 +133,14 @@ class TestFileSources < FileTesting trans = nil assert_nothing_raised { - tofile = Puppet::Type::PFile.new( + tofile = Puppet::Type::PFile.create( :name => todir, "recurse" => true, "backup" => false, "source" => fromdir ) } - comp = Puppet::Type::Component.new( + comp = Puppet::Type::Component.create( :name => "component" ) comp.push tofile @@ -260,7 +260,7 @@ class TestFileSources < FileTesting File.open(file1, "w") { |f| 3.times { f.print rand(100) } } rootobj = nil assert_nothing_raised { - rootobj = Puppet::Type::PFile.new( + rootobj = Puppet::Type::PFile.create( :name => basedir, :recurse => true, :check => %w{type owner} diff --git a/test/types/tc_filetype.rb b/test/types/tc_filetype.rb index 521a4bbb5..c6749ba3d 100644 --- a/test/types/tc_filetype.rb +++ b/test/types/tc_filetype.rb @@ -19,7 +19,7 @@ class TestFileType @passwdtype = Puppet::Type::FileType["passwd"] if @passwdtype.nil? assert_nothing_raised() { - @passwdtype = Puppet::Type::FileType.newtype( + @passwdtype = Puppet::Type::FileType.createtype( :name => "passwd" ) @passwdtype.addrecord( @@ -33,7 +33,7 @@ class TestFileType @syslogtype = Puppet::Type::FileType["syslog"] if @syslogtype.nil? assert_nothing_raised() { - @syslogtype = Puppet::Type::FileType.newtype( + @syslogtype = Puppet::Type::FileType.createtype( :escapednewlines => true, :name => "syslog" ) diff --git a/test/types/tc_group.rb b/test/types/tc_group.rb index a53c49bfb..afbd91cc1 100755 --- a/test/types/tc_group.rb +++ b/test/types/tc_group.rb @@ -171,7 +171,7 @@ class TestGroup < TestPuppet gobj = nil comp = nil assert_nothing_raised { - gobj = Puppet::Type::Group.new( + gobj = Puppet::Type::Group.create( :name => group, :check => [:gid] ) @@ -210,7 +210,7 @@ class TestGroup < TestPuppet assert(missing?(name), "Group %s is still present" % name) assert_nothing_raised { - gobj = Puppet::Type::Group.new( + gobj = Puppet::Type::Group.create( :name => name ) diff --git a/test/types/tc_package.rb b/test/types/tc_package.rb index d4c3f2b12..2437b64f9 100644 --- a/test/types/tc_package.rb +++ b/test/types/tc_package.rb @@ -49,7 +49,7 @@ class TestPackages < FileTesting def mkpkgcomp(pkg) assert_nothing_raised { - pkg = Puppet::Type::Package.new(:name => pkg, :install => true) + pkg = Puppet::Type::Package.create(:name => pkg, :install => true) } assert_nothing_raised { pkg.retrieve @@ -104,7 +104,7 @@ class TestPackages < FileTesting obj = nil assert_nothing_raised { - obj = Puppet::Type::Package.new( + obj = Puppet::Type::Package.create( :name => pkg ) } @@ -139,7 +139,7 @@ class TestPackages < FileTesting pkgs.each { |pkg| assert_nothing_raised { - pkg = Puppet::Type::Package.new(:name => pkg, :install => true) + pkg = Puppet::Type::Package.create(:name => pkg, :install => true) } assert_nothing_raised { pkg.retrieve diff --git a/test/types/tc_query.rb b/test/types/tc_query.rb index 52d641e4c..5ba0e0c64 100644 --- a/test/types/tc_query.rb +++ b/test/types/tc_query.rb @@ -27,7 +27,7 @@ class TestQuery < Test::Unit::TestCase assert_nothing_raised() { cfile = File.join($puppetbase,"examples/root/etc/configfile") unless Puppet::Type::PFile.has_key?(cfile) - Puppet::Type::PFile.new( + Puppet::Type::PFile.create( :path => cfile, :check => [:mode, :owner, :checksum] ) @@ -40,7 +40,7 @@ class TestQuery < Test::Unit::TestCase def service assert_nothing_raised() { unless Puppet::Type::Service.has_key?("sleeper") - Puppet::Type::Service.new( + Puppet::Type::Service.create( :name => "sleeper", :path => File.join($puppetbase,"examples/root/etc/init.d"), :check => [:running] @@ -54,7 +54,7 @@ class TestQuery < Test::Unit::TestCase def component(name,*args) assert_nothing_raised() { - @component = Puppet::Type::Component.new(:name => name) + @component = Puppet::Type::Component.create(:name => name) } args.each { |arg| diff --git a/test/types/tc_service.rb b/test/types/tc_service.rb index 4bbc37594..a1633aec7 100644 --- a/test/types/tc_service.rb +++ b/test/types/tc_service.rb @@ -21,7 +21,7 @@ class TestService < Test::Unit::TestCase Puppet[:loglevel] = :debug if __FILE__ == $0 assert_nothing_raised() { unless Puppet::Type::Service.has_key?("sleeper") - Puppet::Type::Service.new( + Puppet::Type::Service.create( :name => "sleeper", :path => File.join($puppetbase,"examples/root/etc/init.d"), :running => 1 @@ -79,7 +79,7 @@ class TestService < Test::Unit::TestCase def testFailOnNoPath assert_raise(Puppet::Error) { - Puppet::Type::Service.new( + Puppet::Type::Service.create( :name => "sleeper" ) } diff --git a/test/types/tc_symlink.rb b/test/types/tc_symlink.rb index e11c595c3..9c09d2505 100755 --- a/test/types/tc_symlink.rb +++ b/test/types/tc_symlink.rb @@ -40,7 +40,7 @@ class TestSymlink < FileTesting unless hash.include?(:target) hash[:target] = mktmpfile() end - link = Puppet::Type::Symlink.new(hash) + link = Puppet::Type::Symlink.create(hash) return link end diff --git a/test/types/tc_tidy.rb b/test/types/tc_tidy.rb index f41972307..676d866dc 100755 --- a/test/types/tc_tidy.rb +++ b/test/types/tc_tidy.rb @@ -36,7 +36,7 @@ class TestTidy < FileTesting f.puts rand(100) } - tidy = Puppet::Type::Tidy.new( + tidy = Puppet::Type::Tidy.create( :name => dir, :size => "1b", :recurse => true @@ -66,7 +66,7 @@ class TestTidy < FileTesting f.puts rand(100) } - tidy = Puppet::Type::Tidy.new( + tidy = Puppet::Type::Tidy.create( :name => dir, :size => "1b", :age => "1s", diff --git a/test/types/tc_type.rb b/test/types/tc_type.rb index 1cc7669e0..56eb7071b 100644 --- a/test/types/tc_type.rb +++ b/test/types/tc_type.rb @@ -53,7 +53,7 @@ class TestType < TestPuppet path = "/tmp/testfile" assert_nothing_raised() { system("rm -f %s" % path) - file = Puppet::Type::PFile.new( + file = Puppet::Type::PFile.create( :path => path, :create => true, :recurse => true, @@ -69,7 +69,7 @@ class TestType < TestPuppet Puppet::Type::PFile.clear assert_nothing_raised() { system("rm -f %s" % path) - file = Puppet::Type::PFile.new( + file = Puppet::Type::PFile.create( "path" => path, "create" => true, "recurse" => true, @@ -100,7 +100,7 @@ class TestType < TestPuppet # currently groups are the only objects with the namevar as a state group = nil assert_nothing_raised { - group = Puppet::Type::Group.new( + group = Puppet::Type::Group.create( :name => "testing" ) } diff --git a/test/types/tc_user.rb b/test/types/tc_user.rb index a70e55ce6..0e0072b96 100755 --- a/test/types/tc_user.rb +++ b/test/types/tc_user.rb @@ -261,7 +261,7 @@ class TestUser < TestPuppet } assert_nothing_raised { - user = Puppet::Type::User.new( + user = Puppet::Type::User.create( :name => name, :comment => "Puppet Testing User" ) |
